mirror of
https://git.proxmox.com/git/pve-manager
synced 2025-07-26 13:21:36 +00:00
simplify code, improve sort order
This commit is contained in:
parent
31345b9c28
commit
f6735a886a
@ -35,29 +35,24 @@ Ext.define('PVE.form.ControllerSelector', {
|
|||||||
if (property.match(PVE.Utils.bus_match) && !vmconfig[property].match(/media=cdrom/)) {
|
if (property.match(PVE.Utils.bus_match) && !vmconfig[property].match(/media=cdrom/)) {
|
||||||
var foundController = property.match(PVE.Utils.bus_match)[1];
|
var foundController = property.match(PVE.Utils.bus_match)[1];
|
||||||
usedControllers[foundController]++;
|
usedControllers[foundController]++;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var arrayControllers = [
|
// TODO: add to OSDefaults.js?
|
||||||
{name:'ide', count:usedControllers.ide},
|
var sortPriority = (vmconfig.ostype && vmconfig.ostype == "l26") ?
|
||||||
{name:'sata', count:usedControllers.sata},
|
{ scsi: 4 , virtio: 3, sata: 2, ide: 1 } :
|
||||||
{name:'virtio', count:usedControllers.virtio},
|
{ ide: 4, sata: 3, scsi: 2, virtio: 1 };
|
||||||
{name:'scsi', count:usedControllers.scsi}
|
|
||||||
].sort(function compare(a, b){
|
var sortedList = Ext.clone(controllerList);
|
||||||
return b.count - a.count;
|
sortedList.sort(function(a,b) {
|
||||||
|
if (usedControllers[b] == usedControllers[a]) {
|
||||||
|
return sortPriority[b] - sortPriority[a];
|
||||||
|
}
|
||||||
|
return usedControllers[b] - usedControllers[a];
|
||||||
});
|
});
|
||||||
|
|
||||||
if (arrayControllers[0].count > arrayControllers[1].count ) {
|
return sortedList;
|
||||||
// we have a favourite !
|
|
||||||
var favourite = arrayControllers[0].name;
|
|
||||||
sortedList = Ext.Array.remove(controllerList, favourite);
|
|
||||||
sortedList.unshift(favourite);
|
|
||||||
return sortedList;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return controllerList;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setVMConfig: function(vmconfig, autoSelect) {
|
setVMConfig: function(vmconfig, autoSelect) {
|
||||||
|
Loading…
Reference in New Issue
Block a user