Skip to content

Commit cd4cde3

Browse files
authored
JENKINS-74732 - Move jelly inline event handlers and script blocks to JavaScript. (#76)
* Modify floatingbox.jelly according to CSP requirements * Revert "Modify floatingbox.jelly according to CSP requirements" This reverts commit ba1db71. * Move js inline handlers from jelly to js file * Add trailing slash * Move failedcases onlick handlers to javascript * Combine DOMContentLodaded event handlers
1 parent f6ccfc4 commit cd4cde3

File tree

7 files changed

+66
-34
lines changed

7 files changed

+66
-34
lines changed

src/main/resources/hudson/plugins/robot/RobotProjectAction/floatingBox.jelly

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
Copyright 2008-2014 Nokia Solutions and Networks Oy
44
@@ -25,13 +25,13 @@ limitations under the License.
2525
<a href="${from.urlName}">
2626
<img id="passfailgraph" src="" title="Browse results" width="500" height="200"/>
2727
</a><br/>
28-
<p><label><input type="checkbox" id="zoomToChanges" onclick="redrawPassFailGraph('${from.urlName}/');"/>Zoom to changes</label></p>
29-
<p><label><input type="checkbox" id="failedOnly" onclick="redrawPassFailGraph('${from.urlName}/');"/>Show only failed</label></p>
30-
<p><label><input type="checkbox" id="criticalOnly" onclick="redrawPassFailGraph('${from.urlName}/');"/>Show only critical</label></p>
31-
<p><label><input min="0" max="9999" step="1" placeholder="all" value="" type="number" id="maxBuildsToShow" onchange="redrawPassFailGraph('${from.urlName}/');"/>Max builds</label></p>
28+
<span id="robot-fromurl-id" data-url="${from.urlName}/"></span>
29+
<p><label><input type="checkbox" id="zoomToChanges"/>Zoom to changes</label></p>
30+
<p><label><input type="checkbox" id="failedOnly"/>Show only failed</label></p>
31+
<p><label><input type="checkbox" id="criticalOnly"/>Show only critical</label></p>
32+
<p><label><input min="0" max="9999" step="1" placeholder="all" value="" type="number" id="maxBuildsToShow"/>Max builds</label></p>
3233
<br/><p style="float:right"><a id="passfailgraph_hd_link" href="">Show bigger image</a></p>
3334
</div>
34-
<script>initPassFailGraph('${from.urlName}/');</script>
3535
</div>
3636
</j:if>
3737
</j:jelly>

src/main/resources/hudson/plugins/robot/model/RobotCaseResult/index.jelly

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
Copyright 2008-2014 Nokia Solutions and Networks Oy
44
@@ -54,19 +54,17 @@ limitations under the License.
5454
<a id="passfailgraph_hd" href="">
5555
<img id="passfailgraph" src="" title="Show bigger image" width="500" height="200"/>
5656
</a><br/>
57-
<p><label><input min="0" step="1" max="9999" value="" placeholder="all" type="number" id="maxBuildsToShow"
58-
onchange="redrawPassFailGraph(''); redrawDurationGraph('');"/>Max builds</label></p>
57+
<span id="robot-fromurl-id" data-url=""></span>
58+
<p><label><input min="0" step="1" max="9999" value="" placeholder="all" type="number" id="maxBuildsToShow"/>Max builds</label></p>
5959
<br/><p style="float:right"><a id="passfailgraph_hd_link" href="">Show bigger image</a></p>
6060
</div>
61-
<script>initPassFailGraph('');</script>
6261
<div style="float:left; margin: 20px; border: 1px solid #ccc; padding: 10px;">
6362
<h3>Duration Trend</h3>
6463
<a id="durationgraph_hd" href="">
6564
<img id="durationgraph" src="" title="Show bigger image" width="500" height="200"/>
6665
</a><br/>
6766
<p style="float:right"><a id="durationgraph_hd_link" href="">Show bigger image</a></p>
6867
</div>
69-
<script>initDurationGraph('');</script>
7068
<div style="clear:both;"></div>
7169
</div>
7270
</l:main-panel>

src/main/resources/hudson/plugins/robot/model/RobotResult/index.jelly

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
Copyright 2008-2014 Nokia Solutions and Networks Oy
44
@@ -58,22 +58,20 @@ limitations under the License.
5858
<a id="passfailgraph_hd" href="">
5959
<img id="passfailgraph" src="" title="Show bigger image" width="500" height="200"/>
6060
</a><br/>
61-
<p><label><input type="checkbox" id="zoomToChanges" onclick="redrawPassFailGraph('');"/>Zoom to changes</label></p>
62-
<p><label><input type="checkbox" id="failedOnly" onclick="redrawPassFailGraph('');"/>Show only failed</label></p>
63-
<p><label><input type="checkbox" id="criticalOnly" onclick="redrawPassFailGraph('');"/>Show only critical</label></p>
64-
<p><label><input min="0" max="9999" step="1" placeholder="all" value="" type="number" id="maxBuildsToShow"
65-
onchange="redrawPassFailGraph(''); redrawDurationGraph('');"/>Max builds</label></p>
61+
<span id="robot-fromurl-id" data-url=""></span>
62+
<p><label><input type="checkbox" id="zoomToChanges"/>Zoom to changes</label></p>
63+
<p><label><input type="checkbox" id="failedOnly"/>Show only failed</label></p>
64+
<p><label><input type="checkbox" id="criticalOnly"/>Show only critical</label></p>
65+
<p><label><input min="0" max="9999" step="1" placeholder="all" value="" type="number" id="maxBuildsToShow"/>Max builds</label></p>
6666
<br/><p style="float:right"><a id="passfailgraph_hd_link" href="">Show bigger image</a></p>
6767
</div>
68-
<script>initPassFailGraph('');</script>
6968
<div style="float:left; margin: 20px; border: 1px solid #ccc; padding: 10px;">
7069
<h3>Duration Trend</h3>
7170
<a id="durationgraph_hd" href="">
7271
<img id="durationgraph" src="" title="Show bigger image" width="500" height="200"/>
7372
</a><br/>
7473
<p style="float:right"><a id="durationgraph_hd_link" href="">Show bigger image</a></p>
7574
</div>
76-
<script>initDurationGraph('');</script>
7775
<div style="clear:both;"></div>
7876
</div>
7977
<div style="float:left;">

src/main/resources/hudson/plugins/robot/model/RobotSuiteResult/index.jelly

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
Copyright 2008-2014 Nokia Solutions and Networks Oy
44
@@ -59,14 +59,13 @@ limitations under the License.
5959
<a id="passfailgraph_hd" href="">
6060
<img id="passfailgraph" src="" title="Show bigger image" width="500" height="200"/>
6161
</a><br/>
62-
<p><label><input type="checkbox" id="zoomToChanges" onclick="redrawPassFailGraph('');"/>Zoom to changes</label></p>
63-
<p><label><input type="checkbox" id="failedOnly" onclick="redrawPassFailGraph('');"/>Show only failed</label></p>
64-
<p><label><input type="checkbox" id="criticalOnly" onclick="redrawPassFailGraph('');"/>Show only critical</label></p>
65-
<p><label><input min="0" step="1" max="9999" value="" placeholder="all" type="number" id="maxBuildsToShow"
66-
onchange="redrawPassFailGraph(''); redrawDurationGraph('');"/>Max builds</label></p>
62+
<span id="robot-fromurl-id" data-url=""></span>
63+
<p><label><input type="checkbox" id="zoomToChanges"/>Zoom to changes</label></p>
64+
<p><label><input type="checkbox" id="failedOnly"/>Show only failed</label></p>
65+
<p><label><input type="checkbox" id="criticalOnly"/>Show only critical</label></p>
66+
<p><label><input min="0" step="1" max="9999" value="" placeholder="all" type="number" id="maxBuildsToShow"/>Max builds</label></p>
6767
<br/><p style="float:right"><a id="passfailgraph_hd_link" href="">Show bigger image</a></p>
6868
</div>
69-
<script>initPassFailGraph('');</script>
7069
<div style="float:left; margin: 20px; border: 1px solid #ccc; padding: 10px;">
7170
<h3>Duration Trend</h3>
7271
<a id="durationgraph_hd" href="">
@@ -76,7 +75,6 @@ limitations under the License.
7675
</div>
7776
<div style="clear:both;"></div>
7877
</div>
79-
<script>initDurationGraph('');</script>
8078
<j:if test="${!it.caseResults.isEmpty()}">
8179
<h2>Test Cases</h2>
8280
<table class="pane sortable">

src/main/resources/hudson/plugins/robot/model/RobotTestObject/robotcss.jelly

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ span.FAIL {
4040
table.listsummary th, table.listsummary td {
4141
font-size:100%;
4242
}
43-
.expand {
43+
.robot-expand {
4444
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAYAAAAGCAQAAABKxSfDAAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfeCR0JCDHdVYtxAAAAM0lEQVQI103MMQqAMBQFwVHyITaB3P+W1sKzSBC3mW6hRFw0pUB5DvF1bu9FN0RM3X/wAk98CUnvFTakAAAAAElFTkSuQmCC);
4545
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4IiBoZWlnaHQ9IjgiIHZpZXdCb3g9IjAgMCA4IDgiPgogIDxwYXRoIGQ9Ik0zIDB2M2gtM3YyaDN2M2gydi0zaDN2LTJoLTN2LTNoLTJ6IiAvPgo8L3N2Zz4=), none;
4646
}
47-
.collapse {
47+
.robot-collapse {
4848
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAYAAAAGCAQAAABKxSfDAAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfeCR0JChSkZz20AAAAGklEQVQI12NgQAKMDKzInP8IDhOqMk4G7AAANQwBE427PYUAAAAASUVORK5CYII=);
4949
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4IiBoZWlnaHQ9IjgiIHZpZXdCb3g9IjAgMCA4IDgiPgogIDxwYXRoIGQ9Ik0wIDB2Mmg4di0yaC04eiIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMCAzKSIgLz4KPC9zdmc+), none;
5050
}
5151
.error-message {
5252
white-space: pre;
5353
}
54-
.expand, .collapse {
54+
.robot-expand, .robot-collapse {
5555
display: block;
5656
float: left;
5757
left: 3px;

src/main/resources/hudson/plugins/robot/util/failedCases.jelly

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<?jelly escape-by-default='true'?>
33
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:u="/util">
4+
<script src="${rootURL}/plugin/robot/robot.js"/>
45
<j:if test="${!it.allFailedCases.isEmpty()}">
56
<style>
67
td.pane {
@@ -21,8 +22,8 @@
2122
<j:set var="escapedName" value="${h.escape(fullName)}" />
2223
<tr>
2324
<td class="pane">
24-
<a id="${escapedName}-showlink" href="#" onclick="javascript:showStackTrace('${h.jsStringEscape(escapedName)}','${h.jsStringEscape(relativeId)}/summary')" class="expand"></a>
25-
<a id="${escapedName}-hidelink" href="#" onclick="javascript:hideStackTrace('${h.jsStringEscape(escapedName)}')" style="display:none" class="collapse"></a>
25+
<a id="${escapedName}-showlink" href="#" class="robot-expand" data-escaped-name="${escapedName}" data-relative-id="${relativeId}/summary"></a>
26+
<a id="${escapedName}-hidelink" href="#" style="display:none" class="robot-collapse" data-escaped-name="${escapedName}"></a>
2627
<st:nbsp/>
2728
<a href="${relativeId}"><small>${case.getRelativeParent(it)}</small>${case.name}</a>
2829
<div id="${escapedName}" class="hidden" style="display:none">

src/main/webapp/robot.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ function setDurationGraphSrc(target, maxBuildsToShow) {
4949
setLinks("durationgraph", href);
5050
}
5151

52-
function redrawPassFailGraph(target) {
52+
function redrawPassFailGraph() {
5353
var mode = false;
54+
var target = document.getElementById("robot-fromurl-id").getAttribute("data-url");
5455
if (document.getElementById("zoomToChanges")) {
5556
mode = Boolean(document.getElementById('zoomToChanges').checked).toString();
5657
setCookie("RobotResult_zoom",mode, 365);
@@ -72,7 +73,8 @@ function redrawPassFailGraph(target) {
7273
setPassFailGraphSrc(target, mode, failedOnly, criticalOnly, maxBuildsToShow);
7374
}
7475

75-
function redrawDurationGraph(target) {
76+
function redrawDurationGraph() {
77+
var target = document.getElementById("robot-fromurl-id").getAttribute("data-url");
7678
var maxBuildsToShow = getMaxBuildsToShow();
7779
setDurationGraphSrc(target, maxBuildsToShow);
7880
}
@@ -112,3 +114,38 @@ function hideStackTrace(id) {
112114
document.getElementById(id + "-showlink").style.display = "";
113115
document.getElementById(id + "-hidelink").style.display = "none";
114116
}
117+
118+
document.addEventListener("DOMContentLoaded", function(){
119+
var element = document.getElementById("robot-fromurl-id");
120+
if (element) {
121+
var url = element.getAttribute("data-url");
122+
123+
["zoomToChanges", "failedOnly", "criticalOnly"].forEach(function(id) {
124+
if (document.getElementById(id))
125+
document.getElementById(id).addEventListener("click", redrawPassFailGraph);
126+
});
127+
128+
if (document.getElementById("maxBuildsToShow")) {
129+
document.getElementById("maxBuildsToShow").addEventListener("change", redrawPassFailGraph);
130+
if (url == "")
131+
document.getElementById("maxBuildsToShow").addEventListener("change", redrawDurationGraph);
132+
}
133+
initPassFailGraph(url);
134+
if (url == "")
135+
initDurationGraph(url);
136+
}
137+
138+
document.querySelectorAll('.robot-expand').forEach(function(element) {
139+
element.addEventListener('click', function(event) {
140+
event.preventDefault();
141+
showStackTrace(event.target.dataset.escapedName, event.target.dataset.relativeId);
142+
});
143+
});
144+
145+
document.querySelectorAll('.robot-collapse').forEach(function(element) {
146+
element.addEventListener('click', function(event) {
147+
event.preventDefault();
148+
hideStackTrace(event.target.dataset.escapedName);
149+
});
150+
});
151+
});

0 commit comments

Comments
 (0)