forked from maplesteve/JiraTestResultReporter
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-74232][JENKINS-74235] Extract inline JavaScript (#183)
- Loading branch information
1 parent
9e142bb
commit 5a2d45c
Showing
3 changed files
with
129 additions
and
90 deletions.
There are no files selected for viewing
111 changes: 25 additions & 86 deletions
111
src/main/resources/org/jenkinsci/plugins/JiraTestResultReporter/JiraTestAction/badge.jelly
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 |
---|---|---|
@@ -1,90 +1,29 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:l="/lib/layout"> | ||
<script> | ||
/* | ||
Create a map of proxies, since this file will be included once for every test | ||
*/ | ||
if (typeof proxyMap === 'undefined') { | ||
var proxyMap = []; | ||
} | ||
proxyMap["${it}"] = <st:bind value="${it}"/>; | ||
</script> | ||
|
||
<j:choose> | ||
<j:when test="${ it.issueKey == null and it.isTestFailing() == true }"> | ||
<l:icon class="icon-notepad icon-sm" onclick="hideshow(document.getElementById('jira-${it}'))" style="cursor:pointer"/> No issue | ||
<img src="${imagesURL}/spinner.gif" id="spinner-${it}" style="display:none"/> | ||
<div id="jira-${it}" style="display:none"> | ||
<a href="#jira" onClick="createNewIssue(document.getElementById('spinner-${it}'), '${it}', document.getElementById('jiraErrors-${it}'))">Create new issue</a><br/> | ||
Or <input field="key" id="issueKeyInput-${it}" type="text" value="${it.issueKey}"/> | ||
<img src="${resURL}/plugin/JiraTestResultReporter/submit.png" height="16" width="16" style="cursor:pointer" | ||
onClick="doSubmit(document.getElementById('issueKeyInput-${it}'), document.getElementById('spinner-${it}'), '${it}', document.getElementById('jiraErrors-${it}'))" /> | ||
<st:include page="helpIssueKeyInput.jelly" /> | ||
<div id="jiraErrors-${it}"/> | ||
</div> | ||
</j:when> | ||
<j:when test="${ it.issueKey != null }"> | ||
<st:nbsp/><img src="${resURL}/plugin/JiraTestResultReporter/remove.png" onClick="doClear('${it}')" height="16" width="16" style="cursor:pointer"/><st:nbsp/> | ||
<a href="${it.issueUrl}" title="${it.issueSummary}" target="_blank">${it.issueKey}</a> | ||
<st:nbsp/><st:include page="issueStatus.jelly"/> | ||
</j:when> | ||
</j:choose><st:nbsp/> | ||
|
||
|
||
<script> | ||
function hideshow(which){ | ||
if (!document.getElementById) | ||
return; | ||
if (which.style.display=="block") | ||
which.style.display="none"; | ||
else | ||
which.style.display="block"; | ||
} | ||
|
||
|
||
function doSubmit(issueLink, spinner, proxyString, errorsDiv) { | ||
if(!issueLink.value) | ||
return; | ||
spinner.style.display="inline"; | ||
var proxy = proxyMap[proxyString]; | ||
proxy.setIssueKey(issueLink.value, function(t) { | ||
if(t.responseText != "null") { | ||
spinner.style.display="none" | ||
applyErrorMessage(errorsDiv, t); | ||
} | ||
else { | ||
location.reload(); | ||
} | ||
}); | ||
} | ||
|
||
|
||
function doClear(proxyString) { | ||
var proxy = proxyMap[proxyString]; | ||
proxy.clearIssueKey(function(t) { | ||
location.reload(); | ||
}) | ||
} | ||
|
||
function createNewIssue(spinner, proxyString, errorsDiv) { | ||
spinner.style.display="inline"; | ||
var proxy = proxyMap[proxyString]; | ||
var socketTimeout = setTimeout( function() { | ||
spinner.style.display="none"; | ||
errorsDiv.innerHTML = "Error: Socket Timeout. The issue was probably created, but the server did not respond in a timely manner. Check JIRA to avoid creating duplicated issues."; | ||
}, 30000); | ||
proxy.createIssue( function(t) { | ||
clearTimeout(socketTimeout); | ||
if(t.responseText != "null") { | ||
spinner.style.display="none"; | ||
applyErrorMessage(errorsDiv, t); | ||
} | ||
else { | ||
location.reload(); | ||
} | ||
}); | ||
} | ||
|
||
</script> | ||
|
||
<span class="jira-test-action-container"> | ||
<st:adjunct includes="org.jenkinsci.plugins.JiraTestResultReporter.JiraTestAction.resource"/> | ||
<j:set var="proxyKey" value="jiraTestActionProxy${h.generateId()}"/> | ||
<span class="jira-test-action-data-holder" data-proxy-key="${proxyKey}"/> | ||
<st:bind value="${it}" var="${proxyKey}"/> | ||
<j:choose> | ||
<j:when test="${ it.issueKey == null and it.isTestFailing() == true }"> | ||
<l:icon class="icon-notepad icon-sm jira-create-issue-icon" style="cursor:pointer"/> No issue | ||
<img src="${imagesURL}/spinner.gif" class="jira-create-issue-spinner" style="display:none"/> | ||
<div class="jira-create-new-issue-section" style="display:none"> | ||
<a href="#jira" class="jira-create-new-issue-button">Create new issue</a><br/> | ||
Or <input field="key" class="jira-issue-key-input" type="text" value="${it.issueKey}"/> | ||
<img src="${resURL}/plugin/JiraTestResultReporter/submit.png" height="16" width="16" style="cursor:pointer" | ||
class="jira-create-new-issue-submit"/> | ||
<st:include page="helpIssueKeyInput.jelly" /> | ||
<div class="jira-create-issue-validation"/> | ||
</div> | ||
</j:when> | ||
<j:when test="${ it.issueKey != null }"> | ||
<st:nbsp/><img src="${resURL}/plugin/JiraTestResultReporter/remove.png" class="jira-unlink-issue" height="16" width="16" style="cursor:pointer"/><st:nbsp/> | ||
<a href="${it.issueUrl}" title="${it.issueSummary}" target="_blank">${it.issueKey}</a> | ||
<st:nbsp/><st:include page="issueStatus.jelly"/> | ||
</j:when> | ||
</j:choose><st:nbsp/> | ||
</span> | ||
</j:jelly> |
6 changes: 2 additions & 4 deletions
6
...urces/org/jenkinsci/plugins/JiraTestResultReporter/JiraTestAction/helpIssueKeyInput.jelly
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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout"> | ||
|
||
<l:icon class="icon-help icon-sm" style="cursor:pointer" onclick="hideshow(document.getElementById('help-issueKeyInput-${it}'))" /> | ||
<div id="help-issueKeyInput-${it}" class="help" style="display:none">Link an existing issue to this test. Insert a valid issue key. (ex. TST-256)</div> | ||
|
||
<l:icon class="icon-help icon-sm jira-toggle-issue-key-help" style="cursor:pointer" /> | ||
<div class="help help-issue-key-input" style="display:none">Link an existing issue to this test. Insert a valid issue key. (ex. TST-256)</div> | ||
</j:jelly> |
102 changes: 102 additions & 0 deletions
102
src/main/resources/org/jenkinsci/plugins/JiraTestResultReporter/JiraTestAction/resource.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,102 @@ | ||
function hideshow(which) { | ||
if (which.style.display == "block") { | ||
which.style.display = "none"; | ||
} else { | ||
which.style.display = "block"; | ||
} | ||
} | ||
|
||
function doSubmit(issueLink, spinner, proxyKey, errorsDiv) { | ||
if (!issueLink.value) { | ||
return; | ||
} | ||
spinner.style.display = "inline"; | ||
var proxy = window[proxyKey]; | ||
proxy.setIssueKey(issueLink.value, function (t) { | ||
if (t.responseText != undefined) { | ||
spinner.style.display = "none"; | ||
updateValidationArea(errorsDiv, t.responseText); | ||
} else { | ||
location.reload(); | ||
} | ||
}); | ||
} | ||
|
||
function doClear(proxyKey) { | ||
var proxy = window[proxyKey]; | ||
proxy.clearIssueKey(function (t) { | ||
location.reload(); | ||
}); | ||
} | ||
|
||
function createNewIssue(spinner, proxyKey, errorsDiv) { | ||
spinner.style.display = "inline"; | ||
var proxy = window[proxyKey]; | ||
var socketTimeout = setTimeout(function () { | ||
spinner.style.display = "none"; | ||
errorsDiv.innerHTML = "Error: Socket Timeout. The issue was probably created, but the server did not respond in a timely manner. Check JIRA to avoid creating duplicated issues."; | ||
}, 30000); | ||
proxy.createIssue(function (t) { | ||
clearTimeout(socketTimeout); | ||
if (t.responseText != undefined) { | ||
spinner.style.display = "none"; | ||
updateValidationArea(errorsDiv, t.responseText); | ||
} else { | ||
location.reload(); | ||
} | ||
}); | ||
} | ||
|
||
window.addEventListener("DOMContentLoaded", () => { | ||
document.querySelectorAll(".jira-create-issue-icon").forEach((icon) => { | ||
icon.addEventListener("click", (event) => { | ||
const parent = event.target.closest(".jira-test-action-container"); | ||
const createIssueDiv = parent.querySelector(".jira-create-new-issue-section"); | ||
|
||
hideshow(createIssueDiv); | ||
}); | ||
}); | ||
|
||
document.querySelectorAll(".jira-create-new-issue-button").forEach((button) => { | ||
button.addEventListener("click", (event) => { | ||
event.preventDefault(); | ||
|
||
const parent = event.target.closest(".jira-test-action-container"); | ||
const { proxyKey } = parent.querySelector(".jira-test-action-data-holder").dataset; | ||
const spinner = parent.querySelector(".jira-create-issue-spinner"); | ||
const validationArea = parent.querySelector(".jira-create-issue-validation"); | ||
|
||
createNewIssue(spinner, proxyKey, validationArea); | ||
}); | ||
}); | ||
|
||
document.querySelectorAll(".jira-create-new-issue-submit").forEach((element) => { | ||
element.addEventListener("click", (event) => { | ||
const parent = event.target.closest(".jira-test-action-container"); | ||
const { proxyKey } = parent.querySelector(".jira-test-action-data-holder").dataset; | ||
const issueKeyInput = parent.querySelector(".jira-issue-key-input"); | ||
const spinner = parent.querySelector(".jira-create-issue-spinner"); | ||
const validationArea = parent.querySelector(".jira-create-issue-validation"); | ||
|
||
doSubmit(issueKeyInput, spinner, proxyKey, validationArea); | ||
}); | ||
}); | ||
|
||
document.querySelectorAll(".jira-unlink-issue").forEach((element) => { | ||
element.addEventListener("click", (event) => { | ||
const parent = event.target.closest(".jira-test-action-container"); | ||
const { proxyKey } = parent.querySelector(".jira-test-action-data-holder").dataset; | ||
|
||
doClear(proxyKey); | ||
}); | ||
}); | ||
|
||
document.querySelectorAll(".jira-toggle-issue-key-help").forEach((icon) => { | ||
icon.addEventListener("click", (event) => { | ||
const parent = event.target.closest(".jira-test-action-container"); | ||
const helpDiv = parent.querySelector(".help-issue-key-input"); | ||
|
||
hideshow(helpDiv); | ||
}); | ||
}); | ||
}); |