mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 17:06:09 +00:00
A download into a pool listed its volume while it was written. The page let a superuser copy it (the copy got a half-written file, live), attach it to a VM, or stop the pool under it. Now: - the copy job claims its source volume shared, and the worker refuses a copy whose name the source's format changed before the claim; - attaching an existing volume holds it exclusive from its first read, so neither a download nor a copy is under way, and its format is read after the download ended; - stopping or deleting a pool (page and API) holds the pool exclusive, and its backup target's claim if it is one; restores claim the pools they write into shared. Each is refused with the job in the way named, as a volume delete already was. The download recorded its progress every 16 MiB, so a slow server's bar stayed empty for a long time; it records it each second, with the cancel check. The worker checks the name is still free before it starts. A snapshot name or tag typed in the VM list's bulk form keeps the list from reloading, as a chosen VM did.
74 lines
3.8 KiB
JavaScript
74 lines
3.8 KiB
JavaScript
// The VM list's bulk power form. Only the chosen VMs on screen count: one a
|
|
// filter or a collapsed host hides is neither counted nor sent, so a VM chosen
|
|
// before the filters changed is not powered unseen. "Choose the VMs shown"
|
|
// chooses or clears those on screen, and shows whether all, some or none are.
|
|
(function () {
|
|
var form = document.getElementById("bulk-power");
|
|
var shown = document.getElementById("bulk-power-shown");
|
|
var count = document.getElementById("bulk-power-count");
|
|
function onScreen() {
|
|
return Array.prototype.filter.call(document.querySelectorAll("input[name='vm'][form='bulk-power']"),
|
|
function (box) { return box.getClientRects().length > 0; });
|
|
}
|
|
function update() {
|
|
var boxes = onScreen();
|
|
var chosen = boxes.filter(function (box) { return box.checked; }).length;
|
|
var tooMany = chosen > Number(count.dataset.max); // the server takes at most that many
|
|
form.querySelectorAll("button[name='action']").forEach(function (button) { button.disabled = chosen === 0 || tooMany; });
|
|
count.textContent = chosen ? (tooMany ? count.dataset.tooMany : count.dataset.text).replace("%(count)s", chosen) : "";
|
|
shown.disabled = boxes.length === 0;
|
|
shown.checked = boxes.length > 0 && chosen === boxes.length;
|
|
shown.indeterminate = chosen > 0 && chosen < boxes.length;
|
|
}
|
|
shown.addEventListener("change", function () {
|
|
var choose = shown.checked;
|
|
onScreen().forEach(function (box) { box.checked = choose; });
|
|
update();
|
|
});
|
|
// a box, the search, a state or tag pill or a host's collapse changes what is on screen; not
|
|
// "Choose the VMs shown" itself: its input event comes before its change, which chooses the boxes
|
|
function changed(event) {
|
|
if (event.target !== shown) {
|
|
setTimeout(update, 0);
|
|
}
|
|
}
|
|
["change", "input", "click"].forEach(function (type) { document.addEventListener(type, changed); });
|
|
// and a filter that answers later (the address search) hides rows by itself
|
|
var later = null;
|
|
new MutationObserver(function () {
|
|
clearTimeout(later);
|
|
later = setTimeout(update, 50);
|
|
}).observe(document.querySelector(".table-responsive") || document.body,
|
|
{attributes: true, attributeFilter: ["hidden", "class"], subtree: true});
|
|
// Enter in a text box (a tag, a snapshot's name) would send the form with its first button,
|
|
// Start: it sends nothing
|
|
form.querySelectorAll("input[type='text']").forEach(function (box) {
|
|
box.addEventListener("keydown", function (event) {
|
|
if (event.key === "Enter") {
|
|
event.preventDefault();
|
|
}
|
|
});
|
|
});
|
|
form.addEventListener("submit", function (event) {
|
|
document.querySelectorAll("input[name='vm'][form='bulk-power']:checked").forEach(function (box) {
|
|
if (!box.getClientRects().length) {
|
|
box.checked = false; // hidden: not sent
|
|
}
|
|
});
|
|
// counted again: rows may have come on screen since the buttons were last set
|
|
if (document.querySelectorAll("input[name='vm'][form='bulk-power']:checked").length > Number(count.dataset.max)) {
|
|
event.preventDefault();
|
|
update();
|
|
}
|
|
});
|
|
update();
|
|
})();
|
|
|
|
// whether VMs on screen are chosen, or a snapshot name or tag typed: the list's reload
|
|
// (poll.js pageInUse) waits meanwhile
|
|
function bulkPowerChosen() {
|
|
return Array.prototype.some.call(document.querySelectorAll("input[name='vm'][form='bulk-power']:checked"),
|
|
function (box) { return box.getClientRects().length > 0; })
|
|
|| Array.prototype.some.call(document.querySelectorAll("#bulk-power input[type='text']"),
|
|
function (box) { return box.value.trim() !== ""; });
|
|
}
|