Have PolyGerrit footer link preserve current page
The previous implementation used getHostPageBaseUrl, which seems logical, but because Gerrit is a GWT app that uses fragment urls to represent logical pages, this results in always using '/' as the host page base url. This new implementation instead uses the history token, which is the fragment url minus '#', as input to a full UrlBuilder, and ensures it converts both the fragment to a path, and the @-style pseudofragment to an actual fragment. Change-Id: I09b8a711a8d56d36c4c3b33630c456a84097fe37
This commit is contained in:
@@ -138,6 +138,7 @@ public class Gerrit implements EntryPoint {
|
||||
private static ViewSite<Screen> body;
|
||||
private static String lastChangeListToken;
|
||||
private static String lastViewToken;
|
||||
private static Anchor uiSwitcherLink;
|
||||
|
||||
static {
|
||||
SYSTEM_SVC = GWT.create(SystemInfoService.class);
|
||||
@@ -175,6 +176,7 @@ public class Gerrit implements EntryPoint {
|
||||
public static void display(final String token) {
|
||||
if (body.getView() == null || !body.getView().displayToken(token)) {
|
||||
dispatcher.display(token);
|
||||
updateUiLink(token);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,6 +203,7 @@ public class Gerrit implements EntryPoint {
|
||||
LocalComments.saveInlineComments();
|
||||
}
|
||||
body.setView(view);
|
||||
updateUiLink(token);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -532,6 +535,23 @@ public class Gerrit implements EntryPoint {
|
||||
ApiGlue.fireEvent("history", token);
|
||||
}
|
||||
|
||||
private static String getUiSwitcherUrl(String token) {
|
||||
UrlBuilder builder = new UrlBuilder();
|
||||
builder.setProtocol(Location.getProtocol());
|
||||
builder.setHost(Location.getHost());
|
||||
String port = Location.getPort();
|
||||
if (port != null && !port.isEmpty()) {
|
||||
builder.setPort(Integer.parseInt(port));
|
||||
}
|
||||
String[] tokens = token.split("@", 2);
|
||||
builder.setPath(tokens[0]);
|
||||
if (tokens.length == 2) {
|
||||
builder.setHash(tokens[1]);
|
||||
}
|
||||
builder.setParameter("polygerrit", "1");
|
||||
return builder.buildString();
|
||||
}
|
||||
|
||||
private static void populateBottomMenu(RootPanel btmmenu, HostPageData hpd) {
|
||||
String vs = hpd.version;
|
||||
if (vs == null || vs.isEmpty()) {
|
||||
@@ -542,10 +562,10 @@ public class Gerrit implements EntryPoint {
|
||||
|
||||
if (info().gerrit().webUis().contains(UiType.POLYGERRIT)) {
|
||||
btmmenu.add(new InlineLabel(" | "));
|
||||
Anchor a = new Anchor(
|
||||
C.newUi(), GWT.getHostPageBaseURL() + "?polygerrit=1");
|
||||
a.setStyleName("");
|
||||
btmmenu.add(a);
|
||||
uiSwitcherLink = new Anchor(C.newUi(),
|
||||
getUiSwitcherUrl(History.getToken()));
|
||||
uiSwitcherLink.setStyleName("");
|
||||
btmmenu.add(uiSwitcherLink);
|
||||
}
|
||||
|
||||
String reportBugUrl = info().gerrit().reportBugUrl();
|
||||
@@ -563,6 +583,10 @@ public class Gerrit implements EntryPoint {
|
||||
btmmenu.add(new InlineLabel(C.keyHelp()));
|
||||
}
|
||||
|
||||
private static void updateUiLink(String token) {
|
||||
uiSwitcherLink.setHref(getUiSwitcherUrl(token));
|
||||
}
|
||||
|
||||
private void onModuleLoad2(HostPageData hpd) {
|
||||
RESOURCES.gwt_override().ensureInjected();
|
||||
RESOURCES.css().ensureInjected();
|
||||
|
||||
Reference in New Issue
Block a user