Add support for the user data filter that defaults to only the user's data

This commit is contained in:
Oliver-Akins 2025-04-21 01:48:55 -06:00
parent 9eafba6165
commit 87ce956368
4 changed files with 41 additions and 10 deletions

View file

@ -43,12 +43,10 @@ export class StatsViewer extends HandlebarsApplicationMixin(ApplicationV2) {
async _onRender(context, options) {
await super._onRender(context, options);
const { parts } = options;
if (parts.includes(`tableSelect`)) {
this.element
.querySelector(`[data-application-part="tableSelect"] [data-bind]`)
?.addEventListener(`change`, this.#bindListener.bind(this));
const elements = this.element
.querySelectorAll(`[data-bind]`);
for (const input of elements) {
input.addEventListener(`change`, this.#bindListener.bind(this));
};
};
@ -60,6 +58,10 @@ export class StatsViewer extends HandlebarsApplicationMixin(ApplicationV2) {
this.#prepareTableSelectContext(ctx);
break;
};
case `dataFilters`: {
this.#prepareDataFiltersContext(ctx);
break;
};
};
if (import.meta.env.DEV) {
@ -99,6 +101,18 @@ export class StatsViewer extends HandlebarsApplicationMixin(ApplicationV2) {
ctx.subtables = subtableList;
};
_selectedUsers = [game.user.id];
async #prepareDataFiltersContext(ctx) {
ctx.users = [];
ctx.selectedUsers = this._selectedUsers;
for (const user of game.users) {
ctx.users.push({
label: user.name,
value: user.id,
});
};
};
/**
* @param {Event} event
*/
@ -108,6 +122,7 @@ export class StatsViewer extends HandlebarsApplicationMixin(ApplicationV2) {
const binding = data.bind;
if (!binding || !Object.hasOwn(this, binding)) {
Logger.debug(`Skipping change for element with binding "${binding}"`);
return;
};