Skip to content

Commit

Permalink
[JENKINS-69658] - failed-test.jelly javascript un-inlined. (#451)
Browse files Browse the repository at this point in the history
Co-authored-by: Basil Crow <me@basilcrow.com>
Co-authored-by: Tim Jacomb <timjacomb1@gmail.com>
  • Loading branch information
3 people authored Oct 3, 2024
1 parent ab878c3 commit 05e2505
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
9 changes: 4 additions & 5 deletions src/main/resources/lib/hudson/test/failed-test.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ THE SOFTWARE.
}
</style>
</st:once>

<j:set var="id" value="${h.htmlAttributeEscape(url)}"/>
<j:set var="idjs" value="${h.jsStringEscape(url)}"/>
<j:set var="open" value="showFailureSummary('test-${h.jsStringEscape(id)}','${idjs}/summary')"/>
<j:set var="close" value="hideFailureSummary('test-${h.jsStringEscape(id)}')"/>
<a id="test-${id}-showlink" onclick="${open}" title="${%Show details}">

<a id="test-${id}-showlink" title="${%Show details}">
<l:icon src="symbol-add-outline plugin-ionicons-api" class="icon-sm"/>
</a>
<a id="test-${id}-hidelink" onclick="${close}" title="${%Hide details}" style="display:none">
<a id="test-${id}-hidelink" title="${%Hide details}" style="display:none">
<l:icon src="symbol-remove-outline plugin-ionicons-api" class="icon-sm"/>
</a>
<st:nbsp/>
Expand Down
45 changes: 36 additions & 9 deletions src/main/resources/lib/hudson/test/js/failureSummary.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@

function showFailureSummary(id,query) {
var element = document.getElementById(id)
const PREFIX = "test-";
const SHOWLINK_SUFFIX = "-showlink";
const HIDELINK_SUFFIX = "-hidelink";

function showFailureSummary(summaryId, query) {
let element = document.getElementById(summaryId);

element.style.display = "";
document.getElementById(id + "-showlink").style.display = "none";
document.getElementById(id + "-hidelink").style.display = "";
document.getElementById(summaryId + SHOWLINK_SUFFIX).style.display = "none";
document.getElementById(summaryId + HIDELINK_SUFFIX).style.display = "";

if (typeof query !== 'undefined') {
var rqo = new XMLHttpRequest();
let rqo = new XMLHttpRequest();
rqo.open('GET', query, true);
rqo.onreadystatechange = function() { element.innerHTML = rqo.responseText; }
rqo.send(null);
}
}

function hideFailureSummary(id) {
document.getElementById(id).style.display = "none";
document.getElementById(id + "-showlink").style.display = "";
document.getElementById(id + "-hidelink").style.display = "none";
function hideFailureSummary(summaryId) {
document.getElementById(summaryId).style.display = "none";
document.getElementById(summaryId + SHOWLINK_SUFFIX).style.display = "";
document.getElementById(summaryId + HIDELINK_SUFFIX).style.display = "none";
}


document.addEventListener('DOMContentLoaded', () => {
const testShowlinks = document.querySelectorAll("a[id*=test-][id*=-showlink]");
testShowlinks.forEach((element) => {
element.addEventListener('click', (event) => {
const id = element.id.replace(PREFIX, '').replace(SHOWLINK_SUFFIX, '');
const summaryId = PREFIX + id;
showFailureSummary(summaryId, document.URL + id + "summary");
})
});

// add the onclick behavior for all the "hidelinks"
const testHidelinks = document.querySelectorAll("a[id*=test-][id*=-hidelink]");
testHidelinks.forEach((element) => {
element.addEventListener('click', (event) => {
const id = element.id.replace(PREFIX, '').replace(HIDELINK_SUFFIX, '');
const summaryId = PREFIX + id;
hideFailureSummary(summaryId);
})
});
});

0 comments on commit 05e2505

Please sign in to comment.