[pve-devel] [PATCH manager v11 13/13] ui: implement tag ordering from datacenter.cfg
Dominik Csapak
d.csapak at proxmox.com
Wed Nov 16 16:48:15 CET 2022
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 <d.csapak at proxmox.com>
---
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
More information about the pve-devel
mailing list