Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed Mar 30, 2023
1 parent b687d55 commit 3301d35
Show file tree
Hide file tree
Showing 19 changed files with 423 additions and 325 deletions.
17 changes: 10 additions & 7 deletions core/src/main/resources/hudson/PluginManager/installed.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,17 @@ THE SOFTWARE.
btn = Event.element(o);

<!-- trigger -->
new Ajax.Request(btn.getAttribute('url')+"/make"+(btn.checked?"Enable":"Disable")+"d", {
method: "POST",
onFailure : function(req,o) {
$('needRestart').innerHTML = req.responseText;
fetch(btn.getAttribute('url')+"/make"+(btn.checked?"Enable":"Disable")+"d", {
method: 'post',
headers: {
[document.head.dataset.crumbHeader]: document.head.dataset.crumbValue
},
}).then(rsp => {
if (!rsp.ok) {
$('needRestart').innerHTML = req.responseText;
}
});

updateMsg();
updateMsg();
})
}

function updateMsg() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@

var urlToTest = redirectForm.getAttribute("data-url");
var callUrlToTest = function (testWithContext, callback) {
var options = {
onComplete: callback,
};
var body = null;
if (testWithContext === true) {
options.parameters = { testWithContext: true };
body = new URLSearchParams({ testWithContext: "true" });
}
new Ajax.Request(urlToTest, options);
fetch(urlToTest, {
cache: 'no-cache',
headers: {
[document.head.dataset.crumbHeader]: document.head.dataset.crumbValue
},
body
}).then(rsp => callback(rsp))
.catch(rsp => callback(rsp))
};

