[pve-devel] [PATCH pve-manager] ui: node: extend option editor for wake on lan

Christian Ebner c.ebner at proxmox.com
Wed Apr 3 12:10:01 CEST 2024


Commit 3f83a0332ef5850c7b2324ca5958fa9b4b4dd61c switched the nodes
`wakeonlan` configuration parameter to be a property string and the
subsequent patches added bind-interface and broadcast-address as
additional optional parameters.

Make this editable in the node options, by adding a dedicated editor
component.

The editor is used for the wake on lan record of the grid only, by
adding the `handle_editor` function, to calls the required editor
based on the selected record of the grid.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
 www/manager6/node/NodeOptionsView.js | 87 +++++++++++++++++++++++-----
 1 file changed, 74 insertions(+), 13 deletions(-)

diff --git a/www/manager6/node/NodeOptionsView.js b/www/manager6/node/NodeOptionsView.js
index 661c0e90..6a9e3826 100644
--- a/www/manager6/node/NodeOptionsView.js
+++ b/www/manager6/node/NodeOptionsView.js
@@ -1,3 +1,55 @@
+Ext.define('PVE.node.WakeOnLanEdit', {
+    extend: 'Proxmox.window.Edit',
+    xtype: 'pveNodeWakeOnLanEdit',
+
+    subject: gettext('Wake on LAN settings'),
+    width: 350,
+
+    items: [
+	{
+	    xtype: 'textfield',
+	    name: 'mac',
+	    fieldLabel: gettext('MAC address'),
+	    labelWidth: 130,
+	    vtype: 'MacAddress',
+	},
+	{
+	    xtype: 'textfield',
+	    name: 'bind-interface',
+	    fieldLabel: gettext('Bind interface'),
+	    labelWidth: 130,
+	},
+	{
+	    xtype: 'textfield',
+	    name: 'broadcast-address',
+	    fieldLabel: gettext('Broadcast address'),
+	    labelWidth: 130,
+	    vtype: 'IPAddress',
+	},
+    ],
+
+    getValues: function() {
+	let me = this;
+	let wolConfig = {
+	    mac: me.down('textfield[name=mac]').getValue(),
+	    "bind-interface": me.down('textfield[name=bind-interface]').getValue(),
+	    "broadcast-address": me.down('textfield[name=broadcast-address]').getValue(),
+	};
+	let wolString = PVE.Parser.printPropertyString(wolConfig, 'mac');
+	return { wakeonlan: wolString };
+    },
+
+    setValues: function(values) {
+	let me = this;
+	if (values.wakeonlan) {
+	    let wolConfig = PVE.Parser.parsePropertyString(values.wakeonlan, 'mac');
+	    Ext.Object.each(wolConfig, function(name, value) {
+		me.down('textfield[name=' + name + ']').setValue(value);
+	    });
+	}
+    },
+});
+
 Ext.define('Proxmox.node.NodeOptionsView', {
     extend: 'Proxmox.grid.ObjectGrid',
     alias: ['widget.proxmoxNodeOptionsView'],
@@ -15,8 +67,26 @@ Ext.define('Proxmox.node.NodeOptionsView', {
 	return {};
     },
 
+    handle_editor: function() {
+	let me = this;
+	var selection_model = me.getSelectionModel();
+	let record = selection_model.getSelection()[0];
+	if (record.id === 'wakeonlan') {
+	    let baseUrl = `/nodes/${me.nodename}/config`;
+	    Ext.create('PVE.node.WakeOnLanEdit', {
+		url: `/api2/extjs/${baseUrl}`,
+		autoLoad: true,
+		listeners: {
+		    destroy: function() { me.reload(); },
+		},
+	    }).show();
+	} else {
+	    me.run_editor();
+	}
+    },
+
     listeners: {
-	itemdblclick: function() { this.run_editor(); },
+	itemdblclick: function() { this.handle_editor(); },
 	activate: function() { this.rstore.startUpdate(); },
 	destroy: function() { this.rstore.stopUpdate(); },
 	deactivate: function() { this.rstore.stopUpdate(); },
@@ -27,7 +97,7 @@ Ext.define('Proxmox.node.NodeOptionsView', {
 	    text: gettext('Edit'),
 	    xtype: 'proxmoxButton',
 	    disabled: true,
-	    handler: btn => btn.up('grid').run_editor(),
+	    handler: btn => btn.up('grid').handle_editor(),
 	},
     ],
 
@@ -52,17 +122,8 @@ Ext.define('Proxmox.node.NodeOptionsView', {
 	{
 	    xtype: 'text',
 	    name: 'wakeonlan',
-	    text: gettext('MAC address for Wake on LAN'),
-	    vtype: 'MacAddress',
-	    labelWidth: 150,
-	    deleteEmpty: true,
-	    renderer: function(value) {
-		if (value === undefined) {
-		    return Proxmox.Utils.NoneText;
-		}
-
-		return value;
-	    },
+	    text: gettext('Wake on LAN settings'),
+	    defaultValue: Proxmox.Utils.noneText,
 	},
     ],
 });
-- 
2.39.2





More information about the pve-devel mailing list