[pve-devel] r5874 - in pve-manager/pve2/www: css new new/grid new/qemu

svn-commits at proxmox.com svn-commits at proxmox.com
Mon Apr 25 10:08:41 CEST 2011


Author: dietmar
Date: 2011-04-25 10:08:41 +0200 (Mon, 25 Apr 2011)
New Revision: 5874

Added:
   pve-manager/pve2/www/new/qemu/HardwareView.js
Modified:
   pve-manager/pve2/www/css/ext-pve.css
   pve-manager/pve2/www/new/Makefile.am
   pve-manager/pve2/www/new/PVEUtils.js
   pve-manager/pve2/www/new/grid/ObjectGrid.js
   pve-manager/pve2/www/new/grid/ResourceGrid.js
   pve-manager/pve2/www/new/qemu/Config.js
Log:
start hardware view


Modified: pve-manager/pve2/www/css/ext-pve.css
===================================================================
--- pve-manager/pve2/www/css/ext-pve.css	2011-04-25 04:36:57 UTC (rev 5873)
+++ pve-manager/pve2/www/css/ext-pve.css	2011-04-25 08:08:41 UTC (rev 5874)
@@ -7,6 +7,7 @@
     width: 16px;
     height: 18px;
     background-repeat: no-repeat;
+    background-position:3px center;
     padding-left: 20px;
 }
 

Modified: pve-manager/pve2/www/new/Makefile.am
===================================================================
--- pve-manager/pve2/www/new/Makefile.am	2011-04-25 04:36:57 UTC (rev 5873)
+++ pve-manager/pve2/www/new/Makefile.am	2011-04-25 08:08:41 UTC (rev 5874)
@@ -22,6 +22,7 @@
 	node/TimeEdit.js				\
 	node/Config.js					\
 	qemu/Config.js					\
+	qemu/HardwareView.js					\
 	storage/Browser.js				\
 	dc/Config.js					\
 	Workspace.js

Modified: pve-manager/pve2/www/new/PVEUtils.js
===================================================================
--- pve-manager/pve2/www/new/PVEUtils.js	2011-04-25 04:36:57 UTC (rev 5873)
+++ pve-manager/pve2/www/new/PVEUtils.js	2011-04-25 08:08:41 UTC (rev 5874)
@@ -247,8 +247,8 @@
     render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) {
 
 	var cls = 'pve-itype-icon-' + value;
-
-	return "<div class='" + cls + "'</div><div>" + value + "</div>";
+	metaData.css = cls;
+	return value;
     },
 
     render_uptime: function(value, metaData, record, rowIndex, colIndex, store) {

Modified: pve-manager/pve2/www/new/grid/ObjectGrid.js
===================================================================
--- pve-manager/pve2/www/new/grid/ObjectGrid.js	2011-04-25 04:36:57 UTC (rev 5873)
+++ pve-manager/pve2/www/new/grid/ObjectGrid.js	2011-04-25 08:08:41 UTC (rev 5874)
@@ -9,7 +9,7 @@
     initComponent : function() {
 	var me = this;
 
-	var rows = me.rows || {};
+	var rows = me.rows;
 
 	var visible = false;
 
@@ -20,7 +20,10 @@
 	var store = Ext.create('Ext.data.Store', {
 	    model: 'KeyValue',
 	    proxy: 'memory',
-	    autoDestory: true
+	    autoDestory: true,
+	    sorters: {
+		property: 'key'
+	    }
 	});
 
 	var first_load_done = false;
@@ -46,16 +49,21 @@
 			return;
 		    }
 
+		    store.suspendEvents();
+
 		    // remove vanished items
 		    store.each(function(olditem) {
 			var item = rstore.data.get(olditem.data.key);
-			if (!item)
-			    store.remove(olditem);
+			if (!item) {
+			    if (!(rows && rows[olditem.data.key] && 
+				  Ext.isDefined(rows[olditem.data.key].defaultValue)))
+				store.remove(olditem);
+			}
 		    });
 		    
 		    // add/update items
 		    rstore.each(function(item) {
-			if (!rows[item.data.key])
+			if (rows && !rows[item.data.key])
 			    return;
 			var olditem = store.data.get(item.data.key);
 			if (olditem) {
@@ -69,18 +77,41 @@
 			    store.add(newrec);
 			}
 		    });
+		    
+		    // add default value
+		    if (rows) {
+			Ext.Object.each(rows, function(key, rowdef) {
+			    if (store.data.get(key) || !Ext.isDefined(rowdef.defaultValue))
+				return;
+			    var newrec = Ext.ModelMgr.create(
+				{ key: key, value: rowdef.defaultValue }, 
+				store.model, key);
+			    store.add(newrec);  
+			});
+		    }
+				   
+		    store.filterBy(function(item) {
+			if (rows && rows[item.data.key] && 
+			    (rows[item.data.key].visible === false))
+			    return false;
+			return true;
+		    });
+
+		    store.sort();
+		    store.resumeEvents();
+		    store.fireEvent('datachanged', store);
 		}
 	    });
 	});
 
 	var render_key = function(key) {
-	    var rowdef = rows[key] || {};
+	    var rowdef = (rows && rows[key]) ?  rows[key] : {};
 	    return rowdef.header || key;
 	};
 
 	var render_value = function(value, metaData, record, rowIndex, colIndex, store) {
 	    var key = record.data.key;
-	    var rowdef = rows[key] || {};
+	    var rowdef = (rows && rows[key]) ?  rows[key] : {};
 
 	    var renderer = rowdef.renderer;
 	    if (renderer)
@@ -89,9 +120,10 @@
 	    return value;
 	};
 
