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,
|
||||
Config config) throws UnsupportedEncodingException {
|
||||
Config config, boolean setDefault) throws UnsupportedEncodingException {
|
||||
DashboardInfo info = new DashboardInfo(refName, path);
|
||||
info.title = config.getString("dashboard", null, "title");
|
||||
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/");
|
||||
u.put("title", Objects.firstNonNull(info.title, info.path));
|
||||
|
||||
@@ -58,7 +58,8 @@ class GetDashboard implements RestReadView<DashboardResource> {
|
||||
resource.getControl().getProject(),
|
||||
resource.getRefName().substring(REFS_DASHBOARDS.length()),
|
||||
resource.getPathName(),
|
||||
resource.getConfig());
|
||||
resource.getConfig(),
|
||||
true);
|
||||
}
|
||||
|
||||
private DashboardResource defaultOf(ProjectControl ctl)
|
||||
|
||||
@@ -63,17 +63,21 @@ class ListDashboards implements RestReadView<ProjectResource> {
|
||||
public Object apply(ProjectResource resource) throws AuthException,
|
||||
BadRequestException, ResourceConflictException, Exception {
|
||||
if (!inherited) {
|
||||
return scan(resource.getControl());
|
||||
return scan(resource.getControl(), true);
|
||||
}
|
||||
|
||||
List<List<DashboardInfo>> all = Lists.newArrayList();
|
||||
ProjectControl ctl = resource.getControl();
|
||||
Set<Project.NameKey> seen = Sets.newHashSet();
|
||||
boolean setDefault = true;
|
||||
for (;;) {
|
||||
if (ctl.isVisible()) {
|
||||
List<DashboardInfo> list = scan(ctl);
|
||||
List<DashboardInfo> list = scan(ctl, setDefault);
|
||||
for (DashboardInfo d : list) {
|
||||
d.project = ctl.getProject().getName();
|
||||
if (d.isDefault != null && Boolean.TRUE.equals(d.isDefault)) {
|
||||
setDefault = false;
|
||||
}
|
||||
}
|
||||
if (!list.isEmpty()) {
|
||||
all.add(list);
|
||||
@@ -95,7 +99,7 @@ class ListDashboards implements RestReadView<ProjectResource> {
|
||||
return all;
|
||||
}
|
||||
|
||||
private List<DashboardInfo> scan(ProjectControl ctl) throws AuthException,
|
||||
private List<DashboardInfo> scan(ProjectControl ctl, boolean setDefault) throws AuthException,
|
||||
BadRequestException, ResourceConflictException, Exception {
|
||||
Repository git;
|
||||
try {
|
||||
@@ -109,7 +113,7 @@ class ListDashboards implements RestReadView<ProjectResource> {
|
||||
List<DashboardInfo> all = Lists.newArrayList();
|
||||
for (Ref ref : git.getRefDatabase().getRefs(REFS_DASHBOARDS).values()) {
|
||||
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;
|
||||
@@ -122,7 +126,7 @@ class ListDashboards implements RestReadView<ProjectResource> {
|
||||
}
|
||||
|
||||
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();
|
||||
TreeWalk tw = new TreeWalk(rw.getObjectReader());
|
||||
try {
|
||||
@@ -135,7 +139,8 @@ class ListDashboards implements RestReadView<ProjectResource> {
|
||||
project,
|
||||
ref.getName().substring(REFS_DASHBOARDS.length()),
|
||||
tw.getPathString(),
|
||||
new BlobBasedConfig(null, git, tw.getObjectId(0))));
|
||||
new BlobBasedConfig(null, git, tw.getObjectId(0)),
|
||||
setDefault));
|
||||
} catch (ConfigInvalidException e) {
|
||||
log.warn(String.format(
|
||||
"Cannot parse dashboard %s:%s:%s: %s",
|
||||
|
||||
Reference in New Issue
Block a user