add processor type to config

This commit is contained in:
Arthur Lu 2023-06-14 01:13:06 +00:00
parent 7c1c3fbb8b
commit 8fdd970a44

View File

@ -46,15 +46,17 @@ async function getConfig() {
function populateResources() { function populateResources() {
let name = type === "qemu" ? "name" : "hostname"; let name = type === "qemu" ? "name" : "hostname";
document.querySelector("#name").innerHTML = document.querySelector("#name").innerHTML.replace("%{vmname}", config.data[name]); document.querySelector("#name").innerHTML = document.querySelector("#name").innerHTML.replace("%{vmname}", config.data[name]);
addResourceLine("resources", "images/resources/cpu.svg", "Cores", { type: "number", value: config.data.cores, min: 1, max: 8192 }, "Threads"); if (type === "qemu") {
addResourceLine("resources", "images/resources/ram.svg", "Memory", { type: "number", value: config.data.memory, min: 16, step: 1 }, "MiB"); addResourceLine("resources", "images/resources/cpu.svg", "select", "Processors Type", "proctype", { value: config.data.cpu, options: ["host", "kvm64"] });
}
addResourceLine("resources", "images/resources/cpu.svg", "input", "Processors Amount", "cores", { type: "number", value: config.data.cores, min: 1, max: 8192 }, "Cores");
addResourceLine("resources", "images/resources/ram.svg", "input", "Memory", "ram", { type: "number", value: config.data.memory, min: 16, step: 1 }, "MiB");
if (type === "lxc") { if (type === "lxc") {
addResourceLine("resources", "images/resources/swap.svg", "Swap", { type: "number", value: config.data.swap, min: 0, step: 1 }, "MiB"); addResourceLine("resources", "images/resources/swap.svg", "Swap", "swap", { type: "number", value: config.data.swap, min: 0, step: 1 }, "MiB");
} }
} }
function addResourceLine(fieldset, iconHref, labelText, inputAttr, unitText = null) { function addResourceLine(fieldset, iconHref, type, labelText, id, attributes, unitText = null) {
let field = document.querySelector(`#${fieldset}`); let field = document.querySelector(`#${fieldset}`);
let icon = document.createElement("img"); let icon = document.createElement("img");
@ -67,22 +69,42 @@ function addResourceLine(fieldset, iconHref, labelText, inputAttr, unitText = nu
label.htmlFor = labelText; label.htmlFor = labelText;
field.append(label); field.append(label);
if (type === "input") {
let input = document.createElement("input"); let input = document.createElement("input");
for (let k in inputAttr) { for (let k in attributes) {
input.setAttribute(k, inputAttr[k]) input.setAttribute(k, attributes[k])
} }
input.id = labelText; input.id = id;
input.name = labelText; input.name = id;
input.required = true; input.required = true;
input.classList.add("w3-input"); input.classList.add("w3-input");
input.classList.add("w3-border"); input.classList.add("w3-border");
field.append(input); field.append(input);
}
else if (type === "select") {
let select = document.createElement("select");
select.value = attributes.value;
for (let option of attributes.options) {
select.append(new Option(option));
}
select.id = id;
select.name = id;
select.required = true;
select.classList.add("w3-select");
select.classList.add("w3-border");
field.append(select);
}
if (unitText) { if (unitText) {
let unit = document.createElement("p"); let unit = document.createElement("p");
unit.innerText = unitText; unit.innerText = unitText;
field.append(unit); field.append(unit);
} }
else {
let unit = document.createElement("div");
unit.classList.add("hidden");
field.append(unit);
}
} }
function populateDisk() { function populateDisk() {
@ -666,8 +688,9 @@ async function handleFormExit() {
node: node, node: node,
type: type, type: type,
vmid: vmid, vmid: vmid,
cores: document.querySelector("#Cores").value, proctype: document.querySelector("#proctype").value,
memory: document.querySelector("#Memory").value cores: document.querySelector("#cores").value,
memory: document.querySelector("#ram").value
} }
if (type === "lxc") { if (type === "lxc") {
body.swap = document.querySelector("#Swap").value; body.swap = document.querySelector("#Swap").value;