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:
Shawn O. Pearce
2012-11-18 14:48:43 -08:00
committed by Edwin Kempin
parent 5367b8bab5
commit 11b312ae70
7 changed files with 34 additions and 29 deletions

View File

@@ -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.Change.Status;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;
import com.google.gwt.http.client.URL;
import com.google.gwtorm.client.KeyUtil; import com.google.gwtorm.client.KeyUtil;
public class PageLinks { public class PageLinks {
@@ -78,14 +77,13 @@ public class PageLinks {
return "/q/" + KeyUtil.encode(query) + "," + page; return "/q/" + KeyUtil.encode(query) + "," + page;
} }
public static String toProjectDashboard(Project.NameKey projectName, public static String toProjectDashboard(Project.NameKey name, String id) {
String dashboardId) { return PROJECTS + name.get() + DASHBOARDS + id;
return PROJECTS + projectName.get() + DASHBOARDS + dashboardId;
} }
public static String projectQuery(Project.NameKey proj) { public static String projectQuery(Project.NameKey proj) {
return op("project", proj.get()); return op("project", proj.get());
} }
public static String projectQuery(Project.NameKey proj, Status status) { public static String projectQuery(Project.NameKey proj, Status status) {
return status(status) + " " + op("project", proj.get()); return status(status) + " " + op("project", proj.get());

View File

@@ -88,6 +88,7 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.RunAsyncCallback; import com.google.gwt.core.client.RunAsyncCallback;
import com.google.gwt.http.client.URL; import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
import com.google.gwtjsonrpc.client.RemoteJsonException;
import com.google.gwtorm.client.KeyUtil; import com.google.gwtorm.client.KeyUtil;
public class Dispatcher { public class Dispatcher {
@@ -401,20 +402,36 @@ public class Dispatcher {
rest = rest.substring(c); rest = rest.substring(c);
if (matchPrefix(DASHBOARDS, rest)) { if (matchPrefix(DASHBOARDS, rest)) {
final String dashboardId = skip(rest); final String dashboardId = skip(rest);
GerritCallback<DashboardInfo> cb = new GerritCallback<DashboardInfo>() {
@Override
public void onSuccess(DashboardInfo result) {
if (matchPrefix("/dashboard/", result.url())) {
String rest = skip(result.url());
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(":"); c = dashboardId.indexOf(":");
if (0 <= c) { if (0 <= c) {
final String ref = URL.decodePathSegment(dashboardId.substring(0, c)); final String ref = URL.decodePathSegment(dashboardId.substring(0, c));
final String path = URL.decodePathSegment(dashboardId.substring(c + 1)); final String path = URL.decodePathSegment(dashboardId.substring(c + 1));
DashboardList.get(new Project.NameKey(project), ref + ":" + path, DashboardList.get(new Project.NameKey(project), ref + ":" + path, cb);
new GerritCallback<DashboardInfo>() {
@Override
public void onSuccess(DashboardInfo result) {
if (matchPrefix("/dashboard/", result.url())) {
String rest = skip(result.url());
Gerrit.display(token, new CustomDashboardScreen(rest.substring(1)));
}
}
});
return; return;
} }
} }

View File

@@ -98,14 +98,8 @@ public class ProjectListScreen extends Screen {
private Widget createSearchLink(final ProjectInfo projectInfo) { private Widget createSearchLink(final ProjectInfo projectInfo) {
Image image = new Image(Gerrit.RESOURCES.queryProjectLink()); Image image = new Image(Gerrit.RESOURCES.queryProjectLink());
InlineHyperlink h; InlineHyperlink h = new InlineHyperlink(" ",
if (projectInfo.defaultDashboard() != null) { PageLinks.toProjectDashboard(projectInfo.name_key(), "default"));
h = new InlineHyperlink(" ", PageLinks.toProjectDashboard(
projectInfo.name_key(), projectInfo.defaultDashboard()));
} else {
h = new InlineHyperlink(" ", PageLinks.toChangeQuery(PageLinks
.projectQuery(projectInfo.name_key())));
}
h.setTitle(Util.C.projectListQueryLink()); h.setTitle(Util.C.projectListQueryLink());
DOM.insertBefore(h.getElement(), image.getElement(), DOM.insertBefore(h.getElement(), image.getElement(),
DOM.getFirstChild(h.getElement())); DOM.getFirstChild(h.getElement()));

View File

@@ -29,7 +29,7 @@ public class DashboardList extends NativeList<DashboardInfo> {
.get(callback); .get(callback);
} }
public static void defaultDashboard(Project.NameKey project, public static void getDefault(Project.NameKey project,
AsyncCallback<DashboardInfo> callback) { AsyncCallback<DashboardInfo> callback) {
new RestApi(base(project) + "default") new RestApi(base(project) + "default")
.addParameterTrue("inherited") .addParameterTrue("inherited")

View File

@@ -27,7 +27,6 @@ public class ProjectInfo
public final native String name() /*-{ return this.name; }-*/; public final native String name() /*-{ return this.name; }-*/;
public final native String description() /*-{ return this.description; }-*/; public final native String description() /*-{ return this.description; }-*/;
public final native String defaultDashboard() /*-{ return this.default_dashboard; }-*/;
@Override @Override
public final String getDisplayString() { public final String getDisplayString() {

View File

@@ -163,7 +163,7 @@ class DashboardsCollection implements
return query.replace("${project}", project); return query.replace("${project}", project);
} }
public static String defaultOf(Project proj) { private static String defaultOf(Project proj) {
final String defaultId = Objects.firstNonNull( final String defaultId = Objects.firstNonNull(
proj.getLocalDefaultDashboard(), proj.getLocalDefaultDashboard(),
Strings.nullToEmpty(proj.getDefaultDashboard())); Strings.nullToEmpty(proj.getDefaultDashboard()));

View File

@@ -284,8 +284,6 @@ public class ListProjects implements RestReadView<TopLevelResource> {
if (showDescription) { if (showDescription) {
info.description = Strings.emptyToNull(e.getProject().getDescription()); info.description = Strings.emptyToNull(e.getProject().getDescription());
} }
info.defaultDashboard =
Strings.emptyToNull(DashboardsCollection.defaultOf(e.getProject()));
try { try {
if (showBranch != null) { if (showBranch != null) {
@@ -453,7 +451,6 @@ public class ListProjects implements RestReadView<TopLevelResource> {
String id; String id;
String parent; String parent;
String description; String description;
String defaultDashboard;
Map<String, String> branches; Map<String, String> branches;
void setName(String name) { void setName(String name) {