mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 08:56:07 +00:00
fix(instances): the VM list's bulk actions show in a bar while VMs are chosen
The actions on the chosen VMs stood above the table at all times, as two rows of disabled buttons and empty text boxes. They are now a bar at the foot of the window that appears once a VM is chosen and names how many are. The snapshot name and the tag are asked in small menus of the bar, and the table's head has the box that chooses the VMs shown.
This commit is contained in:
parent
85c727d397
commit
3167cf12fe
9 changed files with 92 additions and 41 deletions
|
|
@ -58,38 +58,50 @@
|
|||
{% include 'common/tag_filter.html' %}
|
||||
{% if powerable %}
|
||||
{# the VMs chosen in the list (bulk_power_box.html), a job each (instances.jobs.POWER); bulk_power.js counts those on screen #}
|
||||
<form id="bulk-power" class="d-flex flex-wrap align-items-center gap-2 mb-2" action="{% url 'instances:bulk_power' %}" method="post">{% csrf_token %}{% submission_key %}
|
||||
<div class="form-check mb-0">
|
||||
<input class="form-check-input" type="checkbox" id="bulk-power-shown">
|
||||
<label class="form-check-label" for="bulk-power-shown">{% trans "Choose the VMs shown" %}</label>
|
||||
{# and shows this bar at the foot of the window while any is chosen #}
|
||||
<form id="bulk-power" class="fixed-bottom bg-body border-top shadow-lg py-2" action="{% url 'instances:bulk_power' %}" method="post"
|
||||
aria-label="{% trans "The chosen VMs" %}" hidden>{% csrf_token %}{% submission_key %}
|
||||
<div class="container d-flex flex-wrap align-items-center gap-2">
|
||||
<span class="fw-semibold me-2" id="bulk-power-count" data-text="{% trans "%(count)s chosen" %}"
|
||||
data-too-many="{% blocktrans with max=bulk_max %}%(count)s chosen: at most {{ max }} at once{% endblocktrans %}" data-max="{{ bulk_max }}" aria-live="polite"></span>
|
||||
<div class="btn-group btn-group-sm" role="group" aria-label="{% trans "Power the chosen VMs" %}">
|
||||
<button type="submit" class="btn btn-outline-primary" name="action" value="start">{% trans "Start" %}</button>
|
||||
<button type="submit" class="btn btn-outline-primary" name="action" value="shutdown"
|
||||
data-confirm="{% trans "Shut down the chosen VMs? Their guests are asked to power off." %}">{% trans "Shut down" %}</button>
|
||||
<button type="submit" class="btn btn-outline-danger" name="action" value="force_off"
|
||||
data-confirm="{% trans "Force off the chosen VMs? They stop at once, as if unplugged, and may lose unsaved data." %}">{% trans "Force off" %}</button>
|
||||
</div>
|
||||
{% if snapshotable %}
|
||||
{# external, without memory and without freezing file systems: the VM's Snapshots tab has those choices #}
|
||||
<div class="dropup">
|
||||
<button type="button" class="btn btn-sm btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown" data-bs-auto-close="outside"
|
||||
aria-expanded="false">{% trans "Snapshot" %}</button>
|
||||
<div class="dropdown-menu p-3" style="width: 20rem">
|
||||
<label class="form-label" for="bulk-snapshot-name">{% trans "Snapshot name" %}</label>
|
||||
<div class="input-group input-group-sm">
|
||||
<input class="form-control" type="text" name="snapshot_name" id="bulk-snapshot-name" maxlength="64" aria-describedby="bulk-snapshot-help">
|
||||
<button type="submit" class="btn btn-primary" name="action" value="snapshot" formaction="{% url 'instances:bulk_snapshot' %}">{% trans "Take snapshots" %}</button>
|
||||
</div>
|
||||
<div class="form-text" id="bulk-snapshot-help">{% trans "An external snapshot of each chosen VM, without memory and without freezing its file systems" %}</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if request.user.is_superuser %}
|
||||
{# tags are a superuser's, as on the VM's Settings tab #}
|
||||
<div class="dropup">
|
||||
<button type="button" class="btn btn-sm btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown" data-bs-auto-close="outside"
|
||||
aria-expanded="false">{% trans "Tag" %}</button>
|
||||
<div class="dropdown-menu p-3" style="width: 20rem">
|
||||
<label class="form-label" for="bulk-tag">{% trans "Tag" %}</label>
|
||||
<input class="form-control form-control-sm mb-2" type="text" name="tag" id="bulk-tag" list="bulk-tag-names">
|
||||
<datalist id="bulk-tag-names">{% for tag in tag_names %}<option value="{{ tag }}">{% endfor %}</datalist>
|
||||
<button type="submit" class="btn btn-sm btn-primary" name="action" value="tag_add" formaction="{% url 'instances:bulk_tag' %}">{% trans "Add tag" %}</button>
|
||||
<button type="submit" class="btn btn-sm btn-outline-secondary" name="action" value="tag_remove" formaction="{% url 'instances:bulk_tag' %}">{% trans "Remove tag" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<button type="button" class="btn btn-sm btn-link ms-auto" id="bulk-power-clear">{% trans "Clear the choice" %}</button>
|
||||
</div>
|
||||
<span class="small text-body-secondary" id="bulk-power-count" data-text="{% trans "%(count)s chosen" %}"
|
||||
data-too-many="{% blocktrans with max=bulk_max %}%(count)s chosen: at most {{ max }} at once{% endblocktrans %}" data-max="{{ bulk_max }}" aria-live="polite"></span>
|
||||
<div class="btn-group btn-group-sm" role="group" aria-label="{% trans "Power the chosen VMs" %}">
|
||||
<button type="submit" class="btn btn-outline-primary" name="action" value="start" disabled>{% trans "Start" %}</button>
|
||||
<button type="submit" class="btn btn-outline-primary" name="action" value="shutdown" disabled
|
||||
data-confirm="{% trans "Shut down the chosen VMs? Their guests are asked to power off." %}">{% trans "Shut down" %}</button>
|
||||
<button type="submit" class="btn btn-outline-danger" name="action" value="force_off" disabled
|
||||
data-confirm="{% trans "Force off the chosen VMs? They stop at once, as if unplugged, and may lose unsaved data." %}">{% trans "Force off" %}</button>
|
||||
</div>
|
||||
{% if snapshotable %}
|
||||
{# external, without memory and without freezing file systems: the VM's Snapshots tab has those choices #}
|
||||
<div class="input-group input-group-sm w-auto">
|
||||
<input class="form-control" type="text" name="snapshot_name" maxlength="64" placeholder="{% trans "Snapshot name" %}"
|
||||
aria-label="{% trans "Snapshot name" %}" style="width: 10rem">
|
||||
<button type="submit" class="btn btn-outline-primary" name="action" value="snapshot" formaction="{% url 'instances:bulk_snapshot' %}" disabled
|
||||
title="{% trans "An external snapshot of each chosen VM, without memory and without freezing its file systems" %}">{% trans "Take snapshots" %}</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if request.user.is_superuser %}
|
||||
{# tags are a superuser's, as on the VM's Settings tab #}
|
||||
<div class="input-group input-group-sm w-auto">
|
||||
<input class="form-control" type="text" name="tag" id="bulk-tag" list="bulk-tag-names" placeholder="{% trans "Tag" %}" aria-label="{% trans "Tag" %}" style="width: 9rem">
|
||||
<datalist id="bulk-tag-names">{% for tag in tag_names %}<option value="{{ tag }}">{% endfor %}</datalist>
|
||||
<button type="submit" class="btn btn-outline-primary" name="action" value="tag_add" formaction="{% url 'instances:bulk_tag' %}" disabled>{% trans "Add tag" %}</button>
|
||||
<button type="submit" class="btn btn-outline-secondary" name="action" value="tag_remove" formaction="{% url 'instances:bulk_tag' %}" disabled>{% trans "Remove tag" %}</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endif %}
|
||||
<div id="filter-status" class="visually-hidden" role="status" data-text="{% trans "%(shown)s of %(all)s VMs match" %}"></div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<table class="table table-hover align-middle" data-sortable>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" data-sort-method="none">
|
||||
<th scope="col" data-sort-method="none" class="text-nowrap">
|
||||
{% if powerable %}<input class="form-check-input" type="checkbox" id="bulk-power-shown" aria-label="{% trans "Choose the VMs shown" %}">{% endif %}
|
||||
<button type="button" class="btn btn-sm btn-link p-0" id="hide-all-instances" aria-expanded="true"
|
||||
aria-label="{% trans "Collapse or expand every host" %}">{% bs_icon 'arrows-collapse' %}</button>
|
||||
</th>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<table class="table table-hover align-middle" data-sortable>
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" data-sort-method="none"><span class="visually-hidden">{% trans "Chosen" %}</span></th>
|
||||
<th scope="col" data-sort-method="none">{% if powerable %}<input class="form-check-input" type="checkbox" id="bulk-power-shown" aria-label="{% trans "Choose the VMs shown" %}">{% else %}<span class="visually-hidden">{% trans "Chosen" %}</span>{% endif %}</th>
|
||||
<th scope="col">{% trans 'Name' %}</th>
|
||||
{% if show_hosts %}
|
||||
<th scope="col">{% trans 'Host' %}</th>
|
||||
|
|
|
|||
|
|
@ -198,6 +198,9 @@ class BulkPowerTestCase(TransactionTestCase):
|
|||
(form,) = page.xpath("//form[@id='bulk-power']")
|
||||
self.assertEqual(form.get("action"), reverse("instances:bulk_power"))
|
||||
self.assertEqual(form.xpath(".//button[@name='action'][not(@formaction)]/@value"), ["start", "shutdown", "force_off"])
|
||||
# a bar shown while VMs are chosen; the table's head chooses those shown
|
||||
self.assertIsNotNone(form.get("hidden"))
|
||||
self.assertTrue(page.xpath("//thead//input[@id='bulk-power-shown']"))
|
||||
# an owner: a box on their own VM only
|
||||
owner = get_user_model().objects.create_user("bp-lister", password="pw")
|
||||
UserInstance.objects.create(instance=self.vms[1], user=owner)
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -13108,3 +13108,11 @@ msgstr "IPv6 adresi"
|
|||
#: interfaces/forms.py
|
||||
msgid "IPv6 gateway"
|
||||
msgstr "IPv6 ağ geçidi"
|
||||
|
||||
#: instances/templates/allinstances.html
|
||||
msgid "The chosen VMs"
|
||||
msgstr "Seçilen sanal makineler"
|
||||
|
||||
#: instances/templates/allinstances.html
|
||||
msgid "Clear the choice"
|
||||
msgstr "Seçimi temizle"
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -12279,3 +12279,11 @@ msgstr "IPv6 地址"
|
|||
#: interfaces/forms.py
|
||||
msgid "IPv6 gateway"
|
||||
msgstr "IPv6 网关"
|
||||
|
||||
#: instances/templates/allinstances.html
|
||||
msgid "The chosen VMs"
|
||||
msgstr "所选的虚拟机"
|
||||
|
||||
#: instances/templates/allinstances.html
|
||||
msgid "Clear the choice"
|
||||
msgstr "清除选择"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// The VM list's bulk power form. Only the chosen VMs on screen count: one a
|
||||
// The VM list's bulk action bar. 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.
|
||||
|
|
@ -14,12 +14,28 @@
|
|||
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) : "";
|
||||
form.querySelectorAll("button[name='action']").forEach(function (button) { button.disabled = tooMany; });
|
||||
count.textContent = (tooMany ? count.dataset.tooMany : count.dataset.text).replace("%(count)s", chosen);
|
||||
count.classList.toggle("text-danger", tooMany);
|
||||
// the bar at the window's foot, while any VM is chosen; the page ends above it
|
||||
form.hidden = chosen === 0;
|
||||
if (form.hidden) {
|
||||
document.body.style.removeProperty("padding-bottom");
|
||||
} else { // over base.html's pb-5
|
||||
document.body.style.setProperty("padding-bottom", form.offsetHeight + "px", "important");
|
||||
}
|
||||
shown.disabled = boxes.length === 0;
|
||||
shown.checked = boxes.length > 0 && chosen === boxes.length;
|
||||
shown.indeterminate = chosen > 0 && chosen < boxes.length;
|
||||
}
|
||||
document.getElementById("bulk-power-clear").addEventListener("click", function () {
|
||||
document.querySelectorAll("input[name='vm'][form='bulk-power']").forEach(function (box) { box.checked = false; });
|
||||
update();
|
||||
});
|
||||
// a menu of the bar opens on its text box
|
||||
form.addEventListener("shown.bs.dropdown", function (event) {
|
||||
event.target.parentElement.querySelector("input[type='text']").focus();
|
||||
});
|
||||
shown.addEventListener("change", function () {
|
||||
var choose = shown.checked;
|
||||
onScreen().forEach(function (box) { box.checked = choose; });
|
||||
|
|
@ -40,12 +56,15 @@
|
|||
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
|
||||
// Enter in a text box would send the form with its first button, Start: in a snapshot's
|
||||
// name it takes the snapshots, in a tag (added or removed?) it sends nothing
|
||||
form.querySelectorAll("input[type='text']").forEach(function (box) {
|
||||
box.addEventListener("keydown", function (event) {
|
||||
if (event.key === "Enter") {
|
||||
if (event.key === "Enter" && !event.isComposing) { // not an input method's choice
|
||||
event.preventDefault();
|
||||
if (box.name === "snapshot_name") {
|
||||
form.querySelector("button[value='snapshot']").click();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -64,11 +83,11 @@
|
|||
update();
|
||||
})();
|
||||
|
||||
// whether VMs on screen are chosen, or a snapshot name or tag typed: the list's reload
|
||||
// whether VMs on screen are chosen, or a snapshot name or tag typed in the bar shown: 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']"),
|
||||
|| Array.prototype.some.call(document.querySelectorAll("#bulk-power:not([hidden]) input[type='text']"),
|
||||
function (box) { return box.value.trim() !== ""; });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue