all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christian Ebner <c.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-manager] ui: node: extend option editor for wake on lan
Date: Wed,  3 Apr 2024 12:10:01 +0200	[thread overview]
Message-ID: <20240403101001.182389-1-c.ebner@proxmox.com> (raw)

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@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





                 reply	other threads:[~2024-04-03 10:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240403101001.182389-1-c.ebner@proxmox.com \
    --to=c.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal