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

fix(tags): the Tags page lists the tags by name and has a search box

The list counts each tag's VMs and hosts; a query with a count leaves
the model's ordering out, so the tags came in the order they were made.
With dozens of tags the page also gets the search box the other
administration lists have.
This commit is contained in:
catborise 2026-11-19 13:36:39 +03:00
parent a5d0dbfe66
commit 0a99713dda
7 changed files with 103 additions and 63 deletions

View file

@ -1,5 +1,6 @@
{% extends "base.html" %}
{% load i18n %}
{% load static %}
{% load bootstrap_icons %}
{% block title %}{% trans "Tags" %}{% endblock %}
@ -11,30 +12,43 @@
{% if not tags %}
<div class="alert alert-info shadow-sm">{% bs_icon 'info-circle' %} {% trans "No tags yet" %}</div>
{% else %}
<div class="table-responsive">
<table class="table table-hover align-middle" data-sortable>
<thead>
<tr>
<th scope="col">{% trans "Tag" %}</th>
<th scope="col" data-sort-method="number">{% trans "VMs" %}</th>
<th scope="col" data-sort-method="number">{% trans "Hosts" %}</th>
<th scope="col" data-sort-method="none"><span class="visually-hidden">{% trans "Actions" %}</span></th>
</tr>
</thead>
<tbody>
{% for tag in tags %}
<tr>
<td>{% include 'common/tag_badge.html' with tag=tag.name %}</td>
<td>{{ tag.vm_count }}</td>
<td>{{ tag.host_count }}</td>
<td class="text-end text-nowrap">
<a class="btn btn-sm btn-outline-secondary" href="{% url 'admin:tag_update' tag.id %}">{% trans "Rename" %}</a>
<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:tag_delete' tag.id %}">{% trans "Delete" %}</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="card mb-3">
<div class="card-header d-flex flex-wrap align-items-center gap-2">
<span class="me-auto">{% trans "Tags" %} <span class="badge text-bg-light border">{{ tags|length }}</span></span>
<input id="filter" class="form-control form-control-sm w-auto" type="search" placeholder="{% trans "Search" %}" aria-label="{% trans "Search tags" %}">
</div>
<div class="table-responsive">
<table class="table table-hover align-middle mb-0" data-sortable>
<thead>
<tr>
<th scope="col">{% trans "Tag" %}</th>
<th scope="col" data-sort-method="number">{% trans "VMs" %}</th>
<th scope="col" data-sort-method="number">{% trans "Hosts" %}</th>
<th scope="col" data-sort-method="none"><span class="visually-hidden">{% trans "Actions" %}</span></th>
</tr>
</thead>
<tbody class="searchable">
{% for tag in tags %}
<tr data-search="{{ tag.name }}">
<td>{% include 'common/tag_badge.html' with tag=tag.name %}</td>
<td>{{ tag.vm_count }}</td>
<td>{{ tag.host_count }}</td>
<td class="text-end text-nowrap">
<a class="btn btn-sm btn-outline-secondary" href="{% url 'admin:tag_update' tag.id %}">{% trans "Rename" %}</a>
<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:tag_delete' tag.id %}">{% trans "Delete" %}</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div role="status">
<div id="no-match" class="text-center text-body-secondary py-3" hidden>{% trans "No tag matches the search." %}</div>
</div>
</div>
{% endif %}
{% endblock content %}
{% block script %}
{% if tags %}<script src="{% static 'js/table_filter.js' %}"></script>{% endif %}
{% endblock script %}