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

fix(tags): sixth audit: the tag box tells its rule, trims a paste; clear keeps the focus

- A name typed or pasted into the tag box that cannot be a tag shows the
  rule (letters a-z, digits, dots, dashes, underscores; at most 12
  characters) instead of nothing; the spaces a paste brings are dropped;
  "constructor" is no longer taken for a tag there is.
- "Clear the filters" hides with the message it is in: the search box takes
  the focus.
This commit is contained in:
catborise 2026-11-19 10:03:50 +03:00
parent bc1894e4d8
commit f6b1ee8985
9 changed files with 74 additions and 36 deletions

View file

@ -33,8 +33,10 @@ class TagsWidget(forms.SelectMultiple):
"""The tags there are and those given, to choose from or add to (Tom Select).""" """The tags there are and those given, to choose from or add to (Tom Select)."""
def __init__(self): def __init__(self):
# Tom Select's line for a new name typed (searchable_select.js) # Tom Select's line for a new name typed, and for one that cannot be a tag (searchable_select.js)
super().__init__(attrs={"data-tags": "", "data-add": _("Add tag %(tag)s")}) super().__init__(attrs={"data-tags": "", "data-add": _("Add tag %(tag)s"), "data-rule": _(
"A new tag: letters a-z, digits, dots, dashes and underscores, beginning with a letter or digit; "
"at most 12 characters")})
def optgroups(self, name, value, attrs=None): def optgroups(self, name, value, attrs=None):
self.choices = [(n, n) for n in sorted(set(Tag.objects.values_list("name", flat=True)) | set(value))] self.choices = [(n, n) for n in sorted(set(Tag.objects.values_list("name", flat=True)) | set(value))]

View file

@ -35,6 +35,9 @@ class TagsFieldTests(TestCase):
with translation.override("tr"): with translation.override("tr"):
html = TagsForm().as_p() html = TagsForm().as_p()
self.assertIn('data-add="Etiket ekle: %(tag)s"', html) self.assertIn('data-add="Etiket ekle: %(tag)s"', html)
# and what a new name may be, shown when the one typed cannot be a tag
self.assertIn('data-rule="Yeni etiket: a-z harfleri, rakamlar, nokta, tire ve alt çizgi, harf ya da rakamla başlar; '
'en fazla 12 karakter"', html)
def test_the_tags_are_made_when_saved(self): def test_the_tags_are_made_when_saved(self):
Tag.objects.create(name="prod") Tag.objects.create(name="prod")

View file

