1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 08:56:07 +00:00

feat(ui): the owner and VM lists of the ownership forms are searchable

The VM page's Add owner and a user's Add VM page listed every user and
every VM in a plain drop-down: with 800 users and 300 VMs one was found
by scrolling. They now have a search box (Tom Select, already used by the
create form), through searchable_select.js for a select with
data-searchable.

The box loses focus once an item is chosen: focused, it is a line taller,
and on a phone the tap on Save shrank it and moved the button away from
under the finger, so the first tap did nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-10 09:15:43 +03:00
parent 0368d94f27
commit aefe551450
8 changed files with 44 additions and 2 deletions

View file

@ -15,7 +15,7 @@
{# users who are not owners yet; a superuser can use every VM #}
{% if users %}
<label class="form-label" for="add-owner-user">{% trans "User" %}</label>
<select class="form-select" name="user_id" id="add-owner-user">
<select class="form-select" name="user_id" id="add-owner-user" data-searchable>
{% for user in users %}
<option value="{{ user.id }}">{{ user.username }}</option>
{% endfor %}

View file

@ -7,6 +7,10 @@
{% block title %}{% trans "Instance" %} - {{ instance.name }}{% endblock %}
{% block style %}
{% if request.user.is_superuser and users %}<link href="{% static 'css/tom-select.bootstrap5.min.css' %}" rel="stylesheet">{% endif %}
{% endblock style %}
{% block page_header %}{% endblock page_header %}{# the card below has the heading #}
{% block content %}
@ -126,6 +130,10 @@
{% endblock %}
{% block script %}
{% if request.user.is_superuser and users %}{# Add owner's user list #}
<script src="{% static 'js/tom-select.complete.min.js' %}"></script>
<script src="{% static 'js/searchable_select.js' %}"></script>
{% endif %}
<script src="{% static 'js/ace/ace.js' %}" type="text/javascript" charset="utf-8"></script>
<script src="{% static 'js/xml_editor.js' %}"></script>
<script src="{% static 'js/chart.umd.min.js' %}"></script>

View file

@ -270,6 +270,11 @@ class PendingEditsTestCase(TestCase):
[f"/instances/{self.instance.id}/#users"] * 2)
# not an owner yet and not an administrator, who can use every VM anyway
self.assertEqual(doc.xpath("//select[@id='add-owner-user']/option/text()"), ["pe-new"])
# a search box for a list of every user (searchable_select.js)
self.assertEqual(doc.xpath("//select[@id='add-owner-user']/@data-searchable"), [""])
self.assertIn("/static/js/searchable_select.js", doc.xpath("//script/@src"))
User.objects.filter(username="pe-new").delete() # no one left to add: no search box to load
self.assertNotIn("/static/js/searchable_select.js", self.page().xpath("//script/@src"))
def test_a_paused_vm_offers_to_turn_vcpus_on_only(self):
# unplugging a vCPU needs the guest, which a paused VM does not run