add basic resource viewing
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
@@ -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
30
scripts/resources.js
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user