sort disks in numerical order

This commit is contained in:
Arthur Lu 2023-01-09 23:50:11 -08:00
parent 473c13aa08
commit ff31563f88

View File

@ -18,6 +18,11 @@ async function init () {
cancelButton.addEventListener("click", () => { cancelButton.addEventListener("click", () => {
goToPage("index.html"); goToPage("index.html");
}); });
/**
* Add disk qemu: POST config with sata4:"cephpl:4"
* Add disk lxc POST config with mp2:"cephpl:8,mp=/test/,backup=1"
*/
} }
async function populateForm (node, type, vmid) { async function populateForm (node, type, vmid) {
@ -41,21 +46,19 @@ async function populateForm (node, type, vmid) {
diskTypes = ["IDE", "SATA"]; diskTypes = ["IDE", "SATA"];
} }
for(let j = 0; j < diskPrefixes.length; j++){ for(let i = 0; i < diskPrefixes.length; i++){
let prefix = diskPrefixes[j]; let prefix = diskPrefixes[i];
let type = diskTypes[j]; let type = diskTypes[i];
let disks = {};
Object.keys(config.data).forEach(element => { Object.keys(config.data).forEach(element => {
if (element.startsWith(prefix)) { if (element.startsWith(prefix)) {
addDiskLine("disks", element, config.data[element].includes("media=cdrom") ? "images/resources/disk.svg" : "images/resources/drive.svg", `${type} ${element.replace(prefix, "")}`, config.data[element]); element.replace(prefix, "") = config.data[element];
} }
}) });
let ordered_keys = Object.keys(disks).sort((a,b) => {parseInt(a) - parseInt(b)}); // ordered integer list
let i = 0; ordered_keys.forEach(element => {
while(Object.hasOwn(config.data, `${prefix}${i}`)){ addDiskLine("disks", `${prefix}${element}`, disks[element].includes("media=cdrom") ? "images/resources/disk.svg" : "images/resources/drive.svg", `${type} ${element}`, disks[element]);
});
i++;
}
} }
} }