From 0f29d3b40ee3b9118a05ee7234c36b7d2628be2d Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Wed, 14 Jun 2023 04:56:49 +0000 Subject: [PATCH] fix proc type selector issue in config, update account resource table with new API format --- scripts/account.js | 22 ++++++++++++---------- scripts/config.js | 10 ++++++---- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/scripts/account.js b/scripts/account.js index 44ce422..3c5f2b1 100644 --- a/scripts/account.js +++ b/scripts/account.js @@ -40,16 +40,18 @@ function buildResourceTable(resources, tableid) { if (resources instanceof Object) { let table = document.querySelector(tableid); let tbody = table.querySelector("tbody"); - Object.keys(resources.avail).forEach((element) => { - let row = tbody.insertRow(); - let key = row.insertCell(); - key.innerText = `${element}`; - let used = row.insertCell(); - used.innerText = `${parseNumber(resources.used[element], resources.units[element])}`; - let val = row.insertCell(); - val.innerText = `${parseNumber(resources.avail[element], resources.units[element])}`; - let total = row.insertCell(); - total.innerText = `${parseNumber(resources.max[element], resources.units[element])}`; + Object.keys(resources.resources).forEach((element) => { + if (resources.resources[element].display) { + let row = tbody.insertRow(); + let key = row.insertCell(); + key.innerText = `${element}`; + let used = row.insertCell(); + used.innerText = `${parseNumber(resources.used[element], resources.resources[element])}`; + let val = row.insertCell(); + val.innerText = `${parseNumber(resources.avail[element], resources.resources[element])}`; + let total = row.insertCell(); + total.innerText = `${parseNumber(resources.max[element], resources.resources[element])}`; + } }); } } diff --git a/scripts/config.js b/scripts/config.js index 90fd57f..5a7f65c 100644 --- a/scripts/config.js +++ b/scripts/config.js @@ -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/ram.svg", "input", "Memory", "ram", { type: "number", value: config.data.memory, min: 16, step: 1 }, "MiB"); 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") { let select = document.createElement("select"); - select.value = attributes.value; for (let option of attributes.options) { select.append(new Option(option)); } + select.value = attributes.value; select.id = id; select.name = id; select.required = true; @@ -688,12 +688,14 @@ async function handleFormExit() { node: node, type: type, vmid: vmid, - proctype: document.querySelector("#proctype").value, cores: document.querySelector("#cores").value, memory: document.querySelector("#ram").value } 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); if (result.status === 200) {