[pve-devel] [PATCH manager 2/4] kvm_ostype: move to store-like format

Dominik Csapak d.csapak at proxmox.com
Thu Aug 24 11:24:27 CEST 2017


On 08/22/2017 11:57 AM, Thomas Lamprecht wrote:
> move from the key => value format to one where all versions from a
> base OS type can be directly used as data for a store.
> 
> We will rely on this in the next patch to allow a easy transition to
> combobox UI for the OS type selector.
> 
> We also avoid having the base type multiple times.
> 
> Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
> ---
>   www/manager6/Utils.js | 54 +++++++++++++++++++++++++++++++++++----------------
>   1 file changed, 37 insertions(+), 17 deletions(-)
> 
> diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
> index 0b850977..7560ff29 100644
> --- a/www/manager6/Utils.js
> +++ b/www/manager6/Utils.js
> @@ -58,16 +58,24 @@ Ext.define('PVE.Utils', { utilities: {
>       noSubKeyHtml: 'You do not have a valid subscription for this server. Please visit <a target="_blank" href="http://www.proxmox.com/products/proxmox-ve/subscription-service-plans">www.proxmox.com</a> to get a list of available options.',
>   
>       kvm_ostypes: {
> -	other: gettext('Other OS types'),
> -	wxp: 'Microsoft Windows XP/2003',
> -	w2k: 'Microsoft Windows 2000',
> -	w2k8: 'Microsoft Windows Vista/2008',
> -	win7: 'Microsoft Windows 7/2008r2',
> -	win8: 'Microsoft Windows 8.x/2012/2012r2',
> -	win10: 'Microsoft Windows 10/2016',
> -	l24: 'Linux 2.4 Kernel',
> -	l26: 'Linux 4.X/3.X/2.6 Kernel',
> -	solaris: 'Solaris Kernel'
> +	'Linux': [
> +	    { desc: '4.X/3.X/2.6 Kernel', val: 'l26' },
> +	    { desc: '2.4 Kernel', val: 'l24' }
> +	],
> +	'Microsoft Windows': [
> +	    { desc: '10/2016', val: 'win10' },
> +	    { desc: '8.x/2012/2012r2', val: 'win8' },
> +	    { desc: '7/2008r2', val: 'win7' },
> +	    { desc: 'Vista/2008', val: 'w2k8' },
> +	    { desc: 'XP/2003', val: 'wxp' },
> +	    { desc: '2000', val: 'w2k' }
> +	],
> +	'Solaris Kernel': [
> +	    { desc: '-', val: 'solaris'}
> +	],
> +	'Other': [
> +	    { desc: '-', val: 'other'}
> +	]
>       },
>   
>       get_health_icon: function(state, circle) {
> @@ -124,15 +132,27 @@ Ext.define('PVE.Utils', { utilities: {
>   	return state;
>       },
>   
> -    render_kvm_ostype: function (value) {
> -	if (!value) {
> -	    return gettext('Other OS types');
> +    get_kvm_osinfo: function(value) {
> +	var info = { base: 'Other' }; // default
> +	if (value) {
> +	    Ext.each(Object.keys(PVE.Utils.kvm_ostypes), function(k) {
> +		Ext.each(PVE.Utils.kvm_ostypes[k], function(e) {
> +		    if (e.val === value) {
> +			info = { desc: e.desc, base: k };
> +		    }

here you could do a return false; to cancel the loop when you found the 
value
you could also do this with the outer loop, but this would involve 
checking if you already found your value, which is maybe not that of an 
optimization

but then again my whole comment is not much of an optimization when
going through a list with 4 elements :P

i am not opposed to use it as it is, because it will not be slow
and it is still readable

> +		});
> +	    });
>   	}
> -	var text = PVE.Utils.kvm_ostypes[value];
> -	if (text) {
> -	    return text;
> +	return info;
> +    },
> +
> +    render_kvm_ostype: function (value) {
> +	var osinfo = PVE.Utils.get_kvm_osinfo(value);
> +	if (osinfo.desc && osinfo.desc !== '-') {
> +	    return osinfo.base + ' ' + osinfo.desc;
> +	} else {
> +	    return osinfo.base;
>   	}
> -	return value;
>       },
>   
>       render_hotplug_features: function (value) {
> 




More information about the pve-devel mailing list