[pve-devel] r5808 - in pve-manager/pve2/www/new: . data

svn-commits at proxmox.com svn-commits at proxmox.com
Tue Apr 12 09:48:39 CEST 2011


Author: dietmar
Date: 2011-04-12 09:48:39 +0200 (Tue, 12 Apr 2011)
New Revision: 5808

Modified:
   pve-manager/pve2/www/new/PVEUtils.js
   pve-manager/pve2/www/new/data/ResourceStore.js
Log:
simplify rendering


Modified: pve-manager/pve2/www/new/PVEUtils.js
===================================================================
--- pve-manager/pve2/www/new/PVEUtils.js	2011-04-12 06:18:15 UTC (rev 5807)
+++ pve-manager/pve2/www/new/PVEUtils.js	2011-04-12 07:48:39 UTC (rev 5808)
@@ -64,6 +64,7 @@
 	    return gb.toFixed(2) + "GB";
 
 	var tb =  gb / 1024;
+
 	return tb.toFixed(2) + "TB";
 
     },
@@ -203,36 +204,47 @@
 
 	var per = (cpu * 100) / maxcpu;
 
+	return per.toFixed(1) + '% of ' + maxcpu + (maxcpu > 1 ? 'CPUs' : 'CPU');
+
 	return PVE.Utils.format_html_bar(per, per.toFixed(0) + '% of ' + 
 				     maxcpu + (maxcpu > 1 ? 'CPUs' : 'CPU'));
     },
 
-    render_mem: function(value, metaData, record, rowIndex, colIndex, store) {
+    render_size: function(value, metaData, record, rowIndex, colIndex, store) {
 
+	if (!Ext.isNumeric(value))
+	    return '';
+
+	return PVE.Utils.format_size(value);
+    },
+
+    render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) {
+
 	var mem = value;
 	var maxmem = record.data.maxmem;
 	
-	if (record.data.itype == 'storage' || mem === undefined || maxmem === undefined)
+	if (!(Ext.isNumeric(mem) && maxmem))
 	    return ''
 
-	return PVE.Utils.format_html_bar((mem * 100) / maxmem, 
-				     PVE.Utils.format_size(mem));
+	var per = (mem * 100) / maxmem;
 
+	return per.toFixed(1) + '%';
     },
 
-    render_disk: function(value, metaData, record, rowIndex, colIndex, store) {
+    render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) {
 
 	var disk = value;
 	var maxdisk = record.data.maxdisk;
 
-	if (disk === undefined || maxdisk === undefined)
+	if (!(Ext.isNumeric(disk) && maxdisk))
 	    return ''
 
-	return PVE.Utils.format_html_bar((disk * 100) / maxdisk, 
-				     PVE.Utils.format_size(disk));
+	var per = (disk * 100) / maxdisk;
+
+	return per.toFixed(1) + '%';
     },
 
-    render_itype: function(value, metaData, record, rowIndex, colIndex, store) {
+    render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) {
 
 	var cls = 'pve-itype-icon-' + value;
 

Modified: pve-manager/pve2/www/new/data/ResourceStore.js
===================================================================
--- pve-manager/pve2/www/new/data/ResourceStore.js	2011-04-12 06:18:15 UTC (rev 5807)
+++ pve-manager/pve2/www/new/data/ResourceStore.js	2011-04-12 07:48:39 UTC (rev 5808)
@@ -10,28 +10,50 @@
 	    type: {
 		header: 'Type',
 		type: 'text',
-		renderer: PVE.Utils.render_itype,
+		renderer: PVE.Utils.render_resource_type,
 		sortable: true,
 		hideable: false,
-		width: 50
+		width: 80
 	    },
 	    id: {
 		header: 'ID',
+		type: 'text',
 		hidden: true,
 		sortable: true,
-		type: 'text'
+		width: 80
 	    },
 	    text: {
 		header: 'Text',
 		type: 'text',
 		sortable: true,
-		width: 200
+		width: 200,
+		convert: function(value, record) {
+		    var info = record.data;
+		    var text;
+
+		    if (value)
+			return value;
+
+		    if (info.type === 'node') {
+			text = info.node;
+		    } else if (info.type === 'storage') {
+			text = info.storage + ' (' + info.node + ')';
+		    } else if (info.type === 'qemu' || info.type === 'openvz') {
+			text = info.vmid;
+			if (info.name)
+			    text += " (" + info.name + ')';
+		    } else {
+			text = info.id;
+		    }
+		    return text;
+		}
 	    },
 	    vmid: {
 		header: 'VMID',
+		type: 'integer',
 		hidden: true,
 		sortable: true,
-		type: 'integer'
+		width: 80
 	    },
 	    name: {
 		header: 'Name',
@@ -40,39 +62,41 @@
 		type: 'text'
 	    },
 	    disk: {
-		header: 'Disk',
+		header: 'Disk usage',
 		type: 'integer',
-		renderer: PVE.Utils.render_disk,
+		renderer: PVE.Utils.render_disk_usage,
 		sortable: true,
-		width: 60
+		width: 100
 	    },
 	    maxdisk: {
-		header: 'maxdisk',
+		header: 'Disk size',
 		type: 'integer',
+		renderer: PVE.Utils.render_size,
 		sortable: true,
 		hidden: true,
-		width: 60
+		width: 100
 	    },
 	    mem: {
-		header: 'Memory',
+		header: 'Memory usage',
 		type: 'integer',
-		renderer: PVE.Utils.render_mem,
+		renderer: PVE.Utils.render_mem_usage,
 		sortable: true,
-		width: 60
+		width: 100
 	    },
 	    maxmem: {
-		header: 'maxmem',
+		header: 'Mem size',
 		type:'integer',
+		renderer: PVE.Utils.render_size,
 		hidden: true,
 		sortable: true,
-		width: 60
+		width: 100
 	    },
 	    cpu: {
-		header: 'CPU',
+		header: 'CPU usage',
 		type: 'float',
 		renderer: PVE.Utils.render_cpu,
 		sortable: true,
-		width: 85
+		width: 100
 	    },
 	    maxcpu: {
 		header: 'maxcpu',
@@ -106,35 +130,12 @@
 
 	var fields = [];
 	Ext.Object.each(field_defaults, function(key, value) {
-	    if (name !== 'text')
+	    if (!Ext.isDefined(value.convert))
 		fields.push({name: key, type: value.type});
+	    else if (key === 'text') 
+		fields.push({name: key, type: value.type, convert: value.convert});		
 	});
 
-	fields.push({
-	    name: 'text',
-	    type: 'text',
-            convert: function(value, record) {
-		var info = record.data;
-		var text;
-
-		if (value)
-		    return value;
-
-		if (info.type === 'node') {
-		    text = info.node;
-		} else if (info.type === 'storage') {
-		    text = info.storage + ' (' + info.node + ')';
-		} else if (info.type === 'qemu' || info.type === 'openvz') {
-		    text = info.vmid;
-		    if (info.name)
-			text += " (" + info.name + ')';
-		} else {
-		    text = info.id;
-		}
-		return text;
-	    }
-	});
-
 	Ext.regModel('PVEResources', {
 	    fields: fields,
 	    proxy: {



More information about the pve-devel mailing list