diff --git a/instances/templates/instance_name_cell.html b/instances/templates/instance_name_cell.html index 57cc7481..c98a85e5 100644 --- a/instances/templates/instance_name_cell.html +++ b/instances/templates/instance_name_cell.html @@ -3,7 +3,7 @@ {# a VM's name, its title, and with owners its owners: the first as a badge, the others counted #} {{ instance.name }} {% if instance.info and instance.title %}
{{ instance.title }}
{% endif %} -{% with tags=instance.tags.all %}{% if tags %}
{% include 'common/tag_badges.html' with filter=True %}
{% endif %}{% endwith %} +{% with tags=instance.tags.all %}{% if tags %}
{% include 'common/tag_badges.html' with tags=tags|slice:":3" more=tags|slice:"3:" filter=True %}
{% endif %}{% endwith %} {% if owners %} {% with users=instance.userinstance_set.all %} {% if users %} diff --git a/instances/tests/js/table_filter.test.js b/instances/tests/js/table_filter.test.js index e6e548b3..53aafe9f 100644 --- a/instances/tests/js/table_filter.test.js +++ b/instances/tests/js/table_filter.test.js @@ -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"]); } diff --git a/instances/tests/test_tags.py b/instances/tests/test_tags.py index 2c400878..c524f32e 100644 --- a/instances/tests/test_tags.py +++ b/instances/tests/test_tags.py @@ -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): diff --git a/locale/tr/LC_MESSAGES/django.mo b/locale/tr/LC_MESSAGES/django.mo index c468d4e5..e8d8f981 100644 Binary files a/locale/tr/LC_MESSAGES/django.mo and b/locale/tr/LC_MESSAGES/django.mo differ diff --git a/locale/tr/LC_MESSAGES/django.po b/locale/tr/LC_MESSAGES/django.po index a388a945..87c4d678 100644 --- a/locale/tr/LC_MESSAGES/django.po +++ b/locale/tr/LC_MESSAGES/django.po @@ -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 , 2020\n" "Language-Team: Turkish (https://www.transifex.com/catborise/teams/110663/tr/)\n" @@ -9675,10 +9675,14 @@ msgstr "" msgid "Delete %(object)s?" msgstr "%(object)s 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" diff --git a/locale/zh/LC_MESSAGES/django.mo b/locale/zh/LC_MESSAGES/django.mo index 374f9dc2..2e5a3830 100644 Binary files a/locale/zh/LC_MESSAGES/django.mo and b/locale/zh/LC_MESSAGES/django.mo differ diff --git a/locale/zh/LC_MESSAGES/django.po b/locale/zh/LC_MESSAGES/django.po index 4544b899..5ac696c1 100644 --- a/locale/zh/LC_MESSAGES/django.po +++ b/locale/zh/LC_MESSAGES/django.po @@ -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 %(object)s?" msgstr "删除 %(object)s?" -#: 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 "所有标签" diff --git a/static/css/webvirtcloud.css b/static/css/webvirtcloud.css index 8f0381e0..abb6cfd2 100644 --- a/static/css/webvirtcloud.css +++ b/static/css/webvirtcloud.css @@ -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; +} diff --git a/static/js/table_filter.js b/static/js/table_filter.js index 378da069..fccd4976 100644 --- a/static/js/table_filter.js +++ b/static/js/table_filter.js @@ -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; diff --git a/templates/common/tag_badge.html b/templates/common/tag_badge.html new file mode 100644 index 00000000..a069d1f1 --- /dev/null +++ b/templates/common/tag_badge.html @@ -0,0 +1,2 @@ +{% load i18n %}{% load bootstrap_icons %}{# one of tag_badges.html #} +{% if filter %}{% else %}{% bs_icon 'tag' %} {{ tag }}{% endif %} diff --git a/templates/common/tag_badges.html b/templates/common/tag_badges.html index 60ce0261..7c84c91b 100644 --- a/templates/common/tag_badges.html +++ b/templates/common/tag_badges.html @@ -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 %}{% else %}{% bs_icon 'tag' %} {{ tag }}{% 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 %} + + +{% endif %}