TableView: comment properly
This commit is contained in:
parent
00722e6b76
commit
33e247f1c1
1 changed files with 28 additions and 2 deletions
|
@ -4,6 +4,7 @@ import Emel from 'emel';
|
||||||
import fa_emel from './forkawesome_emel.mjs';
|
import fa_emel from './forkawesome_emel.mjs';
|
||||||
|
|
||||||
import ui_item_index from './ui_item_index.mjs';
|
import ui_item_index from './ui_item_index.mjs';
|
||||||
|
import tabledefs from '../tabledefs/index.mjs';
|
||||||
|
|
||||||
class TableView {
|
class TableView {
|
||||||
constructor(el) {
|
constructor(el) {
|
||||||
|
@ -13,12 +14,22 @@ class TableView {
|
||||||
this.emel = new Emel().emel;
|
this.emel = new Emel().emel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the currently displayed table.
|
||||||
|
* @return {void}
|
||||||
|
*/
|
||||||
clear() {
|
clear() {
|
||||||
this.el_parts.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();
|
// 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) {
|
init(tabledef) {
|
||||||
this.clear();
|
this.clear();
|
||||||
const parts = this.emel(`h2>(${fa_emel(tabledef.icon)}+{?})^div.data-display`, {
|
const parts = this.emel(`h2>(${fa_emel(tabledef.icon)}+{?})^div.data-display`, {
|
||||||
|
@ -44,14 +55,29 @@ class TableView {
|
||||||
this.el.replaceChildren(parts);
|
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) {
|
async switch_table(table_name) {
|
||||||
table_name = table_name.replace(/[^a-z0-9-_]/g, "");
|
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)) {
|
for await (let tabledef of await globalThis.sysquery.table(table_name)) {
|
||||||
this.append_table(tabledef.peer, tabledef.table);
|
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) {
|
append_table(peer, table) {
|
||||||
for(let [ def_name, item_manager ] of this.el_parts) {
|
for(let [ def_name, item_manager ] of this.el_parts) {
|
||||||
if(item_manager === null) continue;
|
if(item_manager === null) continue;
|
||||||
|
|
Loading…
Reference in a new issue