1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 08:56:07 +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

@ -2,6 +2,7 @@
{% load i18n %}
{% load static %}
{% load operations %}
{% load bootstrap_icons %}
{% block title %}{% trans "Bulk Migrate" %} - {{ compute.name }}{% endblock %}
{% block page_heading %}{{ compute.name }} - {% trans "Bulk Migrate" %}{% endblock page_heading %}
@ -15,65 +16,69 @@
<div class="alert alert-warning shadow-sm">{% trans "There is no other host to migrate to." %}</div>
{% else %}
<p class="text-body-secondary">{% trans "Each chosen VM migrates in a job of its own: a running VM live, a shut-off one offline. A VM that fails stays on this host." %}</p>
{% if targets|length > 1 %}
{# another destination reloads the list: which VMs can go depends on it #}
<form method="get" class="mb-3">
<label class="form-label" for="bulk-migrate-target">{% trans "Destination" %}</label>
<select name="target" id="bulk-migrate-target" class="form-select w-auto">
{% for host in targets %}<option value="{{ host.pk }}"{% if host == target %} selected{% endif %}>{{ host.name }}</option>{% endfor %}
</select>
</form>
{% else %}
<p class="mb-3">{% trans "Destination" %}: <strong>{{ target.name }}</strong></p>
{% endif %}
<form method="get" id="bulk-migrate-choose"></form>
{% if not parallel %}
<div class="alert alert-warning shadow-sm">{% trans "The worker runs one job at a time: set Worker Concurrency to 2 or more on the Settings page." %}</div>
{% elif not instances %}
<div class="alert alert-info shadow-sm">{% trans "The host has no VMs." %}</div>
{% else %}
<form method="post">{% csrf_token %}{% submission_key %}
<form method="post" class="card shadow-sm">{% csrf_token %}{% submission_key %}
<input type="hidden" name="target" value="{{ target.pk }}">
<div class="form-check mb-2">
<input class="form-check-input" type="checkbox" id="bulk-migrate-shut-off">
<label class="form-check-label" for="bulk-migrate-shut-off">{% trans "Also migrate the shut-off VMs" %}</label>
<div class="card-header d-flex flex-wrap align-items-center gap-2">
<span class="fw-semibold">{{ compute.name }}</span> {% bs_icon 'arrow-right' %}
{% if targets|length > 1 %}
<select name="target" id="bulk-migrate-target" form="bulk-migrate-choose" class="form-select form-select-sm w-auto" aria-label="{% trans "Destination" %}">
{% for host in targets %}<option value="{{ host.pk }}"{% if host == target %} selected{% endif %}>{{ host.name }}</option>{% endfor %}
</select>
{% else %}
<span class="fw-semibold">{{ target.name }}</span>
{% endif %}
<div class="form-check form-switch ms-auto mb-0">
<input class="form-check-input" type="checkbox" role="switch" id="bulk-migrate-shut-off">
<label class="form-check-label small" for="bulk-migrate-shut-off">{% trans "Also migrate the shut-off VMs" %}</label>
</div>
</div>
<div class="table-responsive">
<table class="table table-hover align-middle">
<table class="table table-hover align-middle mb-0">
<thead>
<tr>
<th scope="col"><input class="form-check-input" type="checkbox" id="bulk-migrate-all" aria-label="{% trans "Select all" %}" title="{% trans "Select all" %}"></th>
<th scope="col" class="ps-3"><input class="form-check-input" type="checkbox" id="bulk-migrate-all" aria-label="{% trans "Select all" %}" title="{% trans "Select all" %}"></th>
<th scope="col">{% trans "Name" %}</th>
<th scope="col">{% trans "Status" %}</th>
<th scope="col">{% trans "VCPU" %}</th>
<th scope="col" class="text-end">{% trans "Memory" %}</th>
<th scope="col"></th>
<th scope="col" class="text-end">vCPU</th>
<th scope="col"><span class="visually-hidden">{% trans "Why" %}</span></th>
</tr>
</thead>
<tbody>
{% for instance in instances %}
<tr>
<td>
<td class="ps-3">
<input class="form-check-input" type="checkbox" name="instance" value="{{ instance.pk }}" id="bulk-migrate-{{ instance.pk }}"
{% if instance.info.0 == 5 %} data-shut-off{% elif not instance.refusal %} checked{% endif %}{% if instance.refusal %} disabled{% endif %}>
</td>
<td><label for="bulk-migrate-{{ instance.pk }}">{{ instance.name }}</label></td>
<td>{% include 'instance_state.html' %}</td>
<td>{{ instance.info.3 }}</td>
<td class="text-end">{% if instance.info %}{% widthratio instance.info.2 1024 1 %} MiB{% endif %}</td>
<td class="small text-danger">{{ instance.refusal|default:"" }}</td>
<td class="text-end text-nowrap">{% if instance.info %}{% widthratio instance.info.2 1 1024 as bytes %}{{ bytes|filesizeformat }}{% endif %}</td>
<td class="text-end">{{ instance.info.3 }}</td>
<td class="small text-body-secondary">{{ instance.refusal|default:"" }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="mb-3">
<label class="form-label" for="bulk-migrate-parallel">{% trans "Migrations at once" %}</label>
<select name="parallel" id="bulk-migrate-parallel" class="form-select w-auto">
{# kept in sight below a long list #}
<div class="card-footer sticky-bottom bg-body-tertiary d-flex flex-wrap align-items-center gap-2">
<label class="small text-body-secondary" for="bulk-migrate-parallel">{% trans "Migrations at once" %}</label>
<select name="parallel" id="bulk-migrate-parallel" class="form-select form-select-sm w-auto">
{% for n in parallel %}<option value="{{ n }}"{% if forloop.last %} selected{% endif %}>{{ n }}</option>{% endfor %}
</select>
{% blocktrans with source=compute.name dest=target.name asvar question %}Migrate the chosen VMs from {{ source }} to {{ dest }}?{% endblocktrans %}
<button type="submit" class="btn btn-primary ms-auto" id="bulk-migrate-submit" data-confirm="{{ question }}">
{% trans "Migrate the chosen VMs" %} <span class="badge text-bg-light" id="bulk-migrate-count"></span>
</button>
</div>
{% blocktrans with source=compute.name dest=target.name asvar question %}Migrate the chosen VMs from {{ source }} to {{ dest }}?{% endblocktrans %}
<button type="submit" class="btn btn-primary" data-confirm="{{ question }}">{% trans "Migrate" %}</button>
</form>
{% endif %}
{% endif %}

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)

Binary file not shown.

View file

@ -11,7 +11,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-11-16 05:10+0000\n"
"POT-Creation-Date: 2026-11-16 06:19+0000\n"
"PO-Revision-Date: 2020-11-04 12:00+0000\n"
"Last-Translator: catborise <muhammetalisag@gmail.com>, 2020\n"
"Language-Team: Turkish (https://www.transifex.com/catborise/teams/110663/tr/)\n"
@ -66,7 +66,7 @@ msgstr "Geçersiz anahtar"
#: accounts/forms.py:95 computes/templates/computes/balance.html:57
#: computes/templates/computes/balance.html:104
#: computes/templates/computes/bulk_migrate.html:45
#: computes/templates/computes/bulk_migrate.html:47
#: computes/templates/computes/instances.html:46
#: instances/templates/add_instance_volume.html:39
#: instances/templates/allinstances_index_grouped.html:11
@ -772,7 +772,7 @@ msgid "vCPUs"
msgstr "vCPU"
#: admin/forms.py:209 computes/templates/computes/balance.html:58
#: computes/templates/computes/bulk_migrate.html:48
#: computes/templates/computes/bulk_migrate.html:49
#: computes/templates/computes/instances.html:50
#: computes/templates/computes/list.html:62 computes/templates/overview.html:66
#: computes/templates/overview.html:150
@ -2120,7 +2120,7 @@ msgstr[0] "Önerilen taşımalar (%(counter)s)"
msgstr[1] "Önerilen taşımalar (%(counter)s)"
#: computes/templates/computes/balance.html:56
#: computes/templates/computes/bulk_migrate.html:44
#: computes/templates/computes/bulk_migrate.html:46
msgid "Select all"
msgstr "Tümünü seç"
@ -2129,7 +2129,7 @@ msgid "Migration"
msgstr "Taşıma"
#: computes/templates/computes/balance.html:81
#: computes/templates/computes/bulk_migrate.html:70
#: computes/templates/computes/bulk_migrate.html:73
msgid "Migrations at once"
msgstr "Aynı anda taşıma"
@ -2145,7 +2145,7 @@ msgid "Migrate the VMs listed?"
msgstr "Listelenen sanal makineler taşınsın mı?"
#: computes/templates/computes/balance.html:88
#: computes/templates/computes/bulk_migrate.html:30
#: computes/templates/computes/bulk_migrate.html:22
msgid ""
"The worker runs one job at a time: set Worker Concurrency to 2 or more on the"
" Settings page."
@ -2167,6 +2167,7 @@ msgid "Let it move"
msgstr "Taşınabilsin"
#: computes/templates/computes/balance.html:106
#: computes/templates/computes/bulk_migrate.html:51
msgid "Why"
msgstr "Neden"
@ -2174,17 +2175,17 @@ msgstr "Neden"
msgid "You kept it here: tick it to let it move"
msgstr "Yerinde tuttunuz: taşınabilmesi için işaretleyin"
#: computes/templates/computes/bulk_migrate.html:5
#: computes/templates/computes/bulk_migrate.html:6
#: computes/templates/computes/bulk_migrate.html:7
#: computes/templates/computes/instances.html:15
msgid "Bulk Migrate"
msgstr "Toplu Taşı"
#: computes/templates/computes/bulk_migrate.html:15 instances/views.py:379
#: computes/templates/computes/bulk_migrate.html:16 instances/views.py:379
msgid "There is no other host to migrate to."
msgstr "Taşınacak başka bir sunucu yok."
#: computes/templates/computes/bulk_migrate.html:17
#: computes/templates/computes/bulk_migrate.html:18
msgid ""
"Each chosen VM migrates in a job of its own: a running VM live, a shut-off "
"one offline. A VM that fails stays on this host."
@ -2192,44 +2193,35 @@ msgstr ""
"Seçilen her sanal makine kendi işinde taşınır: çalışan sanal makine canlı, "
"kapalı olan çevrimdışı. Taşınamayan sanal makine bu sunucuda kalır."
#: computes/templates/computes/bulk_migrate.html:21
#: computes/templates/computes/bulk_migrate.html:27
msgid "Destination"
msgstr "Hedef"
#: computes/templates/computes/bulk_migrate.html:32
#: computes/templates/computes/bulk_migrate.html:24
msgid "The host has no VMs."
msgstr "Bu sunucuda sanal makine yok."
#: computes/templates/computes/bulk_migrate.html:38
#: computes/templates/computes/bulk_migrate.html:31
msgid "Destination"
msgstr "Hedef"
#: computes/templates/computes/bulk_migrate.html:39
msgid "Also migrate the shut-off VMs"
msgstr "Kapalı sanal makineleri de taşı"
#: computes/templates/computes/bulk_migrate.html:46
#: computes/templates/computes/bulk_migrate.html:48
#: computes/templates/computes/instances.html:48
#: instances/templates/allinstances_index_grouped.html:12
#: instances/templates/allinstances_index_nongrouped.html:10
msgid "Status"
msgstr "Durum"
#: computes/templates/computes/bulk_migrate.html:47
#: computes/templates/computes/instances.html:49
msgid "VCPU"
msgstr "VCPU"
#: computes/templates/computes/bulk_migrate.html:75
#: computes/templates/computes/bulk_migrate.html:77
#, python-format
msgid "Migrate the chosen VMs from %(source)s to %(dest)s?"
msgstr ""
"Seçilen sanal makineler %(source)s sunucusundan %(dest)s sunucusuna taşınsın "
"mı?"
#: computes/templates/computes/bulk_migrate.html:76
#: instances/templates/instances/settings_tab.html:60
#: instances/templates/instances/settings_tab.html:617
#: instances/templates/instances/settings_tab.html:620
msgid "Migrate"
msgstr "Taşı"
#: computes/templates/computes/bulk_migrate.html:79
msgid "Migrate the chosen VMs"
msgstr "Seçilen sanal makineleri taşı"
#: computes/templates/computes/capacity_line.txt:2
#, python-format
@ -2473,6 +2465,10 @@ msgstr "Uyarı"
msgid "Hypervisor doesn't have any Instances"
msgstr "Hipervizör üzerinde hiç sanal makine yok"
#: computes/templates/computes/instances.html:49
msgid "VCPU"
msgstr "VCPU"
#: computes/templates/computes/instances.html:51
#: computes/templates/computes/list.html:63
#: instances/templates/allinstances_index_grouped.html:18
@ -5231,6 +5227,12 @@ msgstr "Ağ"
msgid "Host devices"
msgstr "Sunucu aygıtları"
#: instances/templates/instances/settings_tab.html:60
#: instances/templates/instances/settings_tab.html:617
#: instances/templates/instances/settings_tab.html:620
msgid "Migrate"
msgstr "Taşı"
#: instances/templates/instances/settings_tab.html:65
msgid "XML"
msgstr "XML"

Binary file not shown.

View file

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-11-16 05:10+0000\n"
"POT-Creation-Date: 2026-11-16 06:19+0000\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
@ -63,7 +63,7 @@ msgstr "无效的密钥"
#: accounts/forms.py:95 computes/templates/computes/balance.html:57
#: computes/templates/computes/balance.html:104
#: computes/templates/computes/bulk_migrate.html:45
#: computes/templates/computes/bulk_migrate.html:47
#: computes/templates/computes/instances.html:46
#: instances/templates/add_instance_volume.html:39
#: instances/templates/allinstances_index_grouped.html:11
@ -749,7 +749,7 @@ msgid "vCPUs"
msgstr "vCPU"
#: admin/forms.py:209 computes/templates/computes/balance.html:58
#: computes/templates/computes/bulk_migrate.html:48
#: computes/templates/computes/bulk_migrate.html:49
#: computes/templates/computes/instances.html:50
#: computes/templates/computes/list.html:62 computes/templates/overview.html:66
#: computes/templates/overview.html:150
@ -2038,7 +2038,7 @@ msgid_plural "Proposed migrations (%(counter)s)"
msgstr[0] "建议的迁移(%(counter)s)"
#: computes/templates/computes/balance.html:56
#: computes/templates/computes/bulk_migrate.html:44
#: computes/templates/computes/bulk_migrate.html:46
msgid "Select all"
msgstr "全选"
@ -2047,7 +2047,7 @@ msgid "Migration"
msgstr "迁移"
#: computes/templates/computes/balance.html:81
#: computes/templates/computes/bulk_migrate.html:70
#: computes/templates/computes/bulk_migrate.html:73
msgid "Migrations at once"
msgstr "同时迁移数"
@ -2062,7 +2062,7 @@ msgid "Migrate the VMs listed?"
msgstr "迁移列出的虚拟机?"
#: computes/templates/computes/balance.html:88
#: computes/templates/computes/bulk_migrate.html:30
#: computes/templates/computes/bulk_migrate.html:22
msgid ""
"The worker runs one job at a time: set Worker Concurrency to 2 or more on the"
" Settings page."
@ -2082,6 +2082,7 @@ msgid "Let it move"
msgstr "允许迁移"
#: computes/templates/computes/balance.html:106
#: computes/templates/computes/bulk_migrate.html:51
msgid "Why"
msgstr "原因"
@ -2089,58 +2090,49 @@ msgstr "原因"
msgid "You kept it here: tick it to let it move"
msgstr "您将其保留在原处:勾选后即可迁移"
#: computes/templates/computes/bulk_migrate.html:5
#: computes/templates/computes/bulk_migrate.html:6
#: computes/templates/computes/bulk_migrate.html:7
#: computes/templates/computes/instances.html:15
msgid "Bulk Migrate"
msgstr "批量迁移"
#: computes/templates/computes/bulk_migrate.html:15 instances/views.py:379
#: computes/templates/computes/bulk_migrate.html:16 instances/views.py:379
msgid "There is no other host to migrate to."
msgstr "没有其他可迁移到的主机。"
#: computes/templates/computes/bulk_migrate.html:17
#: computes/templates/computes/bulk_migrate.html:18
msgid ""
"Each chosen VM migrates in a job of its own: a running VM live, a shut-off "
"one offline. A VM that fails stays on this host."
msgstr "每台选中的虚拟机在各自的任务中迁移:运行中的虚拟机在线迁移,已关机的离线迁移。迁移失败的虚拟机留在此主机上。"
#: computes/templates/computes/bulk_migrate.html:21
#: computes/templates/computes/bulk_migrate.html:27
msgid "Destination"
msgstr "目标主机"
#: computes/templates/computes/bulk_migrate.html:32
#: computes/templates/computes/bulk_migrate.html:24
msgid "The host has no VMs."
msgstr "此主机没有虚拟机。"
#: computes/templates/computes/bulk_migrate.html:38
#: computes/templates/computes/bulk_migrate.html:31
msgid "Destination"
msgstr "目标主机"
#: computes/templates/computes/bulk_migrate.html:39
msgid "Also migrate the shut-off VMs"
msgstr "同时迁移已关机的虚拟机"
#: computes/templates/computes/bulk_migrate.html:46
#: computes/templates/computes/bulk_migrate.html:48
#: computes/templates/computes/instances.html:48
#: instances/templates/allinstances_index_grouped.html:12
#: instances/templates/allinstances_index_nongrouped.html:10
msgid "Status"
msgstr "状态"
#: computes/templates/computes/bulk_migrate.html:47
#: computes/templates/computes/instances.html:49
msgid "VCPU"
msgstr "VCPU"
#: computes/templates/computes/bulk_migrate.html:75
#: computes/templates/computes/bulk_migrate.html:77
#, python-format
msgid "Migrate the chosen VMs from %(source)s to %(dest)s?"
msgstr "将选中的虚拟机从 %(source)s 迁移到 %(dest)s?"
#: computes/templates/computes/bulk_migrate.html:76
#: instances/templates/instances/settings_tab.html:60
#: instances/templates/instances/settings_tab.html:617
#: instances/templates/instances/settings_tab.html:620
msgid "Migrate"
msgstr "迁移"
#: computes/templates/computes/bulk_migrate.html:79
msgid "Migrate the chosen VMs"
msgstr "迁移所选虚拟机"
#: computes/templates/computes/capacity_line.txt:2
#, python-format
@ -2373,6 +2365,10 @@ msgstr "警告"
msgid "Hypervisor doesn't have any Instances"
msgstr "虚拟机管理程序中没有任何虚拟机"
#: computes/templates/computes/instances.html:49
msgid "VCPU"
msgstr "VCPU"
#: computes/templates/computes/instances.html:51
#: computes/templates/computes/list.html:63
#: instances/templates/allinstances_index_grouped.html:18
@ -4970,6 +4966,12 @@ msgstr "网络"
msgid "Host devices"
msgstr "主机设备"
#: instances/templates/instances/settings_tab.html:60
#: instances/templates/instances/settings_tab.html:617
#: instances/templates/instances/settings_tab.html:620
msgid "Migrate"
msgstr "迁移"
#: instances/templates/instances/settings_tab.html:65
msgid "XML"
msgstr "XML"

View file

@ -1,11 +1,20 @@
// The Bulk Migrate page: another destination reloads the list; the header
// box ticks or unticks every VM that can migrate, "Also migrate the
// shut-off VMs" the shut-off ones.
// shut-off VMs" the shut-off ones. The Migrate button counts the ticked
// VMs and is off while none is.
function tick(selector, checked) {
document.querySelectorAll(selector).forEach(function (box) {
box.checked = checked;
});
}
function count() {
const ticked = document.querySelectorAll("input[name=instance]:checked").length;
const button = document.getElementById("bulk-migrate-submit");
if (button) {
button.disabled = ticked === 0;
document.getElementById("bulk-migrate-count").textContent = ticked;
}
}
document.getElementById("bulk-migrate-target")?.addEventListener("change", function (event) {
event.target.form.submit();
});
@ -15,3 +24,5 @@ document.getElementById("bulk-migrate-all")?.addEventListener("change", function
document.getElementById("bulk-migrate-shut-off")?.addEventListener("change", function (event) {
tick("input[data-shut-off]:not(:disabled)", event.target.checked);
});
document.addEventListener("change", count);
count();