2022-02-26 21:58:51 +00:00
|
|
|
"use strict";
|
|
|
|
|
2022-02-27 02:05:45 +00:00
|
|
|
import Emel from 'emel';
|
|
|
|
import fa_emel from './forkawesome_emel.mjs';
|
|
|
|
|
2022-02-26 21:58:51 +00:00
|
|
|
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();
|
2022-02-27 02:05:45 +00:00
|
|
|
this.emel = new Emel().emel;
|
2022-02-26 21:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
clear() {
|
|
|
|
this.el.replaceChildren();
|
|
|
|
this.el_parts.clear();
|
|
|
|
}
|
|
|
|
|
2022-02-27 02:05:45 +00:00
|
|
|
init(tabledef) {
|
|
|
|
this.clear();
|
|
|
|
const parts = this.emel(`h2>(${fa_emel(tabledef.icon)}+{?})^div[class=data-display]`, {
|
|
|
|
placeholders: [
|
|
|
|
tabledef.name
|
|
|
|
]
|
|
|
|
});
|
|
|
|
for(let def of tabledef.items) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.el.replaceChildren(parts);
|
|
|
|
}
|
|
|
|
|
2022-02-26 21:58:51 +00:00
|
|
|
async switch_table(table_name) {
|
2022-02-27 02:05:45 +00:00
|
|
|
table_name = table_name.replace(/[^a-z0-9-_]/g, "");
|
2022-02-26 21:58:51 +00:00
|
|
|
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;
|