public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Filip Schauer <f.schauer@proxmox.com>
Subject: Re: [pve-devel] [PATCH v2 manager] ui: lxc: add edit window for device passthrough
Date: Fri, 26 Jan 2024 16:23:03 +0100	[thread overview]
Message-ID: <e450eedb-e938-40cf-99b5-2dd9d93de8a2@proxmox.com> (raw)
In-Reply-To: <20231121102100.118669-1-f.schauer@proxmox.com>

Am 21.11.23 um 11:21 schrieb Filip Schauer:
> Signed-off-by: Filip Schauer <f.schauer@proxmox.com>

High-level comment:
- would be nice to have the default values as emptyText for
UID/GID/Acces Mode and maybe also have an example text /dev/XYZ for the path
- if I add /dev/doesnotexist I'll get an error but it'll still be added
to the configuration
- I think the device index should be selectible too, to make it more
consistent with adding a mount point
- There's quite a bit of empty space on the right side in the advanced
options, maybe move one of the fields there?
- The menu entry for "Add" should be hidden or disabled for users
without sufficient permissions.
- Maybe add a warning, because it can be dangerous. Should it even be
exposed in the UI?
- Style nit: 'var' shouldn't be used, see
https://pve.proxmox.com/wiki/Javascript_Style_Guide#Variables

> diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
> index 9f44e560..f028685b 100644
> --- a/www/manager6/Utils.js
> +++ b/www/manager6/Utils.js
> @@ -1605,6 +1605,17 @@ Ext.define('PVE.Utils', {
>  	}
>      },
>  
> +    dev_count: 256,
> +
> +    forEachDev: function(func) {
> +	for (let i = 0; i < PVE.Utils.dev_count; i++) {
> +	    let cont = func(i);
> +	    if (!cont && cont !== undefined) {
> +		return;
> +	    }
> +	}
> +    },
> +
>      hardware_counts: {
>  	net: 32,
>  	usb: 14,

Maybe it's time to finally split PVE.Utils? dev_count and forEachDev is
really too generic of a name for such a module, should be at least
mention "lxc".

> diff --git a/www/manager6/lxc/DeviceEdit.js b/www/manager6/lxc/DeviceEdit.js
> new file mode 100644
> index 00000000..1ee4f309
> --- /dev/null
> +++ b/www/manager6/lxc/DeviceEdit.js
> @@ -0,0 +1,166 @@
> +Ext.define('PVE.lxc.DeviceInputPanel', {
> +    extend: 'Proxmox.panel.InputPanel',
> +    mixins: ['Proxmox.Mixin.CBind'],
> +
> +    autoComplete: false,
> +
> +    cbindData: function(initialConfig) {
> +	let me = this;
> +	if (!me.pveSelNode) {
> +	    throw "no pveSelNode given";
> +	}
> +
> +	return { nodename: me.pveSelNode.data.node };
> +    },
> +
> +    viewModel: {
> +	data: {},
> +    },
> +
> +    setVMConfig: function(vmconfig) {
> +	var me = this;
> +	me.vmconfig = vmconfig;
> +    },
> +
> +    onGetValues: function(values) {
> +	var me = this;
> +	if (!me.confid) {
> +	    let max_devices = 256;

Could use the dev_count from PVE.Util

> +	    for (let i = 0; i < max_devices; i++) {
> +		let id = 'dev' + i.toString();
> +		if (!me.vmconfig[id]) {
> +		    me.confid = id;
> +		    break;
> +		}
> +	    }
> +	}
> +	var val = values.path;
> +	delete values.path;
> +
> +	if (values.mode) {
> +	    val += ',mode=' + values.mode;
> +	}
> +	delete values.mode;
> +
> +	if (values.uid) {
> +	    val += ',uid=' + values.uid;
> +	}
> +	delete values.uid;
> +
> +	if (values.gid) {
> +	    val += ',gid=' + values.gid;
> +	}
> +	delete values.gid;
> +

I think you can use PVE.Parser.printPropertyString() to save some lines
here.

> +	values[me.confid] = val;
> +	return values;
> +    },
> +
> +    items: [
> +	{
> +	    xtype: 'textfield',
> +	    type: 'device',
> +	    name: 'path',
> +	    cbind: { pveSelNode: '{pveSelNode}' },

I might be missing something, but isn't this a normal ExtJS text field?
Does this cbind have any actual consequences? Same for the others.

> +	    editable: true,
> +	    allowBlank: false,
> +	    fieldLabel: gettext('Device Path'),
> +	    labelAlign: 'right',
> +	    validator: function(value) {
> +		if (value.startsWith('/dev/')) {
> +		    return true;
> +		}
> +
> +		return "Path has to start with /dev/";
> +	    },
> +	},
> +    ],
> +
>

---cut---

> +	me.load({
> +	    success: function(response, options) {
> +		ipanel.setVMConfig(response.result.data);
> +		if (me.isCreate) {
> +		    return;
> +		}
> +
> +		let data = PVE.Parser.parsePropertyString(response.result.data[me.confid], 'path');
> +		let path, mode, uid, gid;
> +		path = data.path;
> +		mode = data.mode;
> +		uid = data.uid;
> +		gid = data.gid;
> +
> +		var values = {
> +		    path,
> +		    mode,
> +		    uid,
> +		    gid,
> +		};
> +
> +		ipanel.setValues(values);

Couldn't you pass data directly? Or at least make constructing values
quite a bit shorter ;)




  reply	other threads:[~2024-01-26 15:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-21 10:21 Filip Schauer
2024-01-26 15:23 ` Fiona Ebner [this message]
2024-01-29 14:32   ` Filip Schauer
2024-01-31 15:14   ` Filip Schauer

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=e450eedb-e938-40cf-99b5-2dd9d93de8a2@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=f.schauer@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 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