[pve-devel] [PATCH 7/9] display used memory differently and allow correct sort

Stefan Priebe s.priebe at profihost.ag
Wed Apr 24 11:53:05 CEST 2013


Signed-off-by: Stefan Priebe <s.priebe at profihost.ag>
---
 www/manager/Utils.js              |   34 ++++++++++++++++++++++++++++++++++
 www/manager/data/ResourceStore.js |    2 +-
 www/manager/form/NodeSelector.js  |    4 +++-
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/www/manager/Utils.js b/www/manager/Utils.js
index 902129d..4e02a54 100644
--- a/www/manager/Utils.js
+++ b/www/manager/Utils.js
@@ -740,6 +740,40 @@ Ext.define('PVE.Utils', { statics: {
 	return Ext.Date.format(servertime, 'Y-m-d H:i:s');
     },
 
+    convert_mem_to_memused: function(value, record) {
+	var mem = value;
+	var maxmem = record.data.maxmem;
+
+	if (!record.data.uptime) {
+	    return '';
+	}
+
+	if (!(Ext.isNumeric(mem) && maxmem)) {
+	    return '';
+	}
+
+	var memused = maxmem - mem;
+
+	return memused;
+    },
+
+    render_memused: function(value, metaData, record, rowIndex, colIndex, store) {
+	var memused = value;
+	var maxmem = record.data.maxmem;
+
+	if (!record.data.uptime) {
+	    return '';
+	}
+
+	if (!(Ext.isNumeric(memused) && maxmem)) {
+	    return '';
+	}
+
+	var per = (memused * 100) / maxmem;
+	return PVE.Utils.format_size(memused) + ' (' + per.toFixed(1) + '%)';
+    
+    },
+
     render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) {
 
 	var mem = value;
diff --git a/www/manager/data/ResourceStore.js b/www/manager/data/ResourceStore.js
index 9a27b38..8b3fbc9 100644
--- a/www/manager/data/ResourceStore.js
+++ b/www/manager/data/ResourceStore.js
@@ -108,7 +108,7 @@ Ext.define('PVE.data.ResourceStore', {
 	    mem: {
 		header: gettext('Memory usage'),
 		type: 'integer',
-		renderer: PVE.Utils.render_mem_usage,
+		renderer: PVE.Utils.render_memused,
 		sortable: true,
 		width: 100,
 		align: 'right',
diff --git a/www/manager/form/NodeSelector.js b/www/manager/form/NodeSelector.js
index e92dbbd..723a745 100644
--- a/www/manager/form/NodeSelector.js
+++ b/www/manager/form/NodeSelector.js
@@ -45,7 +45,9 @@ Ext.define('PVE.form.NodeSelector', {
 		    },
 		    {
 			header: 'Memory usage',			
-			renderer: PVE.Utils.render_mem_usage,
+			renderer: PVE.Utils.render_memused,
+			convert: PVE.Utils.convert_mem_to_memused,
+			align: 'right',
 			sortable: true,
 			width: 100,
 			dataIndex: 'mem'
-- 
1.7.10.4




More information about the pve-devel mailing list