diff --git a/module/Apps/StatsViewer.mjs b/module/Apps/StatsViewer.mjs index 6d3ea46..78f5be4 100644 --- a/module/Apps/StatsViewer.mjs +++ b/module/Apps/StatsViewer.mjs @@ -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; }; diff --git a/module/handlebarsHelpers/options.mjs b/module/handlebarsHelpers/options.mjs index a7e68a8..72b04a8 100644 --- a/module/handlebarsHelpers/options.mjs +++ b/module/handlebarsHelpers/options.mjs @@ -6,12 +6,15 @@ */ /** - * @param {string | number} selected + * @param {string | number | string[] | number[]} selected * @param {Array} opts * @param {any} meta */ export function options(selected, opts) { - selected = Handlebars.escapeExpression(selected); + if (!Array.isArray(selected)) { + selected = [selected]; + }; + // selected = selected.map(Handlebars.escapeExpression); const htmlOptions = []; for (let opt of opts) { @@ -22,7 +25,7 @@ export function options(selected, opts) { htmlOptions.push( ` ${ opt.label } diff --git a/public/styles/Apps/StatsViewer.css b/public/styles/Apps/StatsViewer.css index eba05c3..645a45d 100644 --- a/public/styles/Apps/StatsViewer.css +++ b/public/styles/Apps/StatsViewer.css @@ -9,4 +9,9 @@ flex-direction: row; gap: 1rem; } + [data-application-part="dataFilters"] { + display: grid; + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 1rem; + } } diff --git a/public/templates/Apps/StatsViewer/dataFilters.hbs b/public/templates/Apps/StatsViewer/dataFilters.hbs index 91c87fd..cd9b5c0 100644 --- a/public/templates/Apps/StatsViewer/dataFilters.hbs +++ b/public/templates/Apps/StatsViewer/dataFilters.hbs @@ -1,3 +1,11 @@ - Data Filters + + Extra Controls + + {{!-- This currently doesn't support any placeholders :( --}} + + {{ st-options selectedUsers users }} +