Skip to content

Commit

Permalink
[JENKINS-73883] Un-inline JavaScript in history.jelly and `index.je…
Browse files Browse the repository at this point in the history
…lly` (#338)
  • Loading branch information
shlomomdahan authored Oct 10, 2024
1 parent bf43db6 commit c123a55
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<h1>${%Agent Configuration History}</h1>
<div>

<script src="${rootURL}/plugin/jobConfigHistory/deleteRevisionAndTableEntry.js"/>
<st:adjunct includes="hudson.plugins.jobConfigHistory.deleteRevisionAndTableEntry" />
<j:set var="configs" value="${it.getAgentConfigs()}" />
<j:choose>
<j:when test="${configs.size() == 0}">
Expand Down Expand Up @@ -111,7 +111,7 @@
<j:if test="${it.hasDeleteEntryPermission()}">
<td style="text-align:center">
<j:set var="message" value="${%Do you really want to delete the history entry} "/>
<button type="button" class="jch delete-button" onClick="removeEntryFromTable('table-row-${configNr}', '${config.date}', 'null', '${message}')" value="X">
<button type="button" class="jch delete-button agent-config-history-delete-button" data-config-nr="${configNr}" data-config-date="${config.date}" data-message-text="${message}" value="X">
<l:icon class="icon-stop icon-sm" alt="${%Delete Revision}"/>
</button>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<l:main-panel>
<l:app-bar title="${%Job Configuration History}"/>
<div>
<script src="${rootURL}/plugin/jobConfigHistory/deleteRevisionAndTableEntry.js" />
<st:adjunct includes="hudson.plugins.jobConfigHistory.deleteRevisionAndTableEntry" />
<j:set var="defaultEntriesPerPage" value="${it.getMaxEntriesPerPage()}" />
<j:set var="pageNum" value="${request.getParameter('pageNum')}" />
<j:set var="entriesPerPage" value="${request.getParameter('entriesPerPage')}" />
Expand Down Expand Up @@ -131,7 +131,7 @@
<td style="text-align:center">
<j:if test="${it.hasDeleteEntryPermission()}">
<j:set var="message" value="${%Do you really want to delete the history entry} " />
<button type="button" class="jenkins-button jenkins-button--destructive" onClick="removeEntryFromTable('table-row-${configNr}', '${config.date}', 'null', '${message}')" value="X">
<button type="button" class="jenkins-button jenkins-button--destructive system-config-history-delete-button" data-config-nr="${configNr}" data-config-date="${config.date}" data-message-text="${message}" value="X">
<l:icon src="symbol-trash-outline plugin-ionicons-api" class="icon-md" alt="${%Delete Revision}" />
</button>
</j:if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</j:otherwise>
</j:choose>

<script src="${rootURL}/plugin/jobConfigHistory/deleteRevisionAndTableEntry.js" />
<st:adjunct includes="hudson.plugins.jobConfigHistory.deleteRevisionAndTableEntry" />
<div>
<j:choose>
<j:when test="${!it.hasConfigurePermission() and !isDeleted}">
Expand Down Expand Up @@ -133,15 +133,7 @@
<j:if test="${it.hasDeleteEntryPermission() and !config.operation.toString().equals(&quot;Deleted&quot;)}">
<j:set var="message" value="${%Do you really want to delete the history entry} " />
<div id="target-div" jobName="${config.getJob()}">
<script>
var targetDiv = document.querySelector('#target-div');
var JsJobName = targetDiv.getAttribute('jobName');

function removeEntryFromTable2(JsConfigNr, JsConfigDate, JsMessage){
removeEntryFromTable('table-row-' + JsConfigNr, JsConfigDate, JsJobName, JsMessage)
}
</script>
<button type="button" class="jenkins-button jenkins-button--destructive" data-config-date="${config.date}" onClick="removeEntryFromTable2('${configNr}', this.getAttribute('data-config-date'), '${message}')" value="X">
<button type="button" class="jenkins-button jenkins-button--destructive system-config-history-delete-button" data-config-nr="${configNr}" data-config-date="${config.date}" data-message-text="${message}" value="X">
<l:icon src="symbol-trash-outline plugin-ionicons-api" class="icon-md" alt="${%Delete Revision}" />
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//name is an optional parameter for job deletion history and system config history
function removeEntryFromTable(id, timestamp, name, message) {
var confirmPhrase = message + timestamp + '?';
if (confirm(confirmPhrase)) {
var tableRow = document.getElementById(id);
tableRow.parentNode.removeChild(tableRow);

//redirect
var xmlHttp = new XMLHttpRequest();
var url = 'deleteRevision?timestamp=' + timestamp;
if (name != null) {
url += "&name=" + name;
}
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader(document.head.getAttribute('data-crumb-header'), document.head.getAttribute('data-crumb-value'));
xmlHttp.send(null);
}
}

document.addEventListener('DOMContentLoaded', function () {
const targetDiv = document.querySelector('#target-div');
let jobName = null;
if (targetDiv) {
jobName = targetDiv.getAttribute('jobName');
}

const systemConfigDeleteButtons = document.querySelectorAll('.system-config-history-delete-button');
systemConfigDeleteButtons.forEach((button) => {
button.addEventListener('click', () => {
const configNr = button.getAttribute('data-config-nr');
const configDate = button.getAttribute('data-config-date');
const message = button.getAttribute('data-message-text');
removeEntryFromTable(`table-row-${configNr}`, configDate, jobName, message);
});
});

const agentConfigDeleteButtons = document.querySelectorAll('.agent-config-history-delete-button');
agentConfigDeleteButtons.forEach((button) => {
button.addEventListener('click', () => {
const configNr = button.getAttribute('data-config-nr');
const configDate = button.getAttribute('data-config-date');
const message = button.getAttribute('data-message-text');
removeEntryFromTable(`table-row-${configNr}`, configDate, null, message);
});
});
});
20 changes: 0 additions & 20 deletions src/main/webapp/deleteRevisionAndTableEntry.js

This file was deleted.

0 comments on commit c123a55

Please sign in to comment.