[pve-devel] r5787 - in pve-manager/pve2/www/new: . tree

svn-commits at proxmox.com svn-commits at proxmox.com
Tue Apr 5 13:19:58 CEST 2011


Author: dietmar
Date: 2011-04-05 13:19:58 +0200 (Tue, 05 Apr 2011)
New Revision: 5787

Added:
   pve-manager/pve2/www/new/tree/ResourceTree.js
Removed:
   pve-manager/pve2/www/new/ResourceTree.js
Modified:
   pve-manager/pve2/www/new/Makefile.am
Log:


Modified: pve-manager/pve2/www/new/Makefile.am
===================================================================
--- pve-manager/pve2/www/new/Makefile.am	2011-04-05 11:19:34 UTC (rev 5786)
+++ pve-manager/pve2/www/new/Makefile.am	2011-04-05 11:19:58 UTC (rev 5787)
@@ -9,7 +9,7 @@
 	form/RealmComboBox.js				\
 	form/ViewSelector.js				\
 	window/LoginWindow.js				\
-	ResourceTree.js					\
+	tree/ResourceTree.js				\
 	Workspace.js
 
 pvemanagerlib.js: ${JSSRC}

Deleted: pve-manager/pve2/www/new/ResourceTree.js
===================================================================
--- pve-manager/pve2/www/new/ResourceTree.js	2011-04-05 11:19:34 UTC (rev 5786)
+++ pve-manager/pve2/www/new/ResourceTree.js	2011-04-05 11:19:58 UTC (rev 5787)
@@ -1,296 +0,0 @@
-Ext.define('PVE.tree.ResourceTree', {
-    extend: 'Ext.tree.TreePanel',
-    requires: ['Ext.tree.*', 'PVE.Utils', 
-	       'PVE.form.ViewSelector', 
-	       'PVE.data.ResourceStore'],
-    alias: ['widget.pveResourceTree'],
-
-    statics: {
-	typeDefaults: {
-	    node: { 
-		iconCls: 'x-tree-node-server',
-		text: 'Node list'
-	    },
-	    storage: {
-		iconCls: 'x-tree-node-harddisk',
-		text: 'Storage list'
-	    },
-	    qemu: {
-		iconCls: 'x-tree-node-computer',
-		text: 'Virtual machines'
-	    },
-	    openvz: {
-		iconCls: 'x-tree-node-computer',
-		text: 'OpenVZ containers'
-	    } 
-	}
-    },
-
-    // private
-    nodeSortFn: function(node1, node2) {
-	var n1 = node1.data;
-	var n2 = node2.data;
-
-	if ((n1.groupbyid && n2.groupbyid) ||
-	    !(n1.groupbyid || n2.groupbyid)) {
-
-	    var tcmp;
-
-	    var v1 = n1.type;
-	    var v2 = n2.type;
-
-	    if ((tcmp = v1 > v2 ? 1 : (v1 < v2 ? -1 : 0)) != 0)
-		return tcmp;
-
-	    // numeric compare for VM IDs
-	    if (v1 === 'qemu' || v1 === 'openvz') {
-		v1 = n1.vmid;
-		v2 = n2.vmid;
-		if ((tcmp = v1 > v2 ? 1 : (v1 < v2 ? -1 : 0)) != 0)
-		    return tcmp;
-	    }
-
-	    return n1.text > n2.text ? 1 : (n1.text < n2.text ? -1 : 0);
-	} else if (n1.groupbyid) {
-	    return -1;
-	} else if (n2.groupbyid) {
-	    return 1;
-	}
-    },
-
-    // private: fast binary search
-    findInsertIndex: function(node, child, start, end) {
-	var self = this;
-
-	var diff = end - start;
-
-	var mid = start + (diff>>1);
-
-	if (diff <= 0)
-	    return start;
-
-	var res = self.nodeSortFn(child, node.childNodes[mid]);
-	if (res <= 0)
-	    return self.findInsertIndex(node, child, start, mid);
-	else
-	    return self.findInsertIndex(node, child, mid + 1, end);
-    },
-
-    // private
-    addChildSorted: function(node, info) {
-	var self = this;
-
-	var statics = self.statics();
-	var defaults = statics.typeDefaults[info.type];
-	if (defaults && defaults.iconCls)
-	    info.iconCls = defaults.iconCls;
-
-	if (info.type === 'node') {
-	    info.text = info.node;
-	} else if (info.type === 'storage') {
-	    info.text = info.storage + ' (' + info.node + ')';
-	} else  if (info.type === 'qemu' || info.type === 'openvz') {
-	    info.text = info.vmid;
-	    if (info.name)
-		info.text += " (" + info.name + ')';
-	} else if (info.type === 'type') {
-	    defaults = statics.typeDefaults[info.groupbyid];
-	    if (defaults && defaults.text)
-		info.text = defaults.text;
-	    else 
-		info.text = info.groupbyid;	    
-	} else {
-	    info.text = info.id;
-	}
-
-	var child = Ext.ModelMgr.create(info, 'PVETree', info.id);
-
-        var cs = node.childNodes;
-	var pos;
-	if (cs) {
-            var len = cs.length;
-            index = self.findInsertIndex(node, child, 0, len);
-	    pos = cs[index];
-	}
-
-	//var expanded = node.isExpanded();
-	//if (expanded)
-	//node.collapse();		    
-	node.insertBefore(child, pos);
-	//if (expanded)
-	//node.expand();
-
-	return child;
-    },
-
-    // private
-    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 : groupby + "/" + v
-		    };
-		    if (groupby !== 'type')
-			groupinfo[groupby] = v;
-		}
-		groupinfo.leaf = false;
-		groupinfo.groupbyid = v; 
-		group = self.addChildSorted(node, groupinfo);
-		// fixme: remove when EXTJS has fixed those bugs?!
-		group.expand(); group.collapse();
-	    }
-	    if (info.type === groupby)
-		return group;
-	    if (group)
-		return self.groupChild(group, info, groups, level + 1);
-	}
-
-	return self.addChildSorted(node, info);
-    },
-
-    initComponent : function() {
-	var self = this;
-
-	var rstore = PVE.data.ResourceStore;
-
-	var pdata = {
-	    view: {},
-	    dataIndex: {},
-	    updateCount: 0
-	};
-
-	var store = Ext.create('Ext.data.TreeStore', {
-	    model: 'PVETree',
-	    root: {
-		expanded: true,
-		id: 'root',
-		text: "Datacenter"
-	    }
-	});
-
-	var updateTree = function() {
-
-	    var rootnode = self.store.node;
-
-	    var index = pdata.dataIndex;
-
-	    var groups = [].concat(pdata.view.groups);
-
-	    // remove vanished or changed items
-	    for (var key in index) {
-		if (!index.hasOwnProperty(key))
-		    continue;
-
-		var olditem = index[key];
-
-		// 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 " + attr);
-			    changed = true;
-			    break;
-			}
-		    }
-		    // fixme: also test filterfn()?
-		}
-
-		if (!item || changed) {
-		    console.log("REM UID: " + key + " ITEM " + olditem.data.id);
-		    delete index[key];
-		    var parentNode = olditem.parentNode;
-		    //var expanded = parentNode.isExpanded();
-		    //if (expanded)
-		    //parentNode.collapse();		    
-		    parentNode.removeChild(olditem, true);
-		    //if (expanded) 
-		    //parentNode.expand();
-		}
-	    }
-
- 	    // add new items
-            rstore.each(function(item) {
-		var olditem = index[item.data.id];
-		if (olditem)
-		    return;
-
-		console.log("ADD UID: " + item.data.id);
-
-		var info = Ext.apply({ leaf: true }, item.data);
-		var child = self.groupChild(rootnode, info, groups, 0);
-		if (child)
-		    index[item.data.id] = child;
-	    });
-
-	    if (!pdata.updateCount) {
-		rootnode.collapse();
-		rootnode.expand();
-	    }
-
-	    pdata.updateCount++;
-	};
-
-	var selview = new PVE.form.ViewSelector({
-	    listeners: {
-		select: function(combo, records) { 
-		    if (records && records.length) {
-			var view = combo.getViewSettings();
-			self.setView(view);
-		    }
-		}
-	    }
-	});
-
-	pdata.view = selview.getViewSettings();
-
-	Ext.apply(self, {
-	    store: store,
-	    //useArrows: true,
-            //rootVisible: false,
-            title: 'Resource Tree',
-	    tbar: [ ' ', selview ],
-	    listeners: {
-		destroy: function() {
-		    rstore.un("load", updateTree)
-		}
-	    },
-
-	    setView: function(view) {
-		var self = this;
-	
-		pdata.view = view;
-
-		var rootnode = self.store.node;
-		rootnode.collapse();
-		rootnode.removeAll(true);
-		pdata.dataIndex = {};
-		updateTree();
-		rootnode.expand();
-	    }
-	});
-
-	self.callParent();
-
-	rstore.on("load", updateTree);
-	rstore.startUpdate();
-	//rstore.stopUpdate();
-    }
-
-});

