ProxmoxAAS-Dashboard/scripts/resources.js
Arthur Lu 81e4832fa2 add basic resource viewing
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
2023-04-03 21:57:03 +00:00

30 lines
750 B
JavaScript

import {requestPVE, requestAPI} from "./utils.js";
window.addEventListener("DOMContentLoaded", init);
async function init () {
let resources = await requestAPI("/user/resources");
document.querySelector("main").innerHTML = buildTable(resources.resources, 1);
}
function buildTable (object, idx) {
if (object instanceof Object) {
let table = "";
if (idx === 1) { // topmost table gets some margin and a border
table += `<table style="margin-top: 10px; border: 1px solid black;">`;
}
else {
table += `<table>`;
}
Object.keys(object).forEach((element) => {
table += `<tr><td>${element}</td><td>${buildTable(object[element], idx + 1)}</td></tr>`;
});
table += "</table>"
return table;
}
else {
return object;
}
}