From ff31563f882ac7429221cb9808727d169972c61e Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Mon, 9 Jan 2023 23:50:11 -0800 Subject: [PATCH] sort disks in numerical order --- scripts/config.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/scripts/config.js b/scripts/config.js index 7b02c4f..783f4b8 100644 --- a/scripts/config.js +++ b/scripts/config.js @@ -18,6 +18,11 @@ async function init () { cancelButton.addEventListener("click", () => { 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) { @@ -41,21 +46,19 @@ async function populateForm (node, type, vmid) { diskTypes = ["IDE", "SATA"]; } - for(let j = 0; j < diskPrefixes.length; j++){ - let prefix = diskPrefixes[j]; - let type = diskTypes[j]; - + for(let i = 0; i < diskPrefixes.length; i++){ + let prefix = diskPrefixes[i]; + let type = diskTypes[i]; + let disks = {}; Object.keys(config.data).forEach(element => { 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 i = 0; - while(Object.hasOwn(config.data, `${prefix}${i}`)){ - - i++; - } + }); + let ordered_keys = Object.keys(disks).sort((a,b) => {parseInt(a) - parseInt(b)}); // ordered integer list + ordered_keys.forEach(element => { + addDiskLine("disks", `${prefix}${element}`, disks[element].includes("media=cdrom") ? "images/resources/disk.svg" : "images/resources/drive.svg", `${type} ${element}`, disks[element]); + }); } }