Copied: pve-manager/pve2/www/new/tree/ResourceTree.js (from rev 5785, pve-manager/pve2/www/new/ResourceTree.js)
===================================================================
--- pve-manager/pve2/www/new/tree/ResourceTree.js	                        (rev 0)
+++ pve-manager/pve2/www/new/tree/ResourceTree.js	2011-04-05 11:19:58 UTC (rev 5787)
@@ -0,0 +1,296 @@
+Ext.define('PVE.tree.ResourceTree', {
+    extend: 'Ext.tree.TreePanel',
+    requires: ['Ext.tree.*', 'PVE.Utils', 
+	       'PVE.form.ViewSelector', 
+	       'PVE.data.ResourceStore'],
+    alias: ['widget.pveResourceTree'],
+
+    statics: {
+	typeDefaults: {
+	    node: { 
+		iconCls: 'x-tree-node-server',
+		text: 'Node list'
+	    },
+	    storage: {
+		iconCls: 'x-tree-node-harddisk',
+		text: 'Storage list'
+	    },
+	    qemu: {
+		iconCls: 'x-tree-node-computer',
+		text: 'Virtual machines'
+	    },
+	    openvz: {
+		iconCls: 'x-tree-node-computer',
+		text: 'OpenVZ containers'
+	    } 
+	}
+    },
+
+    // private
+    nodeSortFn: function(node1, node2) {
+	var n1 = node1.data;
+	var n2 = node2.data;
+
+	if ((n1.groupbyid && n2.groupbyid) ||
+	    !(n1.groupbyid || n2.groupbyid)) {
+
+	    var tcmp;
+
+	    var v1 = n1.type;
+	    var v2 = n2.type;
+
+	    if ((tcmp = v1 > v2 ? 1 : (v1 < v2 ? -1 : 0)) != 0)
+		return tcmp;
+
+	    // numeric compare for VM IDs
+	    if (v1 === 'qemu' || v1 === 'openvz') {
+		v1 = n1.vmid;
+		v2 = n2.vmid;
+		if ((tcmp = v1 > v2 ? 1 : (v1 < v2 ? -1 : 0)) != 0)
+		    return tcmp;
+	    }
+
+	    return n1.text > n2.text ? 1 : (n1.text < n2.text ? -1 : 0);
+	} else if (n1.groupbyid) {
+	    return -1;
+	} else if (n2.groupbyid) {
+	    return 1;
+	}
+    },
+
+    // private: fast binary search
+    findInsertIndex: function(node, child, start, end) {
+	var self = this;
+
+	var diff = end - start;
+
+	var mid = start + (diff>>1);
+
+	if (diff <= 0)
+	    return start;
+
+	var res = self.nodeSortFn(child, node.childNodes[mid]);
+	if (res <= 0)
+	    return self.findInsertIndex(node, child, start, mid);
+	else
+	    return self.findInsertIndex(node, child, mid + 1, end);
+    },
+
+    // private
+    addChildSorted: function(node, info) {
+	var self = this;
+
+	var statics = self.statics();
+	var defaults = statics.typeDefaults[info.type];
+	if (defaults && defaults.iconCls)
+	    info.iconCls = defaults.iconCls;
+
+	if (info.type === 'node') {
+	    info.text = info.node;
+	} else if (info.type === 'storage') {
+	    info.text = info.storage + ' (' + info.node + ')';
+	} else  if (info.type === 'qemu' || info.type === 'openvz') {
+	    info.text = info.vmid;
+	    if (info.name)
+		info.text += " (" + info.name + ')';
+	} else if (info.type === 'type') {
+	    defaults = statics.typeDefaults[info.groupbyid];
+	    if (defaults && defaults.text)
+		info.text = defaults.text;
+	    else 
+		info.text = info.groupbyid;	    
+	} else {
+	    info.text = info.id;
+	}
+
+	var child = Ext.ModelMgr.create(info, 'PVETree', info.id);
+
+        var cs = node.childNodes;
+	var pos;
+	if (cs) {
+            var len = cs.length;
+            index = self.findInsertIndex(node, child, 0, len);
+	    pos = cs[index];
+	}
+
+	//var expanded = node.isExpanded();
+	//if (expanded)
+	//node.collapse();		    
+	node.insertBefore(child, pos);
+	//if (expanded)
+	//node.expand();
+
+	return child;
+    },
+
+    // private
+    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 : groupby + "/" + v
+		    };
+		    if (groupby !== 'type')
+			groupinfo[groupby] = v;
+		}
+		groupinfo.leaf = false;
+		groupinfo.groupbyid = v; 
+		group = self.addChildSorted(node, groupinfo);
+		// fixme: remove when EXTJS has fixed those bugs?!
+		group.expand(); group.collapse();
+	    }
+	    if (info.type === groupby)
+		return group;
+	    if (group)
+		return self.groupChild(group, info, groups, level + 1);
+	}
+
+	return self.addChildSorted(node, info);
+    },
+
+    initComponent : function() {
+	var self = this;
+
+	var rstore = PVE.data.ResourceStore;
+
+	var pdata = {
+	    view: {},
+	    dataIndex: {},
+	    updateCount: 0
+	};
+
+	var store = Ext.create('Ext.data.TreeStore', {
+	    model: 'PVETree',
+	    root: {
+		expanded: true,
+		id: 'root',
+		text: "Datacenter"
+	    }
+	});
+
+	var updateTree = function() {
+
+	    var rootnode = self.store.node;
+
+	    var index = pdata.dataIndex;
+
+	    var groups = [].concat(pdata.view.groups);
+
+	    // remove vanished or changed items
+	    for (var key in index) {
+		if (!index.hasOwnProperty(key))
+		    continue;
+
+		var olditem = index[key];
+
+		// 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 " + attr);
+			    changed = true;
+			    break;
+			}
+		    }
+		    // fixme: also test filterfn()?
+		}
+
+		if (!item || changed) {
+		    console.log("REM UID: " + key + " ITEM " + olditem.data.id);
+		    delete index[key];
+		    var parentNode = olditem.parentNode;
+		    //var expanded = parentNode.isExpanded();
+		    //if (expanded)
+		    //parentNode.collapse();		    
+		    parentNode.removeChild(olditem, true);
+		    //if (expanded) 
+		    //parentNode.expand();
+		}
+	    }
+
+ 	    // add new items
+            rstore.each(function(item) {
+		var olditem = index[item.data.id];
+		if (olditem)
+		    return;
+
+		console.log("ADD UID: " + item.data.id);
+
+		var info = Ext.apply({ leaf: true }, item.data);
+		var child = self.groupChild(rootnode, info, groups, 0);
+		if (child)
+		    index[item.data.id] = child;
+	    });
+
+	    if (!pdata.updateCount) {
+		rootnode.collapse();
+		rootnode.expand();
+	    }
+
+	    pdata.updateCount++;
+	};
+
+	var selview = new PVE.form.ViewSelector({
+	    listeners: {
+		select: function(combo, records) { 
+		    if (records && records.length) {
+			var view = combo.getViewSettings();
+			self.setView(view);
+		    }
+		}
+	    }
+	});
+
+	pdata.view = selview.getViewSettings();
+
+	Ext.apply(self, {
+	    store: store,
+	    //useArrows: true,
+            //rootVisible: false,
+            title: 'Resource Tree',
+	    tbar: [ ' ', selview ],
+	    listeners: {
+		destroy: function() {
+		    rstore.un("load", updateTree)
+		}
+	    },
+
+	    setView: function(view) {
+		var self = this;
+	
+		pdata.view = view;
+
+		var rootnode = self.store.node;
+		rootnode.collapse();
+		rootnode.removeAll(true);
+		pdata.dataIndex = {};
+		updateTree();
+		rootnode.expand();
+	    }
+	});
+
+	self.callParent();
+
+	rstore.on("load", updateTree);
+	rstore.startUpdate();
+	//rstore.stopUpdate();
+    }
+
+});




More information about the pve-devel mailing list