avoid refreshing page on disk change

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
Arthur Lu 2023-01-26 19:55:17 +00:00
parent 7b712ad80b
commit 8134925c03

View File

@ -20,7 +20,7 @@ async function init () {
type = uriData.type; type = uriData.type;
vmid = uriData.vmid; vmid = uriData.vmid;
config = await requestPVE(`/nodes/${node}/${type}/${vmid}/config`, "GET"); await getConfig();
populateResources(); populateResources();
populateDisk(); populateDisk();
@ -31,7 +31,11 @@ async function init () {
}); });
} }
async function populateResources () { async function getConfig () {
config = await requestPVE(`/nodes/${node}/${type}/${vmid}/config`, "GET");
}
function populateResources () {
let name = type === "qemu" ? "name" : "hostname"; let name = type === "qemu" ? "name" : "hostname";
document.querySelector("#name").innerText = config.data[name]; document.querySelector("#name").innerText = 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/cpu.svg", "Cores", {type: "number", value: config.data.cores, min: 1, max: 8192}, "Threads"); // TODO add max from quota API
@ -69,7 +73,7 @@ function addResourceLine (fieldset, iconHref, labelText, inputAttr, unitText=nul
} }
} }
async function populateDisk () { function populateDisk () {
document.querySelector("#disks").innerHTML = ""; document.querySelector("#disks").innerHTML = "";
for(let i = 0; i < diskMetaData[type].prefixOrder.length; i++){ for(let i = 0; i < diskMetaData[type].prefixOrder.length; i++){
let prefix = diskMetaData[type].prefixOrder[i]; let prefix = diskMetaData[type].prefixOrder[i];
@ -88,7 +92,7 @@ async function populateDisk () {
} }
} }
async function addDiskLine (fieldset, busPrefix, busName, device, disk) { function addDiskLine (fieldset, busPrefix, busName, device, disk) {
let field = document.querySelector(`#${fieldset}`); let field = document.querySelector(`#${fieldset}`);
// Set the disk icon, either drive.svg or disk.svg // Set the disk icon, either drive.svg or disk.svg
@ -146,7 +150,8 @@ async function handleDiskDetach () {
}; };
let result = await requestAPI("/disk/detach", "POST", body); let result = await requestAPI("/disk/detach", "POST", body);
if (result.status === 200) { if (result.status === 200) {
reload(); await getConfig();
populateDisk();
} }
else{ else{
console.error(result); console.error(result);