[pve-devel] [PATCH manager 3/5] add render_*_percentage and calculate_* to Utils

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


these functions will be used for the resource grid

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/Utils.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index 2c536aa..cd61c24 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -846,6 +846,35 @@ Ext.define('PVE.Utils', { statics: {
 	return Ext.Date.format(servertime, 'Y-m-d H:i:s');
     },
 
+    calculate_mem_usage: function(data) {
+	if (!Ext.isNumeric(data.mem) ||
+	    data.maxmem === 0 ||
+	    data.uptime < 1) {
+	    return -1;
+	}
+
+	return (data.mem / data.maxmem);
+    },
+
+    render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
+	if (!Ext.isNumeric(value) || value === -1) {
+	    return '';
+	}
+	if (value > 1 ) {
+	    // we got no percentage but bytes
+	    var mem = value;
+	    var maxmem = record.data.maxmem;
+	    if (!record.data.uptime ||
+		maxmem === 0 ||
+		!Ext.isNumeric(mem)) {
+		return '';
+	    }
+
+	    return ((mem*100)/maxmem).toFixed(1) + " %";
+	}
+	return (value*100).toFixed(1) + " %";
+    },
+
     render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) {
 
 	var mem = value;
@@ -864,6 +893,26 @@ Ext.define('PVE.Utils', { statics: {
 	return per.toFixed(1) + '%';
     },
 
+    calculate_disk_usage: function(data) {
+
+	if (!Ext.isNumeric(data.disk) ||
+	    data.type === 'qemu' ||
+	    (data.type === 'lxc' && data.uptime === 0) ||
+	    data.maxdisk === 0) {
+	    return -1;
+	}
+
+	return (data.disk / data.maxdisk);
+    },
+
+    render_disk_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
+	if (!Ext.isNumeric(value) || value === -1) {
+	    return '';
+	}
+
+	return (value * 100).toFixed(1) + " %";
+    },
+
     render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) {
 
 	var disk = value;
-- 
2.1.4





More information about the pve-devel mailing list