public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v2 widget-toolkit 1/3] convert disk list to disk tree and conditionally include partitions
Date: Mon,  8 Feb 2021 15:23:27 +0100	[thread overview]
Message-ID: <20210208142329.23068-2-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210208142329.23068-1-f.ebner@proxmox.com>

Assigning the store directly to the treepanel doesn't work, more manual
handling is needed. This is mostly based on what we do for PBS's datastore
content view. The store monitoring also needs to be changed slightly.

The buttons are restricted to work on disks only, based on the parent
attribute, that only partitions have.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

Changes from v1:
    * use the 'include-partitions' parameter only if the parent wants it

 src/grid/DiskList.js | 100 +++++++++++++++++++++++++++++++++++--------
 1 file changed, 81 insertions(+), 19 deletions(-)

diff --git a/src/grid/DiskList.js b/src/grid/DiskList.js
index 54f58f8..b67fbd1 100644
--- a/src/grid/DiskList.js
+++ b/src/grid/DiskList.js
@@ -36,20 +36,35 @@ Ext.define('pmx-disk-list', {
 });
 
 Ext.define('Proxmox.DiskList', {
-    extend: 'Ext.grid.GridPanel',
+    extend: 'Ext.tree.Panel',
     alias: 'widget.pmxDiskList',
 
+    rootVisible: false,
+
     emptyText: gettext('No Disks found'),
 
     stateful: true,
-    stateId: 'grid-node-disks',
+    stateId: 'tree-node-disks',
 
     controller: {
 	xclass: 'Ext.app.ViewController',
 
 	reload: function() {
 	    let me = this;
-	    me.getView().getStore().load();
+	    let view = me.getView();
+
+	    let extraParams = {};
+	    if (view.includePartitions) {
+		extraParams['include-partitions'] = 1;
+	    }
+
+	    let url = `${view.baseurl}/list`;
+	    me.store.setProxy({
+		type: 'proxmox',
+		extraParams: extraParams,
+		url: url,
+	    });
+	    me.store.load();
 	},
 
 	openSmartWindow: function() {
@@ -94,27 +109,63 @@ Ext.define('Proxmox.DiskList', {
 	},
 
 	init: function(view) {
-	    Proxmox.Utils.monStoreErrors(view, view.getStore(), true);
-
 	    let nodename = view.nodename || 'localhost';
 	    view.baseurl = `/api2/json/nodes/${nodename}/disks`;
 	    view.exturl = `/api2/extjs/nodes/${nodename}/disks`;
-	    view.getStore().getProxy().setUrl(`${view.baseurl}/list`);
-	    view.getStore().load();
+
+	    this.store = Ext.create('Ext.data.Store', {
+		model: 'pmx-disk-list',
+	    });
+	    this.store.on('load', this.onLoad, this);
+
+	    Proxmox.Utils.monStoreErrors(view, this.store);
+	    this.reload();
 	},
-    },
 
-    store: {
-	model: 'pmx-disk-list',
-	proxy: {
-	    type: 'proxmox',
+	onLoad: function(store, records, success, operation) {
+	    let me = this;
+	    let view = this.getView();
+
+	    if (!success) {
+		Proxmox.Utils.setErrorMask(
+		    view,
+		    Proxmox.Utils.getResponseErrorMessage(operation.getError()),
+		);
+		return;
+	    }
+
+	    let disks = {};
+
+	    for (const item of records) {
+		let data = item.data;
+		data.leaf = true;
+		data.expanded = true;
+		data.children = [];
+		data.iconCls = 'fa fa-fw fa-hdd-o x-fa-tree';
+		if (!data.parent) {
+		    disks[data.devpath] = data;
+		}
+	    }
+	    for (const item of records) {
+		let data = item.data;
+		if (data.parent) {
+		    disks[data.parent].leaf = false;
+		    disks[data.parent].children.push(data);
+		}
+	    }
+
+	    let children = [];
+	    for (const [_, device] of Object.entries(disks)) {
+		children.push(device);
+	    }
+
+	    view.setRootNode({
+		expanded: true,
+		children: children,
+	    });
+
+	    Proxmox.Utils.setErrorMask(view, false);
 	},
-	sorters: [
-	    {
-		property: 'dev',
-		direction: 'ASC',
-	    },
-	],
     },
 
     tbar: [
@@ -125,15 +176,25 @@ Ext.define('Proxmox.DiskList', {
 	{
 	    xtype: 'proxmoxButton',
 	    text: gettext('Show S.M.A.R.T. values'),
+	    parentXType: 'treepanel',
 	    disabled: true,
+	    enableFn: function(rec) {
+		if (!rec || rec.data.parent) {
+		    return false;
+		} else {
+		    return true;
+		}
+	    },
 	    handler: 'openSmartWindow',
 	},
 	{
 	    xtype: 'proxmoxButton',
 	    text: gettext('Initialize Disk with GPT'),
+	    parentXType: 'treepanel',
 	    disabled: true,
 	    enableFn: function(rec) {
-		if (!rec || (rec.data.used && rec.data.used !== 'unused')) {
+		if (!rec || rec.data.parent ||
+		    (rec.data.used && rec.data.used !== 'unused')) {
 		    return false;
 		} else {
 		    return true;
@@ -145,6 +206,7 @@ Ext.define('Proxmox.DiskList', {
 
     columns: [
 	{
+	    xtype: 'treecolumn',
 	    header: gettext('Device'),
 	    width: 150,
 	    sortable: true,
-- 
2.20.1





  reply	other threads:[~2021-02-08 14:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-08 14:23 [pve-devel] [PATCH-SERIES v2] partially fix #2285: extend Diskmanage to also list partitions Fabian Ebner
2021-02-08 14:23 ` Fabian Ebner [this message]
2021-02-08 14:23 ` [pve-devel] [PATCH v2 widget-toolkit 2/3] move DiskList.js from grid/ to panel/ Fabian Ebner
2021-02-08 14:23 ` [pve-devel] [PATCH v2 manager 3/3] ui: disk list: include partitions Fabian Ebner
2021-02-09  8:04 ` [pve-devel] [PATCH v2 storage] Diskmanage: also set type for partitions Fabian Ebner
2021-02-09 10:57   ` [pve-devel] applied: " Thomas Lamprecht
2021-02-09 12:40 ` [pve-devel] applied-series: [PATCH-SERIES v2] partially fix #2285: extend Diskmanage to also list partitions Thomas Lamprecht

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=20210208142329.23068-2-f.ebner@proxmox.com \
    --to=f.ebner@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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal