Update plugin host and avatar to use BaseUrlBehavior
Change-Id: Ibfeb7b2752c9e393c23d4b3a71cceaf53039a665
This commit is contained in:

committed by
Viktar Donich

parent
aee681d5bb
commit
8e1fde02b2
@@ -15,6 +15,7 @@ limitations under the License.
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||||
|
<link rel="import" href="../../../behaviors/base-url-behavior/base-url-behavior.html">
|
||||||
<link rel="import" href="../../shared/gr-js-api-interface/gr-js-api-interface.html">
|
<link rel="import" href="../../shared/gr-js-api-interface/gr-js-api-interface.html">
|
||||||
|
|
||||||
<dom-module id="gr-plugin-host">
|
<dom-module id="gr-plugin-host">
|
||||||
|
@@ -24,6 +24,10 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
behaviors: [
|
||||||
|
Gerrit.BaseUrlBehavior,
|
||||||
|
],
|
||||||
|
|
||||||
_configChanged(config) {
|
_configChanged(config) {
|
||||||
const jsPlugins = config.js_resource_paths || [];
|
const jsPlugins = config.js_resource_paths || [];
|
||||||
const htmlPlugins = config.html_resource_paths || [];
|
const htmlPlugins = config.html_resource_paths || [];
|
||||||
@@ -33,21 +37,16 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
_importHtmlPlugins(plugins) {
|
_importHtmlPlugins(plugins) {
|
||||||
for (let url of plugins) {
|
for (const url of plugins) {
|
||||||
if (!url.startsWith('http')) {
|
|
||||||
url = '/' + url;
|
|
||||||
}
|
|
||||||
this.importHref(
|
this.importHref(
|
||||||
url, Gerrit._pluginInstalled, Gerrit._pluginInstalled, true);
|
this._urlFor(url), Gerrit._pluginInstalled, Gerrit._pluginInstalled,
|
||||||
|
true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_loadJsPlugins(plugins) {
|
_loadJsPlugins(plugins) {
|
||||||
for (let url of plugins) {
|
for (const url of plugins) {
|
||||||
if (!url.startsWith('http')) {
|
this._createScriptTag(this._urlFor(url));
|
||||||
url = '/' + url;
|
|
||||||
}
|
|
||||||
this._createScriptTag(url);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -58,5 +57,12 @@
|
|||||||
el.onerror = Gerrit._pluginInstalled;
|
el.onerror = Gerrit._pluginInstalled;
|
||||||
return document.body.appendChild(el);
|
return document.body.appendChild(el);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_urlFor(pathOrUrl) {
|
||||||
|
if (pathOrUrl.startsWith('http')) {
|
||||||
|
return pathOrUrl;
|
||||||
|
}
|
||||||
|
return this.getBaseUrl() + '/' + pathOrUrl;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
@@ -54,7 +54,7 @@ limitations under the License.
|
|||||||
assert.isTrue(Gerrit._setPluginsCount.calledWith(3));
|
assert.isTrue(Gerrit._setPluginsCount.calledWith(3));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('imports html plugins from config', () => {
|
test('imports relative html plugins from config', () => {
|
||||||
element.config = {
|
element.config = {
|
||||||
html_resource_paths: ['foo/bar', 'baz'],
|
html_resource_paths: ['foo/bar', 'baz'],
|
||||||
};
|
};
|
||||||
@@ -64,13 +64,72 @@ limitations under the License.
|
|||||||
'/baz', Gerrit._pluginInstalled, Gerrit._pluginInstalled, true));
|
'/baz', Gerrit._pluginInstalled, Gerrit._pluginInstalled, true));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('imports js plugins from config', () => {
|
test('imports relative html plugins from config with a base url', () => {
|
||||||
|
sandbox.stub(element, 'getBaseUrl').returns('/the-base');
|
||||||
|
element.config = {
|
||||||
|
html_resource_paths: ['foo/bar', 'baz'],
|
||||||
|
};
|
||||||
|
assert.isTrue(element.importHref.calledWith(
|
||||||
|
'/the-base/foo/bar', Gerrit._pluginInstalled, Gerrit._pluginInstalled,
|
||||||
|
true));
|
||||||
|
assert.isTrue(element.importHref.calledWith(
|
||||||
|
'/the-base/baz', Gerrit._pluginInstalled, Gerrit._pluginInstalled,
|
||||||
|
true));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('imports absolute html plugins from config', () => {
|
||||||
|
element.config = {
|
||||||
|
html_resource_paths: [
|
||||||
|
'http://example.com/foo/bar',
|
||||||
|
'https://example.com/baz',
|
||||||
|
],
|
||||||
|
};
|
||||||
|
assert.isTrue(element.importHref.calledWith(
|
||||||
|
'http://example.com/foo/bar', Gerrit._pluginInstalled,
|
||||||
|
Gerrit._pluginInstalled, true));
|
||||||
|
assert.isTrue(element.importHref.calledWith(
|
||||||
|
'https://example.com/baz', Gerrit._pluginInstalled,
|
||||||
|
Gerrit._pluginInstalled, true));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('adds js plugins from config to the body', () => {
|
||||||
|
element.config = {
|
||||||
|
js_resource_paths: ['foo/bar', 'baz'],
|
||||||
|
};
|
||||||
|
assert.isTrue(document.body.appendChild.calledTwice);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('imports relative js plugins from config', () => {
|
||||||
sandbox.stub(element, '_createScriptTag');
|
sandbox.stub(element, '_createScriptTag');
|
||||||
element.config = {
|
element.config = {
|
||||||
js_resource_paths: ['foo/bar', 'http://baz'],
|
js_resource_paths: ['foo/bar', 'baz'],
|
||||||
};
|
};
|
||||||
assert.isTrue(element._createScriptTag.calledWith('/foo/bar'));
|
assert.isTrue(element._createScriptTag.calledWith('/foo/bar'));
|
||||||
assert.isTrue(element._createScriptTag.calledWith('http://baz'));
|
assert.isTrue(element._createScriptTag.calledWith('/baz'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('imports relative html plugins from config with a base url', () => {
|
||||||
|
sandbox.stub(element, '_createScriptTag');
|
||||||
|
sandbox.stub(element, 'getBaseUrl').returns('/the-base');
|
||||||
|
element.config = {
|
||||||
|
js_resource_paths: ['foo/bar', 'baz'],
|
||||||
|
};
|
||||||
|
assert.isTrue(element._createScriptTag.calledWith('/the-base/foo/bar'));
|
||||||
|
assert.isTrue(element._createScriptTag.calledWith('/the-base/baz'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('imports absolute html plugins from config', () => {
|
||||||
|
sandbox.stub(element, '_createScriptTag');
|
||||||
|
element.config = {
|
||||||
|
js_resource_paths: [
|
||||||
|
'http://example.com/foo/bar',
|
||||||
|
'https://example.com/baz',
|
||||||
|
],
|
||||||
|
};
|
||||||
|
assert.isTrue(element._createScriptTag.calledWith(
|
||||||
|
'http://example.com/foo/bar'));
|
||||||
|
assert.isTrue(element._createScriptTag.calledWith(
|
||||||
|
'https://example.com/baz'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@@ -16,6 +16,7 @@ limitations under the License.
|
|||||||
|
|
||||||
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
<link rel="import" href="../../../bower_components/polymer/polymer.html">
|
||||||
<link rel="import" href="../gr-rest-api-interface/gr-rest-api-interface.html">
|
<link rel="import" href="../gr-rest-api-interface/gr-rest-api-interface.html">
|
||||||
|
<link rel="import" href="../../../behaviors/base-url-behavior/base-url-behavior.html">
|
||||||
<link rel="import" href="../../../styles/shared-styles.html">
|
<link rel="import" href="../../../styles/shared-styles.html">
|
||||||
|
|
||||||
<dom-module id="gr-avatar">
|
<dom-module id="gr-avatar">
|
||||||
|
@@ -28,6 +28,10 @@
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
behaviors: [
|
||||||
|
Gerrit.BaseUrlBehavior,
|
||||||
|
],
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
this.hidden = true;
|
this.hidden = true;
|
||||||
},
|
},
|
||||||
@@ -64,7 +68,8 @@
|
|||||||
return avatars[i].url;
|
return avatars[i].url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return '/accounts/' + account._account_id + '/avatar?s=' + this.imageSize;
|
return this.getBaseUrl() + '/accounts/' +
|
||||||
|
account._account_id + '/avatar?s=' + this.imageSize;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
Reference in New Issue
Block a user