mirror of
https://git.proxmox.com/git/pve-manager
synced 2025-06-05 14:50:02 +00:00
gui: qemu: HardwareView: improve button disable code
this improves following behaviours: * do not loop over items multiple times (we iterated one time extra for efidisk) * do not check every item for cloudinit (we even checked non-disk types) * make the counts more generic using an object * also disable cloudinit button when you have one pending * also disable serial/net button when at limit or the user has not the right priviliges Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
9d8553982d
commit
67847d54fa
@ -522,39 +522,48 @@ Ext.define('PVE.qemu.HardwareView', {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let counts = {};
|
||||||
|
let isAtLimit = (type) => (counts[type] >= PVE.Utils.hardware_counts[type]);
|
||||||
|
|
||||||
var set_button_status = function() {
|
var set_button_status = function() {
|
||||||
var sm = me.getSelectionModel();
|
var sm = me.getSelectionModel();
|
||||||
var rec = sm.getSelection()[0];
|
var rec = sm.getSelection()[0];
|
||||||
|
|
||||||
// disable button when we have an efidisk already
|
// en/disable hardwarebuttons
|
||||||
// disable is ok in this case, because you can instantly
|
counts = {};
|
||||||
// see that there is already one
|
|
||||||
efidisk_menuitem.setDisabled(me.rstore.getData().map.efidisk0 !== undefined);
|
|
||||||
// en/disable usb add button
|
|
||||||
var usbcount = 0;
|
|
||||||
var pcicount = 0;
|
|
||||||
var audiocount = 0;
|
|
||||||
var hasCloudInit = false;
|
var hasCloudInit = false;
|
||||||
me.rstore.getData().items.forEach(function(item){
|
me.rstore.getData().items.forEach(function(item){
|
||||||
if (/^usb\d+/.test(item.id)) {
|
if (!hasCloudInit && (
|
||||||
usbcount++;
|
/vm-.*-cloudinit/.test(item.data.value) ||
|
||||||
} else if (/^hostpci\d+/.test(item.id)) {
|
/vm-.*-cloudinit/.test(item.data.pending)
|
||||||
pcicount++;
|
)) {
|
||||||
} else if (/^audio\d+/.test(item.id)) {
|
|
||||||
audiocount++;
|
|
||||||
}
|
|
||||||
if (!hasCloudInit && /vm-.*-cloudinit/.test(item.data.value)) {
|
|
||||||
hasCloudInit = true;
|
hasCloudInit = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let match = item.id.match(/^([^\d]+)\d+$/);
|
||||||
|
let type;
|
||||||
|
if (match && PVE.Utils.hardware_counts[match[1]] !== undefined) {
|
||||||
|
type = match[1];
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
counts[type] = (counts[type] || 0) + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
// heuristic only for disabling some stuff, the backend has the final word.
|
// heuristic only for disabling some stuff, the backend has the final word.
|
||||||
var noSysConsolePerm = !caps.nodes['Sys.Console'];
|
var noSysConsolePerm = !caps.nodes['Sys.Console'];
|
||||||
var noVMConfigHWTypePerm = !caps.vms['VM.Config.HWType'];
|
var noVMConfigHWTypePerm = !caps.vms['VM.Config.HWType'];
|
||||||
|
var noVMConfigNetPerm = !caps.vms['VM.Config.Network'];
|
||||||
|
|
||||||
me.down('#addusb').setDisabled(noSysConsolePerm || (usbcount >= 5));
|
|
||||||
me.down('#addpci').setDisabled(noSysConsolePerm || (pcicount >= 4));
|
me.down('#addusb').setDisabled(noSysConsolePerm || isAtLimit('usb'));
|
||||||
me.down('#addaudio').setDisabled(noVMConfigHWTypePerm || (audiocount >= 1));
|
me.down('#addpci').setDisabled(noSysConsolePerm || isAtLimit('hostpci'));
|
||||||
|
me.down('#addaudio').setDisabled(noVMConfigHWTypePerm || isAtLimit('audio'));
|
||||||
|
me.down('#addserial').setDisabled(noVMConfigHWTypePerm || isAtLimit('serial'));
|
||||||
|
me.down('#addnet').setDisabled(noVMConfigNetPerm || isAtLimit('net'));
|
||||||
|
efidisk_menuitem.setDisabled(isAtLimit('efidisk'));
|
||||||
me.down('#addci').setDisabled(noSysConsolePerm || hasCloudInit);
|
me.down('#addci').setDisabled(noSysConsolePerm || hasCloudInit);
|
||||||
|
|
||||||
if (!rec) {
|
if (!rec) {
|
||||||
@ -630,6 +639,7 @@ Ext.define('PVE.qemu.HardwareView', {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: gettext('Network Device'),
|
text: gettext('Network Device'),
|
||||||
|
itemId: 'addnet',
|
||||||
iconCls: 'fa fa-fw fa-exchange black',
|
iconCls: 'fa fa-fw fa-exchange black',
|
||||||
disabled: !caps.vms['VM.Config.Network'],
|
disabled: !caps.vms['VM.Config.Network'],
|
||||||
handler: function() {
|
handler: function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user