[pve-devel] r5782 - in pve-manager/pve2/www/new: . data
svn-commits at proxmox.com
svn-commits at proxmox.com
Tue Apr 5 09:37:52 CEST 2011
Author: dietmar
Date: 2011-04-05 09:37:51 +0200 (Tue, 05 Apr 2011)
New Revision: 5782
Modified:
pve-manager/pve2/www/new/ResourceTree.js
pve-manager/pve2/www/new/data/ResourceStore.js
Log:
sort tree
Modified: pve-manager/pve2/www/new/ResourceTree.js
===================================================================
--- pve-manager/pve2/www/new/ResourceTree.js 2011-04-05 04:32:00 UTC (rev 5781)
+++ pve-manager/pve2/www/new/ResourceTree.js 2011-04-05 07:37:51 UTC (rev 5782)
@@ -14,15 +14,85 @@
}
},
- addChild: function(node, info) {
+ 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;
+ }
+ },
+
+ // 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);
+ },
+
+ addChildSorted: 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);
+
+ 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 {
+ 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];
+ }
+ node.insertBefore(child, pos);
return child;
},
@@ -41,15 +111,15 @@
} else {
groupinfo = {
type: groupby,
- id : "group/" + groupby + "/" + v,
- text: v,
+ id : groupby + "/" + v
};
+ if (groupby !== 'type')
+ groupinfo[groupby] = v;
}
groupinfo.leaf = false;
groupinfo.groupbyid = v;
- group = self.addChild(node, groupinfo);
+ group = self.addChildSorted(node, groupinfo);
group.expand(); group.collapse();
- console.log("ADD GROUP " + v + " " + groupinfo.id);
}
if (info.type === groupby)
return group;
@@ -57,7 +127,7 @@
return self.groupChild(group, info, groups, level + 1);
}
- return self.addChild(node, info);
+ return self.addChildSorted(node, info);
},
initComponent : function() {
@@ -76,7 +146,7 @@
root: {
expanded: true,
id: 'root',
- text: "Datacenter 1",
+ text: "Datacenter",
}
});
@@ -105,7 +175,7 @@
for (var i = 0, len = groups.length; i < len; i++) {
var attr = groups[i];
if (item.data[attr] != olditem.data[attr]) {
- //console.log("changed");
+ console.log("changed " + attr);
changed = true;
break;
}
@@ -114,26 +184,23 @@
}
if (!item || changed) {
- console.log("REM UID: " + key);
+ console.log("REM UID: " + key + " ITEM " + olditem.data.id);
delete index[key];
- olditem.remove(true);
}
}
// add new items
rstore.each(function(item) {
- var olditem = index[item.id];
+ var olditem = index[item.data.id];
if (olditem)
return;
- console.log("ADD UID: " + item.id);
- item.data.text = item.data.id;
- item.data.leaf = true;
+ console.log("ADD UID: " + item.data.id);
- var info = Ext.apply({}, item.data);
+ var info = Ext.apply({ leaf: true }, item.data);
var child = self.groupChild(rootnode, info, groups, 0);
if (child)
- index[item.id] = child;
+ index[item.data.id] = child;
});
if (!pdata.updateCount) {
@@ -187,7 +254,7 @@
rstore.on("load", updateTree);
rstore.startUpdate();
- rstore.stopUpdate();
+ //rstore.stopUpdate();
}
});
Modified: pve-manager/pve2/www/new/data/ResourceStore.js
===================================================================
--- pve-manager/pve2/www/new/data/ResourceStore.js 2011-04-05 04:32:00 UTC (rev 5781)
+++ pve-manager/pve2/www/new/data/ResourceStore.js 2011-04-05 07:37:51 UTC (rev 5782)
@@ -83,7 +83,10 @@
}
};
- var fields = Ext.Object.getKeys(field_defaults);
+ var fields = [];
+ Ext.Object.each(field_defaults, function(key, value) {
+ fields.push({name: key, type: value.type});
+ });
Ext.regModel('PVEResources', {
fields: fields,
More information about the pve-devel
mailing list