fix proc type selector issue in config,

update account resource table with new API format
This commit is contained in:
Arthur Lu 2023-06-14 04:56:49 +00:00
parent 8fdd970a44
commit 0bb82dc81a
2 changed files with 18 additions and 14 deletions

View File

@ -40,16 +40,18 @@ function buildResourceTable(resources, tableid) {
if (resources instanceof Object) { if (resources instanceof Object) {
let table = document.querySelector(tableid); let table = document.querySelector(tableid);
let tbody = table.querySelector("tbody"); let tbody = table.querySelector("tbody");
Object.keys(resources.avail).forEach((element) => { Object.keys(resources.resources).forEach((element) => {
if (resources.resources[element].display) {
let row = tbody.insertRow(); let row = tbody.insertRow();
let key = row.insertCell(); let key = row.insertCell();
key.innerText = `${element}`; key.innerText = `${element}`;
let used = row.insertCell(); let used = row.insertCell();
used.innerText = `${parseNumber(resources.used[element], resources.units[element])}`; used.innerText = `${parseNumber(resources.used[element], resources.resources[element])}`;
let val = row.insertCell(); let val = row.insertCell();
val.innerText = `${parseNumber(resources.avail[element], resources.units[element])}`; val.innerText = `${parseNumber(resources.avail[element], resources.resources[element])}`;
let total = row.insertCell(); let total = row.insertCell();
total.innerText = `${parseNumber(resources.max[element], resources.units[element])}`; total.innerText = `${parseNumber(resources.max[element], resources.resources[element])}`;
}
}); });
} }
} }

View File

@ -52,7 +52,7 @@ function populateResources() {
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/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"); 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", "swap", { type: "number", value: config.data.swap, min: 0, step: 1 }, "MiB"); addResourceLine("resources", "images/resources/swap.svg", "input", "Swap", "swap", { type: "number", value: config.data.swap, min: 0, step: 1 }, "MiB");
} }
} }
@ -83,10 +83,10 @@ function addResourceLine(fieldset, iconHref, type, labelText, id, attributes, un
} }
else if (type === "select") { else if (type === "select") {
let select = document.createElement("select"); let select = document.createElement("select");
select.value = attributes.value;
for (let option of attributes.options) { for (let option of attributes.options) {
select.append(new Option(option)); select.append(new Option(option));
} }
select.value = attributes.value;
select.id = id; select.id = id;
select.name = id; select.name = id;
select.required = true; select.required = true;
@ -688,12 +688,14 @@ async function handleFormExit() {
node: node, node: node,
type: type, type: type,
vmid: vmid, vmid: vmid,
proctype: document.querySelector("#proctype").value,
cores: document.querySelector("#cores").value, cores: document.querySelector("#cores").value,
memory: document.querySelector("#ram").value memory: document.querySelector("#ram").value
} }
if (type === "lxc") { if (type === "lxc") {
body.swap = document.querySelector("#Swap").value; body.swap = document.querySelector("#swap").value;
}
else if (type === "qemu") {
body.proctype = document.querySelector("#proctype").value;
} }
let result = await requestAPI("/instance/resources", "POST", body); let result = await requestAPI("/instance/resources", "POST", body);
if (result.status === 200) { if (result.status === 200) {