[pve-devel] [PATCH manager 7/7] ui: MachineEdit: add option for machine version pinning

Stefan Reiter s.reiter at proxmox.com
Thu Mar 4 13:52:09 CET 2021


Hidden behind "Advanced" options, as to not confuse inexperienced users.

Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---
 www/manager6/qemu/MachineEdit.js | 69 ++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/www/manager6/qemu/MachineEdit.js b/www/manager6/qemu/MachineEdit.js
index 8a3a6f7a..4eab6b8f 100644
--- a/www/manager6/qemu/MachineEdit.js
+++ b/www/manager6/qemu/MachineEdit.js
@@ -2,8 +2,51 @@ Ext.define('PVE.qemu.MachineInputPanel', {
     extend: 'Proxmox.panel.InputPanel',
     xtype: 'pveMachineInputPanel',
 
+    controller: {
+	xclass: 'Ext.app.ViewController',
+	control: {
+	    'combobox[name=machine]': {
+		change: 'onMachineChange',
+	    },
+	},
+	onMachineChange: function(field, value) {
+	    let me = this;
+	    let version = me.lookup('version');
+	    let store = version.getStore();
+	    let type = value === 'q35' ? 'q35' : 'i440fx';
+	    store.clearFilter();
+	    store.addFilter(val =>
+		(val.data.name === 'latest' || val.data.name.indexOf(type) !== -1));
+	    version.setValue('latest');
+	},
+    },
+
+    onGetValues: function(values) {
+	if (values.version && values.version !== 'latest') {
+	    values.machine = values.version;
+	    delete values.delete;
+	}
+	delete values.version;
+	return values;
+    },
+
+    setValues: function(values) {
+	let me = this;
+
+	if (values.machine !== '__default__' && values.machine !== 'q35') {
+	    values.version = values.machine;
+	    values.machine = values.version.match(/q35/) ? 'q35' : '__default__';
+
+	    // avoid hiding a pinned version
+	    Ext.ComponentQuery.query("#advancedcb")[0].setValue(true);
+	}
+
+	this.callParent(arguments);
+    },
+
     items: [{
 	name: 'machine',
+	reference: 'machine',
 	xtype: 'proxmoxKVComboBox',
 	fieldLabel: gettext('Machine'),
 	comboItems: [
@@ -11,6 +54,32 @@ Ext.define('PVE.qemu.MachineInputPanel', {
 	    ['q35', 'q35'],
 	],
     }],
+
+    advancedItems: [{
+	name: 'version',
+	reference: 'version',
+	xtype: 'combobox',
+	fieldLabel: gettext('Version'),
+	value: 'latest',
+	allowBlank: false,
+	editable: false,
+	valueField: 'name',
+	displayField: 'name',
+	queryParam: false,
+	store: {
+	    autoLoad: true,
+	    fields: ['name'],
+	    proxy: {
+		type: 'proxmox',
+		url: "/api2/json/nodes/localhost/machine-types",
+	    },
+	    listeners: {
+		load: function(records) {
+		    this.insert(0, { name: 'latest' });
+		},
+	    },
+	},
+    }],
 });
 
 Ext.define('PVE.qemu.MachineEdit', {
-- 
2.20.1






More information about the pve-devel mailing list