Load plugins JS resources upon initial page rendering

Bug: Issue 3915
Change-Id: Ic2d1d96458ecb2cd09dcd1cd204f8a06f234dbb7
This commit is contained in:
Andrew Bonventre
2016-04-19 14:33:53 -04:00
parent 8a867d6414
commit 4adac426a1
7 changed files with 45 additions and 8 deletions

View File

@@ -467,7 +467,6 @@ public class Daemon extends SiteProgram {
modules.add(H2CacheBasedWebSession.module());
modules.add(sysInjector.getInstance(GitOverHttpModule.class));
modules.add(sysInjector.getInstance(WebModule.class));
modules.add(sysInjector.getInstance(StaticModule.class));
modules.add(sysInjector.getInstance(RequireSslFilter.Module.class));
modules.add(new HttpPluginModule());
if (sshd) {
@@ -485,6 +484,9 @@ public class Daemon extends SiteProgram {
}
modules.add(sysInjector.getInstance(GetUserFilter.Module.class));
// StaticModule contains a "/*" wildcard, place it last.
modules.add(sysInjector.getInstance(StaticModule.class));
return sysInjector.createChildInjector(modules);
}

View File

@@ -366,7 +366,6 @@ public class WebAppInitializer extends GuiceServletContextListener
modules.add(RequestMetricsFilter.module());
modules.add(sysInjector.getInstance(GitOverHttpModule.class));
modules.add(sysInjector.getInstance(WebModule.class));
modules.add(sysInjector.getInstance(StaticModule.class));
modules.add(sysInjector.getInstance(RequireSslFilter.Module.class));
if (sshInjector != null) {
modules.add(sshInjector.getInstance(WebSshGlueModule.class));
@@ -384,6 +383,9 @@ public class WebAppInitializer extends GuiceServletContextListener
}
modules.add(sysInjector.getInstance(GetUserFilter.Module.class));
// StaticModule contains a "/*" wildcard, place it last.
modules.add(sysInjector.getInstance(StaticModule.class));
return sysInjector.createChildInjector(modules);
}

View File

@@ -21,6 +21,7 @@ limitations under the License.
<link rel="import" href="../../shared/gr-button/gr-button.html">
<link rel="import" href="../../shared/gr-change-star/gr-change-star.html">
<link rel="import" href="../../shared/gr-date-formatter/gr-date-formatter.html">
<link rel="import" href="../../shared/gr-js-api-interface/gr-js-api-interface.html">
<link rel="import" href="../../shared/gr-linked-text/gr-linked-text.html">
<link rel="import" href="../../shared/gr-overlay/gr-overlay.html">
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
@@ -305,6 +306,7 @@ limitations under the License.
on-cancel="_handleReplyCancel"
hidden$="[[!_loggedIn]]">Reply</gr-reply-dialog>
</gr-overlay>
<gr-js-api-interface id="jsAPI"></gr-js-api-interface>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
</template>
<script src="gr-change-view.js"></script>

View File

@@ -204,6 +204,11 @@
this.set('viewState.showReplyDialog', false);
}
}.bind(this));
this.$.jsAPI.handleEvent(this.$.jsAPI.EventType.SHOW_CHANGE, {
change: this._change,
patchNum: this._patchNum,
});
}.bind(this));
},

View File

@@ -137,6 +137,9 @@ limitations under the License.
view="[[params.view]]"
on-close="_handleKeyboardShortcutDialogClose"></gr-keyboard-shortcuts-dialog>
</gr-overlay>
<template is="dom-repeat" items="[[_serverConfig.plugin.js_resource_paths]]" as="path">
<script src$="/[[path]]" defer></script>
</template>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
</template>
<script src="gr-app.js"></script>

View File

@@ -35,7 +35,8 @@ limitations under the License.
setup(function() {
element = fixture('basic');
Gerrit.install(function(p) { plugin = p; });
Gerrit.install(function(p) { plugin = p; },
'http://test.com/plugins/testplugin/static/test.js');
});
teardown(function() {
@@ -43,6 +44,12 @@ limitations under the License.
plugin = null;
});
test('url', function() {
assert.equal(plugin.url(), 'http://test.com/plugins/testplugin/');
assert.equal(plugin.url('/static/test.js'),
'http://test.com/plugins/testplugin/static/test.js');
});
test('history event', function(done) {
plugin.on(element.EventType.HISTORY, function(path) {
assert.equal(path, '/path/to/awesomesauce');
@@ -56,8 +63,8 @@ limitations under the License.
var testChange = {
_number: 42,
revisions: {
def: { _number: 2 },
abc: { _number: 1 },
def: {_number: 2},
abc: {_number: 1},
},
};
plugin.on(element.EventType.SHOW_CHANGE, function(change, revision) {

View File

@@ -14,13 +14,27 @@
(function(window) {
'use strict';
function Plugin() {}
function Plugin(opt_url) {
this._url = new URL(opt_url);
if (this._url.pathname.indexOf('/plugins') !== 0) {
console.warn('Plugin not being loaded from /plugins base path:',
this._url.href, '— Unable to determine name.');
return;
}
this._name = this._url.pathname.split('/')[2];
}
Plugin.prototype._name = '';
Plugin.prototype.on = function(eventName, callback) {
document.createElement('gr-js-api-interface').addEventCallback(eventName,
callback);
};
Plugin.prototype.url = function(opt_path) {
return this._url.origin + '/plugins/' + this._name + (opt_path || '/');
};
var Gerrit = window.Gerrit || {};
Gerrit.css = function(rulesStr) {
@@ -35,8 +49,10 @@
return name;
},
Gerrit.install = function(callback) {
callback(new Plugin());
Gerrit.install = function(callback, opt_src) {
// TODO(andybons): Polyfill currentScript for IE10/11 (edge supports it).
var src = opt_src || (document.currentScript && document.currentScript.src);
callback(new Plugin(src));
};
window.Gerrit = Gerrit;