public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH manager] fix #5787: ui: display vm description in confirm dialogs
@ 2024-10-21 12:17 Timothy Nicholson
  2024-10-22  6:58 ` Thomas Lamprecht
  0 siblings, 1 reply; 3+ messages in thread
From: Timothy Nicholson @ 2024-10-21 12:17 UTC (permalink / raw)
  To: pve-devel

Signed-off-by: Timothy Nicholson <t.nicholson@proxmox.com>
---

This patch adds a new function to the PVE Utils that formats a task confirmation message to display in confirm dialogs, for example when shutting down a VM. As requested by the Bugzilla entry #5787, the message now includes the VM name in addition to the VM ID.

 www/manager6/Utils.js            |  4 ++++
 www/manager6/lxc/CmdMenu.js      |  4 ++--
 www/manager6/lxc/Config.js       |  8 +++++---
 www/manager6/qemu/CmdMenu.js     |  4 ++--
 www/manager6/qemu/Config.js      | 14 ++++++++------
 www/manager6/window/GuestStop.js |  2 +-
 6 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index db86fa9a..462eb148 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -1960,6 +1960,10 @@ Ext.define('PVE.Utils', {
 	}
 	return languageCookie || Proxmox.defaultLang || 'en';
     },
+
+    format_task_confirmation_message: function(type, vmid, vmname) {
+	return `${Proxmox.Utils.format_task_description(type, `${vmid} (${vmname})`)}?`;
+    },
 },
 
     singleton: true,
diff --git a/www/manager6/lxc/CmdMenu.js b/www/manager6/lxc/CmdMenu.js
index 76b39423..b6d57a6e 100644
--- a/www/manager6/lxc/CmdMenu.js
+++ b/www/manager6/lxc/CmdMenu.js
@@ -22,7 +22,7 @@ Ext.define('PVE.lxc.CmdMenu', {
 	    });
 	};
 	let confirmedVMCommand = (cmd, params) => {
-	    let msg = Proxmox.Utils.format_task_description(`vz${cmd}`, info.vmid);
+	    let msg = PVE.Utils.format_task_confirmation_message(`vz${cmd}`, info.vmid, info.name);
 	    Ext.Msg.confirm(gettext('Confirm'), msg, btn => {
 		if (btn === 'yes') {
 		    vm_command(cmd, params);
@@ -108,7 +108,7 @@ Ext.define('PVE.lxc.CmdMenu', {
 		text: gettext('Convert to template'),
 		iconCls: 'fa fa-fw fa-file-o',
 		handler: function() {
-		    let msg = Proxmox.Utils.format_task_description('vztemplate', info.vmid);
+		    let msg = PVE.Utils.format_task_confirmation_message('vztemplate', info.vmid, info.name);
 		    Ext.Msg.confirm(gettext('Confirm'), msg, function(btn) {
 			if (btn === 'yes') {
 			    Proxmox.Utils.API2Request({
diff --git a/www/manager6/lxc/Config.js b/www/manager6/lxc/Config.js
index d0e40fc4..8211dfdd 100644
--- a/www/manager6/lxc/Config.js
+++ b/www/manager6/lxc/Config.js
@@ -20,6 +20,8 @@ Ext.define('PVE.lxc.Config', {
 	    throw "no VM ID specified";
 	}
 
+	var vmname = vm.name;
+
 	var template = !!vm.template;
 
 	var running = !!vm.uptime;
@@ -59,7 +61,7 @@ Ext.define('PVE.lxc.Config', {
 	    text: gettext('Shutdown'),
 	    disabled: !caps.vms['VM.PowerMgmt'] || !running,
 	    hidden: template,
-	    confirmMsg: Proxmox.Utils.format_task_description('vzshutdown', vmid),
+	    confirmMsg: PVE.Utils.format_task_confirmation_message('vzshutdown', vmid, vmname),
 	    handler: function() {
 		vm_command('shutdown');
 	    },
@@ -67,7 +69,7 @@ Ext.define('PVE.lxc.Config', {
 		items: [{
 		    text: gettext('Reboot'),
 		    disabled: !caps.vms['VM.PowerMgmt'],
-		    confirmMsg: Proxmox.Utils.format_task_description('vzreboot', vmid),
+		    confirmMsg: PVE.Utils.format_task_confirmation_message('vzreboot', vmid, vmname),
 		    tooltip: Ext.String.format(gettext('Reboot {0}'), 'CT'),
 		    handler: function() {
 			vm_command("reboot");
@@ -124,7 +126,7 @@ Ext.define('PVE.lxc.Config', {
 		    xtype: 'pveMenuItem',
 		    iconCls: 'fa fa-fw fa-file-o',
 		    hidden: !caps.vms['VM.Allocate'],
-		    confirmMsg: Proxmox.Utils.format_task_description('vztemplate', vmid),
+		    confirmMsg: PVE.Utils.format_task_confirmation_message('vztemplate', vmid, vmname),
 		    handler: function() {
 			Proxmox.Utils.API2Request({
 			    url: base_url + '/template',
diff --git a/www/manager6/qemu/CmdMenu.js b/www/manager6/qemu/CmdMenu.js
index 834577e7..b621d9df 100644
--- a/www/manager6/qemu/CmdMenu.js
+++ b/www/manager6/qemu/CmdMenu.js
@@ -23,7 +23,7 @@ Ext.define('PVE.qemu.CmdMenu', {
 	};
 	let confirmedVMCommand = (cmd, params, confirmTask) => {
 	    let task = confirmTask || `qm${cmd}`;
-	    let msg = Proxmox.Utils.format_task_description(task, info.vmid);
+	    let msg = PVE.Utils.format_task_confirmation_message(task, info.vmid, info.name);
 	    Ext.Msg.confirm(gettext('Confirm'), msg, btn => {
 		if (btn === 'yes') {
 		    vm_command(cmd, params);
@@ -136,7 +136,7 @@ Ext.define('PVE.qemu.CmdMenu', {
 		iconCls: 'fa fa-fw fa-file-o',
 		hidden: !caps.vms['VM.Allocate'],
 		handler: function() {
-		    let msg = Proxmox.Utils.format_task_description('qmtemplate', info.vmid);
+		    let msg = PVE.Utils.format_task_confirmation_message('qmtemplate', info.vmid, info.name);
 		    Ext.Msg.confirm(gettext('Confirm'), msg, btn => {
 			if (btn === 'yes') {
 			    Proxmox.Utils.API2Request({
diff --git a/www/manager6/qemu/Config.js b/www/manager6/qemu/Config.js
index f28ee67b..c117778c 100644
--- a/www/manager6/qemu/Config.js
+++ b/www/manager6/qemu/Config.js
@@ -19,6 +19,8 @@ Ext.define('PVE.qemu.Config', {
 	    throw "no VM ID specified";
 	}
 
+	var vmname = vm.name;
+
 	var template = !!vm.template;
 
 	var running = !!vm.uptime;
@@ -97,7 +99,7 @@ Ext.define('PVE.qemu.Config', {
 		    xtype: 'pveMenuItem',
 		    iconCls: 'fa fa-fw fa-file-o',
 		    hidden: !caps.vms['VM.Allocate'],
-		    confirmMsg: Proxmox.Utils.format_task_description('qmtemplate', vmid),
+		    confirmMsg: PVE.Utils.format_task_confirmation_message('qmtemplate', vmid, vmname),
 		    handler: function() {
 			Proxmox.Utils.API2Request({
 			    url: base_url + '/template',
@@ -142,7 +144,7 @@ Ext.define('PVE.qemu.Config', {
 	    text: gettext('Shutdown'),
 	    disabled: !caps.vms['VM.PowerMgmt'] || !running,
 	    hidden: template,
-	    confirmMsg: Proxmox.Utils.format_task_description('qmshutdown', vmid),
+	    confirmMsg: PVE.Utils.format_task_confirmation_message('qmshutdown', vmid, vmname),
 	    handler: function() {
 		vm_command('shutdown');
 	    },
@@ -151,7 +153,7 @@ Ext.define('PVE.qemu.Config', {
 		    text: gettext('Reboot'),
 		    disabled: !caps.vms['VM.PowerMgmt'],
 		    tooltip: Ext.String.format(gettext('Shutdown, apply pending changes and reboot {0}'), 'VM'),
-		    confirmMsg: Proxmox.Utils.format_task_description('qmreboot', vmid),
+		    confirmMsg: PVE.Utils.format_task_confirmation_message('qmreboot', vmid, vmname),
 		    handler: function() {
 			vm_command("reboot");
 		    },
@@ -159,7 +161,7 @@ Ext.define('PVE.qemu.Config', {
 		}, {
 		    text: gettext('Pause'),
 		    disabled: !caps.vms['VM.PowerMgmt'],
-		    confirmMsg: Proxmox.Utils.format_task_description('qmpause', vmid),
+		    confirmMsg: PVE.Utils.format_task_confirmation_message('qmpause', vmid, vmname),
 		    handler: function() {
 			vm_command("suspend");
 		    },
@@ -167,7 +169,7 @@ Ext.define('PVE.qemu.Config', {
 		}, {
 		    text: gettext('Hibernate'),
 		    disabled: !caps.vms['VM.PowerMgmt'],
-		    confirmMsg: Proxmox.Utils.format_task_description('qmsuspend', vmid),
+		    confirmMsg: PVE.Utils.format_task_confirmation_message('qmsuspend', vmid, vmname),
 		    tooltip: gettext('Suspend to disk'),
 		    handler: function() {
 			vm_command("suspend", { todisk: 1 });
@@ -189,7 +191,7 @@ Ext.define('PVE.qemu.Config', {
 		    text: gettext('Reset'),
 		    disabled: !caps.vms['VM.PowerMgmt'],
 		    tooltip: Ext.String.format(gettext('Reset {0} immediately'), 'VM'),
-		    confirmMsg: Proxmox.Utils.format_task_description('qmreset', vmid),
+		    confirmMsg: PVE.Utils.format_task_confirmation_message('qmreset', vmid, vmname),
 		    handler: function() {
 			vm_command("reset");
 		    },
diff --git a/www/manager6/window/GuestStop.js b/www/manager6/window/GuestStop.js
index fbd45c7a..039ddfcb 100644
--- a/www/manager6/window/GuestStop.js
+++ b/www/manager6/window/GuestStop.js
@@ -68,7 +68,7 @@ Ext.define('PVE.GuestStop', {
 	let cfg = {
 	    title: gettext('Confirm'),
 	    icon: Ext.Msg.WARNING,
-	    msg: Proxmox.Utils.format_task_description(me.taskType, me.vm.vmid),
+	    msg: PVE.Utils.format_task_confirmation_message(me.taskType, me.vm.vmid, me.vm.name),
 	    buttons: Ext.Msg.YESNO,
 	    callback: btn => me.handler(btn),
 	};
-- 
2.39.5


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pve-devel] [PATCH manager] fix #5787: ui: display vm description in confirm dialogs
  2024-10-21 12:17 [pve-devel] [PATCH manager] fix #5787: ui: display vm description in confirm dialogs Timothy Nicholson
@ 2024-10-22  6:58 ` Thomas Lamprecht
  2024-10-22 10:39   ` Fiona Ebner
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Lamprecht @ 2024-10-22  6:58 UTC (permalink / raw)
  To: Proxmox VE development discussion, Timothy Nicholson

The subject made me think you added the VM description property, i.e. the
comment a user can set for VMs in the note field, to the confirmation.
But it's for all guests, i.e., bot VMs and CTs, and it's the guest name, so
I'd go for something like:

fix #5787: ui: display guest name in confirm dialogs

Am 21/10/2024 um 14:17 schrieb Timothy Nicholson:
> Signed-off-by: Timothy Nicholson <t.nicholson@proxmox.com>
> ---
> 
> This patch adds a new function to the PVE Utils that formats a task confirmation message to display in confirm dialogs, for example when shutting down a VM. As requested by the Bugzilla entry #5787, the message now includes the VM name in addition to the VM ID.

why isn't above stated in the commit message but only as patch note?

> 
>  www/manager6/Utils.js            |  4 ++++
>  www/manager6/lxc/CmdMenu.js      |  4 ++--
>  www/manager6/lxc/Config.js       |  8 +++++---
>  www/manager6/qemu/CmdMenu.js     |  4 ++--
>  www/manager6/qemu/Config.js      | 14 ++++++++------
>  www/manager6/window/GuestStop.js |  2 +-
>  6 files changed, 22 insertions(+), 14 deletions(-)
> 
> diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
> index db86fa9a..462eb148 100644
> --- a/www/manager6/Utils.js
> +++ b/www/manager6/Utils.js
> @@ -1960,6 +1960,10 @@ Ext.define('PVE.Utils', {
>  	}
>  	return languageCookie || Proxmox.defaultLang || 'en';
>      },
> +
> +    format_task_confirmation_message: function(type, vmid, vmname) {

As this is not for arbitrary tasks but for guests I'd change the signature
of this function to:

format_guest_confirmation: function(taskType, vmid, guestName) {

vmid could also become guestId, but vmid is so widely used in various code
bases that it is often easier to ignore that it implies VMs only, as "vmid"
seldom does that.

And yes, we have some wrong terminology in LXC code, like the "vm" variable
below, but for new functions I'd still like to use the generic terms if the
function is applicable for both, CTs and VMs.

> +	return `${Proxmox.Utils.format_task_description(type, `${vmid} (${vmname})`)}?`;

This also adds a "?" at the end, is that all right? The nested template string
isn't making things easier to read IMO, and if the "?" is indeed superfluous then
a simple

return Proxmox.Utils.format_task_description(taskType, `${vmid} (${guestName})`);


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pve-devel] [PATCH manager] fix #5787: ui: display vm description in confirm dialogs
  2024-10-22  6:58 ` Thomas Lamprecht
