populate disks in separate fieldset

This commit is contained in:
Arthur Lu 2023-01-08 20:26:20 -08:00
parent ae3d8c5cf1
commit e4c7f45e6c
2 changed files with 32 additions and 27 deletions

View File

@ -17,7 +17,11 @@
</fieldset>
<fieldset>
<legend>Resources</legend>
<div class="input-grid" id="resources" style="grid-template-columns: repeat(4, auto);"></div>
<div class="input-grid" id="resources" style="grid-template-columns: repeat(3, auto) 1fr;"></div>
</fieldset>
<fieldset>
<legend>Disks</legend>
<div class="input-grid" id="disks" style="grid-template-columns: repeat(2, auto) 1fr;"></div>
</fieldset>
<fieldset class="fieldset-no-border">
<div class="btn-group" id="form-actions">

View File

@ -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);
}