[pve-devel] r4872 - in pve-manager/pve2: . www/manager

svn-commits at proxmox.com svn-commits at proxmox.com
Mon Jul 5 11:24:31 CEST 2010


Author: dietmar
Date: 2010-07-05 09:24:31 +0000 (Mon, 05 Jul 2010)
New Revision: 4872

Modified:
   pve-manager/pve2/ChangeLog
   pve-manager/pve2/www/manager/PVECache.js
   pve-manager/pve2/www/manager/PVESearch.js
   pve-manager/pve2/www/manager/PVEUtils.js
   pve-manager/pve2/www/manager/ResourceTree.js
Log:
	* www/manager/PVEUtils.js: add filterfn - enable filtered views



Modified: pve-manager/pve2/ChangeLog
===================================================================
--- pve-manager/pve2/ChangeLog	2010-07-05 07:52:02 UTC (rev 4871)
+++ pve-manager/pve2/ChangeLog	2010-07-05 09:24:31 UTC (rev 4872)
@@ -1,5 +1,7 @@
 2010-07-05  Proxmox Support Team  <support at proxmox.com>
 
+	* www/manager/PVEUtils.js: add filterfn - enable filtered views
+
 	* www/manager/startup.pl: install startup.pl script to init
 	PVE::Config an logging.
 

Modified: pve-manager/pve2/www/manager/PVECache.js
===================================================================
--- pve-manager/pve2/www/manager/PVECache.js	2010-07-05 07:52:02 UTC (rev 4871)
+++ pve-manager/pve2/www/manager/PVECache.js	2010-07-05 09:24:31 UTC (rev 4872)
@@ -67,6 +67,8 @@
 
 	var text_filter = '';
 
+	var viewname = 'server';
+
 	var text_filter_fn = function(item) {
 	    if (text_filter) {
 		var match = false;
@@ -85,10 +87,16 @@
 	    return false;
 	};
 
+	var item_filter_fn;
+
 	var group_filter = [];
 
 	var filterFn = function(item, itype) {
 
+	    if (item_filter_fn && !item_filter_fn(item, itype)) {
+		return true;
+	    }
+
 	    for (var i = 0, len = group_filter.length; i < len; i++) {
 		var filter = group_filter[i];
 		var field = filter.field;
@@ -168,8 +176,10 @@
 		run_search_task(200);
 	    },
 
-	    setGroupFilter: function(filterinfo) {
+	    setGroupFilter: function(viewname, filterinfo) {
 
+		item_filter_fn = PVE.Utils.default_groups[viewname].filterfn;
+
 		group_filter = filterinfo;
 
 		run_search_task(10);

Modified: pve-manager/pve2/www/manager/PVESearch.js
===================================================================
--- pve-manager/pve2/www/manager/PVESearch.js	2010-07-05 07:52:02 UTC (rev 4871)
+++ pve-manager/pve2/www/manager/PVESearch.js	2010-07-05 09:24:31 UTC (rev 4872)
@@ -6,9 +6,9 @@
 
 	var n = this.pveSelNode;
 	var tree = n.getOwnerTree();
-	var view = tree.viewname;
+	var viewname = tree.viewname;
 
-	console.log("VIEW " + view);
+	console.log("VIEW " + viewname);
 
 	var groupfilter = [];
 
@@ -21,11 +21,11 @@
 
 	var store = PVE.Cache.searchstore;
 
-	store.setGroupFilter(groupfilter);
+	store.setGroupFilter(viewname, groupfilter);
 
 	var textfilter = store.getTextFilter();
 	
-	var coldef = PVE.Utils.get_column_defaults(view);
+	var coldef = PVE.Utils.get_column_defaults(viewname);
 
 	Ext.apply(this, {
 	    store: PVE.Cache.searchstore,

Modified: pve-manager/pve2/www/manager/PVEUtils.js
===================================================================
--- pve-manager/pve2/www/manager/PVEUtils.js	2010-07-05 07:52:02 UTC (rev 4871)
+++ pve-manager/pve2/www/manager/PVEUtils.js	2010-07-05 09:24:31 UTC (rev 4872)
@@ -301,7 +301,10 @@
 	storage: {
 	    text: 'Storage View',
 	    fields: Ext.apply({}, visible_fields),
-	    groups: ['storage', 'node']
+	    groups: ['node', 'storage'],
+	    filterfn: function(n, itype) {
+		return itype === 'storage';
+	    }
 	}
     };
 

Modified: pve-manager/pve2/www/manager/ResourceTree.js
===================================================================
--- pve-manager/pve2/www/manager/ResourceTree.js	2010-07-05 07:52:02 UTC (rev 4871)
+++ pve-manager/pve2/www/manager/ResourceTree.js	2010-07-05 09:24:31 UTC (rev 4872)
@@ -166,15 +166,14 @@
 
     viewname: 'server',
 
-    initGroups: function(groupname) {
-	this.viewname = groupname;
-	this.groups = [].concat(PVE.Utils.default_groups[groupname].groups);
+    initView: function(viewname) {
+	this.viewname = viewname;
     },
 
-    setGroups: function(groupname) {
+    setView: function(viewname) {
 	var tree = this;
 
-	tree.initGroups(groupname);
+	tree.initView(viewname);
 
 	var sm = this.getSelectionModel();
 
@@ -222,6 +221,9 @@
 
 	//console.log("update tree " + tree);
 
+	var groups = [].concat(PVE.Utils.default_groups[this.viewname].groups);
+	var filterfn = PVE.Utils.default_groups[this.viewname].filterfn;
+
 	var rootnode = tree.getRootNode();
 	if (!rootnode)
 	    throw "no rootnode in tree";
@@ -239,8 +241,8 @@
 
 	    if (item) {
 		// test if any grouping attributes changed
-		for (var i = 0, len = tree.groups.length; i < len; i++) {
-		    var attr = tree.groups[i];
+		for (var i = 0, len = groups.length; i < len; i++) {
+		    var attr = groups[i];
 		    if (attr === 'itype') {
 			continue;
 		    } else if (item.data[attr] != info.data[attr]) {
@@ -249,6 +251,7 @@
 			break;
 		    }
 		}
+		// fixme: also test filterfn()?
 	    }
 
 	    if (!item || changed) {
@@ -264,6 +267,10 @@
 
 	    var olddata = tree.data[uid];
 
+	    if (filterfn && !filterfn(item, itype)) {
+		return;
+	    }
+
 	    if (!olddata) {
 		
 		var info = { data: {} };
@@ -278,7 +285,7 @@
 		    leaf: true
 		});		    
 
-		var child = rootnode.groupChild(info, tree.groups, 0);
+		var child = rootnode.groupChild(info, groups, 0);
                 if (child) {
 		    info.treenode = child;
 		    tree.data[uid] = info;
@@ -338,7 +345,7 @@
 	    value: tree.viewname,
 	    listeners: {
 		select: function(combo, record, index) { 
-		    tree.setGroups(combo.getValue());
+		    tree.setView(combo.getValue());
 		}		    
 	    },
 	    getState: function() {
@@ -347,7 +354,7 @@
 	    applyState : function(state) {
 		if (state && state.view) {
 		    this.setValue(state.view);
-		    tree.initGroups(state.view);
+		    tree.initView(state.view);
 		}
 	    },
 	    stateEvents: [ 'select' ],
@@ -357,7 +364,6 @@
 
 	Ext.apply(this, {
 	    data: {},
-	    groups: [ 'itype' ],
             width: 250,
             title: 'Resource Tree',
 	    autoScroll: true,
@@ -380,7 +386,7 @@
 				    viewcombo.setValue(view);
 				    // fixme: save custom view
 				    viewcombo.saveState();
-				    tree.setGroups(view);
+				    tree.setView(view);
 				} 
 			    }
 			});
@@ -395,7 +401,7 @@
 	    }
 	});
 
-	tree.initGroups(tree.viewname);
+	tree.initView(tree.viewname);
 
 	PVE.ResourceTree.superclass.initComponent.call(this);
 



More information about the pve-devel mailing list