From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id 5C6031FF56B
	for <inbox@lore.proxmox.com>; Mon, 22 Apr 2024 11:34:17 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 60011D3D2;
	Mon, 22 Apr 2024 11:34:19 +0200 (CEST)
Message-ID: <2a004a96-fe68-41c0-94bd-4c6cea151dee@proxmox.com>
Date: Mon, 22 Apr 2024 11:33:46 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird Beta
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
 Markus Frank <m.frank@proxmox.com>
References: <20240408103305.780097-1-m.frank@proxmox.com>
Content-Language: en-US
From: Dominik Csapak <d.csapak@proxmox.com>
In-Reply-To: <20240408103305.780097-1-m.frank@proxmox.com>
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.015 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: Re: [pve-devel] [PATCH manager v16 1/2] ui: qemu: change
 DisplayEdit logic to use ViewModel instead of listener function
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="us-ascii"; Format="flowed"
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

one minor nit inline, otherwise

Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Dominik Csapak <d.csapak@proxmox.com>

On 4/8/24 12:33, Markus Frank wrote:
> Signed-off-by: Markus Frank <m.frank@proxmox.com>
> ---
>   www/manager6/qemu/DisplayEdit.js | 57 ++++++++++++++++++--------------
>   1 file changed, 33 insertions(+), 24 deletions(-)
> 
> diff --git a/www/manager6/qemu/DisplayEdit.js b/www/manager6/qemu/DisplayEdit.js
> index 9bb1763e..17b02ee4 100644
> --- a/www/manager6/qemu/DisplayEdit.js
> +++ b/www/manager6/qemu/DisplayEdit.js
> @@ -11,6 +11,33 @@ Ext.define('PVE.qemu.DisplayInputPanel', {
>   	return { vga: ret };
>       },
>   
> +    viewModel: {
> +	data: {
> +	    type: '__default__',
> +	    nonGUIOptionRegex: /^(serial\d|none)$/,
> +	},
> +	formulas: {
> +	    matchNonGUIOption: function(get) {
> +		return get('type').match(get('nonGUIOptionRegex'));

since this regex is only used once, i'd inline it where it's used

> +	    },
> +	    memoryEmptyText: function(get) {
> +		let val = get('type');
> +		if (val === "cirrus") {
> +		    return "4";
> +		} else if (val === "std" || val.match(/^qxl\d?$/) || val === "vmware") {
> +		    return "16";
> +		} else if (val.match(/^virtio/)) {
> +		    return "256";
> +		} else if (get('matchNonGUIOption')) {
> +		    return "N/A";
> +		} else {
> +		    console.debug("unexpected display type", val);
> +		    return Proxmox.Utils.defaultText;
> +		}
> +	    },
> +	},
> +    },
> +
>       items: [{
>   	name: 'type',
>   	xtype: 'proxmoxKVComboBox',
> @@ -27,39 +54,21 @@ Ext.define('PVE.qemu.DisplayInputPanel', {
>   	    }
>   	    return true;
>   	},
> -	listeners: {
> -	    change: function(cb, val) {
> -		if (!val) {
> -		    return;
> -		}
> -		let memoryfield = this.up('panel').down('field[name=memory]');
> -		let disableMemoryField = false;
> -
> -		if (val === "cirrus") {
> -		    memoryfield.setEmptyText("4");
> -		} else if (val === "std" || val.match(/^qxl\d?$/) || val === "vmware") {
> -		    memoryfield.setEmptyText("16");
> -		} else if (val.match(/^virtio/)) {
> -		    memoryfield.setEmptyText("256");
> -		} else if (val.match(/^(serial\d|none)$/)) {
> -		    memoryfield.setEmptyText("N/A");
> -		    disableMemoryField = true;
> -		} else {
> -		    console.debug("unexpected display type", val);
> -		    memoryfield.setEmptyText(Proxmox.Utils.defaultText);
> -		}
> -		memoryfield.setDisabled(disableMemoryField);
> -	    },
> +	bind: {
> +	    value: '{type}',
>   	},
>       },
>       {
>   	xtype: 'proxmoxintegerfield',
> -	emptyText: Proxmox.Utils.defaultText,
>   	fieldLabel: gettext('Memory') + ' (MiB)',
>   	minValue: 4,
>   	maxValue: 512,
>   	step: 4,
>   	name: 'memory',
> +	bind: {
> +	    emptyText: '{memoryEmptyText}',
> +	    disabled: '{matchNonGUIOption}',
> +	},
>       }],
>   });
>   



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