-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-73964] Extract event handlers in `MultiJobTestResults/index.…
…jelly` (#376)
- Loading branch information
1 parent
56b5bcb
commit 6633374
Showing
2 changed files
with
58 additions
and
26 deletions.
There are no files selected for viewing
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
55 changes: 55 additions & 0 deletions
55
...urces/com/tikal/jenkins/plugins/multijob/MultiJobTestResults/show-hide-failure-summary.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,55 @@ | ||
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(summaryId + SHOWLINK_SUFFIX).style.display = "none"; | ||
document.getElementById(summaryId + HIDELINK_SUFFIX).style.display = ""; | ||
|
||
if (typeof query !== 'undefined' && element.innerHTML.trim() === 'Loading...') { | ||
let rqo = new XMLHttpRequest(); | ||
rqo.open('GET', query, true); | ||
rqo.onreadystatechange = function() { | ||
element.innerHTML = rqo.responseText; | ||
initializeShowHideLinks(element); | ||
} | ||
rqo.send(null); | ||
} | ||
|
||
} | ||
|
||
function hideFailureSummary(summaryId) { | ||
document.getElementById(summaryId).style.display = "none"; | ||
document.getElementById(summaryId + SHOWLINK_SUFFIX).style.display = ""; | ||
document.getElementById(summaryId + HIDELINK_SUFFIX).style.display = "none"; | ||
} | ||
|
||
function initializeShowHideLinks(container) { | ||
container = container || document; | ||
|
||
container.querySelectorAll('a[id$="-showlink"], a[id$="-hidelink"]').forEach(link => { | ||
link.addEventListener('click', handleShowHideClick); | ||
link.style.cursor = 'pointer'; | ||
}); | ||
} | ||
|
||
function handleShowHideClick(event) { | ||
event.preventDefault(); | ||
|
||
let link = event.target.closest('a[id$="-showlink"], a[id$="-hidelink"]'); | ||
const id = link.id.replace(/-showlink$/, '').replace(/-hidelink$/, ''); | ||
const queryUrl = link.dataset.queryUrl; | ||
|
||
if (link.id.endsWith('-showlink')) { | ||
showFailureSummary(id, queryUrl); | ||
} else { | ||
hideFailureSummary(id); | ||
} | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
initializeShowHideLinks(); | ||
}); |