Update GWT footer link to be page specific Previously, the GWT UI link at the bottom of every page linked to the Gerrit GWT homepage. This change updates the path of that link whenever the location-change event is fired. Bug: Issue 4619 Change-Id: Iddbd83fddec750c165831c673a0e3394318c4ae2
diff --git a/polygerrit-ui/app/elements/gr-app.html b/polygerrit-ui/app/elements/gr-app.html index 051ee2e..9382f3a 100644 --- a/polygerrit-ui/app/elements/gr-app.html +++ b/polygerrit-ui/app/elements/gr-app.html
@@ -129,7 +129,7 @@ target="_blank">Report PolyGerrit Bug</a> <template is="dom-if" if="[[_computeShowGwtUiLink(_serverConfig)]]"> | - <a href="/?polygerrit=0" rel="external">GWT UI</a> + <a id="gwtLink" href$="/?polygerrit=0#[[_path]]" rel="external">GWT UI</a> </template> </footer> <gr-overlay id="keyboardShortcuts" with-backdrop>
diff --git a/polygerrit-ui/app/elements/gr-app.js b/polygerrit-ui/app/elements/gr-app.js index 84467a0..372fea9 100644 --- a/polygerrit-ui/app/elements/gr-app.js +++ b/polygerrit-ui/app/elements/gr-app.js
@@ -43,11 +43,13 @@ _showSettingsView: Boolean, _viewState: Object, _lastError: Object, + _path: String, }, listeners: { 'page-error': '_handlePageError', 'title-change': '_handleTitleChange', + 'location-change': '_handleLocationChange', }, observers: [ @@ -158,6 +160,15 @@ } }, + _handleLocationChange: function() { + var hash = location.hash.substring(1); + var pathname = location.pathname; + if (pathname.startsWith('/c/') && parseInt(hash, 10) > 0) { + pathname += '@' + hash; + } + this.set('_path', encodeURIComponent(pathname)); + }, + _handleTitleChange: function(e) { if (e.detail.title) { document.title = e.detail.title + ' · Gerrit Code Review';
diff --git a/polygerrit-ui/app/elements/gr-app_test.html b/polygerrit-ui/app/elements/gr-app_test.html index 0c23c4f..f941d0f 100644 --- a/polygerrit-ui/app/elements/gr-app_test.html +++ b/polygerrit-ui/app/elements/gr-app_test.html
@@ -39,6 +39,14 @@ stub('gr-reporting', { appStarted: sandbox.stub(), }); + var config = { + gerrit: {web_uis: ['GWT', 'POLYGERRIT']}, + plugin: {js_resource_paths: []}, + }; + stub('gr-rest-api-interface', { + getConfig: function() { return Promise.resolve(config); }, + }); + element = fixture('basic'); flush(done); }); @@ -49,5 +57,12 @@ test('reporting', function() { assert.isTrue(element.$.reporting.appStarted.calledOnce); }); + + test('location change updates gwt footer', function() { + element._path = '/test/path'; + var gwtLink = element.$$('#gwtLink'); + assert.equal(gwtLink.href, + 'http://' + location.host + '/?polygerrit=0#/test/path'); + }); }); </script>