1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +00:00

fix(ui): a block or a job's cancel asks first; every delete and save says it is done

- Block in the Users list asks first: the user is signed out and their
  API tokens are deleted, which unblocking does not bring back. Block
  and Unblock then say what they did.
- Cancel on a job's page and in the job panel asks first, naming the
  job; the button says Cancel the job, apart from the dialog's Cancel.
- Deleting a user or a group, removing a host from the panel or an
  owner from a VM, and deleting an interface, a network filter or a
  secret say so, as the other deletes do.
- Renaming a tag and saving a VM's title and description say so.
This commit is contained in:
catborise 2026-11-21 20:47:26 +03:00
parent 00a44f7621
commit e79817e7db
22 changed files with 247 additions and 39 deletions

View file

@ -1,6 +1,7 @@
// Reloads the page while it shows an active job, so the page follows the job to its end.
setInterval(function () {
if (!document.hidden && !document.querySelector("form :focus")) {
// not while a form is filled in or a dialog asks (a job's Cancel)
if (!document.hidden && !document.querySelector("form :focus, .modal.show")) {
window.location.reload();
}
}, 5000);

View file

@ -67,7 +67,7 @@ function jobPanel(element, urls, csrfToken, initialIds, states, text) {
function jobHtml(job) {
var cancel = job.cancellable ? '<button type="button" class="btn btn-sm btn-outline-danger" data-cancel="'
+ esc(job.id) + '"' + (cancelling[job.id] ? " disabled" : "") + ">" + esc(text.cancel) + "</button>" : "";
+ esc(job.id) + '" data-label="' + esc(job.label) + '"' + (cancelling[job.id] ? " disabled" : "") + ">" + esc(text.cancel) + "</button>" : "";
// an uncertain job keeps its claims, so it stays in the list with its error
return alertHtml(job.state, header(job.label, job.state, job.phase, cancel) + errorHtml(job) + bar(job));
}
@ -190,7 +190,12 @@ function jobPanel(element, urls, csrfToken, initialIds, states, text) {
if (t.dataset.refresh) { window.location.reload(); }
if (t.dataset.dismiss) { dismissed[t.dataset.dismiss] = true; delete outcomes[t.dataset.dismiss]; render(); }
if (t.dataset.dismissError) { notice = ""; render(); }
if (t.dataset.cancel && !cancelling[t.dataset.cancel]) { cancel(t.dataset.cancel); }
// asked first (confirm_dialog.js); the list may be drawn again meanwhile
if (t.dataset.cancel && !cancelling[t.dataset.cancel]) {
var id = t.dataset.cancel;
confirmAction(text.cancel, text.cancel_confirm.replace("%(job)s", t.dataset.label), true,
function () { if (!cancelling[id]) { cancel(id); } }, t);
}
});
function cancel(id) {

View file

@ -28,7 +28,8 @@
{% if job.cancellable %}
<form method="post" action="{% url 'operations:cancel' job.id %}" aria-label="{% trans 'Cancel job form' %}">
{% csrf_token %}
<button class="btn btn-sm btn-outline-warning" type="submit">{% trans "Cancel" %}</button>
<button class="btn btn-sm btn-outline-warning" type="submit"
data-confirm="{% blocktrans with job=job.label %}Cancel {{ job }}? It stops where it is.{% endblocktrans %}">{% trans "Cancel the job" %}</button>
</form>
{% endif %}
</div>

View file

@ -87,7 +87,8 @@ def job_panel_script(context, resource):
"remembered": take_remembered(context["request"], resource),
"states": {state: str(label) for state, label in STATE_LABELS.items()},
"text": {
"cancel": gettext("Cancel"),
"cancel": gettext("Cancel the job"),
"cancel_confirm": gettext("Cancel %(job)s? It stops where it is."),
"open": pgettext("verb", "Open"),
"refresh": gettext("Refresh"),
"dismiss": gettext("Dismiss"),

View file

@ -53,7 +53,7 @@ const urls = { resource: "/r", job: (id) => "/j/" + id, cancel: (id) => "/c/" +
// the labels and texts the page gives (job_panel_script), here as in English
const STATES = { queued: "queued", running: "running", cancelling: "cancelling", succeeded: "succeeded",
failed: "failed", cancelled: "cancelled", uncertain: "uncertain" };
const TEXT = { cancel: "Cancel", open: "Open", refresh: "Refresh", dismiss: "Dismiss", finishing: "Finishing\u2026",
const TEXT = { cancel: "Cancel", cancel_confirm: "Cancel %(job)s?", open: "Open", refresh: "Refresh", dismiss: "Dismiss", finishing: "Finishing\u2026",
not_removed: "Files not removed:", short_operation: "A short operation is in progress.",
worker_unavailable: "Worker unavailable, last seen", never: "never",
cancel_failed: "Cancel failed (HTTP %(status)s).",
@ -224,9 +224,15 @@ const queued = { ...running, id: "q", state: "queued", cancellable: true, progre
jobPanel(el9, urls, "tok", undefined, STATES, TEXT);
advance(0);
answer("/r", { ...empty, jobs: [queued] });
assert.ok(el9.innerHTML.includes('data-cancel="q">Cancel</button>'), "an enabled cancel button");
click9({ target: { dataset: { cancel: "q" } } });
assert.ok(el9.innerHTML.includes('data-cancel="q" disabled>'), "disabled while the request runs");
assert.ok(el9.innerHTML.includes('data-cancel="q" data-label="' + queued.label + '">Cancel</button>'), "an enabled cancel button");
// asked first (confirm_dialog.js): nothing is sent until it is confirmed
let asked = [];
global.confirmAction = (action, question, danger, act) => asked.push({ action, question, act });
click9({ target: { dataset: { cancel: "q", label: queued.label } } });
assert.deepStrictEqual(asked.map((a) => [a.action, a.question]), [["Cancel", "Cancel " + queued.label + "?"]]);
assert.ok(!open.some((r) => r.url === "/c/q"), "not cancelled before it is confirmed");
asked[0].act();
assert.ok(el9.innerHTML.includes('data-label="' + queued.label + '" disabled>'), "disabled while the request runs");
answer("/c/q", { status: 400, responseJSON: { detail: "This job cannot be cancelled once it has started" } }, false);
assert.ok(el9.innerHTML.includes("This job cannot be cancelled once it has started")
&& el9.innerHTML.includes('class="alert alert-danger'), "the server's reason shows");
@ -238,7 +244,8 @@ click9({ target: { dataset: { dismissError: "1" } } });
assert.ok(!el9.innerHTML.includes("cannot be cancelled"), "the reason can be dismissed");
advance(3000);
answer("/r", { ...empty, jobs: [queued] });
click9({ target: { dataset: { cancel: "q" } } });
click9({ target: { dataset: { cancel: "q", label: queued.label } } });
asked[asked.length - 1].act();
answer("/c/q", { status: 0 }, false);
assert.ok(el9.innerHTML.includes("could not be reached"), "a network error shows");