1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-10 20:26:48 +00:00

feat(instances): the VM lists follow changes by themselves

A VM list showed what it read when it was loaded: a VM stopped from
inside its guest or with virsh, or made or removed elsewhere, showed only
after a reload, unlike the VM page, which reloads when its VM's state
changes. The lists of all VMs and of one host's VMs now poll the states
of their VMs, at once and then every 5 s as the VM page does, and reload
when an answer differs from the one before. The states come from one
libvirt call per host; a user who does not see hosts gets only their own
VMs. The page in use (a dialog, a field, an unsaved XML edit, a job
outcome shown) holds the reload until it is free; that check is shared
with the job panel.
This commit is contained in:
catborise 2026-11-01 19:37:33 +03:00
parent f88deb22c1
commit eb6e6ca626
15 changed files with 276 additions and 11 deletions

View file

@ -120,14 +120,6 @@ function jobPanel(element, urls, csrfToken, initialIds) {
return job.state === "succeeded" && !result.warning && !(result.left_behind || []).length;
}
// a dialog open, a field in use or an XML edit not saved: its outcome waits in the panel, with Refresh
function interacting() {
var active = document.activeElement;
return !!document.querySelector(".modal.show")
|| !!(active && active.matches && active.matches("input, select, textarea"))
|| !!(window.xmlEditUnsaved && window.xmlEditUnsaved());
}
function fetchOutcome(id) {
if (inflight[id]) { return; }
inflight[id] = true;
@ -140,7 +132,8 @@ function jobPanel(element, urls, csrfToken, initialIds) {
delete pending[id];
// only when no other job runs, is shown or awaited: a reload would lose its outcome
var others = Object.keys(outcomes).length + Object.keys(pending).length + Object.keys(shown).length;
if (quiet(job) && !interacting() && !others) {
// the page in use (poll.js): its outcome waits in the panel, with Refresh
if (quiet(job) && !pageInUse() && !others) {
window.location.reload(); // the job is not remembered again: no loop
return;
}