public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH manager] ui: resource tree: add collapse/expand all button
@ 2024-11-19  9:22 Dominik Csapak
  2024-11-19  9:30 ` Thomas Lamprecht
  0 siblings, 1 reply; 6+ messages in thread
From: Dominik Csapak @ 2024-11-19  9:22 UTC (permalink / raw)
  To: pve-devel

which defaults to expand all, and only if all expanded, collapse all.

Changes icon dynamically when nodes expand/collapse.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
if we'd find an icon that would fit for both cases, we could omit the
event bubbling probably. If there are many nodes, the 'hasCollapsed'
check will trigger more often, iterating over all tree nodes..


 www/manager6/Workspace.js         | 20 ++++++++++++++++++++
 www/manager6/tree/ResourceTree.js | 31 +++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/www/manager6/Workspace.js b/www/manager6/Workspace.js
index 922e01df..7bc2aeea 100644
--- a/www/manager6/Workspace.js
+++ b/www/manager6/Workspace.js
@@ -260,6 +260,15 @@ Ext.define('PVE.StdWorkspace', {
 		    },
 		},
 	    },
+	    listeners: {
+		expansionchange: function(tree) {
+		    if (tree.hasCollapsed()) {
+			me.down('#collapseButton').setIconCls('fa fa-fw fa-plus-square-o x-btn-icon-el-default-toolbar-small');
+		    } else {
+			me.down('#collapseButton').setIconCls('fa fa-fw fa-minus-square-o x-btn-icon-el-default-toolbar-small');
+		    }
+		},
+	    },
 	});
 
 	selview.on('select', function(combo, records) {
@@ -470,6 +479,17 @@ Ext.define('PVE.StdWorkspace', {
 			    padding: '0 0 5 0',
 			    items: [
 				selview,
+				{
+				    xtype: 'button',
+				    cls: 'x-btn-default-toolbar-small',
+				    itemId: 'collapseButton',
+				    tooltip: gettext('Expand/Collapse Tree'),
+				    iconCls: 'fa fa-fw fa-plus-square-o x-btn-icon-el-default-toolbar-small',
+				    handler: () => {
+					let rt = me.down('pveResourceTree');
+					rt.toggleExpansion();
+				    },
+				},
 				{
 				    xtype: 'button',
 				    cls: 'x-btn-default-toolbar-small',
diff --git a/www/manager6/tree/ResourceTree.js b/www/manager6/tree/ResourceTree.js
index 8b7c2521..cef869f7 100644
--- a/www/manager6/tree/ResourceTree.js
+++ b/www/manager6/tree/ResourceTree.js
@@ -255,6 +255,30 @@ Ext.define('PVE.tree.ResourceTree', {
 	return changed;
     },
 
+    hasCollapsed: function() {
+	let me = this;
+	let root = me.store.getRootNode();
+	let collapsed = false;
+	root.cascade(function(rec) {
+	    if (!rec.isExpanded() && !rec.isLeaf()) {
+		collapsed = true;
+		return false;
+	    }
+	    return true;
+	});
+	return collapsed;
+    },
+
+    toggleExpansion: function() {
+	let me = this;
+	let root = me.store.getRootNode();
+	if (me.hasCollapsed()) {
+	    root.expandChildren(true);
+	} else {
+	    root.collapseChildren(false);
+	}
+    },
+
     initComponent: function() {
 	let me = this;
 	me.saveSortingOptions();
@@ -562,6 +586,13 @@ Ext.define('PVE.tree.ResourceTree', {
 	rstore.on("load", updateTree);
 	rstore.startUpdate();
 
+	store.on('nodeexpand', function() {
+	    me.fireEvent('expansionchange', me);
+	});
+	store.on('nodecollapse', function() {
+	    me.fireEvent('expansionchange', me);
+	});
+
 	me.mon(Ext.GlobalEvents, 'loadedUiOptions', () => {
 	    me.store.getRootNode().cascadeBy({
 		before: function(node) {
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [pve-devel] [PATCH manager] ui: resource tree: add collapse/expand all button
  2024-11-19  9:22 [pve-devel] [PATCH manager] ui: resource tree: add collapse/expand all button Dominik Csapak
@ 2024-11-19  9:30 ` Thomas Lamprecht
  2024-11-19  9:36   ` Dominik Csapak
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Lamprecht @ 2024-11-19  9:30 UTC (permalink / raw)
  To: Proxmox VE development discussion, Dominik Csapak

Am 19.11.24 um 10:22 schrieb Dominik Csapak:
> which defaults to expand all, and only if all expanded, collapse all.
> 
> Changes icon dynamically when nodes expand/collapse.
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> if we'd find an icon that would fit for both cases, we could omit the
> event bubbling probably. If there are many nodes, the 'hasCollapsed'
> check will trigger more often, iterating over all tree nodes..

We could also just do two separate buttons, FWIW.


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [pve-devel] [PATCH manager] ui: resource tree: add collapse/expand all button
  2024-11-19  9:30 ` Thomas Lamprecht
@ 2024-11-19  9:36   ` Dominik Csapak
  2024-11-19  9:39     ` Thomas Lamprecht
  0 siblings, 1 reply; 6+ messages in thread
