Update the Memory database and StatsViewer to better conform to the abstract implementation
This commit is contained in:
parent
b8b8f8f16b
commit
d79597d1e2
2 changed files with 6 additions and 11 deletions
|
|
@ -72,7 +72,7 @@ export class StatsViewer extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
|
|
||||||
async _onFirstRender(context, options) {
|
async _onFirstRender(context, options) {
|
||||||
await super._onFirstRender(context, options);
|
await super._onFirstRender(context, options);
|
||||||
CONFIG.StatsDatabase.apps[this.id] = this;
|
CONFIG.StatsDatabase.addApp(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
async _onRender(context, options) {
|
async _onRender(context, options) {
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,8 @@ export class MemoryDatabase extends Database {
|
||||||
|
|
||||||
static createTable(tableConfig) {
|
static createTable(tableConfig) {
|
||||||
this.#tables[tableConfig.name] = tableConfig;
|
this.#tables[tableConfig.name] = tableConfig;
|
||||||
|
this.render();
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @returns {Array<Table>} */
|
/** @returns {Array<Table>} */
|
||||||
|
|
@ -96,7 +98,7 @@ export class MemoryDatabase extends Database {
|
||||||
row._id ||= randomID();
|
row._id ||= randomID();
|
||||||
|
|
||||||
this.#rows[userID][table].push(row);
|
this.#rows[userID][table].push(row);
|
||||||
this.render();
|
this.render({ userUpdated: userID });
|
||||||
};
|
};
|
||||||
|
|
||||||
static getRows(tableID, userIDs, privacy = `none`) {
|
static getRows(tableID, userIDs, privacy = `none`) {
|
||||||
|
|
@ -124,7 +126,7 @@ export class MemoryDatabase extends Database {
|
||||||
let row = this.#rows[userID][table].find(row => row._id === rowID);
|
let row = this.#rows[userID][table].find(row => row._id === rowID);
|
||||||
if (!row) { return };
|
if (!row) { return };
|
||||||
mergeObject(row, changes);
|
mergeObject(row, changes);
|
||||||
this.render();
|
this.render({ userUpdated: userID });
|
||||||
};
|
};
|
||||||
|
|
||||||
static deleteRow(table, userID, rowID) {
|
static deleteRow(table, userID, rowID) {
|
||||||
|
|
@ -132,14 +134,7 @@ export class MemoryDatabase extends Database {
|
||||||
let rowIndex = this.#rows[userID][table].findIndex(row => row._id === rowID);
|
let rowIndex = this.#rows[userID][table].findIndex(row => row._id === rowID);
|
||||||
if (rowIndex === -1) { return };
|
if (rowIndex === -1) { return };
|
||||||
this.#rows[userID][table].splice(rowIndex, 1);
|
this.#rows[userID][table].splice(rowIndex, 1);
|
||||||
this.render();
|
this.render({ userUpdated: userID });
|
||||||
};
|
|
||||||
|
|
||||||
static apps = {};
|
|
||||||
static render() {
|
|
||||||
for (const app of Object.values(this.apps)) {
|
|
||||||
app.render();
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue