[pve-devel] [PATCH manager] fix reselection on vm/ct migrate in gui

Dominik Csapak d.csapak at proxmox.com
Fri Jun 23 11:00:58 CEST 2017


there were a number of problems in how we reselected vms when they
migrated and selected:

we relied on the data in the configpanel to be static, but since
pveselnode is a reference, it actually changes when the resourcestore
changes
also, handling the reselection as a response to the statusstore failure
is very inconsistent, because we know exactly when a vm moves node in
the tree

this patch removes the whole configpanel vm migration code,
and lets the tree handle it
for this, we have to check if we have to reselect the entry,
deselect it manually and after the treeupdate reselect it

also in the right click selection check we have to check if it is
already selected, else the next selection will get canceled

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/Workspace.js         |  6 ------
 www/manager6/lxc/Config.js        |  1 -
 www/manager6/qemu/Config.js       |  1 -
 www/manager6/tree/ResourceTree.js | 31 ++++++++++++++++---------------
 4 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/www/manager6/Workspace.js b/www/manager6/Workspace.js
index a516319d..30a51b1b 100644
--- a/www/manager6/Workspace.js
+++ b/www/manager6/Workspace.js
@@ -140,12 +140,6 @@ Ext.define('PVE.StdWorkspace', {
 	tree.selectById(nodeid);
     },
 
-    checkVmMigration: function(record) {
-	var me = this;
-	var tree = me.down('pveResourceTree');
-	tree.checkVmMigration(record);
-    },
-
     onLogin: function(loginData) {
 	var me = this;
 
diff --git a/www/manager6/lxc/Config.js b/www/manager6/lxc/Config.js
index bf8cf319..245de8ed 100644
--- a/www/manager6/lxc/Config.js
+++ b/www/manager6/lxc/Config.js
@@ -273,7 +273,6 @@ Ext.define('PVE.lxc.Config', {
 	me.mon(me.statusStore, 'load', function(s, records, success) {
 	    var status;
 	    if (!success) {
-		me.workspace.checkVmMigration(me.pveSelNode);
 		status = 'unknown';
 	    } else {
 		var rec = s.data.get('status');
diff --git a/www/manager6/qemu/Config.js b/www/manager6/qemu/Config.js
index 879ea322..3b1ff018 100644
--- a/www/manager6/qemu/Config.js
+++ b/www/manager6/qemu/Config.js
@@ -307,7 +307,6 @@ Ext.define('PVE.qemu.Config', {
 	    var spice = false;
 
 	    if (!success) {
-		me.workspace.checkVmMigration(me.pveSelNode);
 		status = qmpstatus = 'unknown';
 	    } else {
 		var rec = s.data.get('status');
diff --git a/www/manager6/tree/ResourceTree.js b/www/manager6/tree/ResourceTree.js
index 56e7fddd..b928f95d 100644
--- a/www/manager6/tree/ResourceTree.js
+++ b/www/manager6/tree/ResourceTree.js
@@ -244,6 +244,7 @@ Ext.define('PVE.tree.ResourceTree', {
 	    var sm = me.getSelectionModel();
 
 	    var lastsel = sm.getSelection()[0];
+	    var reselect = false;
 	    var parents = [];
 	    var p = lastsel;
 	    while (p && !!(p = p.parentNode)) {
@@ -314,6 +315,16 @@ Ext.define('PVE.tree.ResourceTree', {
 			//console.log("REM UID: " + key + " ITEM " + olditem.data.id);
 			delete index[key];
 			var parentNode = olditem.parentNode;
+			// when the selected item disappears,
+			// we have to deselect it here, and reselect it
+			// later
+			if (lastsel && olditem.data.id === lastsel.data.id) {
+			    reselect = true;
+			    sm.deselect(olditem);
+			}
+			// since the store events are suspended, we
+			// manually remove the item from the store also
+			store.remove(olditem);
 			parentNode.removeChild(olditem, true);
 		    }
 		}
@@ -352,6 +363,8 @@ Ext.define('PVE.tree.ResourceTree', {
 		    }
 		}
 		me.selectById(lastsel.data.id);
+	    } else if (lastsel && reselect) {
+		me.selectById(lastsel.data.id);
 	    }
 
 	    // on first tree load set the selection from the stateful provider
@@ -389,8 +402,10 @@ Ext.define('PVE.tree.ResourceTree', {
 		    rstore.un("load", updateTree);
 		},
 		beforecellmousedown: function (tree, td, cellIndex, record, tr, rowIndex, ev) {
+		    var sm = me.getSelectionModel();
 		    // disable selection when right clicking
-		    me.allowSelection = (ev.button !== 2);
+		    // except the record is already selected
+		    me.allowSelection = (ev.button !== 2) || sm.isSelected(record);
 		},
 		beforeselect: function (tree, record, index, eopts) {
 		    var allow = me.allowSelection;
@@ -439,20 +454,6 @@ Ext.define('PVE.tree.ResourceTree', {
 		}
 		return node;
 	    },
-	    checkVmMigration: function(record) {
-		if (!(record.data.type === 'qemu' || record.data.type === 'lxc')) {
-		    throw "not a vm type";
-		}
-
-		var rootnode = me.store.getRootNode();
-		var node = rootnode.findChild('id', record.data.id, true);
-
-		if (node && node.data.type === record.data.type &&
-		    node.data.node !== record.data.node) {
-		    // defer select (else we get strange errors)
-		    Ext.defer(function() { me.selectExpand(node); }, 100, me);
-		}
-	    },
 	    applyState : function(state) {
 		var sm = me.getSelectionModel();
 		if (state && state.value) {
-- 
2.11.0





More information about the pve-devel mailing list