Dynamically load the default dashboard
Instead of trying to include the default id in the /projects/ output, always redirect to /projects/{project},dashboards/default. This will RPC to the server for the definition of the inherited dashboard, if any exists. If none is found the server will return 404 and the query project:{project} will be used instead. Change-Id: Ibaa9f1fd02b716c9201dd353e757a668ef2b01fb
This commit is contained in:

committed by
Edwin Kempin

parent
5367b8bab5
commit
11b312ae70
@@ -19,7 +19,6 @@ import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Change.Status;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gwt.http.client.URL;
|
||||
import com.google.gwtorm.client.KeyUtil;
|
||||
|
||||
public class PageLinks {
|
||||
@@ -78,9 +77,8 @@ public class PageLinks {
|
||||
return "/q/" + KeyUtil.encode(query) + "," + page;
|
||||
}
|
||||
|
||||
public static String toProjectDashboard(Project.NameKey projectName,
|
||||
String dashboardId) {
|
||||
return PROJECTS + projectName.get() + DASHBOARDS + dashboardId;
|
||||
public static String toProjectDashboard(Project.NameKey name, String id) {
|
||||
return PROJECTS + name.get() + DASHBOARDS + id;
|
||||
}
|
||||
|
||||
public static String projectQuery(Project.NameKey proj) {
|
||||
|
@@ -88,6 +88,7 @@ import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.core.client.RunAsyncCallback;
|
||||
import com.google.gwt.http.client.URL;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwtjsonrpc.client.RemoteJsonException;
|
||||
import com.google.gwtorm.client.KeyUtil;
|
||||
|
||||
public class Dispatcher {
|
||||
@@ -401,12 +402,7 @@ public class Dispatcher {
|
||||
rest = rest.substring(c);
|
||||
if (matchPrefix(DASHBOARDS, rest)) {
|
||||
final String dashboardId = skip(rest);
|
||||
c = dashboardId.indexOf(":");
|
||||
if (0 <= c) {
|
||||
final String ref = URL.decodePathSegment(dashboardId.substring(0, c));
|
||||
final String path = URL.decodePathSegment(dashboardId.substring(c + 1));
|
||||
DashboardList.get(new Project.NameKey(project), ref + ":" + path,
|
||||
new GerritCallback<DashboardInfo>() {
|
||||
GerritCallback<DashboardInfo> cb = new GerritCallback<DashboardInfo>() {
|
||||
@Override
|
||||
public void onSuccess(DashboardInfo result) {
|
||||
if (matchPrefix("/dashboard/", result.url())) {
|
||||
@@ -414,7 +410,28 @@ public class Dispatcher {
|
||||
Gerrit.display(token, new CustomDashboardScreen(rest.substring(1)));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
if ("default".equals(dashboardId)
|
||||
&& caught instanceof RemoteJsonException
|
||||
&& ((RemoteJsonException) caught).getCode() == 404) {
|
||||
Gerrit.display(PageLinks.toChangeQuery(
|
||||
PageLinks.projectQuery(new Project.NameKey(project))));
|
||||
} else {
|
||||
super.onFailure(caught);
|
||||
}
|
||||
}
|
||||
};
|
||||
if ("default".equals(dashboardId)) {
|
||||
DashboardList.getDefault(new Project.NameKey(project), cb);
|
||||
return;
|
||||
}
|
||||
c = dashboardId.indexOf(":");
|
||||
if (0 <= c) {
|
||||
final String ref = URL.decodePathSegment(dashboardId.substring(0, c));
|
||||
final String path = URL.decodePathSegment(dashboardId.substring(c + 1));
|
||||
DashboardList.get(new Project.NameKey(project), ref + ":" + path, cb);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -98,14 +98,8 @@ public class ProjectListScreen extends Screen {
|
||||
|
||||
private Widget createSearchLink(final ProjectInfo projectInfo) {
|
||||
Image image = new Image(Gerrit.RESOURCES.queryProjectLink());
|
||||
InlineHyperlink h;
|
||||
if (projectInfo.defaultDashboard() != null) {
|
||||
h = new InlineHyperlink(" ", PageLinks.toProjectDashboard(
|
||||
projectInfo.name_key(), projectInfo.defaultDashboard()));
|
||||
} else {
|
||||
h = new InlineHyperlink(" ", PageLinks.toChangeQuery(PageLinks
|
||||
.projectQuery(projectInfo.name_key())));
|
||||
}
|
||||
InlineHyperlink h = new InlineHyperlink(" ",
|
||||
PageLinks.toProjectDashboard(projectInfo.name_key(), "default"));
|
||||
h.setTitle(Util.C.projectListQueryLink());
|
||||
DOM.insertBefore(h.getElement(), image.getElement(),
|
||||
DOM.getFirstChild(h.getElement()));
|
||||
|
@@ -29,7 +29,7 @@ public class DashboardList extends NativeList<DashboardInfo> {
|
||||
.get(callback);
|
||||
}
|
||||
|
||||
public static void defaultDashboard(Project.NameKey project,
|
||||
public static void getDefault(Project.NameKey project,
|
||||
AsyncCallback<DashboardInfo> callback) {
|
||||
new RestApi(base(project) + "default")
|
||||
.addParameterTrue("inherited")
|
||||
|
@@ -27,7 +27,6 @@ public class ProjectInfo
|
||||
|
||||
public final native String name() /*-{ return this.name; }-*/;
|
||||
public final native String description() /*-{ return this.description; }-*/;
|
||||
public final native String defaultDashboard() /*-{ return this.default_dashboard; }-*/;
|
||||
|
||||
@Override
|
||||
public final String getDisplayString() {
|
||||
|
@@ -163,7 +163,7 @@ class DashboardsCollection implements
|
||||
return query.replace("${project}", project);
|
||||
}
|
||||
|
||||
public static String defaultOf(Project proj) {
|
||||
private static String defaultOf(Project proj) {
|
||||
final String defaultId = Objects.firstNonNull(
|
||||
proj.getLocalDefaultDashboard(),
|
||||
Strings.nullToEmpty(proj.getDefaultDashboard()));
|
||||
|
@@ -284,8 +284,6 @@ public class ListProjects implements RestReadView<TopLevelResource> {
|
||||
if (showDescription) {
|
||||
info.description = Strings.emptyToNull(e.getProject().getDescription());
|
||||
}
|
||||
info.defaultDashboard =
|
||||
Strings.emptyToNull(DashboardsCollection.defaultOf(e.getProject()));
|
||||
|
||||
try {
|
||||
if (showBranch != null) {
|
||||
@@ -453,7 +451,6 @@ public class ListProjects implements RestReadView<TopLevelResource> {
|
||||
String id;
|
||||
String parent;
|
||||
String description;
|
||||
String defaultDashboard;
|
||||
Map<String, String> branches;
|
||||
|
||||
void setName(String name) {
|
||||
|
Reference in New Issue
Block a user