update client user resource data format
This commit is contained in:
parent
4f6dc18162
commit
ea8d2e5b8c
11
account.html
11
account.html
@ -13,16 +13,15 @@
|
|||||||
<style>
|
<style>
|
||||||
@media screen and (width >= 1264px){
|
@media screen and (width >= 1264px){
|
||||||
#resource-container {
|
#resource-container {
|
||||||
display: flex;
|
display: grid;
|
||||||
flex-direction: row;
|
grid-template-columns: repeat(auto-fill, calc(100% / 6));
|
||||||
gap: 0px;
|
grid-gap: 0px;
|
||||||
flex-wrap: nowrap;
|
justify-content: space-between;
|
||||||
justify-content: left;
|
|
||||||
}
|
}
|
||||||
#resource-container > * {
|
#resource-container > * {
|
||||||
position: relative;
|
position: relative;
|
||||||
min-width: 200px;
|
min-width: 200px;
|
||||||
width: 100%;
|
max-width: 400px;
|
||||||
aspect-ratio: 1 / 1;
|
aspect-ratio: 1 / 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,24 +26,29 @@ async function init () {
|
|||||||
goToPage("login.html");
|
goToPage("login.html");
|
||||||
}
|
}
|
||||||
const resources = await requestAPI("/user/dynamic/resources");
|
const resources = await requestAPI("/user/dynamic/resources");
|
||||||
|
const meta = await requestAPI("/global/config/resources");
|
||||||
const instances = await requestAPI("/user/config/cluster");
|
const instances = await requestAPI("/user/config/cluster");
|
||||||
const nodes = await requestAPI("/user/config/nodes");
|
const nodes = await requestAPI("/user/config/nodes");
|
||||||
document.querySelector("#username").innerText = `Username: ${getCookie("username")}`;
|
document.querySelector("#username").innerText = `Username: ${getCookie("username")}`;
|
||||||
document.querySelector("#pool").innerText = `Pool: ${instances.pool}`;
|
document.querySelector("#pool").innerText = `Pool: ${instances.pool}`;
|
||||||
document.querySelector("#vmid").innerText = `VMID Range: ${instances.vmid.min} - ${instances.vmid.max}`;
|
document.querySelector("#vmid").innerText = `VMID Range: ${instances.vmid.min} - ${instances.vmid.max}`;
|
||||||
document.querySelector("#nodes").innerText = `Nodes: ${nodes.toString()}`;
|
document.querySelector("#nodes").innerText = `Nodes: ${nodes.toString()}`;
|
||||||
buildResourceTable("#resource-container", resources);
|
populateResources("#resource-container", meta, resources);
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildResourceTable (containerID, resources) {
|
function populateResources (containerID, meta, resources) {
|
||||||
if (resources instanceof Object) {
|
if (resources instanceof Object) {
|
||||||
const container = document.querySelector(containerID);
|
const container = document.querySelector(containerID);
|
||||||
Object.keys(resources.resources).forEach((element) => {
|
Object.keys(meta).forEach((resourceType) => {
|
||||||
if (resources.resources[element].display) {
|
if (meta[resourceType].display) {
|
||||||
if (resources.resources[element].type === "list") {
|
if (meta[resourceType].type === "list") {
|
||||||
|
resources[resourceType].forEach((listResource) => {
|
||||||
|
const chart = createResourceUsageChart(listResource.name, listResource.avail, listResource.used, listResource.max, null);
|
||||||
|
container.append(chart);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const chart = createResourceUsageChart(resources.resources[element].title, resources.avail[element], resources.used[element], resources.max[element], resources.resources[element]);
|
const chart = createResourceUsageChart(meta[resourceType].name, resources[resourceType].avail, resources[resourceType].used, resources[resourceType].max, meta[resourceType]);
|
||||||
container.append(chart);
|
container.append(chart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,6 +104,9 @@ function createResourceUsageChart (resourceName, resourceAvail, resourceUsed, re
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseNumber (value, unitData) {
|
function parseNumber (value, unitData) {
|
||||||
|
if (!unitData) {
|
||||||
|
return `${value}`;
|
||||||
|
}
|
||||||
const compact = unitData.compact;
|
const compact = unitData.compact;
|
||||||
const multiplier = unitData.multiplier;
|
const multiplier = unitData.multiplier;
|
||||||
const base = unitData.base;
|
const base = unitData.base;
|
||||||
|
@ -55,22 +55,23 @@ async function populateResources () {
|
|||||||
const user = await requestAPI("/user/config/resources");
|
const user = await requestAPI("/user/config/resources");
|
||||||
let options = [];
|
let options = [];
|
||||||
if (global.cpu.whitelist) {
|
if (global.cpu.whitelist) {
|
||||||
options = user.max.cpu.sort((a, b) => {
|
user.cpu.forEach((userType) => {
|
||||||
|
options.push(userType.name);
|
||||||
|
});
|
||||||
|
options = options.sort((a, b) => {
|
||||||
return a.localeCompare(b);
|
return a.localeCompare(b);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const supported = await requestPVE(`/nodes/${node}/capabilities/qemu/cpu`);
|
const supported = await requestPVE(`/nodes/${node}/capabilities/qemu/cpu`);
|
||||||
supported.data.forEach((element) => {
|
supported.data.forEach((supportedType) => {
|
||||||
if (!user.max.cpu.includes(element.name)) {
|
if (!user.cpu.some((userType) => supportedType.name === userType.name)) {
|
||||||
options.push(element.name);
|
options.push(supportedType.name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
options = options.sort((a, b) => {
|
options = options.sort((a, b) => {
|
||||||
return a.localeCompare(b);
|
return a.localeCompare(b);
|
||||||
});
|
});
|
||||||
console.log(options);
|
|
||||||
console.log("blacklist not yet supported");
|
|
||||||
}
|
}
|
||||||
addResourceLine("resources", "images/resources/cpu.svg", "select", "CPU Type", "proctype", { value: config.data.cpu, options });
|
addResourceLine("resources", "images/resources/cpu.svg", "select", "CPU Type", "proctype", { value: config.data.cpu, options });
|
||||||
}
|
}
|
||||||
|
@ -192,8 +192,8 @@ async function handleInstanceAdd () {
|
|||||||
|
|
||||||
const userResources = await requestAPI("/user/dynamic/resources", "GET");
|
const userResources = await requestAPI("/user/dynamic/resources", "GET");
|
||||||
const userCluster = await requestAPI("/user/config/cluster", "GET");
|
const userCluster = await requestAPI("/user/config/cluster", "GET");
|
||||||
d.querySelector("#cores").max = userResources.avail.cores;
|
d.querySelector("#cores").max = userResources.cores.avail;
|
||||||
d.querySelector("#memory").max = userResources.avail.memory;
|
d.querySelector("#memory").max = userResources.memory.avail;
|
||||||
d.querySelector("#vmid").min = userCluster.vmid.min;
|
d.querySelector("#vmid").min = userCluster.vmid.min;
|
||||||
d.querySelector("#vmid").max = userCluster.vmid.max;
|
d.querySelector("#vmid").max = userCluster.vmid.max;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ function init () {
|
|||||||
function handleSaveSettings (event) {
|
function handleSaveSettings (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const form = new FormData(document.querySelector("#settings"));
|
const form = new FormData(document.querySelector("#settings"));
|
||||||
console.log(form.get("sync-scheme"));
|
|
||||||
localStorage.setItem("sync-scheme", form.get("sync-scheme"));
|
localStorage.setItem("sync-scheme", form.get("sync-scheme"));
|
||||||
localStorage.setItem("sync-rate", form.get("sync-rate"));
|
localStorage.setItem("sync-rate", form.get("sync-rate"));
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
|
Loading…
Reference in New Issue
Block a user