@ -150,7 +150,7 @@ function run(elements, stored) {
return listeners.click; return listeners.click;
} }
const listPage = () => ({ const listPage = () => ({
filter: {value: "", hasAttribute: () => false, addEventListener() {}}, filter: {value: "", hasAttribute: () => false, addEventListener() {}, focus() { this.focused = true; }},
"state-filter": {value: "", addEventListener() {}}, "state-filter": {value: "", addEventListener() {}},
"state-pills": pillRow(["", "Active", "Off"]), "state-pills": pillRow(["", "Active", "Off"]),
"tag-filter": {value: ""}, "tag-filter": {value: ""},
@ -182,6 +182,15 @@ const listPage = () => ({
assert.strictEqual(focused, "plain"); assert.strictEqual(focused, "plain");
} }
// "Clear the filters" hides with the message it is in: the search box takes the focus
{
const elements = listPage();
elements["clear-filters"] = {addEventListener: (name, fn) => { elements["clear-filters"].click = fn; }};
run(elements, {"VMs_filter_tag": "prod"});
elements["clear-filters"].click();
assert.deepStrictEqual([elements["tag-filter"].value, elements.filter.focused], ["", true]);
}
// a kept tag no pill has any longer is forgotten: made again later, it is not chosen by itself // a kept tag no pill has any longer is forgotten: made again later, it is not chosen by itself
{ {
const stored = {"VMs_filter_tag": "gone"}; const stored = {"VMs_filter_tag": "gone"};

Binary file not shown.

View file

@ -11,7 +11,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-11-19 06:32+0000\n" "POT-Creation-Date: 2026-11-19 07:03+0000\n"
"PO-Revision-Date: 2020-11-04 12:00+0000\n" "PO-Revision-Date: 2020-11-04 12:00+0000\n"
"Last-Translator: catborise <muhammetalisag@gmail.com>, 2020\n" "Last-Translator: catborise <muhammetalisag@gmail.com>, 2020\n"
"Language-Team: Turkish (https://www.transifex.com/catborise/teams/110663/tr/)\n" "Language-Team: Turkish (https://www.transifex.com/catborise/teams/110663/tr/)\n"
@ -1030,7 +1030,7 @@ msgid "Failed"
msgstr "Başarısız" msgstr "Başarısız"
#: admin/templates/admin/tag_list.html:5 admin/templates/admin/tag_list.html:7 #: admin/templates/admin/tag_list.html:5 admin/templates/admin/tag_list.html:7
#: computes/forms.py:53 instances/templates/instances/settings_tab.html:925 #: computes/forms.py:55 instances/templates/instances/settings_tab.html:925
#: instances/views.py:244 templates/common/tag_filter.html:5 #: instances/views.py:244 templates/common/tag_filter.html:5
#: templates/navbar.html:39 #: templates/navbar.html:39
msgid "Tags" msgid "Tags"
@ -2032,7 +2032,15 @@ msgstr "Kayıtlı, korumak için boş bırakın"
msgid "Add tag %(tag)s" msgid "Add tag %(tag)s"
msgstr "Etiket ekle: %(tag)s" msgstr "Etiket ekle: %(tag)s"
#: computes/forms.py:97 computes/templates/computes/instances.html:53 #: computes/forms.py:38
msgid ""
"A new tag: letters a-z, digits, dots, dashes and underscores, beginning with "
"a letter or digit; at most 12 characters"
msgstr ""
"Yeni etiket: a-z harfleri, rakamlar, nokta, tire ve alt çizgi, harf ya da "
"rakamla başlar; en fazla 12 karakter"
#: computes/forms.py:99 computes/templates/computes/instances.html:53
#: instances/templates/instances/settings_tab.html:872 #: instances/templates/instances/settings_tab.html:872
#: instances/templates/instances/settings_tab.html:904 #: instances/templates/instances/settings_tab.html:904
#: instances/templates/instances/snapshots_tab.html:27 #: instances/templates/instances/snapshots_tab.html:27
@ -2040,43 +2048,43 @@ msgstr "Etiket ekle: %(tag)s"
msgid "Description" msgid "Description"
msgstr "Tanım" msgstr "Tanım"
#: computes/forms.py:98 #: computes/forms.py:100
msgid "Shown on the hosts list" msgid "Shown on the hosts list"
msgstr "Sunucu listesinde gösterilir" msgstr "Sunucu listesinde gösterilir"
#: computes/forms.py:99 #: computes/forms.py:101
msgid "SASL login" msgid "SASL login"
msgstr "SASL kullanıcı adı" msgstr "SASL kullanıcı adı"
#: computes/forms.py:99 #: computes/forms.py:101
msgid "SASL password" msgid "SASL password"
msgstr "SASL parolası" msgstr "SASL parolası"
#: computes/forms.py:105 computes/templates/create_comp_block.html:10 #: computes/forms.py:107 computes/templates/create_comp_block.html:10
msgid "libvirt over TCP, with a SASL login" msgid "libvirt over TCP, with a SASL login"
msgstr "TCP üzerinden libvirt, SASL girişiyle" msgstr "TCP üzerinden libvirt, SASL girişiyle"
#: computes/forms.py:119 computes/templates/create_comp_block.html:14 #: computes/forms.py:121 computes/templates/create_comp_block.html:14
msgid "libvirt over SSH, with the panel's SSH key" msgid "libvirt over SSH, with the panel's SSH key"
msgstr "SSH üzerinden libvirt, panelin SSH anahtarıyla" msgstr "SSH üzerinden libvirt, panelin SSH anahtarıyla"
#: computes/forms.py:120 #: computes/forms.py:122
msgid "FQDN/IP" msgid "FQDN/IP"
msgstr "FQDN/IP" msgstr "FQDN/IP"
#: computes/forms.py:125 #: computes/forms.py:127
msgid "SSH user" msgid "SSH user"
msgstr "SSH kullanıcısı" msgstr "SSH kullanıcısı"
#: computes/forms.py:133 computes/templates/create_comp_block.html:18 #: computes/forms.py:135 computes/templates/create_comp_block.html:18
msgid "libvirt over TLS, with certificates" msgid "libvirt over TLS, with certificates"
msgstr "TLS üzerinden libvirt, sertifikalarla" msgstr "TLS üzerinden libvirt, sertifikalarla"
#: computes/forms.py:146 computes/templates/create_comp_block.html:21 #: computes/forms.py:148 computes/templates/create_comp_block.html:21
msgid "Local" msgid "Local"
msgstr "Yerel" msgstr "Yerel"
#: computes/forms.py:147 computes/templates/create_comp_block.html:22 #: computes/forms.py:149 computes/templates/create_comp_block.html:22
msgid "the libvirt of the host the panel runs on, by its socket" msgid "the libvirt of the host the panel runs on, by its socket"
msgstr "panelin çalıştığı sunucunun libvirt'i, soketi üzerinden" msgstr "panelin çalıştığı sunucunun libvirt'i, soketi üzerinden"

Binary file not shown.

View file

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-11-19 06:32+0000\n" "POT-Creation-Date: 2026-11-19 07:03+0000\n"
"PO-Revision-Date: \n" "PO-Revision-Date: \n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
@ -1002,7 +1002,7 @@ msgid "Failed"
msgstr "失败" msgstr "失败"
#: admin/templates/admin/tag_list.html:5 admin/templates/admin/tag_list.html:7 #: admin/templates/admin/tag_list.html:5 admin/templates/admin/tag_list.html:7
#: computes/forms.py:53 instances/templates/instances/settings_tab.html:925 #: computes/forms.py:55 instances/templates/instances/settings_tab.html:925
#: instances/views.py:244 templates/common/tag_filter.html:5 #: instances/views.py:244 templates/common/tag_filter.html:5
#: templates/navbar.html:39 #: templates/navbar.html:39
msgid "Tags" msgid "Tags"
@ -1956,7 +1956,13 @@ msgstr "已保存,留空则保持不变"
msgid "Add tag %(tag)s" msgid "Add tag %(tag)s"
msgstr "添加标签:%(tag)s" msgstr "添加标签:%(tag)s"
#: computes/forms.py:97 computes/templates/computes/instances.html:53 #: computes/forms.py:38
msgid ""
"A new tag: letters a-z, digits, dots, dashes and underscores, beginning with "
"a letter or digit; at most 12 characters"
msgstr "新标签:字母 a-z、数字、点、短横线和下划线,以字母或数字开头;最多 12 个字符"
#: computes/forms.py:99 computes/templates/computes/instances.html:53
#: instances/templates/instances/settings_tab.html:872 #: instances/templates/instances/settings_tab.html:872
#: instances/templates/instances/settings_tab.html:904 #: instances/templates/instances/settings_tab.html:904
#: instances/templates/instances/snapshots_tab.html:27 #: instances/templates/instances/snapshots_tab.html:27
@ -1964,43 +1970,43 @@ msgstr "添加标签:%(tag)s"
msgid "Description" msgid "Description"
msgstr "描述" msgstr "描述"
#: computes/forms.py:98 #: computes/forms.py:100
msgid "Shown on the hosts list" msgid "Shown on the hosts list"
msgstr "显示在主机列表中" msgstr "显示在主机列表中"
#: computes/forms.py:99 #: computes/forms.py:101
msgid "SASL login" msgid "SASL login"
msgstr "SASL 登录名" msgstr "SASL 登录名"
#: computes/forms.py:99 #: computes/forms.py:101
msgid "SASL password" msgid "SASL password"
msgstr "SASL 密码" msgstr "SASL 密码"
#: computes/forms.py:105 computes/templates/create_comp_block.html:10 #: computes/forms.py:107 computes/templates/create_comp_block.html:10
msgid "libvirt over TCP, with a SASL login" msgid "libvirt over TCP, with a SASL login"
msgstr "通过 TCP 连接 libvirt,使用 SASL 登录" msgstr "通过 TCP 连接 libvirt,使用 SASL 登录"
#: computes/forms.py:119 computes/templates/create_comp_block.html:14 #: computes/forms.py:121 computes/templates/create_comp_block.html:14
msgid "libvirt over SSH, with the panel's SSH key" msgid "libvirt over SSH, with the panel's SSH key"
msgstr "通过 SSH 连接 libvirt,使用面板的 SSH 密钥" msgstr "通过 SSH 连接 libvirt,使用面板的 SSH 密钥"
#: computes/forms.py:120 #: computes/forms.py:122
msgid "FQDN/IP" msgid "FQDN/IP"
msgstr "FQDN/IP" msgstr "FQDN/IP"
#: computes/forms.py:125 #: computes/forms.py:127
msgid "SSH user" msgid "SSH user"
msgstr "SSH 用户" msgstr "SSH 用户"
#: computes/forms.py:133 computes/templates/create_comp_block.html:18 #: computes/forms.py:135 computes/templates/create_comp_block.html:18
msgid "libvirt over TLS, with certificates" msgid "libvirt over TLS, with certificates"
msgstr "通过 TLS 连接 libvirt,使用证书" msgstr "通过 TLS 连接 libvirt,使用证书"
#: computes/forms.py:146 computes/templates/create_comp_block.html:21 #: computes/forms.py:148 computes/templates/create_comp_block.html:21
msgid "Local" msgid "Local"
msgstr "本地" msgstr "本地"
#: computes/forms.py:147 computes/templates/create_comp_block.html:22 #: computes/forms.py:149 computes/templates/create_comp_block.html:22
msgid "the libvirt of the host the panel runs on, by its socket" msgid "the libvirt of the host the panel runs on, by its socket"
msgstr "面板所在主机的 libvirt,通过其套接字连接" msgstr "面板所在主机的 libvirt,通过其套接字连接"

View file

@ -8,23 +8,32 @@ document.querySelectorAll("select[data-searchable]").forEach(function (select) {
}); });
// A <select multiple data-tags>: the tags there are, and a new one typed (the // A <select multiple data-tags>: the tags there are, and a new one typed (the
// server checks it), in lower case as the tags are kept: "Prod" is "prod"; // server checks it) of at most 12 characters (computes.models.TAG_LENGTH), as
// a new one of at most 12 characters (computes.models.TAG_LENGTH). // the tags are kept: without the spaces a paste brings, in lower case ("Prod"
// is "prod"). A name that cannot be a tag gets the rule (data-rule), not silence.
function tagName(input) {
return input.trim().toLowerCase();
}
function isTagName(input) {
return /^[a-z0-9][a-z0-9._-]{0,11}$/.test(tagName(input));
}
document.querySelectorAll("select[data-tags]").forEach(function (select) { document.querySelectorAll("select[data-tags]").forEach(function (select) {
new TomSelect(select, { new TomSelect(select, {
create: function (input) { create: function (input) {
return {value: input.toLowerCase(), text: input.toLowerCase()}; return {value: tagName(input), text: tagName(input)};
}, },
createFilter: function (input) { createFilter: function (input) {
return /^[A-Za-z0-9][A-Za-z0-9._-]{0,11}$/.test(input) && !this.options[input.toLowerCase()]; return isTagName(input) && !Object.hasOwn(this.options, tagName(input));
}, },
persist: false, persist: false,
render: { render: {
// the page's own words (data-add): the library's are English // the page's own words (data-add, data-rule): the library's are English
option_create: function (data, escape) { option_create: function (data, escape) {
return '<div class="create">' + escape(select.dataset.add.replace("%(tag)s", data.input.toLowerCase())) + "</div>"; return '<div class="create">' + escape(select.dataset.add.replace("%(tag)s", tagName(data.input))) + "</div>";
},
no_results: function (data, escape) {
return isTagName(data.input) ? null : '<div class="no-results">' + escape(select.dataset.rule) + "</div>";
}, },
no_results: null,
}, },
}); });
}); });

View file

@ -189,6 +189,7 @@ if (typeof module !== "undefined") {
states.value = ""; states.value = "";
} }
filterTable(document); filterTable(document);
search.focus(); // the button hid with the message it is in
}); });
} }
filterTable(document); filterTable(document);