Rewrite GWT UI to use project name in addition to numeric change ID
This change adapts the GWT UI to recognize a project name in the URL alongside the numeric change ID and integrate it into all REST API calls made on /changes. This is an effort towards having the project in all REST API calls to /changes which will make routing Gerrit requests easier. On top, it doesn't require secondary index lookups for trivial calls like /detail. In contrast to the original proposal, changes will be served at /c/project-name/+/123 instead of /p/project-name/+c/1234. This is to stay more consistent with the REST API which serves all changes at /changes instead of /projects. The only difference between the UI and the API is now that the UI uses '/+/' as a delimiter while the API uses '~'. In addition project names in the API need to be URL encoded. This enables us to use the new change id that includes the project also in a later part of the URL. In the UI, this isn't needed and at the same time we want to maximize the readability of URLs which is done by the two differences noted above. If a user uses a URL without the project (/c/123), we retrieve the project upon the first API call and rewrite the URL. All instances of Project.NameKey and String project are marked @Nullable where they can actually be null. In the API layer they are consistently marked @Nullable to reflect the current status of the backend. That is, a project can optionally be provided. This might be changed to a more strict policy at a later stage. Change-Id: Ie3feee2e3b3e3b91b8d646d0326b7ada6134a0f9
This commit is contained in:
@@ -22,6 +22,8 @@ import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gwtorm.client.KeyUtil;
|
||||
|
||||
public class PageLinks {
|
||||
public static final String PROJECT_CHANGE_DELIMITER = "/+/";
|
||||
|
||||
public static final String SETTINGS = "/settings/";
|
||||
public static final String SETTINGS_PREFERENCES = "/settings/preferences";
|
||||
public static final String SETTINGS_DIFF_PREFERENCES = "/settings/diff-preferences";
|
||||
@@ -51,20 +53,21 @@ public class PageLinks {
|
||||
public static final String MY_GROUPS = "/groups/self";
|
||||
public static final String DOCUMENTATION = "/Documentation/";
|
||||
|
||||
public static String toChangeInEditMode(Change.Id c) {
|
||||
return "/c/" + c + ",edit/";
|
||||
public static String toChangeInEditMode(@Nullable Project.NameKey project, Change.Id c) {
|
||||
return toChangeNoSlash(project, c) + ",edit/";
|
||||
}
|
||||
|
||||
public static String toChange(Change.Id c) {
|
||||
return "/c/" + c + "/";
|
||||
public static String toChange(@Nullable Project.NameKey project, Change.Id c) {
|
||||
return toChangeNoSlash(project, c) + "/";
|
||||
}
|
||||
|
||||
public static String toChange(Change.Id c, String p) {
|
||||
return "/c/" + c + "/" + p;
|
||||
public static String toChange(@Nullable Project.NameKey project, Change.Id c, String p) {
|
||||
return toChange(project, c) + p;
|
||||
}
|
||||
|
||||
public static String toChange(Change.Id c, String b, String p) {
|
||||
String u = "/c/" + c + "/";
|
||||
public static String toChange(
|
||||
@Nullable Project.NameKey project, Change.Id c, String b, String p) {
|
||||
String u = toChange(project, c);
|
||||
if (b != null) {
|
||||
u += b + "..";
|
||||
}
|
||||
@@ -72,8 +75,15 @@ public class PageLinks {
|
||||
return u;
|
||||
}
|
||||
|
||||
public static String toChange(PatchSet.Id ps) {
|
||||
return "/c/" + ps.getParentKey() + "/" + ps.getId();
|
||||
public static String toChangeId(@Nullable Project.NameKey project, Change.Id c) {
|
||||
if (project == null) {
|
||||
return String.valueOf(c.get());
|
||||
}
|
||||
return project.get() + PROJECT_CHANGE_DELIMITER + c.get();
|
||||
}
|
||||
|
||||
public static String toChange(@Nullable Project.NameKey project, PatchSet.Id ps) {
|
||||
return toChange(project, ps.getParentKey()) + ps.getId();
|
||||
}
|
||||
|
||||
public static String toProject(Project.NameKey p) {
|
||||
@@ -166,6 +176,13 @@ public class PageLinks {
|
||||
}
|
||||
}
|
||||
|
||||
private static String toChangeNoSlash(@Nullable Project.NameKey project, Change.Id c) {
|
||||
if (project != null) {
|
||||
return "/c/" + project.get() + PROJECT_CHANGE_DELIMITER + c;
|
||||
}
|
||||
return "/c/" + c;
|
||||
}
|
||||
|
||||
public static String op(String op, int value) {
|
||||
return op + ":" + value;
|
||||
}
|
||||
|
Reference in New Issue
Block a user