From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 517FC6B417 for ; Tue, 26 Jan 2021 12:46:14 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5F98E15B17 for ; Tue, 26 Jan 2021 12:45:43 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id C20FA15999 for ; Tue, 26 Jan 2021 12:45:36 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 89C19460FE for ; Tue, 26 Jan 2021 12:45:36 +0100 (CET) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Tue, 26 Jan 2021 12:45:29 +0100 Message-Id: <20210126114530.8753-14-f.ebner@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210126114530.8753-1-f.ebner@proxmox.com> References: <20210126114530.8753-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.006 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [this.store] Subject: [pve-devel] [PATCH widget-toolkit 13/14] convert disk list to disk tree including the partitions X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jan 2021 11:46:14 -0000 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 --- src/grid/DiskList.js | 97 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 78 insertions(+), 19 deletions(-) diff --git a/src/grid/DiskList.js b/src/grid/DiskList.js index 4d8ef1b..4a4f239 100644 --- a/src/grid/DiskList.js +++ b/src/grid/DiskList.js @@ -36,20 +36,32 @@ 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 url = `${view.baseurl}/list`; + me.store.setProxy({ + type: 'proxmox', + extraParams: { + 'include-partitions': 1, + }, + url: url, + }); + me.store.load(); }, openSmartWindow: function() { @@ -94,27 +106,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 +173,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 +203,7 @@ Ext.define('Proxmox.DiskList', { columns: [ { + xtype: 'treecolumn', header: gettext('Device'), width: 150, sortable: true, -- 2.20.1