From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager v10 08/13] ui: add form/Tag
Date: Tue, 15 Nov 2022 14:02:43 +0100 [thread overview]
Message-ID: <20221115130248.1007325-19-d.csapak@proxmox.com> (raw)
In-Reply-To: <20221115130248.1007325-1-d.csapak@proxmox.com>
displays a single tag, with the ability to edit inline on click (when
the mode is set to editable). This brings up a list of globally available tags
for simple selection.
this is a basic ext component, with 'i' tags for the icons (handle and
add/remove button) and a span (for the tag text)
shows the tag by default, and if put in editable mode, makes the
span editable. when actually starting the edit, shows a picker
with available tags to select from
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from v9:
* don't listen to the global event anymore
www/css/ext6-pve.css | 32 ++++++
www/manager6/Makefile | 1 +
www/manager6/form/Tag.js | 232 +++++++++++++++++++++++++++++++++++++++
3 files changed, 265 insertions(+)
create mode 100644 www/manager6/form/Tag.js
diff --git a/www/css/ext6-pve.css b/www/css/ext6-pve.css
index f7d0c4201..daaffa6ec 100644
--- a/www/css/ext6-pve.css
+++ b/www/css/ext6-pve.css
@@ -656,3 +656,35 @@ table.osds td:first-of-type {
padding-top: 0px;
padding-bottom: 0px;
}
+
+.pve-edit-tag > i {
+ cursor: pointer;
+ font-size: 14px;
+}
+
+.pve-edit-tag > i.handle {
+ padding-right: 5px;
+ cursor: grab;
+}
+
+.pve-edit-tag > i.action {
+ padding-left: 5px;
+}
+
+.pve-edit-tag.normal > i {
+ display: none;
+}
+
+.pve-edit-tag.editable span,
+.pve-edit-tag.inEdit span {
+ background-color: #ffffff;
+ border: 1px solid #a8a8a8;
+ color: #000;
+ padding-left: 2px;
+ padding-right: 2px;
+ min-width: 2em;
+}
+
+.pve-edit-tag.inEdit span {
+ border: 1px solid #000;
+}
diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index 83c2effcf..21be8da8e 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -75,6 +75,7 @@ JSSRC= \
form/iScsiProviderSelector.js \
form/TagColorGrid.js \
form/ListField.js \
+ form/Tag.js \
grid/BackupView.js \
grid/FirewallAliases.js \
grid/FirewallOptions.js \
diff --git a/www/manager6/form/Tag.js b/www/manager6/form/Tag.js
new file mode 100644
index 000000000..cc4413d29
--- /dev/null
+++ b/www/manager6/form/Tag.js
@@ -0,0 +1,232 @@
+Ext.define('Proxmox.Tag', {
+ extend: 'Ext.Component',
+ alias: 'widget.pmxTag',
+
+ mode: 'editable',
+
+ icons: {
+ editable: 'fa fa-minus-square',
+ normal: '',
+ inEdit: 'fa fa-check-square',
+ },
+
+ tag: '',
+ cls: 'pve-edit-tag',
+
+ tpl: [
+ '<i class="handle fa fa-bars"></i>',
+ '<span>{tag}</span>',
+ '<i class="action {iconCls}"></i>',
+ ],
+
+ // we need to do this in mousedown, because that triggers before
+ // focusleave (which triggers before click)
+ onMouseDown: function(event) {
+ let me = this;
+ if (event.target.tagName !== 'I' || event.target.classList.contains('handle')) {
+ return;
+ }
+ switch (me.mode) {
+ case 'editable':
+ me.setVisible(false);
+ me.setTag('');
+ break;
+ case 'inEdit':
+ me.setTag(me.tagEl().innerHTML);
+ me.setMode('editable');
+ break;
+ default: break;
+ }
+ },
+
+ onClick: function(event) {
+ let me = this;
+ if (event.target.tagName !== 'SPAN' || me.mode !== 'editable') {
+ return;
+ }
+ me.setMode('inEdit');
+
+ // select text in the element
+ let tagEl = me.tagEl();
+ tagEl.contentEditable = true;
+ let range = document.createRange();
+ range.selectNodeContents(tagEl);
+ let sel = window.getSelection();
+ sel.removeAllRanges();
+ sel.addRange(range);
+
+ me.showPicker();
+ },
+
+ showPicker: function() {
+ let me = this;
+ if (!me.picker) {
+ me.picker = Ext.widget({
+ xtype: 'boundlist',
+ minWidth: 70,
+ scrollable: true,
+ floating: true,
+ hidden: true,
+ userCls: 'proxmox-tags-full',
+ displayField: 'tag',
+ itemTpl: [
+ '{[Proxmox.Utils.getTagElement(values.tag, PVE.Utils.tagOverrides)]}',
+ ],
+ store: [],
+ listeners: {
+ select: function(picker, rec) {
+ me.setTag(rec.data.tag);
+ me.setMode('editable');
+ me.picker.hide();
+ },
+ },
+ });
+ }
+ me.picker.getStore()?.clearFilter();
+ let taglist = PVE.Utils.tagList.map(v => ({ tag: v }));
+ if (taglist.length < 1) {
+ return;
+ }
+ me.picker.getStore().setData(taglist);
+ me.picker.showBy(me, 'tl-bl');
+ me.picker.setMaxHeight(200);
+ },
+
+ setMode: function(mode) {
+ let me = this;
+ if (me.icons[mode] === undefined) {
+ throw "invalid mode";
+ }
+ let tagEl = me.tagEl();
+ if (tagEl) {
+ tagEl.contentEditable = mode === 'inEdit';
+ }
+ me.removeCls(me.mode);
+ me.addCls(mode);
+ me.mode = mode;
+ me.updateData();
+ },
+
+ onKeyPress: function(event) {
+ let me = this;
+ let key = event.browserEvent.key;
+ switch (key) {
+ case 'Enter':
+ if (me.tagEl().innerHTML !== '') {
+ me.setTag(me.tagEl().innerHTML);
+ me.setMode('editable');
+ return;
+ }
+ break;
+ case 'Escape':
+ me.cancelEdit();
+ return;
+ case 'Backspace':
+ case 'Delete':
+ return;
+ default:
+ if (key.match(PVE.Utils.tagCharRegex)) {
+ return;
+ }
+ }
+ event.browserEvent.preventDefault();
+ event.browserEvent.stopPropagation();
+ },
+
+ beforeInput: function(event) {
+ let me = this;
+ me.updateLayout();
+ let tag = event.event.data ?? event.event.dataTransfer?.getData('text/plain');
+ if (!tag) {
+ return;
+ }
+ if (tag.match(PVE.Utils.tagCharRegex) === null) {
+ event.event.preventDefault();
+ event.event.stopPropagation();
+ }
+ },
+
+ onInput: function(event) {
+ let me = this;
+ me.picker.getStore().filter({
+ property: 'tag',
+ value: me.tagEl().innerHTML,
+ anyMatch: true,
+ });
+ },
+
+ cancelEdit: function(list, event) {
+ let me = this;
+ if (me.mode === 'inEdit') {
+ me.setTag(me.tag);
+ me.setMode('editable');
+ }
+ me.picker?.hide();
+ },
+
+
+ setTag: function(tag) {
+ let me = this;
+ let oldtag = me.tag;
+ me.tag = tag;
+ let rgb = PVE.Utils.tagOverrides[tag] ?? Proxmox.Utils.stringToRGB(tag);
+
+ let cls = Proxmox.Utils.getTextContrastClass(rgb);
+ let color = Proxmox.Utils.rgbToCss(rgb);
+ me.setUserCls(`proxmox-tag-${cls}`);
+ me.setStyle('background-color', color);
+ if (rgb.length > 3) {
+ let fgcolor = Proxmox.Utils.rgbToCss([rgb[3], rgb[4], rgb[5]]);
+
+ me.setStyle('color', fgcolor);
+ } else {
+ me.setStyle('color');
+ }
+ me.updateData();
+ if (oldtag !== tag) {
+ me.fireEvent('change', me, tag, oldtag);
+ }
+ },
+
+ updateData: function() {
+ let me = this;
+ if (me.destroying || me.destroyed) {
+ return;
+ }
+ me.update({
+ tag: me.tag,
+ iconCls: me.icons[me.mode],
+ });
+ },
+
+ tagEl: function() {
+ return this.el?.dom?.getElementsByTagName('span')?.[0];
+ },
+
+ listeners: {
+ mousedown: 'onMouseDown',
+ click: 'onClick',
+ focusleave: 'cancelEdit',
+ keydown: 'onKeyPress',
+ beforeInput: 'beforeInput',
+ input: 'onInput',
+ element: 'el',
+ scope: 'this',
+ },
+
+ initComponent: function() {
+ let me = this;
+
+ me.setTag(me.tag);
+ me.setMode(me.mode ?? 'normal');
+ me.callParent();
+ },
+
+ destroy: function() {
+ let me = this;
+ if (me.picker) {
+ Ext.destroy(me.picker);
+ }
+ me.callParent();
+ },
+});
--
2.30.2
next prev parent reply other threads:[~2022-11-15 13:11 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-15 13:02 [pve-devel] [PATCH cluster/guest-common/qemu-server/container/wt/manager v10 0/5] add tags to ui Dominik Csapak
2022-11-15 13:02 ` [pve-devel] [PATCH cluster v10 1/5] add CFS_IPC_GET_GUEST_CONFIG_PROPERTIES method Dominik Csapak
2022-11-16 9:50 ` Wolfgang Bumiller
2022-11-15 13:02 ` [pve-devel] [PATCH cluster v10 2/5] Cluster: add get_guest_config_properties Dominik Csapak
2022-11-15 13:02 ` [pve-devel] [PATCH cluster v10 3/5] datacenter.cfg: add option for tag-style Dominik Csapak
2022-11-15 13:02 ` [pve-devel] [PATCH cluster v10 4/5] datacenter.cfg: add tag rights control to the datacenter config Dominik Csapak
2022-11-15 15:17 ` Fabian Grünbichler
2022-11-16 7:48 ` Thomas Lamprecht
2022-11-16 8:47 ` Dominik Csapak
2022-11-16 8:51 ` Fabian Grünbichler
2022-11-16 8:54 ` Thomas Lamprecht
2022-11-16 9:04 ` Dominik Csapak
2022-11-16 9:10 ` Thomas Lamprecht
2022-11-16 9:31 ` Fabian Grünbichler
2022-11-16 9:38 ` Dominik Csapak
2022-11-16 9:40 ` Thomas Lamprecht
2022-11-16 9:51 ` Fabian Grünbichler
2022-11-16 13:56 ` Thomas Lamprecht
2022-11-15 13:02 ` [pve-devel] [PATCH cluster v10 5/5] datacenter.cfg: add 'ordering' to 'tag-style' config Dominik Csapak
2022-11-15 13:02 ` [pve-devel] [PATCH guest-common v10 1/1] GuestHelpers: add 'assert_tag_permissions' Dominik Csapak
2022-11-15 15:34 ` Fabian Grünbichler
2022-11-15 13:02 ` [pve-devel] [PATCH qemu-server v10 1/1] api: update: check for tags permissions with 'assert_tag_permissions' Dominik Csapak
2022-11-15 13:02 ` [pve-devel] [PATCH container v10 1/1] check_ct_modify_config_perm: " Dominik Csapak
2022-11-15 13:02 ` [pve-devel] [PATCH widget-toolkit v10 1/2] add tag related helpers Dominik Csapak
2022-11-16 13:48 ` [pve-devel] applied: " Thomas Lamprecht
2022-11-15 13:02 ` [pve-devel] [PATCH widget-toolkit v10 2/2] Toolkit: add override for Ext.dd.DragDropManager Dominik Csapak
2022-11-16 13:49 ` [pve-devel] applied: " Thomas Lamprecht
2022-11-15 13:02 ` [pve-devel] [PATCH manager v10 01/13] api: /cluster/resources: add tags to returned properties Dominik Csapak
2022-11-16 8:02 ` Thomas Lamprecht
2022-11-15 13:02 ` [pve-devel] [PATCH manager v10 02/13] api: add /ui-options api call Dominik Csapak
2022-11-15 13:02 ` [pve-devel] [PATCH manager v10 03/13] ui: call '/ui-options' and save the result in PVE.UIOptions Dominik Csapak
2022-11-15 13:02 ` [pve-devel] [PATCH manager v10 04/13] ui: parse and save tag infos from /ui-options Dominik Csapak
2022-11-15 13:02 ` [pve-devel] [PATCH manager v10 05/13] ui: add form/TagColorGrid Dominik Csapak
2022-11-15 13:02 ` [pve-devel] [PATCH manager v10 06/13] ui: add PVE.form.ListField Dominik Csapak
2022-11-15 13:02 ` [pve-devel] [PATCH manager v10 07/13] ui: dc/OptionView: add editors for tag settings Dominik Csapak
2022-11-15 13:02 ` Dominik Csapak [this message]
2022-11-16 14:57 ` [pve-devel] [PATCH manager v10 08/13] ui: add form/Tag Thomas Lamprecht
2022-11-15 13:02 ` [pve-devel] [PATCH manager v10 09/13] ui: add form/TagEdit.js Dominik Csapak
2022-11-16 15:00 ` Thomas Lamprecht
2022-11-16 15:02 ` Dominik Csapak
2022-11-15 13:02 ` [pve-devel] [PATCH manager v10 10/13] ui: {lxc, qemu}/Config: show Tags and make them editable Dominik Csapak
2022-11-15 13:02 ` [pve-devel] [PATCH manager v10 11/13] ui: tree/ResourceTree: show Tags in tree Dominik Csapak
2022-11-15 13:02 ` [pve-devel] [PATCH manager v10 12/13] ui: add tags to ResourceGrid and GlobalSearchField Dominik Csapak
2022-11-15 13:02 ` [pve-devel] [PATCH manager v10 13/13] ui: implement tag ordering from datacenter.cfg Dominik Csapak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221115130248.1007325-19-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox