add basic resource viewing

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

View File

@ -6,7 +6,6 @@
<title>tronnet - client</title> <title>tronnet - client</title>
<link rel="icon" href="images/favicon.svg" sizes="any" type="image/svg+xml"> <link rel="icon" href="images/favicon.svg" sizes="any" type="image/svg+xml">
<link rel="stylesheet" href="css/style.css" type="text/css"> <link rel="stylesheet" href="css/style.css" type="text/css">
<link rel="stylesheet" href="css/form.css" type="text/css">
<link rel="stylesheet" href="css/buttons.css" type="text/css"> <link rel="stylesheet" href="css/buttons.css" type="text/css">
<script src="scripts/index.js" type="module"></script> <script src="scripts/index.js" type="module"></script>
<script src="scripts/instance.js" type="module"></script> <script src="scripts/instance.js" type="module"></script>
@ -15,6 +14,7 @@
<header> <header>
<nav> <nav>
<a href="index.html" aria-current="true">INSTANCES</a> <a href="index.html" aria-current="true">INSTANCES</a>
<a href="resources.html">RESOURCES</a>
<a href="login.html">LOGOUT</a> <a href="login.html">LOGOUT</a>
</nav> </nav>
</header> </header>

23
resources.html Normal file
View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>tronnet - client</title>
<link rel="icon" href="images/favicon.svg" sizes="any" type="image/svg+xml">
<link rel="stylesheet" href="css/style.css" type="text/css">
<script src="scripts/resources.js" type="module"></script>
</head>
<body>
<header>
<nav>
<a href="index.html">INSTANCES</a>
<a href="resources.html" aria-current="true">RESOURCES</a>
<a href="login.html">LOGOUT</a>
</nav>
</header>
<main>
</main>
<footer><p>&copy; tronnet</p></footer>
</body>
</html>

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"; import { Dialog } from "./dialog.js";
window.addEventListener("DOMContentLoaded", init); 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;
}
}