From: Dominik Csapak @ 2024-11-19  9:36 UTC (permalink / raw)
  To: Thomas Lamprecht, Proxmox VE development discussion

On 11/19/24 10:30, Thomas Lamprecht wrote:
> Am 19.11.24 um 10:22 schrieb Dominik Csapak:
>> which defaults to expand all, and only if all expanded, collapse all.
>>
>> Changes icon dynamically when nodes expand/collapse.
>>
>> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
>> ---
>> if we'd find an icon that would fit for both cases, we could omit the
>> event bubbling probably. If there are many nodes, the 'hasCollapsed'
>> check will trigger more often, iterating over all tree nodes..
> 
> We could also just do two separate buttons, FWIW.

true, but the space there is already a bit limited IMO, and
only one of the buttons makes sense at one point in time


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [pve-devel] [PATCH manager] ui: resource tree: add collapse/expand all button
  2024-11-19  9:36   ` Dominik Csapak
@ 2024-11-19  9:39     ` Thomas Lamprecht
  2024-11-19  9:41       ` Dominik Csapak
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Lamprecht @ 2024-11-19  9:39 UTC (permalink / raw)
  To: Dominik Csapak, Proxmox VE development discussion

Am 19.11.24 um 10:36 schrieb Dominik Csapak:
> On 11/19/24 10:30, Thomas Lamprecht wrote:
>> Am 19.11.24 um 10:22 schrieb Dominik Csapak:
>>> which defaults to expand all, and only if all expanded, collapse all.
>>>
>>> Changes icon dynamically when nodes expand/collapse.
>>>
>>> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
>>> ---
>>> if we'd find an icon that would fit for both cases, we could omit the
>>> event bubbling probably. If there are many nodes, the 'hasCollapsed'
>>> check will trigger more often, iterating over all tree nodes..
>>
>> We could also just do two separate buttons, FWIW.
> 
> true, but the space there is already a bit limited IMO, and

it's just two icons and the view selector is mostly empty space as the entries
are all relatively short

> only one of the buttons makes sense at one point in time
> 

That's not completely true, if I got a few nodes expanded and a few nodes
closed then having both allows to avoid an extra click and some potential UX
confusion.


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [pve-devel] [PATCH manager] ui: resource tree: add collapse/expand all button
  2024-11-19  9:39     ` Thomas Lamprecht
@ 2024-11-19  9:41       ` Dominik Csapak
  2024-11-19  9:46         ` Thomas Lamprecht
  0 siblings, 1 reply; 6+ messages in thread
From: Dominik Csapak @ 2024-11-19  9:41 UTC (permalink / raw)
  To: Thomas Lamprecht, Proxmox VE development discussion

On 11/19/24 10:39, Thomas Lamprecht wrote:
> Am 19.11.24 um 10:36 schrieb Dominik Csapak:
>> On 11/19/24 10:30, Thomas Lamprecht wrote:
>>> Am 19.11.24 um 10:22 schrieb Dominik Csapak:
>>>> which defaults to expand all, and only if all expanded, collapse all.
>>>>
>>>> Changes icon dynamically when nodes expand/collapse.
>>>>
>>>> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
>>>> ---
>>>> if we'd find an icon that would fit for both cases, we could omit the
>>>> event bubbling probably. If there are many nodes, the 'hasCollapsed'
>>>> check will trigger more often, iterating over all tree nodes..
>>>
>>> We could also just do two separate buttons, FWIW.
>>
>> true, but the space there is already a bit limited IMO, and
> 
> it's just two icons and the view selector is mostly empty space as the entries
> are all relatively short
> 
>> only one of the buttons makes sense at one point in time
>>
> 
> That's not completely true, if I got a few nodes expanded and a few nodes
> closed then having both allows to avoid an extra click and some potential UX
> confusion.

true, i'll send a v2 with two buttons, icons are ok for you or do you have a different
sugggestion?


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [pve-devel] [PATCH manager] ui: resource tree: add collapse/expand all button
  2024-11-19  9:41       ` Dominik Csapak
@ 2024-11-19  9:46         ` Thomas Lamprecht
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Lamprecht @ 2024-11-19  9:46 UTC (permalink / raw)
  To: Dominik Csapak, Proxmox VE development discussion

Am 19.11.24 um 10:41 schrieb Dominik Csapak:
> true, i'll send a v2 with two buttons, icons are ok for you or do you have a different
> sugggestion?
> 

And don't get me wrong, that's certainly minor, but if the single button
is already not ideal implementation wise it might be worth to try.

Another option might be to have those stacked, I agree that it is slightly
niche, and thus having this a bit tinier can be still enough I think.

W.r.t. icons, as they're wrapped in a x-btn-icon-el-default-toolbar-small they
should look like the setting gear beside it, or? In that case it might be fine
to use the plus/minus without any square, but no hard feelings.



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-11-19  9:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-19  9:22 [pve-devel] [PATCH manager] ui: resource tree: add collapse/expand all button Dominik Csapak
2024-11-19  9:30 ` Thomas Lamprecht
2024-11-19  9:36   ` Dominik Csapak
2024-11-19  9:39     ` Thomas Lamprecht
2024-11-19  9:41       ` Dominik Csapak
2024-11-19  9:46         ` Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal