[pve-devel] r5847 - pve-manager/pve2/www/new

svn-commits at proxmox.com svn-commits at proxmox.com
Thu Apr 21 13:19:50 CEST 2011


Author: dietmar
Date: 2011-04-21 13:19:50 +0200 (Thu, 21 Apr 2011)
New Revision: 5847

Modified:
   pve-manager/pve2/www/new/StateProvider.js
Log:
compress state url


Modified: pve-manager/pve2/www/new/StateProvider.js
===================================================================
--- pve-manager/pve2/www/new/StateProvider.js	2011-04-21 09:15:40 UTC (rev 5846)
+++ pve-manager/pve2/www/new/StateProvider.js	2011-04-21 11:19:50 UTC (rev 5847)
@@ -1,7 +1,7 @@
 /* This state provider keeps part of the state inside
  * the browser history.
  *
- * TODO: compress (shorten) url using dictionary based compression
+ * We compress (shorten) url using dictionary based compression
  * i.e. use column separated list instead of url encoded hash:
  * #v\d*       version/format
  * :=          indicates string values
@@ -30,39 +30,115 @@
 	return changes;
     },
 
-    constructor: function(config){
+    // private
+    hslist: [
+	// order is important for notifications
+	// [ name, default ]
+	['view', 'server'],
+	['rid', 'root'],
+	['ltab', 'clog'],
+	['nodetab', ''],
+	['storagetab', ''],
+	['kvmtab', ''],
+	['dctab', '']
+    ],
+
+    hprefix: 'v1',
+
+    compDict: {
+	content: 19,
+	root: 18,
+	domains: 17,
+	roles: 16,
+	groups: 15,
+	users: 14,
+	time: 13,
+	dns: 12,
+	network: 11,
+	services: 10,
+	options: 9,
+	console: 8,
+	hardware: 7,
+	permissions: 6,
+	summary: 5,
+	tasks: 4,
+	clog: 3,
+	storage: 2,
+	folder: 1,
+	server: 0
+    },
+
+    decodeHToken: function(token) {
 	var self = this;
 
-	self.callParent([config]);
+	var state = {};
+	if (!token) {
+	    Ext.Array.each(self.hslist, function(rec) {
+		state[rec[0]] = rec[1];
+	    });
+	    return state;
+	}
 
-	self.UIState = {};
+	// return Ext.urlDecode(token);
 
-	// order is important for notifications
-	var list = [
-	    'view',
-	    'rid',
-	    'ltab',
-	    'nodetab',
-	    'storagetab',
-	    'kvmtab',
-	    'dctab'
-	];
- 
-	var defaults = {
-	    view: 'server',
-	    ltab: 'clog',
-	    nodetab: '',
-	    storagetab: '',
-	    kvmtab: '',
-	    dctab: '',
-	    rid: 'root'
-	};
+	var items = token.split(':');
+	var prefix = items.shift();
 
-	Ext.Array.each(list, function(name) {
-	    self.UIState[name] = Ext.isDefined(defaults[name]) ?
-		defaults[name] : null;
+	if (prefix != self.hprefix)
+	    return self.decodeHToken();
+	    
+	Ext.Array.each(self.hslist, function(rec) {
+	    var value = items.shift();
+	    if (value === '') {
+		console.log("DECEMPTY");
+	    } else if (value[0] === '=') {
+		value = decodeURIComponent(value.slice(1));
+	    } else {
+		Ext.Object.each(self.compDict, function(key, cv) {
+		    if (value == cv) {
+			value = key;
+			return false;
+		    }
+		});
+	    }
+	    state[rec[0]] = value;
 	});
 
+	return state;
+    },
+
+    encodeHToken: function(state) {
+	var self = this;
+
+	// return Ext.urlEncode(state);
+
+	var ctoken = self.hprefix;
+	Ext.Array.each(self.hslist, function(rec) {
+	    var value = state[rec[0]];
+	    if (!Ext.isDefined(value))
+		value = rec[1];
+	    value = encodeURIComponent(value);
+	    if (!value) {
+		ctoken += ':';
+	    } else {
+		var comp = self.compDict[value];
+		if (Ext.isDefined(comp))
+		    ctoken += ":" + comp;
+		else
+		    ctoken += ":=" + value;
+	    }
+	});
+
+	return ctoken;
+    },
+
+    constructor: function(config){
+	var self = this;
+
+	self.callParent([config]);
+
+	self.UIState = self.decodeHToken(); // set default
+
 	var history_change_cb = function(token) {
 	    //console.log("HC " + token);
 	    if (!token) {
@@ -76,11 +152,11 @@
 		return;
 	    }
 
-	    var newstate = Ext.urlDecode(token);
-	    Ext.Array.each(list, function(name) {
-		if (typeof newstate[name] == "undefined")
+	    var newstate = self.decodeHToken(token);
+	    Ext.Array.each(self.hslist, function(rec) {
+		if (typeof newstate[rec[0]] == "undefined")
 		    return;
-		self.setHV(name, newstate[name], true);
+		self.setHV(rec[0], newstate[rec[0]], true);
 	    });
 	};
 
@@ -88,7 +164,7 @@
 	if (start_token) {
 	    history_change_cb(start_token);
 	} else {
-	    var htext = Ext.urlEncode(self.UIState);
+	    var htext = self.encodeHToken(self.UIState);
 	    Ext.History.add(htext);
 	}
 
@@ -126,7 +202,7 @@
 	if (typeof self.UIState[name] != "undefined") {
 	    var newvalue = value ? value.value : null;
 	    if (self.setHV(name, newvalue, false)) {
-		var htext = Ext.urlEncode(self.UIState);
+		var htext = self.encodeHToken(self.UIState);
 		Ext.History.add(htext);
 	    }
 	} else {




More information about the pve-devel mailing list