From a27bbb3aa575adce5795248581c9faa9da7f2da5 Mon Sep 17 00:00:00 2001 From: lemorse Date: Mon, 24 Oct 2022 19:52:31 +0200 Subject: [PATCH 1/3] [JENKINS-69658] - failed-test.jelly javascript un-inlined. --- .../lib/hudson/test/failed-test.jelly | 7 ++----- .../lib/hudson/test/js/failureSummary.js | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/main/resources/lib/hudson/test/failed-test.jelly b/src/main/resources/lib/hudson/test/failed-test.jelly index 4fc5c9cba..391f01e33 100644 --- a/src/main/resources/lib/hudson/test/failed-test.jelly +++ b/src/main/resources/lib/hudson/test/failed-test.jelly @@ -60,13 +60,10 @@ THE SOFTWARE. } - - - - + - diff --git a/src/main/resources/lib/hudson/test/js/failureSummary.js b/src/main/resources/lib/hudson/test/js/failureSummary.js index 2ba8a909a..aae5b2e30 100644 --- a/src/main/resources/lib/hudson/test/js/failureSummary.js +++ b/src/main/resources/lib/hudson/test/js/failureSummary.js @@ -18,3 +18,24 @@ function hideFailureSummary(id) { document.getElementById(id + "-showlink").style.display = ""; document.getElementById(id + "-hidelink").style.display = "none"; } + + +document.addEventListener('DOMContentLoaded', (event) => { + + const testShowlinks = document.querySelectorAll("a[id*=-showlink]"); + testShowlinks.forEach((element) => { + element.onclick = (_) => { + const testId = element.id.replace('-showlink', ''); + showFailureSummary(testId, document.URL + "/summary"); + } + }); + + const testHidelinks = document.querySelectorAll("a[id*=-hidelink]"); + testHidelinks.forEach((element) => { + element.onclick = (_) => { + const testId = element.id.replace('-hidelink', ''); + hideFailureSummary(testId); + } + }); + +}); From 7e1486a9da14fe908202e40d4f27f5eb73f495b6 Mon Sep 17 00:00:00 2001 From: lemorse Date: Mon, 31 Oct 2022 19:31:35 +0100 Subject: [PATCH 2/3] [JENKINS-69658] - failed-test.jelly javascript improved! --- .../lib/hudson/test/js/failureSummary.js | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/main/resources/lib/hudson/test/js/failureSummary.js b/src/main/resources/lib/hudson/test/js/failureSummary.js index aae5b2e30..cd0c1b5ac 100644 --- a/src/main/resources/lib/hudson/test/js/failureSummary.js +++ b/src/main/resources/lib/hudson/test/js/failureSummary.js @@ -1,40 +1,50 @@ -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 = ""; + console.log(query); 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', (event) => { +document.addEventListener('DOMContentLoaded', () => { - const testShowlinks = document.querySelectorAll("a[id*=-showlink]"); + // add the onclick behavior for all the "showlinks" + const testShowlinks = document.querySelectorAll("a[id*=test-][id*=-showlink]"); testShowlinks.forEach((element) => { element.onclick = (_) => { - const testId = element.id.replace('-showlink', ''); - showFailureSummary(testId, document.URL + "/summary"); + const id = element.id.replace(PREFIX, '').replace(SHOWLINK_SUFFIX, ''); + const summaryId =PREFIX + id; + showFailureSummary(summaryId, document.URL + id + "summary"); } }); - const testHidelinks = document.querySelectorAll("a[id*=-hidelink]"); + // add the onclick behavior for all the "hidelinks" + const testHidelinks = document.querySelectorAll("a[id*=test-][id*=-hidelink]"); testHidelinks.forEach((element) => { element.onclick = (_) => { - const testId = element.id.replace('-hidelink', ''); - hideFailureSummary(testId); + const id = element.id.replace(PREFIX, '').replace(HIDELINK_SUFFIX, ''); + const summaryId = PREFIX + id; + hideFailureSummary(summaryId); } }); From 365f5aad6640ee9121ec990fb0f6103cc2f0f791 Mon Sep 17 00:00:00 2001 From: Tim Jacomb Date: Thu, 3 Oct 2024 15:34:28 +0100 Subject: [PATCH 3/3] Cleanup code --- .../lib/hudson/test/js/failureSummary.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/resources/lib/hudson/test/js/failureSummary.js b/src/main/resources/lib/hudson/test/js/failureSummary.js index ac0dbb135..f178bfaef 100644 --- a/src/main/resources/lib/hudson/test/js/failureSummary.js +++ b/src/main/resources/lib/hudson/test/js/failureSummary.js @@ -26,30 +26,22 @@ function hideFailureSummary(summaryId) { document.addEventListener('DOMContentLoaded', () => { - - // add the onclick behavior for all the "showlinks" const testShowlinks = document.querySelectorAll("a[id*=test-][id*=-showlink]"); testShowlinks.forEach((element) => { - element.onclick = (_) => { - console.log("testShowlinks clicked"); + element.addEventListener('click', (event) => { const id = element.id.replace(PREFIX, '').replace(SHOWLINK_SUFFIX, ''); const summaryId = PREFIX + id; - console.log(`testShowlinks url ${document.URL + id + 'summary'}`); 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.onclick = (_) => { - console.log("testHidelinks clicked"); + element.addEventListener('click', (event) => { const id = element.id.replace(PREFIX, '').replace(HIDELINK_SUFFIX, ''); const summaryId = PREFIX + id; hideFailureSummary(summaryId); - } + }) }); - - console.log("listeners added"); - });