Run manual diagnostic attachments in the background
This commit is contained in:
1 parent
d845a5e4b6
commit
89ac4d5bcd
40 files changed
+1560
-58
No files matched your search
@@ -0,0 +1,61 @@
|
||||
(() => {
|
||||
const form = document.getElementById("diagnostics-attach");
|
||||
const submit = document.getElementById("diagnostics-submit");
|
||||
const connection = document.getElementById("diagnostics-connection");
|
||||
const operation = () => document.getElementById("diagnostics-operation");
|
||||
const statusLink = connection.querySelector("a");
|
||||
let sending = false;
|
||||
|
||||
function updateSubmit() {
|
||||
const current = operation();
|
||||
if (current) {
|
||||
submit.disabled = sending || current.dataset.pending === "true";
|
||||
}
|
||||
}
|
||||
|
||||
document.body.addEventListener("htmx:configRequest", (event) => {
|
||||
const { triggeringEvent, parameters } = event.detail;
|
||||
if (triggeringEvent?.type === "diagnostics-changed") {
|
||||
parameters.operation = triggeringEvent.detail.operation;
|
||||
}
|
||||
});
|
||||
document.body.addEventListener("htmx:beforeRequest", (event) => {
|
||||
if (event.detail.elt === form) {
|
||||
if (sending || operation()?.dataset.pending === "true") {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
sending = true;
|
||||
connection.hidden = true;
|
||||
}
|
||||
});
|
||||
|
||||
document.body.addEventListener("htmx:afterSettle", (event) => {
|
||||
if (event.detail.elt.id === "diagnostics-operation") {
|
||||
updateSubmit();
|
||||
connection.hidden = true;
|
||||
}
|
||||
});
|
||||
document.body.addEventListener("htmx:afterRequest", (event) => {
|
||||
if (event.detail.requestConfig.elt === form) {
|
||||
sending = false;
|
||||
updateSubmit();
|
||||
}
|
||||
});
|
||||
|
||||
for (const name of ["htmx:sendError", "htmx:timeout", "htmx:responseError"]) {
|
||||
document.body.addEventListener(name, (event) => {
|
||||
const source = event.detail.requestConfig?.elt;
|
||||
if (source === form) {
|
||||
connection.firstElementChild.textContent = "Запуск пока не подтверждён. Можно повторить отправку.";
|
||||
statusLink.href = "/diagnostics?operation=" + encodeURIComponent(document.getElementById("diagnostics-key").value);
|
||||
statusLink.hidden = false;
|
||||
connection.hidden = false;
|
||||
} else if (source?.id === "diagnostics-operation") {
|
||||
connection.firstElementChild.textContent = "Связь со страницей статуса прервалась. Продолжаем проверять…";
|
||||
statusLink.hidden = true;
|
||||
connection.hidden = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
})();
|
||||
Reference in new issue
Block a user