[pve-devel] [PATCH manager 4/5] fix #143: add disk/mem percent sort

Dominik Csapak d.csapak at proxmox.com
Fri Apr 15 15:26:28 CEST 2016


previously, we had a disk/memory usage column in the resource grid,
whose raw data were the bytes used, but we added a renderer
to display it as percentage

with this, the columns sorted by bytes and not by percentage,
which made the column rather confusing

with this patch, we add a real percentage column (where the
data is a float from 0 to 1) so it sorts correctly

also make the old columns show the used size in B/KiB/etc.
by default we still only show the percentage column

since the disk usage part was always zero with qemu guests,
leave it empty there

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/Utils.js              | 14 +++++++-------
 www/manager6/data/ResourceStore.js | 29 ++++++++++++++++++++++++++---
 www/manager6/form/NodeSelector.js  |  4 ++--
 3 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index cd61c24..9c6dd8d 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -888,9 +888,7 @@ Ext.define('PVE.Utils', { statics: {
 	    return '';
 	}
 
-	var per = (mem * 100) / maxmem;
-
-	return per.toFixed(1) + '%';
+	return PVE.Utils.render_size(value);
     },
 
     calculate_disk_usage: function(data) {
@@ -917,14 +915,16 @@ Ext.define('PVE.Utils', { statics: {
 
 	var disk = value;
 	var maxdisk = record.data.maxdisk;
+	var type = record.data.type;
 
-	if (!(Ext.isNumeric(disk) && maxdisk)) {
+	if (!Ext.isNumeric(disk) ||
+	    type === 'qemu' ||
+	    maxdisk === 0 ||
+	    (type === 'lxc' && record.data.uptime === 0)) {
 	    return '';
 	}
 
-	var per = (disk * 100) / maxdisk;
-
-	return per.toFixed(1) + '%';
+	return PVE.Utils.render_size(value);
     },
 
     render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) {
diff --git a/www/manager6/data/ResourceStore.js b/www/manager6/data/ResourceStore.js
index 4c409de..538f860 100644
--- a/www/manager6/data/ResourceStore.js
+++ b/www/manager6/data/ResourceStore.js
@@ -94,7 +94,17 @@ Ext.define('PVE.data.ResourceStore', {
 		type: 'integer',
 		renderer: PVE.Utils.render_disk_usage,
 		sortable: true,
-		width: 100
+		width: 100,
+		hidden: true,
+	    },
+	    diskuse: {
+		header: gettext('Disk usage') + " %",
+		type: 'number',
+		sortable: true,
+		renderer: PVE.Utils.render_disk_usage_percent,
+		width: 100,
+		calculate: PVE.Utils.calculate_disk_usage,
+		sortType: 'asFloat',
 	    },
 	    maxdisk: {
 		header: gettext('Disk size'),
@@ -109,6 +119,16 @@ Ext.define('PVE.data.ResourceStore', {
 		type: 'integer',
 		renderer: PVE.Utils.render_mem_usage,
 		sortable: true,
+		hidden: true,
+		width: 100
+	    },
+	    memuse: {
+		header: gettext('Memory usage') + " %",
+		type: 'number',
+		renderer: PVE.Utils.render_mem_usage_percent,
+		calculate: PVE.Utils.calculate_mem_usage,
+		sortType: 'asFloat',
+		sortable: true,
 		width: 100
 	    },
 	    maxmem: {
@@ -205,13 +225,16 @@ Ext.define('PVE.data.ResourceStore', {
 	var fields = [];
 	var fieldNames = [];
 	Ext.Object.each(field_defaults, function(key, value) {
-	    if (!Ext.isDefined(value.convert)) {
+	    if (!Ext.isDefined(value.convert) && !Ext.isDefined(value.calculate)) {
 		fields.push({name: key, type: value.type});
 		fieldNames.push(key);
 	    } else if (key === 'text' || key === 'running') { 
 		fields.push({name: key, type: value.type, convert: value.convert});
 		fieldNames.push(key);
-	    }		
+	    } else {
+		value.name = key;
+		fields.push(value);
+	    }
 	});
 
 	Ext.define('PVEResources', {
diff --git a/www/manager6/form/NodeSelector.js b/www/manager6/form/NodeSelector.js
index 2a7f013..8c69430 100644
--- a/www/manager6/form/NodeSelector.js
+++ b/www/manager6/form/NodeSelector.js
@@ -43,8 +43,8 @@ Ext.define('PVE.form.NodeSelector', {
 		flex: 1
 	    },
 	    {
-		header: gettext('Memory usage'),
-		renderer: PVE.Utils.render_mem_usage,
+		header: gettext('Memory usage') + " %",
+		renderer: PVE.Utils.render_mem_usage_percent,
 		sortable: true,
 		width: 100,
 		dataIndex: 'mem'
-- 
2.1.4





More information about the pve-devel mailing list