[pve-devel] [PATCH widget-toolkit 07/11] disk list: factor out renderers for type and usage

Fabian Ebner f.ebner at proxmox.com
Fri Apr 23 12:14:57 CEST 2021


to be re-used later.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 src/panel/DiskList.js | 64 +++++++++++++++++++++++++------------------
 1 file changed, 37 insertions(+), 27 deletions(-)

diff --git a/src/panel/DiskList.js b/src/panel/DiskList.js
index ad965c8..10cf840 100644
--- a/src/panel/DiskList.js
+++ b/src/panel/DiskList.js
@@ -173,6 +173,39 @@ Ext.define('Proxmox.DiskList', {
 	},
     },
 
+    renderDiskType: function(v) {
+	if (v === undefined) return Proxmox.Utils.unknownText;
+	switch (v) {
+	    case 'ssd': return 'SSD';
+	    case 'hdd': return 'Hard Disk';
+	    case 'usb': return 'USB';
+	    default: return v;
+	}
+    },
+
+    renderDiskUsage: function(v, metaData, rec) {
+	let extendedInfo = '';
+	if (rec) {
+	    let types = [];
+	    if (rec.data.osdid !== undefined && rec.data.osdid >= 0) {
+		types.push(`OSD.${rec.data.osdid.toString()}`);
+	    }
+	    if (rec.data.journals > 0) {
+		types.push('Journal');
+	    }
+	    if (rec.data.db > 0) {
+		types.push('DB');
+	    }
+	    if (rec.data.wal > 0) {
+		types.push('WAL');
+	    }
+	    if (types.length > 0) {
+		extendedInfo = `, Ceph (${types.join(', ')})`;
+	    }
+	}
+	return v ? `${v}${extendedInfo}` : Proxmox.Utils.noText;
+    },
+
     tbar: [
 	{
 	    text: gettext('Reload'),
@@ -223,13 +256,8 @@ Ext.define('Proxmox.DiskList', {
 	    sortable: true,
 	    dataIndex: 'disk-type',
 	    renderer: function(v) {
-		if (v === undefined) return Proxmox.Utils.unknownText;
-		switch (v) {
-		    case 'ssd': return 'SSD';
-		    case 'hdd': return 'Hard Disk';
-		    case 'usb': return 'USB';
-		    default: return v;
-		}
+		let me = this;
+		return me.renderDiskType(v);
 	    },
 	},
 	{
@@ -237,26 +265,8 @@ Ext.define('Proxmox.DiskList', {
 	    width: 150,
 	    sortable: false,
 	    renderer: function(v, metaData, rec) {
-		let extendedInfo = '';
-		if (rec) {
-		    let types = [];
-		    if (rec.data.osdid !== undefined && rec.data.osdid >= 0) {
-			types.push(`OSD.${rec.data.osdid.toString()}`);
-		    }
-		    if (rec.data.journals > 0) {
-			types.push('Journal');
-		    }
-		    if (rec.data.db > 0) {
-			types.push('DB');
-		    }
-		    if (rec.data.wal > 0) {
-			types.push('WAL');
-		    }
-		    if (types.length > 0) {
-			extendedInfo = `, Ceph (${types.join(', ')})`;
-		    }
-		}
-		return v ? `${v}${extendedInfo}` : Proxmox.Utils.noText;
+		let me = this;
+		return me.renderDiskUsage(v, metaData, rec);
 	    },
 	    dataIndex: 'used',
 	},
-- 
2.20.1






More information about the pve-devel mailing list