[pve-devel] r5988 - in pve-manager/pve2/www/new: . data node

svn-commits at proxmox.com svn-commits at proxmox.com
Tue May 17 13:16:48 CEST 2011


Author: dietmar
Date: 2011-05-17 13:16:47 +0200 (Tue, 17 May 2011)
New Revision: 5988

Added:
   pve-manager/pve2/www/new/data/DiffStore.js
Modified:
   pve-manager/pve2/www/new/Makefile.am
   pve-manager/pve2/www/new/node/ServiceView.js
Log:
impl. DiffStore


Modified: pve-manager/pve2/www/new/Makefile.am
===================================================================
--- pve-manager/pve2/www/new/Makefile.am	2011-05-17 08:30:29 UTC (rev 5987)
+++ pve-manager/pve2/www/new/Makefile.am	2011-05-17 11:16:47 UTC (rev 5988)
@@ -9,6 +9,7 @@
 	data/PVEProxy.js				\
 	data/UpdateQueue.js				\
 	data/UpdateStore.js				\
+	data/DiffStore.js				\
 	data/ObjectStore.js				\
 	data/ResourceStore.js				\
 	form/RRDTypeSelector.js				\

Added: pve-manager/pve2/www/new/data/DiffStore.js
===================================================================
--- pve-manager/pve2/www/new/data/DiffStore.js	                        (rev 0)
+++ pve-manager/pve2/www/new/data/DiffStore.js	2011-05-17 11:16:47 UTC (rev 5988)
@@ -0,0 +1,65 @@
+/* Config properties:
+ * rstore: A storage to track changes
+ * Only works if rstore has a model and use 'idProperty'
+ */
+Ext.define('PVE.data.DiffStore', {
+    extend: 'Ext.data.Store',
+
+    constructor: function(config) {
+	var me = this;
+
+	config = config || {};
+
+	if (!config.rstore) 
+	    throw "no rstore specified";
+	if (!config.rstore.model) 
+	    throw "no rstore model specified";
+
+	rstore = config.rstore;
+
+	Ext.apply(config, {
+	    model: rstore.model,
+	    proxy: { type: 'memory' }
+	});
+
+	me.callParent([config]);
+
+	var cond_add_item = function(data, id) {
+	    var olditem = me.getById(id);
+	    if (olditem) {
+		olditem.beginEdit()
+		me.model.prototype.fields.eachKey(function(field) {
+		    if (olditem.data[field] !== data[field])
+			olditem.set(field, data[field]);
+		});
+		olditem.endEdit(true);
+		olditem.commit(); 
+	    } else {
+		var newrec = Ext.ModelMgr.create(data, me.model, id);
+		me.add(newrec);
+	    }
+	};
+
+	me.mon(rstore, 'load', function(s, records, success) {
+
+	    if (!success)
+		return;
+
+	    me.suspendEvents();
+
+	    // remove vanished items
+	    me.each(function(olditem) {
+		var item = rstore.getById(olditem.getId());
+		if (!item)
+		    me.remove(olditem);
+	    });
+		    
+	    rstore.each(function(item) {
+		cond_add_item(item.data, item.getId());
+	    });
+	    	    
+	    me.resumeEvents();
+	    me.fireEvent('datachanged', me);
+	});
+    }
+});

Modified: pve-manager/pve2/www/new/node/ServiceView.js
===================================================================
--- pve-manager/pve2/www/new/node/ServiceView.js	2011-05-17 08:30:29 UTC (rev 5987)
+++ pve-manager/pve2/www/new/node/ServiceView.js	2011-05-17 11:16:47 UTC (rev 5988)
@@ -10,30 +10,22 @@
 	if (!nodename) 
 	    throw "no node name specified";
 