@ 2024-10-22 10:39   ` Fiona Ebner
  0 siblings, 0 replies; 3+ messages in thread
From: Fiona Ebner @ 2024-10-22 10:39 UTC (permalink / raw)
  To: Proxmox VE development discussion, Thomas Lamprecht, Timothy Nicholson

Am 22.10.24 um 08:58 schrieb Thomas Lamprecht:
> Am 21/10/2024 um 14:17 schrieb Timothy Nicholson:
>> Signed-off-by: Timothy Nicholson <t.nicholson@proxmox.com>
>> ---
>>
>> This patch adds a new function to the PVE Utils that formats a task confirmation message to display in confirm dialogs, for example when shutting down a VM. As requested by the Bugzilla entry #5787, the message now includes the VM name in addition to the VM ID.
> 
> why isn't above stated in the commit message but only as patch note?
> 

Also please note (from [0]):

> Make sure the line-length (text-width, column count) of the commit's message is not longer than 72 characters.

which is a good limit for readability in mails in general :)

[0]:
https://pve.proxmox.com/wiki/Developer_Documentation#Commits_and_Commit_Messages


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-22 10:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-21 12:17 [pve-devel] [PATCH manager] fix #5787: ui: display vm description in confirm dialogs Timothy Nicholson
2024-10-22  6:58 ` Thomas Lamprecht
2024-10-22 10:39   ` Fiona Ebner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal