From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@proxmox.com>
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 9E2886BC1A
 for <pve-devel@lists.proxmox.com>; Tue, 21 Sep 2021 13:22:13 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 917C8D641
 for <pve-devel@lists.proxmox.com>; Tue, 21 Sep 2021 13:22:13 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (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 66BD1D630
 for <pve-devel@lists.proxmox.com>; Tue, 21 Sep 2021 13:22:12 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 41AA3448B9
 for <pve-devel@lists.proxmox.com>; Tue, 21 Sep 2021 13:22:12 +0200 (CEST)
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Tue, 21 Sep 2021 13:22:06 +0200
Message-Id: <20210921112208.48084-3-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20210921112208.48084-1-f.ebner@proxmox.com>
References: <20210921112208.48084-1-f.ebner@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.319 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 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. [params.target]
Subject: [pve-devel] [PATCH v2 manager 2/4] ui: storage selector: add new
 clusterView option
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 21 Sep 2021 11:22:13 -0000

which allows selecting storages available in the whole cluster and
controls whether usage information or node/shared information is
displayed. It is still possible to filter by node and content type.

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

Changes from v1:
    * Extend existing storage selector to also support a cluster view
      instead of adding a new storage selector.

 www/manager6/form/StorageSelector.js | 98 +++++++++++++++++++++++-----
 1 file changed, 80 insertions(+), 18 deletions(-)

diff --git a/www/manager6/form/StorageSelector.js b/www/manager6/form/StorageSelector.js
index bb56f159..5a394538 100644
--- a/www/manager6/form/StorageSelector.js
+++ b/www/manager6/form/StorageSelector.js
@@ -1,11 +1,19 @@
 Ext.define('PVE.form.StorageSelector', {
     extend: 'Proxmox.form.ComboGrid',
     alias: 'widget.pveStorageSelector',
+    mixins: ['Proxmox.Mixin.CBind'],
+
+    cbindData: {
+	clusterView: false,
+    },
 
     allowBlank: false,
     valueField: 'storage',
     displayField: 'storage',
     listConfig: {
+	cbind: {
+	    clusterView: '{clusterView}',
+	},
 	width: 450,
 	columns: [
 	    {
@@ -24,37 +32,87 @@ Ext.define('PVE.form.StorageSelector', {
 		width: 90,
 		dataIndex: 'avail',
 		renderer: Proxmox.Utils.format_size,
+		cbind: {
+		    hidden: '{clusterView}',
+		},
 	    },
 	    {
 		header: gettext('Capacity'),
 		width: 90,
 		dataIndex: 'total',
 		renderer: Proxmox.Utils.format_size,
+		cbind: {
+		    hidden: '{clusterView}',
+		},
+	    },
+	    {
+		header: gettext('Nodes'),
+		width: 120,
+		dataIndex: 'nodes',
+		renderer: (value) => value ? value : '-- ' + gettext('All') + ' --',
+		cbind: {
+		    hidden: '{!clusterView}',
+		},
+	    },
+	    {
+		header: gettext('Shared'),
+		width: 70,
+		dataIndex: 'shared',
+		renderer: Proxmox.Utils.format_boolean,
+		cbind: {
+		    hidden: '{!clusterView}',
+		},
 	    },
 	],
     },
 
     reloadStorageList: function() {
 	let me = this;
-	if (!me.nodename) {
-	    return;
-	}
 
-	let params = {
-	    format: 1,
-	};
-	if (me.storageContent) {
-	    params.content = me.storageContent;
-	}
-	if (me.targetNode) {
-	    params.target = me.targetNode;
-	    params.enabled = 1; // skip disabled storages
+	if (me.clusterView) {
+	    me.getStore().setProxy({
+		type: 'proxmox',
+		url: `/api2/json/storage`,
+	    });
+
+	    // filter here, back-end does not support it currently
+	    let filters = [(storage) => !storage.data.disable];
+
+	    if (me.storageContent) {
+		filters.push(
+		    (storage) => storage.data.content.split(',').includes(me.storageContent),
+		);
+	    }
+
+	    if (me.nodename) {
+		filters.push(
+		    (storage) => !storage.data.nodes || storage.data.nodes.includes(me.nodename),
+		);
+	    }
+
+	    me.getStore().clearFilter();
+	    me.getStore().setFilters(filters);
+	} else {
+	    if (!me.nodename) {
+		return;
+	    }
+
+	    let params = {
+		format: 1,
+	    };
+	    if (me.storageContent) {
+		params.content = me.storageContent;
+	    }
+	    if (me.targetNode) {
+		params.target = me.targetNode;
+		params.enabled = 1; // skip disabled storages
+	    }
+	    me.store.setProxy({
+		type: 'proxmox',
+		url: `/api2/json/nodes/${me.nodename}/storage`,
+		extraParams: params,
+	    });
 	}
-	me.store.setProxy({
-	    type: 'proxmox',
-	    url: `/api2/json/nodes/${me.nodename}/storage`,
-	    extraParams: params,
-	});
 
 	me.store.load(() => me.validate());
     },
@@ -66,6 +124,10 @@ Ext.define('PVE.form.StorageSelector', {
 	    return;
 	}
 
+	if (me.clusterView) {
+	    throw "setting targetNode with clusterView is not implemented";
+	}
+
 	me.targetNode = targetNode;
 
 	me.reloadStorageList();
@@ -110,7 +172,7 @@ Ext.define('PVE.form.StorageSelector', {
 }, function() {
     Ext.define('pve-storage-status', {
 	extend: 'Ext.data.Model',
-	fields: ['storage', 'active', 'type', 'avail', 'total'],
+	fields: ['storage', 'active', 'type', 'avail', 'total', 'nodes', 'shared'],
 	idProperty: 'storage',
     });
 });
-- 
2.30.2