1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 17:06:09 +00:00

feat(tags): smaller tag badges, three on the VM list

Tag badges are smaller than other badges everywhere, and the VM list
shows a VM's first three tags and "…" for the others: it names them in
its tooltip and shows them when pressed, by mouse or keyboard. A VM with
many tags no longer widens the name column and the table with it; the
tag list still filters by any of them.
This commit is contained in:
catborise 2026-11-18 23:28:12 +03:00
parent b74e798e70
commit 7810fb39fe
11 changed files with 56 additions and 8 deletions

View file

@ -3,7 +3,7 @@
{# a VM's name, its title, and with owners its owners: the first as a badge, the others counted #}
<a class="fw-semibold text-break" href="{% url 'instances:instance' instance.id %}">{{ instance.name }}</a>
{% if instance.info and instance.title %}<div class="small text-body-secondary text-break">{{ instance.title }}</div>{% endif %}
{% with tags=instance.tags.all %}{% if tags %}<div class="mt-1">{% include 'common/tag_badges.html' with filter=True %}</div>{% endif %}{% endwith %}
{% with tags=instance.tags.all %}{% if tags %}<div class="mt-1">{% include 'common/tag_badges.html' with tags=tags|slice:":3" more=tags|slice:"3:" filter=True %}</div>{% endif %}{% endwith %}
{% if owners %}
{% with users=instance.userinstance_set.all %}
{% if users %}

View file

@ -157,4 +157,10 @@ assert.deepStrictEqual(visible(turkish), ["Şişli"]);
listeners.click({target: {closest: (s) => (s === "[data-tag-filter]" ? badge : null)}});
assert.strictEqual(elements["tag-filter"].value, "web", "a badge chooses its tag");
assert.strictEqual(stored["VMs_filter_tag"], "web", "and it is remembered");
// "…" shows a VM's other tags, and the first of them takes the focus
let focused = null;
const others = {hidden: true, querySelector: () => ({focus: () => { focused = "d4"; }})};
const ellipsis = {hidden: false, nextElementSibling: others};
listeners.click({target: {closest: (s) => (s === "[data-show-tags]" ? ellipsis : null)}});
assert.deepStrictEqual([others.hidden, ellipsis.hidden, focused], [false, true, "d4"]);
}

View file

@ -82,6 +82,15 @@ class VmTagsTests(TestCase):
html = render_to_string("instance_name_cell.html", {"instance": self.vm})
self.assertIn("prod", html)
def test_the_vm_list_shows_three_and_the_others_behind_an_ellipsis(self):
self.vm.tags.add(*(Tag.objects.create(name=name) for name in ("a1", "b2", "c3", "d4", "e5")))
cell = lxml_html.fromstring(render_to_string("instance_name_cell.html", {"instance": self.vm}))
self.assertEqual(cell.xpath("//button[not(ancestor::*[@hidden])]/@data-tag-filter"), ["a1", "b2", "c3"])
# "…" names the others and shows them when pressed (table_filter.js), with the keyboard too
(more,) = cell.xpath("//button[@data-show-tags]")
self.assertEqual((more.get("title"), more.text_content().strip()), ("d4, e5", "… more tags"))
self.assertEqual(cell.xpath("//*[@hidden]//button/@data-tag-filter"), ["d4", "e5"])
class VmListTagFilterTests(TestCase):
def setUp(self):

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-18 20:12+0000\n"
"POT-Creation-Date: 2026-11-18 20:30+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"
@ -9675,10 +9675,14 @@ msgstr ""
msgid "Delete <strong>%(object)s</strong>?"
msgstr "<strong>%(object)s</strong> silinsin mi?"
#: templates/common/tag_badges.html:2
#: templates/common/tag_badge.html:2
msgid "Show only this tag"
msgstr "Yalnız bu etiketi göster"
#: templates/common/tag_badges.html:6
msgid "more tags"
msgstr "diğer etiketler"
#: templates/common/tag_filter.html:4
msgid "All tags"
msgstr "Tüm etiketler"

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-18 20:12+0000\n"
"POT-Creation-Date: 2026-11-18 20:30+0000\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
@ -9108,10 +9108,14 @@ msgstr "请重新加载页面重试。如果问题持续出现,请将时间告
msgid "Delete <strong>%(object)s</strong>?"
msgstr "删除 <strong>%(object)s</strong>?"
#: templates/common/tag_badges.html:2
#: templates/common/tag_badge.html:2
msgid "Show only this tag"
msgstr "只显示此标签"
#: templates/common/tag_badges.html:6
msgid "more tags"
msgstr "更多标签"
#: templates/common/tag_filter.html:4
msgid "All tags"
msgstr "所有标签"

