Set default flag only for the effective default dashboard
When listing the dashboards for a project only the dashboard which is the effective default of this project should be marked as default. At the moment any dashboard which is the default dashboard for any project in the parent line is marked as default. As result for a project more than one dashboard might be marked as default in the UI. Change-Id: I99dcb7950e93c7038438449043cffb5eb16dcc1b Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
@@ -139,11 +139,11 @@ class DashboardsCollection implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
static DashboardInfo parse(Project project, String refName, String path,
|
static DashboardInfo parse(Project project, String refName, String path,
|
||||||
Config config) throws UnsupportedEncodingException {
|
Config config, boolean setDefault) throws UnsupportedEncodingException {
|
||||||
DashboardInfo info = new DashboardInfo(refName, path);
|
DashboardInfo info = new DashboardInfo(refName, path);
|
||||||
info.title = config.getString("dashboard", null, "title");
|
info.title = config.getString("dashboard", null, "title");
|
||||||
info.description = config.getString("dashboard", null, "description");
|
info.description = config.getString("dashboard", null, "description");
|
||||||
info.isDefault = info.id.equals(defaultOf(project)) ? true : null;
|
info.isDefault = setDefault ? (info.id.equals(defaultOf(project)) ? true : null) : null;
|
||||||
|
|
||||||
UrlEncoded u = new UrlEncoded("/dashboard/");
|
UrlEncoded u = new UrlEncoded("/dashboard/");
|
||||||
u.put("title", Objects.firstNonNull(info.title, info.path));
|
u.put("title", Objects.firstNonNull(info.title, info.path));
|
||||||
|
@@ -58,7 +58,8 @@ class GetDashboard implements RestReadView<DashboardResource> {
|
|||||||
resource.getControl().getProject(),
|
resource.getControl().getProject(),
|
||||||
resource.getRefName().substring(REFS_DASHBOARDS.length()),
|
resource.getRefName().substring(REFS_DASHBOARDS.length()),
|
||||||
resource.getPathName(),
|
resource.getPathName(),
|
||||||
resource.getConfig());
|
resource.getConfig(),
|
||||||
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DashboardResource defaultOf(ProjectControl ctl)
|
private DashboardResource defaultOf(ProjectControl ctl)
|
||||||
|
@@ -63,17 +63,21 @@ class ListDashboards implements RestReadView<ProjectResource> {
|
|||||||
public Object apply(ProjectResource resource) throws AuthException,
|
public Object apply(ProjectResource resource) throws AuthException,
|
||||||
BadRequestException, ResourceConflictException, Exception {
|
BadRequestException, ResourceConflictException, Exception {
|
||||||
if (!inherited) {
|
if (!inherited) {
|
||||||
return scan(resource.getControl());
|
return scan(resource.getControl(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<List<DashboardInfo>> all = Lists.newArrayList();
|
List<List<DashboardInfo>> all = Lists.newArrayList();
|
||||||
ProjectControl ctl = resource.getControl();
|
ProjectControl ctl = resource.getControl();
|
||||||
Set<Project.NameKey> seen = Sets.newHashSet();
|
Set<Project.NameKey> seen = Sets.newHashSet();
|
||||||
|
boolean setDefault = true;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (ctl.isVisible()) {
|
if (ctl.isVisible()) {
|
||||||
List<DashboardInfo> list = scan(ctl);
|
List<DashboardInfo> list = scan(ctl, setDefault);
|
||||||
for (DashboardInfo d : list) {
|
for (DashboardInfo d : list) {
|
||||||
d.project = ctl.getProject().getName();
|
d.project = ctl.getProject().getName();
|
||||||
|
if (d.isDefault != null && Boolean.TRUE.equals(d.isDefault)) {
|
||||||
|
setDefault = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!list.isEmpty()) {
|
if (!list.isEmpty()) {
|
||||||
all.add(list);
|
all.add(list);
|
||||||
@@ -95,7 +99,7 @@ class ListDashboards implements RestReadView<ProjectResource> {
|
|||||||
return all;
|
return all;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<DashboardInfo> scan(ProjectControl ctl) throws AuthException,
|
private List<DashboardInfo> scan(ProjectControl ctl, boolean setDefault) throws AuthException,
|
||||||
BadRequestException, ResourceConflictException, Exception {
|
BadRequestException, ResourceConflictException, Exception {
|
||||||
Repository git;
|
Repository git;
|
||||||
try {
|
try {
|
||||||
@@ -109,7 +113,7 @@ class ListDashboards implements RestReadView<ProjectResource> {
|
|||||||
List<DashboardInfo> all = Lists.newArrayList();
|
List<DashboardInfo> all = Lists.newArrayList();
|
||||||
for (Ref ref : git.getRefDatabase().getRefs(REFS_DASHBOARDS).values()) {
|
for (Ref ref : git.getRefDatabase().getRefs(REFS_DASHBOARDS).values()) {
|
||||||
if (ctl.controlForRef(ref.getName()).canRead()) {
|
if (ctl.controlForRef(ref.getName()).canRead()) {
|
||||||
all.addAll(scanDashboards(ctl.getProject(), git, rw, ref));
|
all.addAll(scanDashboards(ctl.getProject(), git, rw, ref, setDefault));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return all;
|
return all;
|
||||||
@@ -122,7 +126,7 @@ class ListDashboards implements RestReadView<ProjectResource> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<DashboardInfo> scanDashboards(Project project,
|
private List<DashboardInfo> scanDashboards(Project project,
|
||||||
Repository git, RevWalk rw, Ref ref) throws IOException {
|
Repository git, RevWalk rw, Ref ref, boolean setDefault) throws IOException {
|
||||||
List<DashboardInfo> list = Lists.newArrayList();
|
List<DashboardInfo> list = Lists.newArrayList();
|
||||||
TreeWalk tw = new TreeWalk(rw.getObjectReader());
|
TreeWalk tw = new TreeWalk(rw.getObjectReader());
|
||||||
try {
|
try {
|
||||||
@@ -135,7 +139,8 @@ class ListDashboards implements RestReadView<ProjectResource> {
|
|||||||
project,
|
project,
|
||||||
ref.getName().substring(REFS_DASHBOARDS.length()),
|
ref.getName().substring(REFS_DASHBOARDS.length()),
|
||||||
tw.getPathString(),
|
tw.getPathString(),
|
||||||
new BlobBasedConfig(null, git, tw.getObjectId(0))));
|
new BlobBasedConfig(null, git, tw.getObjectId(0)),
|
||||||
|
setDefault));
|
||||||
} catch (ConfigInvalidException e) {
|
} catch (ConfigInvalidException e) {
|
||||||
log.warn(String.format(
|
log.warn(String.format(
|
||||||
"Cannot parse dashboard %s:%s:%s: %s",
|
"Cannot parse dashboard %s:%s:%s: %s",
|
||||||
|
Reference in New Issue
Block a user