Merge "Add PolyGerrit probe of /Documentation/index.html" into stable-2.14

This commit is contained in:
David Pursehouse 2017-04-25 15:19:40 +00:00 committed by Gerrit Code Review
commit 9e14e59e22
3 changed files with 26 additions and 6 deletions

View File

@ -111,11 +111,10 @@
}, },
_docBaseUrl: { _docBaseUrl: {
type: String, type: String,
value: null,
}, },
_links: { _links: {
type: Array, type: Array,
computed: '_computeLinks(_defaultLinks, _userLinks, _adminLinks,' + computed: '_computeLinks(_defaultLinks, _userLinks, _adminLinks, ' +
'_docBaseUrl)', '_docBaseUrl)',
}, },
_loginURL: { _loginURL: {
@ -220,10 +219,23 @@
}, },
_loadConfig: function() { _loadConfig: function() {
return this.$.restAPI.getConfig().then(function(config) { this.$.restAPI.getConfig().then(function(config) {
if (config && config.gerrit) { if (config && config.gerrit) {
this._docBaseUrl = config.gerrit.doc_url; 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)); }.bind(this));
}, },

View File

@ -41,6 +41,7 @@ limitations under the License.
sandbox = sinon.sandbox.create(); sandbox = sinon.sandbox.create();
stub('gr-rest-api-interface', { stub('gr-rest-api-interface', {
getConfig: function() { return Promise.resolve({}); }, getConfig: function() { return Promise.resolve({}); },
probePath: function(path) { return Promise.resolve(false); },
}); });
stub('gr-main-header', { stub('gr-main-header', {
_loadAccount: function() {}, _loadAccount: function() {},
@ -135,7 +136,7 @@ limitations under the License.
var docLinks = [ var docLinks = [
{ {
name: 'Table of Contents', 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), [{ assert.deepEqual(element._getDocLinks('base', docLinks), [{
name: 'Table of Contents', name: 'Table of Contents',
target: '_blank', target: '_blank',
url: 'base/Documentation/index.html', url: 'base/index.html',
}]); }]);
assert.deepEqual(element._getDocLinks('base/', docLinks), [{ assert.deepEqual(element._getDocLinks('base/', docLinks), [{
name: 'Table of Contents', name: 'Table of Contents',
target: '_blank', target: '_blank',
url: 'base/Documentation/index.html', url: 'base/index.html',
}]); }]);
}); });
}); });

View File

@ -1052,5 +1052,12 @@
return this.send('DELETE', return this.send('DELETE',
this.getChangeActionURL(changeNum, null, '/assignee')); this.getChangeActionURL(changeNum, null, '/assignee'));
}, },
probePath: function(path) {
return fetch(new Request(path, {method: 'HEAD'}))
.then(function(response) {
return response.ok;
});
},
}); });
})(); })();