add basic resource viewing

Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
2023-04-03 21:57:03 +00:00
parent 33fe93089e
commit 8e60ece366
4 changed files with 55 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
import {requestPVE, requestAPI, goToPage, deleteAllCookies} from "./utils.js";
import {requestPVE, requestAPI, goToPage} from "./utils.js";
import { Dialog } from "./dialog.js";
window.addEventListener("DOMContentLoaded", init);

30
scripts/resources.js Normal file
View File

@@ -0,0 +1,30 @@
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;
}
}