[pve-devel] r5806 - in pve-manager/pve2/www/new: . grid

svn-commits at proxmox.com svn-commits at proxmox.com
Mon Apr 11 12:03:23 CEST 2011


Author: dietmar
Date: 2011-04-11 12:03:23 +0200 (Mon, 11 Apr 2011)
New Revision: 5806

Modified:
   pve-manager/pve2/www/new/PVEUtils.js
   pve-manager/pve2/www/new/grid/ResourceGrid.js
Log:
 grid improvements


Modified: pve-manager/pve2/www/new/PVEUtils.js
===================================================================
--- pve-manager/pve2/www/new/PVEUtils.js	2011-04-08 10:56:41 UTC (rev 5805)
+++ pve-manager/pve2/www/new/PVEUtils.js	2011-04-11 10:03:23 UTC (rev 5806)
@@ -198,7 +198,7 @@
 	var cpu = value;
 	var maxcpu = record.data.maxcpu;
 
-	if (cpu === undefined || maxcpu === undefined)
+	if (!(Ext.isNumeric(value) && Ext.isNumeric(maxcpu) && (maxcpu >= 1)))
 	    return ''
 
 	var per = (cpu * 100) / maxcpu;

Modified: pve-manager/pve2/www/new/grid/ResourceGrid.js
===================================================================
--- pve-manager/pve2/www/new/grid/ResourceGrid.js	2011-04-08 10:56:41 UTC (rev 5805)
+++ pve-manager/pve2/www/new/grid/ResourceGrid.js	2011-04-11 10:03:23 UTC (rev 5806)
@@ -25,63 +25,89 @@
 	});
 
 	var pdata = {
-	    dataIndex: {},
 	    updateCount: 0
 	};
 
 	var updateGrid = function() {
 
-	    var index = pdata.dataIndex;
-
 	    var filterfn = null;
 	    
 	    console.log("START GRID UPDATE");
 
-	    // remove vanished or changed items
-	    var rmlist = [];
-	    for (var key in index) {
-		if (!index.hasOwnProperty(key))
-		    continue;
+	    store.suspendEvents();
 
-		var olditem = index[key];
+	    var nodeidx = {};
+	    var gather_child_nodes = function(cn) {
+                var cs = cn.childNodes,
+		len = cs.length,
+                i = 0, n, res;
 
-		// getById() use find(), which is slow (ExtJS4 beta2) 
-		//var item = rstore.getById(olditem.data.id);
-		var item = rstore.data.get(olditem.data.id);
+                for (; i < len; i++) {
+                    n = cs[i];
+		    var orgnode = rstore.data.get(n.data.id);
+		    if (orgnode) 
+			nodeidx[n.data.id] = rstore.data.get(n.data.id);
+ 		    gather_child_nodes(n);
+		}
+ 	    };
+	    gather_child_nodes(me.pveSelNode);
 
+	    // remove vanished items
+	    var rmlist = [];
+	    store.each(function(olditem) {
+		var item = nodeidx[olditem.data.id];
 		if (!item) {
-		    console.log("GRID REM UID: " + key + " ITEM " + olditem.data.id);
-		    delete index[key];
+		    //console.log("GRID REM UID: " + olditem.data.id);
 		    rmlist.push(item);
-
 		}
-	    }
+	    });
 	    if (rmlist.length) 
 		store.remove(rmlist);
 
  	    // add new items
 	    var addlist = [];
-            rstore.each(function(item) {
-		var olditem = index[item.data.id];
-		if (olditem)
-		    return;
+	    for (var key in nodeidx) {
+		if (!nodeidx.hasOwnProperty(key))
+		    continue;
 
-		if (filterfn && !filterfn(item))
-		    return;
+		var item = nodeidx[key];
+		
+		// getById() use find(), which is slow (ExtJS4 DP5) 
+		//var olditem = store.getById(item.data.id);
+		var olditem = store.data.get(item.data.id);
 
-		//console.log("GRID ADD UID: " + item.data.id);
-
-		var info = Ext.apply({}, item.data);
-		var child = Ext.ModelMgr.create(info, store.model, info.id);
-		addlist.push(item);
-		index[item.data.id] = child;
-	    });
-
+		if (!olditem) {
+		    //console.log("GRID ADD UID: " + item.data.id);
+		    var info = Ext.apply({}, item.data);
+		    var child = Ext.ModelMgr.create(info, store.model, info.id);
+		    addlist.push(item);
+		    continue;
+		}
+		// try to detect changes
+		var changes = false;
+		store.model.prototype.fields.eachKey(function(field) {
+		    if (field != 'id' && item.data[field] != olditem.data[field]) {
+			changes = true;
+			console.log("changed item " + item.id + " " + field + " " + item.data[field] + " != " + olditem.data[field]);
+			olditem.beginEdit()
+			olditem.set(field, item.data[field]);
+		    }
+		});
+		if (changes) {
+		    olditem.endEdit(true)
+		    olditem.commit(true); 
+		}
+	    };
 	    if (addlist.length) {
 		store.cacheRecords(addlist);
-		store.guaranteeRange(0, 49);
+		store.guaranteeRange(0, 50);
 	    }
 
+	    store.sort();
+
+	    store.resumeEvents();
+	    store.fireEvent('datachanged', store);
+
 	    console.log("END GRID UPDATE");
 	    if (!pdata.updateCount) {
 		//self.applyState(sp.get(stateid));
@@ -94,10 +120,11 @@
 	    title: 'Search',
 	    store: store,
 	    viewConfig: {
+		invalidateScrollerOnRefresh: false,
+		stripeRows: true,
 		trackOver: false
             },
-            invalidateScrollerOnRefresh: false,
-	    verticalScroller: {
+ 	    verticalScroller: {
 		xtype: 'paginggridscroller',
 		activePrefetch: false
             },
@@ -106,10 +133,17 @@
 		    rstore.un("load", updateGrid)
 		}
 	    },
-            columns:[{
-		text: 'ID',
-		dataIndex: 'id'
-	    }]
+            columns:[
+		{ text: 'ID', dataIndex: 'id', sortable: true },
+		{ text: 'Type', dataIndex: 'type', sortable: true,
+		  renderer: PVE.Utils.render_itype },
+		{
+		    text: 'CPU',
+		    dataIndex: 'cpu',
+		    sortable: true,
+		    renderer: PVE.Utils.render_cpu
+		},
+	    ]
 	});
 
 	me.callParent();




More information about the pve-devel mailing list