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

fix(computes): the Bulk Migrate page keeps its list and button together

The page showed memory as MiB counts ("16768 MiB"), the destination and
the shut-off switch apart from the list, and a Migrate button below the
whole list that did not say how many VMs it would migrate. Now the list
is one card: "host -> destination" (a choice when there are several) and
the shut-off switch in its header, sizes as on the Computes and Balance
pages, and a footer that stays in sight below a long list with the
number at once and a "Migrate the chosen VMs" button that counts the
ticked VMs and is off while none is.
This commit is contained in:
catborise 2026-11-16 09:20:16 +03:00
parent 54487052e5
commit cf288a54cf
8 changed files with 120 additions and 90 deletions

View file

@ -89,7 +89,7 @@ class BulkMigratePageTests(TestCase):
def test_one_destination_is_named_and_several_are_a_choice(self):
self.assertEqual(self.page().xpath("//select[@name='target']"), [])
self.assertIn("ev-other", self.page().xpath("//strong/text()"))
self.assertIn("ev-other", self.page().xpath("//div[contains(@class, 'card-header')]/span/text()"))
Compute.objects.create(name="ev-third", hostname="198.51.100.32", login="", password="", type=4)
self.assertEqual(self.page().xpath("//select[@name='target']/option/text()"), ["ev-other", "ev-third"])

View file

@ -20,23 +20,29 @@ const boxes = [
];
const handlers = {};
const box = (id) => ({addEventListener: (name, fn) => { handlers[id] = fn; }});
const ids = {"bulk-migrate-all": box("all"), "bulk-migrate-shut-off": box("shut-off"), "bulk-migrate-target": box("target")};
const button = {disabled: false}, counter = {textContent: ""};
const ids = {"bulk-migrate-all": box("all"), "bulk-migrate-shut-off": box("shut-off"), "bulk-migrate-target": box("target"),
"bulk-migrate-submit": button, "bulk-migrate-count": counter};
let submitted = 0;
const selectors = {
"input[name=instance]:not(:disabled)": (b) => !b.disabled,
"input[data-shut-off]:not(:disabled)": (b) => b.shutOff && !b.disabled,
"input[name=instance]:checked": (b) => b.checked,
};
vm.runInNewContext(SCRIPT, vm.createContext({document: {
getElementById: (id) => ids[id],
querySelectorAll: (selector) => boxes.filter(selectors[selector]),
addEventListener: (name, fn) => { handlers.document = fn; },
}}));
const ticked = () => boxes.filter((b) => b.checked).map((b) => b.name);
const seen = [];
const seen = [], counts = [[counter.textContent, button.disabled]];
for (const [id, checked] of STEPS) {
handlers[id]({target: {checked, form: {submit: () => { submitted += 1; }}}});
handlers.document(); // the change bubbles to the page
seen.push(ticked());
counts.push([counter.textContent, button.disabled]);
}
console.log(JSON.stringify({seen, submitted}));
console.log(JSON.stringify({seen, submitted, counts}));
"""
@ -54,5 +60,9 @@ class BulkMigrateScriptTests(unittest.TestCase):
def test_the_shut_off_box_ticks_only_the_shut_off_vms(self):
self.assertEqual(self.run_script([["shut-off", True], ["shut-off", False]])["seen"], [["run", "off"], ["run"]])
def test_the_button_counts_the_ticked_vms_and_is_off_without_one(self):
self.assertEqual(self.run_script([["all", False], ["all", True]])["counts"],
[[1, False], [0, True], [2, False]])
def test_another_destination_reloads_the_list(self):
self.assertEqual(self.run_script([["target", False]])["submitted"], 1)