From 405df9acfcab870b2b190b643e514daf17e5d00d Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sat, 26 Feb 2022 21:58:51 +0000 Subject: [PATCH] client: create TableView scaffolding for updating the UI --- src/static/app.mjs | 11 ++++++++++- src/static/js/TableView.mjs | 27 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/static/js/TableView.mjs diff --git a/src/static/app.mjs b/src/static/app.mjs index 358a66e..bfe4032 100644 --- a/src/static/app.mjs +++ b/src/static/app.mjs @@ -1,11 +1,20 @@ +"use strict"; + import SystemQueryClient from './js/SystemQueryClient.mjs'; import make_router from './js/routes_client.mjs'; +import TableView from './js/TableView.mjs'; + window.addEventListener("load", async (_event) => { + const el_version = document.querySelector(".version"); + const el_table = document.querySelector("main"); + globalThis.sysquery = new SystemQueryClient(); globalThis.sysquery_router = make_router(); + globalThis.sysui = { + tableview: new TableView(el_table) + } - const el_version = document.querySelector(".version"); const status = await globalThis.sysquery.status(); diff --git a/src/static/js/TableView.mjs b/src/static/js/TableView.mjs new file mode 100644 index 0000000..250ba97 --- /dev/null +++ b/src/static/js/TableView.mjs @@ -0,0 +1,27 @@ +"use strict"; + +class TableView { + constructor(el) { + if(this.el === null || typeof this.el === "undefined") throw new Error(`Expected HTML element as the first argument, but got null or undefined.`); + this.el = el; + this.el_parts = new Map(); + } + + clear() { + this.el.replaceChildren(); + this.el_parts.clear(); + } + + async switch_table(table_name) { + this.clear(); + for await (let tabledef of await globalThis.sysquery.table(table_name)) { + this.append_table(tabledef.peer, tabledef.table); + } + } + + append_table(peer, table) { + + } +} + +export default TableView;