-	var store = Ext.create('Ext.data.Store', {
-	    fields: [ 'service', 'name', 'desc', 'state' ],
-            proxy: {
-                type: 'pve',
-                url: "/api2/json/nodes/" + nodename + "/services",
-            }
+	var rstore = Ext.create('PVE.data.UpdateStore', {
+	    interval: 1000,
+	    storeid: 'pve-services',
+	    model: Ext.define('pve-services', {
+		extend: 'Ext.data.Model',
+		fields: [ 'service', 'name', 'desc', 'state' ],
+		idProperty: 'service',
+		proxy: {
+                    type: 'pve',
+                    url: "/api2/json/nodes/" + nodename + "/services",
+		}
+	    })
 	});
 
-	var prev_selection;
-	store.on('beforeload', function() {
-	    var sm = me.getSelectionModel();
-	    prev_selection = sm.getLastSelected();
-	});
+	var store = Ext.create('PVE.data.DiffStore', { rstore: rstore });
 
-	store.on("load", function() {
-	    if (prev_selection) {
-		var rec = store.find('service', prev_selection.data.service);
-		if (rec) {
-		    var sm = me.getSelectionModel();
-		    sm.select(rec);
-		}
-	    }
-	}); 
-
 	var service_cmd = function(cmd) {
 	    var sm = me.getSelectionModel();
 	    var rec = sm.getLastSelected();
@@ -43,10 +35,10 @@
 		method: 'PUT',
 		failure: function(response, opts) {
 		    Ext.Msg.alert('Error', response.htmlStatus);
-		    store.load();
+		    me.loading = true;
 		},
 		success: function(response, opts) {
-		    store.load();
+		    rstore.startUpdate();
 		}
 	    });
 	};
@@ -75,6 +67,53 @@
 	    }
 	});
 
+	var set_button_status = function() {
+	    var sm = me.getSelectionModel();
+	    var rec = sm.getLastSelected();
+
+	    if (!rec) {
+		start_btn.disable();
+		stop_btn.disable();
+		restart_btn.disable();
+		return;
+	    }
+	    var service = rec.data.service;
+	    var state = rec.data.state;
+	    if (service == 'apache' ||
+		service == 'pvecluster' ||
+		service == 'pvedaemon') {
+		if (state == 'running') {
+		    start_btn.disable();
+		    restart_btn.enable();
+		} else {
+		    start_btn.enable();
+		    restart_btn.disable();
+		}
+		stop_btn.disable();
+	    } else {
+		if (state == 'running') {
+		    start_btn.disable();
+		    restart_btn.enable();
+		    stop_btn.enable();
+		} else {
+		    start_btn.enable();
+		    restart_btn.disable();
+		    stop_btn.disable();
+		}
+	    }
+	};
+
+	me.mon(store, 'datachanged', set_button_status);
+
+	me.mon(rstore, 'load', function(s, records, success) {
+	    if (!success) {
+		me.setLoading("Data load error");
+		return;
+	    } else {
+		me.setLoading(false);
+	    }
+	});
+
 	Ext.apply(me, {
 	    store: store,
 	    stateful: false,
@@ -99,42 +138,10 @@
 		}
 	    ],
 	    listeners: {
-		selectionchange: function(t, selections) {
-		    var rec = selections[0];
-		    if (!rec) {
-			start_btn.disable();
-			stop_btn.disable();
-			restart_btn.disable();
-			return;
-		    }
-		    var service = rec.data.service;
-		    var state = rec.data.state;
-		    if (service == 'apache' ||
-			service == 'pvecluster' ||
-			service == 'pvedaemon') {
-			if (state == 'running') {
-			    start_btn.disable();
-			    restart_btn.enable();
-			} else {
-			    start_btn.enable();
-			    restart_btn.disable();
-			}
-			stop_btn.disable();
-		    } else {
-			if (state == 'running') {
-			    start_btn.disable();
-			    restart_btn.enable();
-			    stop_btn.enable();
-			} else {
-			    start_btn.enable();
-			    restart_btn.disable();
-			    stop_btn.disable();
-			}
-		    }
-		},
-		show: function() {
-		    store.load();
-		}
+		selectionchange: set_button_status,
+		show: rstore.startUpdate,
+		hide: rstore.stopUpdate,
+		destroy: rstore.stopUpdate,
 	    }
 	});
 




More information about the pve-devel mailing list