View file

@ -308,3 +308,12 @@ fieldset:not(:has(input[value="set"]:checked)) > .console-new-password {
#tag-filter {
max-width: 15rem;
}
/* a VM's or host's tags: smaller than other badges, so a row with several stays narrow */
.tag-badge {
font-size: 0.65rem;
font-weight: 500;
}
.tag-badge svg {
width: 0.85em;
height: 0.85em;
}

View file

@ -6,7 +6,8 @@
// buttons and menus. With a state list, the row's [data-state] must
// be the chosen state too; with a tag list (#tag-filter), the chosen tag
// one of the row's data-tags (names split by spaces), or "-" none of them.
// A tag's badge ([data-tag-filter]) chooses it in the list. In a grouped list a search for a group's host
// A tag's badge ([data-tag-filter]) chooses it in the list; a row's "…"
// ([data-show-tags]) shows its other tags. In a grouped list a search for a group's host
// shows all of its rows, and its header row (data-group-header) shows while
// any of its rows does. A page's #no-match shows while no row does. The
// search is remembered for a day, per page, unless its box has data-forget.
@ -129,6 +130,13 @@ if (typeof module !== "undefined") {
filterTable(document);
});
document.addEventListener("click", function (event) {
var more = event.target.closest("[data-show-tags]");
if (more) {
more.hidden = true;
more.nextElementSibling.hidden = false;
more.nextElementSibling.querySelector("button").focus(); // the focus is not lost with the button
return;
}
var badge = event.target.closest("[data-tag-filter]");
if (badge) {
tags.value = badge.dataset.tagFilter;

View file

@ -0,0 +1,2 @@
{% load i18n %}{% load bootstrap_icons %}{# one of tag_badges.html #}
{% if filter %}<button type="button" class="badge tag-badge text-bg-light border" data-tag-filter="{{ tag }}" title="{% trans "Show only this tag" %}">{% bs_icon 'tag' %} {{ tag }}</button>{% else %}<span class="badge tag-badge text-bg-light border">{% bs_icon 'tag' %} {{ tag }}</span>{% endif %}

View file

@ -1,2 +1,8 @@
{% load i18n %}{% load bootstrap_icons %}{# tags: a VM's or host's tags (or their names), as badges; with filter, each chooses its tag in the list's tag filter (table_filter.js) #}
{% for tag in tags %}{% if filter %}<button type="button" class="badge text-bg-light border" data-tag-filter="{{ tag }}" title="{% trans "Show only this tag" %}">{% bs_icon 'tag' %} {{ tag }}</button>{% else %}<span class="badge text-bg-light border">{% bs_icon 'tag' %} {{ tag }}</span>{% endif %}{% endfor %}
{% load i18n %}{% load bootstrap_icons %}
{# tags: a VM's or host's tags (or their names), as small badges; with filter, each chooses its tag in the list's tag filter; #}
{# more: the tags after them, behind "…" that shows them (table_filter.js) #}
{% for tag in tags %}{% include 'common/tag_badge.html' %} {% endfor %}
{% if more %}
<button type="button" class="badge tag-badge text-bg-light border" data-show-tags title="{{ more|join:", " }}">…<span class="visually-hidden"> {% trans "more tags" %}</span></button>
<span hidden>{% for tag in more %}{% include 'common/tag_badge.html' %} {% endfor %}</span>
{% endif %}