TableView: comment properly

This commit is contained in:
Starbeamrainbowlabs 2022-03-11 01:48:58 +00:00
parent 00722e6b76
commit 33e247f1c1
Signed by: sbrl
GPG key ID: 1BE5172E637709C2

View file

@ -4,6 +4,7 @@ import Emel from 'emel';
import fa_emel from './forkawesome_emel.mjs';
import ui_item_index from './ui_item_index.mjs';
import tabledefs from '../tabledefs/index.mjs';
class TableView {
constructor(el) {
@ -13,12 +14,22 @@ class TableView {
this.emel = new Emel().emel;
}
/**
* Clears the currently displayed table.
* @return {void}
*/
clear() {
this.el_parts.clear();
// No need to call this here, as evereything gets replaced instantly at the end of init()
// No need to call this here, as everything gets replaced instantly at the end of init()
// this.el.replaceChildren();
}
/**
* Initialises the view to display a new table.
* You probably want to call .switch_table() instead.
* @param {Object} tabledef The table definition to use to render the display for the new table.
* @return {void}
*/
init(tabledef) {
this.clear();
const parts = this.emel(`h2>(${fa_emel(tabledef.icon)}+{?})^div.data-display`, {
@ -44,14 +55,29 @@ class TableView {
this.el.replaceChildren(parts);
}
/**
* Switches the view to display a new table.
* Fetches table data from the server, so this may take a moment.
* @param {string} table_name The name of the new table to display.
* @return {Promise} A Promise that resolves when the updating of the UI is complete.
*/
async switch_table(table_name) {
table_name = table_name.replace(/[^a-z0-9-_]/g, "");
this.clear();
if(typeof tabledefs[table_name] === "undefined")
throw new Error(`Error: No definition found for table with the name '${table_name}' (in future, we should render thee raw JSON with a header containing the table name or something).`);
this.init(tabledefs[table_name]);
for await (let tabledef of await globalThis.sysquery.table(table_name)) {
this.append_table(tabledef.peer, tabledef.table);
}
}
/**
* Appends the given peer and table data to the UI.
* @param {{id: string, name: string}} peer The peer information.
* @param {Object} table The table itself to display.
* @return {void}
*/
append_table(peer, table) {
for(let [ def_name, item_manager ] of this.el_parts) {
if(item_manager === null) continue;