[pve-devel] r5780 - in pve-manager/pve2/www/new: . form

svn-commits at proxmox.com svn-commits at proxmox.com
Mon Apr 4 13:57:52 CEST 2011


Author: dietmar
Date: 2011-04-04 13:57:52 +0200 (Mon, 04 Apr 2011)
New Revision: 5780

Modified:
   pve-manager/pve2/www/new/ResourceTree.js
   pve-manager/pve2/www/new/Workspace.js
   pve-manager/pve2/www/new/form/ViewSelector.js
Log:
build a correct tree - first try


Modified: pve-manager/pve2/www/new/ResourceTree.js
===================================================================
--- pve-manager/pve2/www/new/ResourceTree.js	2011-04-04 05:15:21 UTC (rev 5779)
+++ pve-manager/pve2/www/new/ResourceTree.js	2011-04-04 11:57:52 UTC (rev 5780)
@@ -1,16 +1,72 @@
-Ext.define('PVE.ResourceTree', {
+Ext.define('PVE.tree.ResourceTree', {
     extend: 'Ext.tree.TreePanel',
     requires: ['Ext.tree.*', 'PVE.Utils', 
-	       'PVE.form.ViewSelector', 'PVE.data.ResourceStore'],
+	       'PVE.form.ViewSelector', 
+	       'PVE.data.ResourceStore'],
     alias: ['widget.pveResourceTree'],
-    
+
+    statics: {
+	iconClsHash: {
+	    node: 'x-tree-node-server',
+	    storage: 'x-tree-node-harddisk',
+	    qemu: 'x-tree-node-computer',
+	    openvz: 'x-tree-node-computer',
+	} 
+    },
+
+    addChild: function(node, info) {
+	var self = this;
+
+	var statics = self.statics();
+	var iconCls = statics.iconClsHash[info.type];
+	if (iconCls) 
+	    info.iconCls = iconCls;
+	var child = Ext.ModelMgr.create(info,  'PVETree');
+	node.appendChild(child);
+	return child;
+    },
+
+    groupChild: function(node, info, groups, level) {
+	var self = this;
+
+	var groupby = groups[level];
+	var v = info[groupby];
+
+	if (v) {
+            var group = node.findChild('groupbyid', v);
+	    if (!group) {
+		var groupinfo;
+		if (info.type === groupby) {
+		    groupinfo = info;
+		} else {
+		    groupinfo = {
+			type: groupby,
+			id : "group/" + groupby + "/" + v,
+			text: v,
+		    };
+		}
+		groupinfo.leaf = false;
+		groupinfo.groupbyid = v; 
+		group = self.addChild(node, groupinfo);
+		group.expand(); group.collapse();
+		console.log("ADD GROUP " + v + " " + groupinfo.id);
+	    }
+	    if (info.type === groupby)
+		return group;
+	    if (group)
+		return self.groupChild(group, info, groups, level + 1);
+	}
+
+	return self.addChild(node, info);
+    },
+
     initComponent : function() {
 	var self = this;
 
 	var rstore = PVE.data.ResourceStore;
-	
+
 	var pdata = {
-	    view: {},
+	    view: PVE.form.ViewSelector.defaultView,
 	    dataIndex: {},
 	    updateCount: 0
 	};
@@ -30,6 +86,7 @@
 
 	    var index = pdata.dataIndex;
 
+	    var groups = [].concat(pdata.view.groups);
 
 	    // remove vanished or changed items
 	    for (var key in index) {
@@ -38,11 +95,24 @@
 
 		var olditem = index[key];
 
-		var changed = false;
 		// getById() use find(), which is slow (ExtJS4 DP5) 
 		//var item = rstore.getById(olditem.data.id);
 		var item = rstore.data.get(olditem.data.id);
 
+		var changed = false;
+		if (item) {
+		    // test if any grouping attributes changed
+		    for (var i = 0, len = groups.length; i < len; i++) {
+			var attr = groups[i];
+			if (item.data[attr] != olditem.data[attr]) {
+			    //console.log("changed");
+			    changed = true;
+			    break;
+			}
+		    }
+		    // fixme: also test filterfn()?
+		}
+
 		if (!item || changed) {
 		    console.log("REM UID: " + key);
 		    delete index[key];
@@ -56,16 +126,14 @@
 		if (olditem)
 		    return;
 
-		var itype = item.data.type;
 		console.log("ADD UID: " + item.id);
-		item.data.text = item.id;
+		item.data.text = item.data.id;
 		item.data.leaf = true;
-		item.data.cls = 'x-tree-icon-parent';
 
-		var ni = Ext.apply({}, item.data);
-		var nn = Ext.ModelMgr.create(ni,  'PVETree');
-		rootnode.appendChild(nn);
-		index[item.id] = nn;
+		var info = Ext.apply({}, item.data);
+		var child = self.groupChild(rootnode, info, groups, 0);
+		if (child)
+		    index[item.id] = child;
 	    });
 
 	    if (!pdata.updateCount) {
@@ -113,10 +181,11 @@
 
 	});
 
-	PVE.ResourceTree.superclass.initComponent.call(self);
+	self.callParent();
 
 	rstore.on("load", updateTree);
 	rstore.startUpdate();
+	rstore.stopUpdate();
     }
 
 });

Modified: pve-manager/pve2/www/new/Workspace.js
===================================================================
--- pve-manager/pve2/www/new/Workspace.js	2011-04-04 05:15:21 UTC (rev 5779)
+++ pve-manager/pve2/www/new/Workspace.js	2011-04-04 11:57:52 UTC (rev 5780)
@@ -1,6 +1,6 @@
 Ext.define('PVE.Workspace', {
     extend: 'Ext.container.Viewport',
-    requires: ['PVE.window.LoginWindow', 'PVE.Utils', 'PVE.ResourceTree'],
+    requires: ['PVE.window.LoginWindow', 'PVE.Utils', 'PVE.tree.ResourceTree'],
 
     // private
     defaultView: {

Modified: pve-manager/pve2/www/new/form/ViewSelector.js
===================================================================
--- pve-manager/pve2/www/new/form/ViewSelector.js	2011-04-04 05:15:21 UTC (rev 5779)
+++ pve-manager/pve2/www/new/form/ViewSelector.js	2011-04-04 11:57:52 UTC (rev 5780)
@@ -3,14 +3,18 @@
     requires: ['Ext.data.Store'],
     alias: ['widget.pveViewSelector'],
 
+    statics: {
+	defaultView: {
+	    text: 'Server View',
+	    groups: ['node']
+	}
+    },
+
     initComponent: function() {
 	var self = this;
 
 	var default_views = {
-	    server: {
-		text: 'Server View',
-		groups: ['node']
-	    },
+	    server: self.statics().defaultView,
 	    folder: {
 		text: 'Folder View',
 		groups: ['type']




More information about the pve-devel mailing list