-	Ext.apply(me, {
+	Ext.applyIf(me, {
 	    store: store,
 	    hideHeaders: true,
+	    stateful: false,
 	    columns: [
 		{
 		    header: 'Name',

Modified: pve-manager/pve2/www/new/grid/ResourceGrid.js
===================================================================
--- pve-manager/pve2/www/new/grid/ResourceGrid.js	2011-04-25 04:36:57 UTC (rev 5873)
+++ pve-manager/pve2/www/new/grid/ResourceGrid.js	2011-04-25 08:08:41 UTC (rev 5874)
@@ -25,7 +25,8 @@
 	'PVE.data.ResourceStore'
     ],
     alias: ['widget.pveResourceGrid'],
-    features: [ {ftype: 'chunking'}],
+    // fixme: use chunking to improve performance
+    //features: [ {ftype: 'chunking'}],
     
     initComponent : function() {
 	var me = this;

Modified: pve-manager/pve2/www/new/qemu/Config.js
===================================================================
--- pve-manager/pve2/www/new/qemu/Config.js	2011-04-25 04:36:57 UTC (rev 5873)
+++ pve-manager/pve2/www/new/qemu/Config.js	2011-04-25 08:08:41 UTC (rev 5874)
@@ -35,7 +35,7 @@
 		{
 		    title: 'Hardware',
 		    itemId: 'hardware',
-		    html: 'hardware ' + vmid
+		    xtype: 'PVE.qemu.HardwareView'
 		},
 		{
 		    title: 'Options',

Added: pve-manager/pve2/www/new/qemu/HardwareView.js
===================================================================
--- pve-manager/pve2/www/new/qemu/HardwareView.js	                        (rev 0)
+++ pve-manager/pve2/www/new/qemu/HardwareView.js	2011-04-25 08:08:41 UTC (rev 5874)
@@ -0,0 +1,107 @@
+Ext.define('PVE.qemu.HardwareView', {
+    extend: 'PVE.grid.ObjectGrid',
+    alias: ['widget.PVE.qemu.HardwareView'],
+
+    initComponent : function() {
+	var me = this;
+	var i;
+
+	var nodename = me.pveSelNode.data.node;
+	if (!nodename) 
+	    throw "no node name specified";
+
+	var vmid = me.pveSelNode.data.vmid;
+	if (!vmid) 
+	    throw "no VM ID specified";
+
+	var rows = {
+	    memory: {
+		header: 'Memory',
+		renderer: function(value) {
+		    return PVE.Utils.format_size(value*1024*1024);
+		}
+	    },
+	    sockets: {
+		header: 'Processors',
+		defaultValue: 1,
+		renderer: function(value, metaData, record, rowIndex, colIndex, store) {
+		    var cores = store.snapshot.get('cores');
+		    console.log(store);
+		    return cores ? value * cores.data.value : value;
+		}
+	    },
+	    cores: {
+		header: 'Cores',
+		visible: false
+	    }
+	};
+
+	for (i = 0; i < 4; i++) {
+	    rows["ide" + i] = {
+		css: 'pve-itype-icon-storage',
+		header: 'Hard Disk (IDE)'
+	    };
+	}
+	for (i = 0; i < 16; i++) {
+	    rows["net" + i] = {
+		header: 'Network Adapter'
+	    };
+	}
+
+	
+	var render_key = function(key, metaData, record, rowIndex, colIndex, store) {
+	    var rowdef = rows[key] || {};
+
+	    if (rowdef.css)
+		metaData.css = rowdef.css;
+
+	    return rowdef.header || key;
+	};
+
+	var render_value = function(value, metaData, record, rowIndex, colIndex, store) {
+	    var key = record.data.key;
+	    var rowdef = rows[key] || {};
+
+	    var renderer = rowdef.renderer;
+	    if (renderer)
+		return renderer(value, metaData, record, rowIndex, colIndex, store);
+
+	    return value;
+	};
+
+	Ext.applyIf(me, {
+	    url: "/api2/json/nodes/" + nodename + "/qemu/" + vmid + "/config",
+	    cwidth1: 150,
+	    interval: 1000,
+	    tbar: [ 
+		{
+		    text: "Edit",
+		    //handler: run_editor
+		}
+	    ],
+	    rows: rows,
+	    columns: [
+		{
+		    header: 'Name',
+		    width: 120,
+		    dataIndex: 'key',
+		    renderer: render_key
+		},
+		{
+		    flex: 1,
+		    header: 'Value',
+		    dataIndex: 'value',
+		    renderer: render_value
+		}
+
+	    ],
+	    listeners: {
+		itemdblclick: function() {
+		    //run_editor();
+		}
+	    }
+	});
+
+	me.callParent();
+    }
+});




More information about the pve-devel mailing list