[pve-devel] [PATCH widget-toolkit 1/2] add DiskSelector from PVE

Dominik Csapak d.csapak at proxmox.com
Tue Jun 16 11:06:33 CEST 2020


to be usable with other products.
also add a parameter 'typeProperty' to be able to configure
the backend property for the usage type

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/Makefile             |  1 +
 src/form/DiskSelector.js | 80 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+)
 create mode 100644 src/form/DiskSelector.js

diff --git a/src/Makefile b/src/Makefile
index 659e876..2696103 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -29,6 +29,7 @@ JSSRC=					\
 	form/NetworkSelector.js		\
 	form/RealmComboBox.js		\
 	form/RoleSelector.js		\
+	form/DiskSelector.js		\
 	button/Button.js		\
 	button/HelpButton.js		\
 	grid/ObjectGrid.js		\
diff --git a/src/form/DiskSelector.js b/src/form/DiskSelector.js
new file mode 100644
index 0000000..4552beb
--- /dev/null
+++ b/src/form/DiskSelector.js
@@ -0,0 +1,80 @@
+Ext.define('Proxmox.form.DiskSelector', {
+    extend: 'Proxmox.form.ComboGrid',
+    xtype: 'pmxDiskSelector',
+
+    // can be
+    // undefined: all
+    // unused: only unused
+    // journal_disk: all disks with gpt
+    diskType: undefined,
+
+    // the property the backend wnats for the type ('type' by default)
+    typeProperty: 'type',
+
+    valueField: 'devpath',
+    displayField: 'devpath',
+    emptyText: gettext('No Disks unused'),
+    listConfig: {
+	width: 600,
+	columns: [
+	    {
+		header: gettext('Device'),
+		flex: 3,
+		sortable: true,
+		dataIndex: 'devpath',
+	    },
+	    {
+		header: gettext('Size'),
+		flex: 2,
+		sortable: false,
+		renderer: Proxmox.Utils.format_size,
+		dataIndex: 'size',
+	    },
+	    {
+		header: gettext('Serial'),
+		flex: 5,
+		sortable: true,
+		dataIndex: 'serial',
+	    },
+	],
+    },
+
+    initComponent: function() {
+	var me = this;
+
+	var nodename = me.nodename;
+	if (!nodename) {
+	    throw "no node name specified";
+	}
+
+	let extraParams = {};
+
+	if (me.diskType) {
+	    extraParams[me.typeProperty] = me.diskType;
+	}
+
+	var store = Ext.create('Ext.data.Store', {
+	    filterOnLoad: true,
+	    model: 'pmx-disk-list',
+	    proxy: {
+                type: 'proxmox',
+                url: `/api2/json/nodes/${nodename}/disks/list`,
+		extraParams,
+	    },
+	    sorters: [
+		{
+		    property: 'devpath',
+		    direction: 'ASC',
+		},
+	    ],
+	});
+
+	Ext.apply(me, {
+	    store: store,
+	});
+
+        me.callParent();
+
+	store.load();
+    },
+});
-- 
2.20.1





More information about the pve-devel mailing list