From 0ed845c7de6e2e08ad749f609af6a617d6e4cc50 Mon Sep 17 00:00:00 2001 From: Logan Hanks Date: Tue, 25 Apr 2017 10:13:54 +0200 Subject: [PATCH] Add PolyGerrit probe of /Documentation/index.html Change-Id: I5817e033e1620e5f28a339e57699b366956037e5 --- .../core/gr-main-header/gr-main-header.js | 18 +++++++++++++++--- .../gr-main-header/gr-main-header_test.html | 7 ++++--- .../gr-rest-api-interface.js | 7 +++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js index 1dcedd1e5b..ccf0f5705a 100644 --- a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js +++ b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js @@ -111,11 +111,10 @@ }, _docBaseUrl: { type: String, - value: null, }, _links: { type: Array, - computed: '_computeLinks(_defaultLinks, _userLinks, _adminLinks,' + + computed: '_computeLinks(_defaultLinks, _userLinks, _adminLinks, ' + '_docBaseUrl)', }, _loginURL: { @@ -220,10 +219,23 @@ }, _loadConfig: function() { - return this.$.restAPI.getConfig().then(function(config) { + this.$.restAPI.getConfig().then(function(config) { if (config && config.gerrit) { this._docBaseUrl = config.gerrit.doc_url; } + if (!this._docBaseUrl) { + return this._probeDocLink('/Documentation/index.html'); + } + }.bind(this)); + }, + + _probeDocLink: function(path) { + return this.$.restAPI.probePath(path).then(function(ok) { + if (ok) { + this._docBaseUrl = '/Documentation'; + } else { + this._docBaseUrl = null; + } }.bind(this)); }, diff --git a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header_test.html b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header_test.html index abb1f546c1..4582b4f9c2 100644 --- a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header_test.html +++ b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header_test.html @@ -41,6 +41,7 @@ limitations under the License. sandbox = sinon.sandbox.create(); stub('gr-rest-api-interface', { getConfig: function() { return Promise.resolve({}); }, + probePath: function(path) { return Promise.resolve(false); }, }); stub('gr-main-header', { _loadAccount: function() {}, @@ -135,7 +136,7 @@ limitations under the License. var docLinks = [ { name: 'Table of Contents', - url: '/Documentation/index.html', + url: '/index.html', }, ]; @@ -147,13 +148,13 @@ limitations under the License. assert.deepEqual(element._getDocLinks('base', docLinks), [{ name: 'Table of Contents', target: '_blank', - url: 'base/Documentation/index.html', + url: 'base/index.html', }]); assert.deepEqual(element._getDocLinks('base/', docLinks), [{ name: 'Table of Contents', target: '_blank', - url: 'base/Documentation/index.html', + url: 'base/index.html', }]); }); }); diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js index 8ae56ef70e..66a69a1a46 100644 --- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js +++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js @@ -1052,5 +1052,12 @@ return this.send('DELETE', this.getChangeActionURL(changeNum, null, '/assignee')); }, + + probePath: function(path) { + return fetch(new Request(path, {method: 'HEAD'})) + .then(function(response) { + return response.ok; + }); + }, }); })();