From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager v2 6/6] fix #1408: ui: ResourceTree: sort the tree according to tree-sorting options
Date: Thu, 2 Feb 2023 15:41:35 +0100 [thread overview]
Message-ID: <20230202144135.3892582-7-d.csapak@proxmox.com> (raw)
In-Reply-To: <20230202144135.3892582-1-d.csapak@proxmox.com>
Considers the newly added options from browser local storage. We have to
save the last sorting mechanism there, so we can detect if it changes
and trigger the movement/text changes (otherwise the tree nodes won't
be updated/moved)
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
www/manager6/UIOptions.js | 12 +++++++
www/manager6/tree/ResourceTree.js | 54 ++++++++++++++++++++++++-------
2 files changed, 54 insertions(+), 12 deletions(-)
diff --git a/www/manager6/UIOptions.js b/www/manager6/UIOptions.js
index dcdf01ee1..cb5a17552 100644
--- a/www/manager6/UIOptions.js
+++ b/www/manager6/UIOptions.js
@@ -86,6 +86,18 @@ Ext.define('PVE.UIOptions', {
return !(PVE.UIOptions.options['tag-style']?.ordering === 'config');
},
+ getTreeSortingValue: function(key) {
+ let localStorage = Ext.state.Manager.getProvider();
+ let browserValues = localStorage.get('pve-tree-sorting');
+ let defaults = {
+ 'sort-field': 'vmid',
+ 'group-templates': true,
+ 'group-guest-types': true,
+ };
+
+ return browserValues?.[key] ?? defaults[key];
+ },
+
fireUIConfigChanged: function() {
if (!PVE.data.ResourceStore.isLoading() && PVE.data.ResourceStore.isLoaded()) {
PVE.data.ResourceStore.fireEvent('load');
diff --git a/www/manager6/tree/ResourceTree.js b/www/manager6/tree/ResourceTree.js
index 7fcdfed5d..7d7900b59 100644
--- a/www/manager6/tree/ResourceTree.js
+++ b/www/manager6/tree/ResourceTree.js
@@ -44,24 +44,34 @@ Ext.define('PVE.tree.ResourceTree', {
// private
nodeSortFn: function(node1, node2) {
+ let me = this;
let n1 = node1.data, n2 = node2.data;
if (!n1.groupbyid === !n2.groupbyid) {
- // first sort (group) by type
- if (n1.type > n2.type) {
- return 1;
- } else if (n1.type < n2.type) {
- return -1;
+ let n1IsGuest = n1.type === 'qemu' || n1.type === 'lxc';
+ let n2IsGuest = n2.type === 'qemu' || n2.type === 'lxc';
+ if (me['group-guest-types'] || !n1IsGuest || !n2IsGuest) {
+ // first sort (group) by type
+ if (n1.type > n2.type) {
+ return 1;
+ } else if (n1.type < n2.type) {
+ return -1;
+ }
}
+
// then sort (group) by ID
- if (n1.type === 'qemu' || n2.type === 'lxc') {
- if (!n1.template !== !n2.template) {
+ if (n1IsGuest) {
+ if (me['group-templates'] && (!n1.template !== !n2.template)) {
return n1.template ? 1 : -1; // sort templates after regular VMs
}
- if (n1.vmid > n2.vmid) { // prefer VMID as metric for guests
- return 1;
- } else if (n1.vmid < n2.vmid) {
- return -1;
+ if (me['sort-field'] === 'vmid') {
+ if (n1.vmid > n2.vmid) { // prefer VMID as metric for guests
+ return 1;
+ } else if (n1.vmid < n2.vmid) {
+ return -1;
+ }
+ } else {
+ return n1.name.localeCompare(n2.name);
}
}
// same types but not a guest
@@ -115,6 +125,11 @@ Ext.define('PVE.tree.ResourceTree', {
status += '</div> ';
}
}
+ if (Ext.isNumeric(info.vmid) && info.vmid > 0) {
+ if (PVE.UIOptions.getTreeSortingValue('sort-field') !== 'vmid') {
+ info.text = `${info.name} (${String(info.vmid)})`;
+ }
+ }
info.text += PVE.Utils.renderTags(info.tags, PVE.UIOptions.tagOverrides);
@@ -203,8 +218,22 @@ Ext.define('PVE.tree.ResourceTree', {
return me.addChildSorted(node, info);
},
+ saveSortingOptions: function() {
+ let me = this;
+ let changed = false;
+ for (const key of ['sort-field', 'group-templates', 'group-guest-types']) {
+ let newValue = PVE.UIOptions.getTreeSortingValue(key);
+ if (me[key] !== newValue) {
+ me[key] = newValue;
+ changed = true;
+ }
+ }
+ return changed;
+ },
+
initComponent: function() {
let me = this;
+ me.saveSortingOptions();
let rstore = PVE.data.ResourceStore;
let sp = Ext.state.Manager.getProvider();
@@ -242,6 +271,7 @@ Ext.define('PVE.tree.ResourceTree', {
let sm = me.getSelectionModel();
let lastsel = sm.getSelection()[0];
let parents = [];
+ let sorting_changed = me.saveSortingOptions();
for (let node = lastsel; node; node = node.parentNode) {
parents.push(node);
}
@@ -258,7 +288,7 @@ Ext.define('PVE.tree.ResourceTree', {
// getById() use find(), which is slow (ExtJS4 DP5)
let item = rstore.data.get(olditem.data.id);
- let changed = false, moved = false;
+ let changed = sorting_changed, moved = sorting_changed;
if (item) {
// test if any grouping attributes changed, catches migrated tree-nodes in server view too
for (const attr of moveCheckAttrs) {
--
2.30.2
next prev parent reply other threads:[~2023-02-02 14:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-02 14:41 [pve-devel] [PATCH manager v2 0/6] fix #1408: ui: make tree sorting configurable Dominik Csapak
2023-02-02 14:41 ` [pve-devel] [PATCH manager v2 1/6] ui: remove 'Storage View' Dominik Csapak
2023-02-09 16:22 ` Thomas Lamprecht
2023-02-02 14:41 ` [pve-devel] [PATCH manager v2 2/6] ui: remove unused booleanfield Dominik Csapak
2023-02-02 14:41 ` [pve-devel] [PATCH manager v2 3/6] ui: refactor ui option related methods into UIOptions Dominik Csapak
2023-02-02 14:41 ` [pve-devel] [PATCH manager v2 4/6] ui: refactor refreshing the the resource store/tree Dominik Csapak
2023-02-02 14:41 ` [pve-devel] [PATCH manager v2 5/6] ui: add window for changing tree related options Dominik Csapak
2023-02-09 10:33 ` Aaron Lauterer
2023-02-02 14:41 ` Dominik Csapak [this message]
2023-02-09 10:34 ` [pve-devel] [PATCH manager v2 0/6] fix #1408: ui: make tree sorting configurable Aaron Lauterer
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=20230202144135.3892582-7-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