diff --git a/config.html b/config.html index a3fdf28..5fe9909 100644 --- a/config.html +++ b/config.html @@ -17,7 +17,11 @@
Resources -
+
+
+
+ Disks +
diff --git a/scripts/config.js b/scripts/config.js index 2ed78f3..39274e6 100644 --- a/scripts/config.js +++ b/scripts/config.js @@ -25,43 +25,28 @@ async function populateForm (node, type, vmid) { console.log(config); let name = type === "qemu" ? "name" : "hostname"; - addFormLine("name", null, "Name", {type: "text", value: config.data[name]}); - addFormLine("resources", "images/resources/cpu.svg", "Cores", {type: "number", value: config.data.cores, min: 1, max: 8192}, "Threads"); - addFormLine("resources", "images/resources/ram.svg", "Memory", {type: "number", value: config.data.memory / 1024, min: 0, step: 0.001}, "GiB"); + addResourceLine("name", null, "Name", {type: "text", value: config.data[name]}); + addResourceLine("resources", "images/resources/cpu.svg", "Cores", {type: "number", value: config.data.cores, min: 1, max: 8192}, "Threads"); // TODO add max from quota API + addResourceLine("resources", "images/resources/ram.svg", "Memory", {type: "number", value: config.data, min: 16, step: 1}, "MiB"); // TODO add max from quota API if (type === "lxc") { - addFormLine("resources", "images/resources/swap.svg", "Swap", {type: "number", value: config.data.swap / 1024, min: 0, step: 0.001}, "GiB"); + addResourceLine("resources", "images/resources/swap.svg", "Swap", {type: "number", value: config.data.swap, min: 0, step: 1}, "GiB"); // TODO add max from quota API + addDiskLine("disks", "images/resources/disk.svg", "Root FS", config.data.rootfs); } - - if (type === "qemu") { + else { // qemu let i = 0; while(Object.hasOwn(config.data, `sata${i}`)){ - let sata = config.data[`sata${i}`]; - sata = `{"${sata.replaceAll(":", '":"').replaceAll("=", '":"').replaceAll(",", '","')}"}`; - sata = JSON.parse(sata); - let sizeNum = +(sata.size.replaceAll("G", "").replaceAll("M", "")); - let sizeUnit = sata.size.includes("G") ? "GiB" : "MiB"; - addFormLine("resources", "images/resources/disk.svg", `SATA ${i}`, {type: "number", value: sizeUnit === "GiB" ? sizeNum.toFixed(3) : (sizeNum / 1024).toFixed(3), min: 0, step: 0.001}, "GiB"); + addDiskLine("disks", "images/resources/disk.svg", `SATA ${i}`, config.data[`sata${i}`]); i++; } } - else { - let rootfs = config.data.rootfs; - rootfs = `{"${rootfs.replaceAll(":", '":"').replaceAll("=", '":"').replaceAll(",", '","')}"}`; - rootfs = JSON.parse(rootfs); - let sizeNum = +(rootfs.size.replaceAll("G", "").replaceAll("M", "")); - let sizeUnit = rootfs.size.includes("G") ? "GiB" : "MiB"; - addFormLine("resources", "images/resources/disk.svg", "Root FS", {type: "number", value: sizeUnit === "GiB" ? sizeNum.toFixed(3) : (sizeNum / 1024).toFixed(3), min: 0, step: 0.001}, "GiB"); - } } -function addFormLine (fieldset, iconHref, labelText, inputAttr, unitText=null) { +function addResourceLine (fieldset, iconHref, labelText, inputAttr, unitText=null) { let field = document.querySelector(`#${fieldset}`); - if (iconHref) { - let icon = document.createElement("img"); - icon.src = iconHref; - field.append(icon); - } + let icon = document.createElement("img"); + icon.src = iconHref; + field.append(icon); let label = document.createElement("label"); label.innerHTML = labelText; @@ -78,4 +63,20 @@ function addFormLine (fieldset, iconHref, labelText, inputAttr, unitText=null) { unit.innerText = unitText; field.append(unit); } +} + +function addDiskLine (fieldset, id, iconHref, label, value) { + let field = document.querySelector(`#${fieldset}`); + + let icon = document.createElement("img"); + icon.src = iconHref; + field.append(icon); + + let label = document.createElement("label"); + label.innerHTML = labelText; + field.append(label); + + let value = document.createElement("p"); + value.innerText = value; + field.append(value); } \ No newline at end of file