var displayWarningMessage = function (withContextMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function getData(eventSource1, current, min, max) {
},
}
).then((t) => {
if (t.status !== 0) {
if (t.ok) {
t.json()
.then((json) => {
eventSource1.loadJSON(json, ".");
Expand Down
54 changes: 31 additions & 23 deletions core/src/main/resources/hudson/model/UpdateCenter/update-center.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,41 @@ Behaviour.specify(

function refresh() {
window.setTimeout(function () {
new Ajax.Request("./body", {
onSuccess: function (rsp) {
var div = document.createElement("div");
div.innerHTML = rsp.responseText;
fetch('./body')
.then(rsp => {
{
if (rsp.ok) {
rsp.text()
.then(responseText => {
var div = document.createElement("div");
div.innerHTML = responseText;

var rows = div.children[0].rows;
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var target = document.getElementById(row.id);
if (target == null) {
document.getElementById("log").appendChild(row);
} else {
var tcell = target.cells[1];
var scell = row.cells[1];
if (scell.id != tcell.id) {
tcell.innerHTML = scell.innerHTML;
tcell.id = scell.id;
}
var rows = div.children[0].rows;
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var target = document.getElementById(row.id);
if (target == null) {
document.getElementById("log").appendChild(row);
} else {
var tcell = target.cells[1];
var scell = row.cells[1];
if (scell.id !== tcell.id) {
tcell.innerHTML = scell.innerHTML;
tcell.id = scell.id;
}
}
}
var scheduleDiv = document.getElementById("scheduleRestartBlock");
scheduleDiv.innerHTML = div.lastElementChild.innerHTML;
Behaviour.applySubtree(scheduleDiv);
refresh();
})
}
}
var scheduleDiv = document.getElementById("scheduleRestartBlock");
scheduleDiv.innerHTML = div.lastElementChild.innerHTML;
Behaviour.applySubtree(scheduleDiv);
refresh();
},
});
})

}, 5000);
}

window.scrollTo(0, 10000);
refresh();
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Behaviour.specify(
var icon = document.getElementById(id);

icon.onclick = function () {
new Ajax.Request(url);
// TODO what is this doing? this is just ignored? is it notifying if url succeeded?
fetch(url)
hoverNotification(message, this, -100);
return false;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
}
close();
}

function onEscClose(e) {
var escapeKeyCode = 27;
if (e.keyCode === escapeKeyCode) {
Expand All @@ -31,20 +32,23 @@
options.closeAll();
}

new Ajax.Request(url, {
method: "GET",
onSuccess: function (rsp) {
var popupContent = rsp.responseText;
amList.innerHTML = popupContent;
amMonitorRoot.classList.add("visible");
document.addEventListener("click", onClose);
document.addEventListener("keydown", onEscClose);

// Applies all initialization code to the elements within the popup
// Among other things, this sets the CSRF crumb to the forms within
Behaviour.applySubtree(amList);
},
});
fetch(url)
.then(rsp => {
if (rsp.ok) {
rsp.text()
.then(responseText => {
var popupContent = responseText;
amList.innerHTML = popupContent;
amMonitorRoot.classList.add("visible");
document.addEventListener("click", onClose);
document.addEventListener("keydown", onEscClose);

// Applies all initialization code to the elements within the popup
// Among other things, this sets the CSRF crumb to the forms within
Behaviour.applySubtree(amList);
})
}
})
}

function close() {
Expand Down
149 changes: 80 additions & 69 deletions core/src/main/resources/jenkins/security/ApiTokenProperty/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,27 @@ window.revokeToken = function (anchorRevoke) {
var tokenUuid = inputUuid.value;

if (confirm(confirmMessage)) {
new Ajax.Request(targetUrl, {
method: "post",
parameters: { tokenUuid: tokenUuid },
onSuccess: function () {
if (repeatedChunk.querySelectorAll(".legacy-token").length > 0) {
// we are revoking the legacy token
var messageIfLegacyRevoked = anchorRevoke.getAttribute(
"data-message-if-legacy-revoked"
);

var legacyInput = document.getElementById("apiToken");
legacyInput.value = messageIfLegacyRevoked;
}
repeatedChunk.remove();
adjustTokenEmptyListMessage(tokenList);
fetch(targetUrl, {
body: new URLSearchParams({ tokenUuid: tokenUuid }),
method: 'post',
headers: {
[document.head.dataset.crumbHeader]: document.head.dataset.crumbValue
},
});
}).then(rsp => {
if (rsp.ok) {
if (repeatedChunk.querySelectorAll(".legacy-token").length > 0) {
// we are revoking the legacy token
var messageIfLegacyRevoked = anchorRevoke.getAttribute(
"data-message-if-legacy-revoked"
);

var legacyInput = document.getElementById("apiToken");
legacyInput.value = messageIfLegacyRevoked;
}
repeatedChunk.remove();
adjustTokenEmptyListMessage(tokenList);
}
})
}

return false;
Expand All @@ -65,60 +69,67 @@ window.saveApiToken = function (button) {
var nameInput = repeatedChunk.querySelector('[name="tokenName"]');
var tokenName = nameInput.value;

new Ajax.Request(targetUrl, {
method: "post",
parameters: { newTokenName: tokenName },
onSuccess: function (rsp) {
var json = rsp.responseJSON;
var errorSpan = repeatedChunk.querySelector(".error");
if (json.status === "error") {
errorSpan.innerHTML = json.message;
errorSpan.addClassName("visible");

button.removeClassName("request-pending");
} else {
errorSpan.removeClassName("visible");

var tokenName = json.data.tokenName;
// in case the name was empty, the application will propose a default one
nameInput.value = tokenName;

var tokenValue = json.data.tokenValue;
var tokenValueSpan = repeatedChunk.querySelector(".new-token-value");
tokenValueSpan.innerText = tokenValue;
tokenValueSpan.addClassName("visible");

// show the copy button
var tokenCopyButton = repeatedChunk.querySelector(
".jenkins-copy-button"
);
tokenCopyButton.setAttribute("text", tokenValue);
tokenCopyButton.removeClassName("jenkins-hidden");

var tokenUuid = json.data.tokenUuid;
var uuidInput = repeatedChunk.querySelector('[name="tokenUuid"]');
uuidInput.value = tokenUuid;

var warningMessage = repeatedChunk.querySelector(
".display-after-generation"
);
warningMessage.addClassName("visible");

// we do not want to allow user to create twice a token using same name by mistake
button.remove();

var revokeButton = repeatedChunk.querySelector(".token-revoke");
revokeButton.removeClassName("hidden-button");

var cancelButton = repeatedChunk.querySelector(".token-cancel");
cancelButton.addClassName("hidden-button");

repeatedChunk.addClassName("token-list-fresh-item");

adjustTokenEmptyListMessage(tokenList);
}
fetch(targetUrl, {
body: new URLSearchParams({ newTokenName: tokenName }),
method: 'post',
headers: {
[document.head.dataset.crumbHeader]: document.head.dataset.crumbValue
},
});
}).then(rsp => {
if (rsp.ok) {
rsp.json()
.then(json => {
var errorSpan = repeatedChunk.querySelector(".error");
if (json.status === "error") {
errorSpan.innerHTML = json.message;
errorSpan.addClassName("visible");

button.removeClassName("request-pending");
} else {
errorSpan.removeClassName("visible");

var tokenName = json.data.tokenName;
// in case the name was empty, the application will propose a default one
nameInput.value = tokenName;

var tokenValue = json.data.tokenValue;
var tokenValueSpan = repeatedChunk.querySelector(".new-token-value");
tokenValueSpan.innerText = tokenValue;
tokenValueSpan.addClassName("visible");

// show the copy button
var tokenCopyButton = repeatedChunk.querySelector(
".jenkins-copy-button"
);
tokenCopyButton.setAttribute("text", tokenValue);
tokenCopyButton.removeClassName("jenkins-hidden");

var tokenUuid = json.data.tokenUuid;
var uuidInput = repeatedChunk.querySelector('[name="tokenUuid"]');
uuidInput.value = tokenUuid;

var warningMessage = repeatedChunk.querySelector(
".display-after-generation"
);
warningMessage.addClassName("visible");

// we do not want to allow user to create twice a token using same name by mistake
button.remove();

var revokeButton = repeatedChunk.querySelector(".token-revoke");
revokeButton.removeClassName("hidden-button");

var cancelButton = repeatedChunk.querySelector(".token-cancel");
cancelButton.addClassName("hidden-button");

repeatedChunk.addClassName("token-list-fresh-item");

adjustTokenEmptyListMessage(tokenList);
}
})
}
})

};

function adjustTokenEmptyListMessage(tokenList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,21 @@ window.confirmAndRevokeAllSelected = function (button) {
selectedValues.push({ userId: userId, uuid: uuid });
}

var params = { values: selectedValues };
new Ajax.Request(url, {
postBody: Object.toJSON(params),
contentType: "application/json",
encoding: "UTF-8",
onComplete: function () {
window.location.reload();
},
});
// Workaround prototype.js breaking JSON.stringify
// Given this page is isolated, it's safe to not restore these after to the prototype version
delete Array.prototype.toJSON;
delete Object.prototype.toJSON;
delete Hash.prototype.toJSON;
delete String.prototype.toJSON;

fetch(url, {
method: "post",
body: JSON.stringify({ values: selectedValues }),
headers: {
'Content-Type': "application/json",
[document.head.dataset.crumbHeader]: document.head.dataset.crumbValue
}
}).then(() => window.location.reload())
}
}
};
Expand Down
Loading

0 comments on commit 3301d35

Please sign in to comment.