[pve-devel] [PATCH manager v10 13/13] ui: implement tag ordering from datacenter.cfg

Dominik Csapak d.csapak at proxmox.com
Tue Nov 15 14:02:48 CET 2022


ui-options/datacenter.cfg return an 'ordering' option. parse that and
use it to order the tags when viewing.

when having that enabled, 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 <d.csapak at proxmox.com>
---
new in v10
 www/css/ext6-pve.css          |  5 +++++
 www/manager6/Utils.js         |  7 +++++++
 www/manager6/dc/OptionView.js | 17 +++++++++++++++++
 www/manager6/form/TagEdit.js  | 13 ++++++++++++-
 4 files changed, 41 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 2e819ce84..d34ac53ac 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -1931,6 +1931,9 @@ Ext.define('PVE.Utils', {
 	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);
@@ -1939,6 +1942,10 @@ Ext.define('PVE.Utils', {
 	return text;
     },
 
+    shouldSortTags: function() {
+	return PVE.UIOptions?.['tag-style']?.ordering === 'alphabetical';
+    },
+
     tagCharRegex: /^[a-z0-9+_.-]$/i,
 },
 
diff --git a/www/manager6/dc/OptionView.js b/www/manager6/dc/OptionView.js
index ef2989d6c..65d057036 100644
--- a/www/manager6/dc/OptionView.js
+++ b/www/manager6/dc/OptionView.js
@@ -323,6 +323,7 @@ Ext.define('PVE.dc.OptionView', {
 		let shape = value.shape;
 		let shapeText = PVE.Utils.tagTreeStyles[shape] ?? Proxmox.Utils.defaultText;
 		let txt = Ext.String.format(gettext("Tree Shape: {0}"), shapeText);
+		txt += `, ${Ext.String.format(gettext("Ordering: {0}"), value.ordering ?? 'config')}`;
 		if (Object.keys(colors).length > 0) {
 		    txt += ', ';
 		}
@@ -361,6 +362,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 +384,19 @@ Ext.define('PVE.dc.OptionView', {
 				defaultValue: '__default__',
 				deleteEmpty: true,
 			    },
+			    {
+				name: 'ordering',
+				xtype: 'proxmoxKVComboBox',
+				fieldLabel: gettext('Ordering'),
+				comboItems: [
+				    ['__default__', `${Proxmox.Utils.defaultText} (config)`],
+				    ['config', 'config'],
+				    ['alphabetical', 'alphabetical'],
+				],
+				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 7200e3c09..7219845ae 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: 'pmxTag',
 		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






More information about the pve-devel mailing list