-
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-74067] Extract inline JavaScript from `BuildMonitorView/inde…
…x.jelly` (#1034)
- Loading branch information
1 parent
f827941
commit 0e937b4
Showing
5 changed files
with
101 additions
and
80 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...s/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/collect-usage-stats.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
window.addEventListener("DOMContentLoaded", () => { | ||
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; | ||
|
||
const { | ||
buildMonitorVersion, | ||
jenkinsVersion, | ||
installationSize, | ||
itemsSize, | ||
installationAudience, | ||
anonymousCorrelationId | ||
} = document.querySelector('.build-monitor-ga-data-holder').dataset; | ||
|
||
ga('create', 'UA-61694827-4', 'auto', { | ||
'userId': anonymousCorrelationId, | ||
'sampleRate': 1 | ||
}); | ||
|
||
ga('set', { | ||
'forceSSL': true, | ||
'appName': 'Build Monitor', | ||
'appId': 'build-monitor-plugin', | ||
|
||
'appVersion': buildMonitorVersion, | ||
'appInstallerId': jenkinsVersion, | ||
|
||
'dimension1': installationSize, | ||
'dimension2': itemsSize, | ||
'dimension3': installationAudience, | ||
'dimension4': anonymousCorrelationId | ||
}); | ||
|
||
ga('send', 'screenview', {screenName: 'Dashboard'}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...es/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/init-build-monitor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
(function() { | ||
const { buildMonitorVersion, csrfCrumbFieldName } = document.querySelector(".build-monitor-data-holder").dataset; | ||
|
||
angular | ||
.module('buildMonitor') | ||
.constant('BUILD_MONITOR_VERSION', buildMonitorVersion) | ||
.constant('CSRF_CRUMB_FIELD_NAME', csrfCrumbFieldName) | ||
.config(function(proxyProvider, cookieJarProvider, hashCodeProvider) { | ||
var hashCodeOf = hashCodeProvider.hashCodeOf; | ||
|
||
proxyProvider.configureProxiesUsing(window.bindings); | ||
|
||
cookieJarProvider.describe({ | ||
label: 'buildMonitor.' + hashCodeOf(document.body.dataset.displayName) | ||
}); | ||
}); | ||
})(); |
26 changes: 26 additions & 0 deletions
26
...com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/replace-stapler-proxy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* todo: (13.08.2013) Replace the below workaround with a custom Jelly tag (ExposeBindTag) | ||
* extending either org.kohsuke.stapler.jelly.BindTag or AbstractStaplerTag, | ||
* that would supersede currently defective BindTag implementation: | ||
* - https://groups.google.com/forum/#!topic/jenkinsci-dev/S9bhX4ts0g4 | ||
* - https://issues.jenkins-ci.org/browse/JENKINS-18641 | ||
* | ||
* Defect in BindTag manifests itself by causing a JavaScript error and preventing scripts after | ||
* the <st:bind> invocation from executing, which results in an "empty Build Monitor". | ||
* The issue occurs on Jenkins 1.521-1.526, only if the jQuery plugin is used. | ||
* | ||
* Motivation behind a custom Jelly tag: | ||
* Original implementation of the BindTag doesn't provide an easy way of handling AJAX errors, | ||
* which may happen if a network connection is lost or when Jenkins is restarted (which then makes | ||
* Stapler's binding hash obsolete and Jenkins return 404 for any subsequent requests). | ||
* | ||
* Custom Jelly tag should generate a JSON object exposing the binding, leaving the implementation | ||
* of the proxy to the Developer. It makes more sense for a developer to require a binding adapter | ||
* implementation specific to their JavaScript framework of choice, rather than for Stapler to try | ||
* to predict what JavaScript libraries will ever be used with it in the future... | ||
*/ | ||
window.originalMakeStaplerProxy = window.makeStaplerProxy; | ||
window.makeStaplerProxy = function(url, crumb, methods) { | ||
return { url, crumb, methods } | ||
}; | ||
window.bindings = {}; |
7 changes: 7 additions & 0 deletions
7
...com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/restore-stapler-proxy.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
window.bindings['buildMonitor'] = buildMonitorBind; | ||
window.makeStaplerProxy = window.originalMakeStaplerProxy; | ||
try { | ||
delete window.originalMakeStaplerProxy; | ||
} catch(e) { | ||
window["originalMakeStaplerProxy"] = undefined; | ||
} |