From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 90CEF8D56 for ; Wed, 16 Nov 2022 16:52:58 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 74D9B22603 for ; Wed, 16 Nov 2022 16:52:58 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 16 Nov 2022 16:52:56 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id B90ED43E35 for ; Wed, 16 Nov 2022 16:48:19 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Wed, 16 Nov 2022 16:48:15 +0100 Message-Id: <20221116154815.358385-22-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221116154815.358385-1-d.csapak@proxmox.com> References: <20221116154815.358385-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: =?UTF-8?Q?0=0A=09?=AWL 0.065 Adjusted score from AWL reputation of From: =?UTF-8?Q?address=0A=09?=BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict =?UTF-8?Q?Alignment=0A=09?=SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF =?UTF-8?Q?Record=0A=09?=SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH manager v11 13/13] ui: implement tag ordering from datacenter.cfg X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Nov 2022 15:52:58 -0000 datacenter.cfg returns an 'ordering' option. parse that and use it to order the tags when viewing. default is alphabetical. with alphabetical ordering, drag & drop when editing is disabled and the tags will be inserted at the right place. when saving, the sorted order will be written into the config Signed-off-by: Dominik Csapak --- www/css/ext6-pve.css | 5 +++++ www/manager6/Utils.js | 13 +++++++++++++ www/manager6/dc/OptionView.js | 14 ++++++++++++++ www/manager6/form/TagEdit.js | 13 ++++++++++++- 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/www/css/ext6-pve.css b/www/css/ext6-pve.css index 4fc83a878..b8c713c48 100644 --- a/www/css/ext6-pve.css +++ b/www/css/ext6-pve.css @@ -668,6 +668,11 @@ table.osds td:first-of-type { cursor: grab; } +.hide-handles .pve-edit-tag > i.handle { + display: none; + padding-right: 0px; +} + .pve-edit-tag > i.action, .pve-add-tag > i.action { padding-left: 5px; diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js index 940752469..8484372f2 100644 --- a/www/manager6/Utils.js +++ b/www/manager6/Utils.js @@ -1930,10 +1930,19 @@ Ext.define('PVE.Utils', { 'none': Proxmox.Utils.NoneText, }, + tagOrderOptions: { + '__default__': `${Proxmox.Utils.defaultText} (${gettext('Alphabetical')})`, + 'config': gettext('Configuration'), + 'alphabetical': gettext('Alphabetical'), + }, + renderTags: function(tagstext, overrides) { let text = ''; if (tagstext) { let tags = (tagstext.split(/[,; ]/) || []).filter(t => !!t); + if (PVE.Utils.shouldSortTags()) { + tags = tags.sort(); + } text += ' '; tags.forEach((tag) => { text += Proxmox.Utils.getTagElement(tag, overrides); @@ -1942,6 +1951,10 @@ Ext.define('PVE.Utils', { return text; }, + shouldSortTags: function() { + return !(PVE.UIOptions?.['tag-style']?.ordering === 'config'); + }, + tagCharRegex: /^[a-z0-9+_.-]$/i, }, diff --git a/www/manager6/dc/OptionView.js b/www/manager6/dc/OptionView.js index be9e2abb2..aeab024e4 100644 --- a/www/manager6/dc/OptionView.js +++ b/www/manager6/dc/OptionView.js @@ -323,6 +323,8 @@ Ext.define('PVE.dc.OptionView', { let shape = value.shape; let shapeText = PVE.Utils.tagTreeStyles[shape ?? '__default__']; let txt = Ext.String.format(gettext("Tree Shape: {0}"), shapeText); + let orderText = PVE.Utils.tagOrderOptions[value.ordering ?? '__default__']; + txt += `, ${Ext.String.format(gettext("Ordering: {0}"), orderText)}`; if (Object.keys(colors).length > 0) { txt += ', '; } @@ -361,6 +363,9 @@ Ext.define('PVE.dc.OptionView', { if (values.shape) { style.shape = values.shape; } + if (values.ordering) { + style.ordering = values.ordering; + } let value = PVE.Parser.printPropertyString(style); if (value === '') { return { @@ -380,6 +385,15 @@ Ext.define('PVE.dc.OptionView', { defaultValue: '__default__', deleteEmpty: true, }, + { + name: 'ordering', + xtype: 'proxmoxKVComboBox', + fieldLabel: gettext('Ordering'), + comboItems: Object.entries(PVE.Utils.tagOrderOptions), + defaultValue: '__default__', + value: '__default__', + deleteEmpty: true, + }, { xtype: 'displayfield', fieldLabel: gettext('Color Overrides'), diff --git a/www/manager6/form/TagEdit.js b/www/manager6/form/TagEdit.js index a6e14349e..6325d39df 100644 --- a/www/manager6/form/TagEdit.js +++ b/www/manager6/form/TagEdit.js @@ -37,6 +37,8 @@ Ext.define('PVE.panel.TagEditContainer', { onRender: function(v) { let me = this; let view = me.getView(); + view.toggleCls('hide-handles', PVE.Utils.shouldSortTags()); + view.dragzone = Ext.create('Ext.dd.DragZone', v.getEl(), { getDragData: function(e) { let source = e.getTarget('.handle'); @@ -168,6 +170,14 @@ Ext.define('PVE.panel.TagEditContainer', { let view = me.getView(); let vm = me.getViewModel(); let index = view.items.indexOf(me.lookup('addTagBtn')); + if (PVE.Utils.shouldSortTags()) { + index = view.items.findIndexBy(tagField => { + if (tagField.reference === 'addTagBtn') { + return true; + } + return tagField.tag >= tag; + }, 1); + } view.insert(index, { xtype: 'pveTag', tag, @@ -226,7 +236,8 @@ Ext.define('PVE.panel.TagEditContainer', { } me.mon(Ext.GlobalEvents, 'loadedUiOptions', () => { - me.loadTags(me.oldTags, true); // refresh tag colors + view.toggleCls('hide-handles', PVE.Utils.shouldSortTags()); + me.loadTags(me.oldTags, true); // refresh tag colors and order }); }, }, -- 2.30.2