Load plugins JS resources upon initial page rendering
Bug: Issue 3915 Change-Id: Ic2d1d96458ecb2cd09dcd1cd204f8a06f234dbb7
This commit is contained in:
@@ -467,7 +467,6 @@ public class Daemon extends SiteProgram {
|
|||||||
modules.add(H2CacheBasedWebSession.module());
|
modules.add(H2CacheBasedWebSession.module());
|
||||||
modules.add(sysInjector.getInstance(GitOverHttpModule.class));
|
modules.add(sysInjector.getInstance(GitOverHttpModule.class));
|
||||||
modules.add(sysInjector.getInstance(WebModule.class));
|
modules.add(sysInjector.getInstance(WebModule.class));
|
||||||
modules.add(sysInjector.getInstance(StaticModule.class));
|
|
||||||
modules.add(sysInjector.getInstance(RequireSslFilter.Module.class));
|
modules.add(sysInjector.getInstance(RequireSslFilter.Module.class));
|
||||||
modules.add(new HttpPluginModule());
|
modules.add(new HttpPluginModule());
|
||||||
if (sshd) {
|
if (sshd) {
|
||||||
@@ -485,6 +484,9 @@ public class Daemon extends SiteProgram {
|
|||||||
}
|
}
|
||||||
modules.add(sysInjector.getInstance(GetUserFilter.Module.class));
|
modules.add(sysInjector.getInstance(GetUserFilter.Module.class));
|
||||||
|
|
||||||
|
// StaticModule contains a "/*" wildcard, place it last.
|
||||||
|
modules.add(sysInjector.getInstance(StaticModule.class));
|
||||||
|
|
||||||
return sysInjector.createChildInjector(modules);
|
return sysInjector.createChildInjector(modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -366,7 +366,6 @@ public class WebAppInitializer extends GuiceServletContextListener
|
|||||||
modules.add(RequestMetricsFilter.module());
|
modules.add(RequestMetricsFilter.module());
|
||||||
modules.add(sysInjector.getInstance(GitOverHttpModule.class));
|
modules.add(sysInjector.getInstance(GitOverHttpModule.class));
|
||||||
modules.add(sysInjector.getInstance(WebModule.class));
|
modules.add(sysInjector.getInstance(WebModule.class));
|
||||||
modules.add(sysInjector.getInstance(StaticModule.class));
|
|
||||||
modules.add(sysInjector.getInstance(RequireSslFilter.Module.class));
|
modules.add(sysInjector.getInstance(RequireSslFilter.Module.class));
|
||||||
if (sshInjector != null) {
|
if (sshInjector != null) {
|
||||||
modules.add(sshInjector.getInstance(WebSshGlueModule.class));
|
modules.add(sshInjector.getInstance(WebSshGlueModule.class));
|
||||||
@@ -384,6 +383,9 @@ public class WebAppInitializer extends GuiceServletContextListener
|
|||||||
}
|
}
|
||||||
modules.add(sysInjector.getInstance(GetUserFilter.Module.class));
|
modules.add(sysInjector.getInstance(GetUserFilter.Module.class));
|
||||||
|
|
||||||
|
// StaticModule contains a "/*" wildcard, place it last.
|
||||||
|
modules.add(sysInjector.getInstance(StaticModule.class));
|
||||||
|
|
||||||
return sysInjector.createChildInjector(modules);
|
return sysInjector.createChildInjector(modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ limitations under the License.
|
|||||||
<link rel="import" href="../../shared/gr-button/gr-button.html">
|
<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-change-star/gr-change-star.html">
|
||||||
<link rel="import" href="../../shared/gr-date-formatter/gr-date-formatter.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-linked-text/gr-linked-text.html">
|
||||||
<link rel="import" href="../../shared/gr-overlay/gr-overlay.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">
|
<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"
|
on-cancel="_handleReplyCancel"
|
||||||
hidden$="[[!_loggedIn]]">Reply</gr-reply-dialog>
|
hidden$="[[!_loggedIn]]">Reply</gr-reply-dialog>
|
||||||
</gr-overlay>
|
</gr-overlay>
|
||||||
|
<gr-js-api-interface id="jsAPI"></gr-js-api-interface>
|
||||||
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
||||||
</template>
|
</template>
|
||||||
<script src="gr-change-view.js"></script>
|
<script src="gr-change-view.js"></script>
|
||||||
|
|||||||
@@ -204,6 +204,11 @@
|
|||||||
this.set('viewState.showReplyDialog', false);
|
this.set('viewState.showReplyDialog', false);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
this.$.jsAPI.handleEvent(this.$.jsAPI.EventType.SHOW_CHANGE, {
|
||||||
|
change: this._change,
|
||||||
|
patchNum: this._patchNum,
|
||||||
|
});
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -137,6 +137,9 @@ limitations under the License.
|
|||||||
view="[[params.view]]"
|
view="[[params.view]]"
|
||||||
on-close="_handleKeyboardShortcutDialogClose"></gr-keyboard-shortcuts-dialog>
|
on-close="_handleKeyboardShortcutDialogClose"></gr-keyboard-shortcuts-dialog>
|
||||||
</gr-overlay>
|
</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>
|
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
||||||
</template>
|
</template>
|
||||||
<script src="gr-app.js"></script>
|
<script src="gr-app.js"></script>
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ limitations under the License.
|
|||||||
|
|
||||||
setup(function() {
|
setup(function() {
|
||||||
element = fixture('basic');
|
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() {
|
teardown(function() {
|
||||||
@@ -43,6 +44,12 @@ limitations under the License.
|
|||||||
plugin = null;
|
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) {
|
test('history event', function(done) {
|
||||||
plugin.on(element.EventType.HISTORY, function(path) {
|
plugin.on(element.EventType.HISTORY, function(path) {
|
||||||
assert.equal(path, '/path/to/awesomesauce');
|
assert.equal(path, '/path/to/awesomesauce');
|
||||||
@@ -56,8 +63,8 @@ limitations under the License.
|
|||||||
var testChange = {
|
var testChange = {
|
||||||
_number: 42,
|
_number: 42,
|
||||||
revisions: {
|
revisions: {
|
||||||
def: { _number: 2 },
|
def: {_number: 2},
|
||||||
abc: { _number: 1 },
|
abc: {_number: 1},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
plugin.on(element.EventType.SHOW_CHANGE, function(change, revision) {
|
plugin.on(element.EventType.SHOW_CHANGE, function(change, revision) {
|
||||||
|
|||||||
@@ -14,13 +14,27 @@
|
|||||||
(function(window) {
|
(function(window) {
|
||||||
'use strict';
|
'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) {
|
Plugin.prototype.on = function(eventName, callback) {
|
||||||
document.createElement('gr-js-api-interface').addEventCallback(eventName,
|
document.createElement('gr-js-api-interface').addEventCallback(eventName,
|
||||||
callback);
|
callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Plugin.prototype.url = function(opt_path) {
|
||||||
|
return this._url.origin + '/plugins/' + this._name + (opt_path || '/');
|
||||||
|
};
|
||||||
|
|
||||||
var Gerrit = window.Gerrit || {};
|
var Gerrit = window.Gerrit || {};
|
||||||
|
|
||||||
Gerrit.css = function(rulesStr) {
|
Gerrit.css = function(rulesStr) {
|
||||||
@@ -35,8 +49,10 @@
|
|||||||
return name;
|
return name;
|
||||||
},
|
},
|
||||||
|
|
||||||
Gerrit.install = function(callback) {
|
Gerrit.install = function(callback, opt_src) {
|
||||||
callback(new Plugin());
|
// 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;
|
window.Gerrit = Gerrit;
|
||||||
|
|||||||
Reference in New Issue
Block a user