[pve-devel] [PATCH v7 manager 2/3] add cmd parameter & rework query string creation

Tim Marx t.marx at proxmox.com
Wed Mar 6 12:29:39 CET 2019


Signed-off-by: Tim Marx <t.marx at proxmox.com>
---
v7 changes:
* moved clean to Utils
* fixed if statement logic

 www/manager6/Utils.js      | 11 +++++++++++
 www/manager6/VNCConsole.js | 22 +++++++++++++++-------
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index b9fa25b7..326a2527 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -1091,6 +1091,17 @@ Ext.define('PVE.Utils', { utilities: {
 		return;
 	    }
 	}
+    },
+
+    cleanEmptyObjectKeys: function (obj) {
+	var propName;
+	for (propName in obj) {
+	    if (obj.hasOwnProperty(propName)) {
+		if (obj[propName] === null || obj[propName] === undefined) {
+		    delete obj[propName];
+		}
+	    }
+	}
     }
 },
 
diff --git a/www/manager6/VNCConsole.js b/www/manager6/VNCConsole.js
index 1438dd0c..cd8fa243 100644
--- a/www/manager6/VNCConsole.js
+++ b/www/manager6/VNCConsole.js
@@ -6,7 +6,9 @@ Ext.define('PVE.noVncConsole', {
 
     vmid: undefined,
 
-    consoleType: undefined, // lxc or kvm
+    cmd: undefined,
+
+    consoleType: undefined, // lxc, kvm, shell, cmd
 
     layout: 'fit',
 
@@ -14,6 +16,7 @@ Ext.define('PVE.noVncConsole', {
 
     border: false,
 
+
     initComponent : function() {
 	var me = this;
 
@@ -25,7 +28,7 @@ Ext.define('PVE.noVncConsole', {
 	    throw "no console type specified";
 	}
 
-	if (!me.vmid && me.consoleType !== 'shell') {
+	if (!me.vmid && me.consoleType !== 'shell' && me.consoleType !== 'cmd') {
 	    throw "no VM ID specified";
 	}
 
@@ -34,15 +37,20 @@ Ext.define('PVE.noVncConsole', {
 	var box = Ext.create('Ext.ux.IFrame', { itemid : "vncconsole" });
 
 	var type = me.xtermjs ? 'xtermjs' : 'novnc';
-
 	Ext.apply(me, {
 	    items: box,
 	    listeners: {
 		activate: function() {
-		    var url = '/?console=' + me.consoleType + '&' + type + '=1&node=' + me.nodename + '&resize=scale';
-		    if (me.vmid) {
-			url += '&vmid='+ me.vmid;
-		    }
+		    var queryDict = {
+			console: me.consoleType, // kvm, lxc, upgrade or shell
+			vmid: me.vmid,
+			node: me.nodename,
+			cmd: me.cmd,
+			resize: 'scale'
+		    };
+		    queryDict[type] = 1;
+		    PVE.Utils.cleanEmptyObjectKeys(queryDict);
+		    var url = '/?' + Ext.Object.toQueryString(queryDict);
 		    box.load(url);
 		}
 	    }
-- 
2.11.0



More information about the pve-devel mailing list