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:
		@@ -41,11 +41,13 @@ import com.google.gerrit.client.rpc.RestApi;
 | 
			
		||||
import com.google.gerrit.client.rpc.ScreenLoadCallback;
 | 
			
		||||
import com.google.gerrit.client.ui.InlineHyperlink;
 | 
			
		||||
import com.google.gerrit.client.ui.Screen;
 | 
			
		||||
import com.google.gerrit.common.Nullable;
 | 
			
		||||
import com.google.gerrit.common.PageLinks;
 | 
			
		||||
import com.google.gerrit.extensions.client.KeyMapType;
 | 
			
		||||
import com.google.gerrit.extensions.client.Theme;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.Patch;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.PatchSet;
 | 
			
		||||
import com.google.gerrit.reviewdb.client.Project;
 | 
			
		||||
import com.google.gwt.core.client.GWT;
 | 
			
		||||
import com.google.gwt.core.client.JsArray;
 | 
			
		||||
import com.google.gwt.core.client.Scheduler;
 | 
			
		||||
@@ -99,6 +101,7 @@ public class EditScreen extends Screen {
 | 
			
		||||
    String hideBase();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Nullable private Project.NameKey projectKey;
 | 
			
		||||
  private final PatchSet.Id revision;
 | 
			
		||||
  private final String path;
 | 
			
		||||
  private final int startLine;
 | 
			
		||||
@@ -129,7 +132,8 @@ public class EditScreen extends Screen {
 | 
			
		||||
  private HandlerRegistration closeHandler;
 | 
			
		||||
  private int generation;
 | 
			
		||||
 | 
			
		||||
  public EditScreen(Patch.Key patch, int startLine) {
 | 
			
		||||
  public EditScreen(@Nullable Project.NameKey projectKey, Patch.Key patch, int startLine) {
 | 
			
		||||
    this.projectKey = projectKey;
 | 
			
		||||
    this.revision = patch.getParentKey();
 | 
			
		||||
    this.path = patch.get();
 | 
			
		||||
    this.startLine = startLine - 1;
 | 
			
		||||
@@ -187,11 +191,13 @@ public class EditScreen extends Screen {
 | 
			
		||||
            }));
 | 
			
		||||
 | 
			
		||||
    ChangeApi.detail(
 | 
			
		||||
        Project.NameKey.asStringOrNull(projectKey),
 | 
			
		||||
        revision.getParentKey().get(),
 | 
			
		||||
        group1.add(
 | 
			
		||||
            new AsyncCallback<ChangeInfo>() {
 | 
			
		||||
              @Override
 | 
			
		||||
              public void onSuccess(ChangeInfo c) {
 | 
			
		||||
                projectKey = c.projectNameKey();
 | 
			
		||||
                project.setInnerText(c.project());
 | 
			
		||||
                SafeHtml.setInnerHTML(filePath, Header.formatPath(path));
 | 
			
		||||
              }
 | 
			
		||||
@@ -202,6 +208,7 @@ public class EditScreen extends Screen {
 | 
			
		||||
 | 
			
		||||
    if (revision.get() == 0) {
 | 
			
		||||
      ChangeEditApi.getMeta(
 | 
			
		||||
          Project.NameKey.asStringOrNull(projectKey),
 | 
			
		||||
          revision,
 | 
			
		||||
          path,
 | 
			
		||||
          group1.add(
 | 
			
		||||
@@ -217,6 +224,7 @@ public class EditScreen extends Screen {
 | 
			
		||||
 | 
			
		||||
      if (prefs.showBase()) {
 | 
			
		||||
        ChangeEditApi.get(
 | 
			
		||||
            projectKey,
 | 
			
		||||
            revision,
 | 
			
		||||
            path,
 | 
			
		||||
            true /* base */,
 | 
			
		||||
@@ -237,7 +245,7 @@ public class EditScreen extends Screen {
 | 
			
		||||
    } else {
 | 
			
		||||
      // TODO(davido): We probably want to create dedicated GET EditScreenMeta
 | 
			
		||||
      // REST endpoint. Abuse GET diff for now, as it retrieves links we need.
 | 
			
		||||
      DiffApi.diff(revision, path)
 | 
			
		||||
      DiffApi.diff(Project.NameKey.asStringOrNull(projectKey), revision, path)
 | 
			
		||||
          .webLinksOnly()
 | 
			
		||||
          .get(
 | 
			
		||||
              group1.addFinal(
 | 
			
		||||
@@ -253,6 +261,7 @@ public class EditScreen extends Screen {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ChangeEditApi.get(
 | 
			
		||||
        projectKey,
 | 
			
		||||
        revision,
 | 
			
		||||
        path,
 | 
			
		||||
        group2.add(
 | 
			
		||||
@@ -427,6 +436,7 @@ public class EditScreen extends Screen {
 | 
			
		||||
    if (shouldShow) {
 | 
			
		||||
      if (baseContent == null) {
 | 
			
		||||
        ChangeEditApi.get(
 | 
			
		||||
            projectKey,
 | 
			
		||||
            revision,
 | 
			
		||||
            path,
 | 
			
		||||
            true /* base */,
 | 
			
		||||
@@ -529,7 +539,7 @@ public class EditScreen extends Screen {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private void upToChange() {
 | 
			
		||||
    Gerrit.display(PageLinks.toChangeInEditMode(revision.getParentKey()));
 | 
			
		||||
    Gerrit.display(PageLinks.toChangeInEditMode(projectKey, revision.getParentKey()));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private void initEditor() {
 | 
			
		||||
@@ -606,14 +616,14 @@ public class EditScreen extends Screen {
 | 
			
		||||
    InlineHyperlink sbs = new InlineHyperlink();
 | 
			
		||||
    sbs.setHTML(new ImageResourceRenderer().render(Gerrit.RESOURCES.sideBySideDiff()));
 | 
			
		||||
    sbs.setTargetHistoryToken(
 | 
			
		||||
        Dispatcher.toPatch("sidebyside", null, new Patch.Key(revision, path)));
 | 
			
		||||
        Dispatcher.toPatch(projectKey, "sidebyside", null, new Patch.Key(revision, path)));
 | 
			
		||||
    sbs.setTitle(PatchUtil.C.sideBySideDiff());
 | 
			
		||||
    linkPanel.add(sbs);
 | 
			
		||||
 | 
			
		||||
    InlineHyperlink unified = new InlineHyperlink();
 | 
			
		||||
    unified.setHTML(new ImageResourceRenderer().render(Gerrit.RESOURCES.unifiedDiff()));
 | 
			
		||||
    unified.setTargetHistoryToken(
 | 
			
		||||
        Dispatcher.toPatch("unified", null, new Patch.Key(revision, path)));
 | 
			
		||||
        Dispatcher.toPatch(projectKey, "unified", null, new Patch.Key(revision, path)));
 | 
			
		||||
    unified.setTitle(PatchUtil.C.unifiedDiff());
 | 
			
		||||
    linkPanel.add(unified);
 | 
			
		||||
  }
 | 
			
		||||
@@ -656,6 +666,7 @@ public class EditScreen extends Screen {
 | 
			
		||||
        }
 | 
			
		||||
        final int g = cmEdit.changeGeneration(false);
 | 
			
		||||
        ChangeEditApi.put(
 | 
			
		||||
            Project.NameKey.asStringOrNull(projectKey),
 | 
			
		||||
            revision.getParentKey().get(),
 | 
			
		||||
            path,
 | 
			
		||||
            text,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user