Add support for the user data filter that defaults to only the user's data
This commit is contained in:
parent
9eafba6165
commit
87ce956368
4 changed files with 41 additions and 10 deletions
|
|
@ -43,12 +43,10 @@ export class StatsViewer extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
async _onRender(context, options) {
|
async _onRender(context, options) {
|
||||||
await super._onRender(context, options);
|
await super._onRender(context, options);
|
||||||
|
|
||||||
const { parts } = options;
|
const elements = this.element
|
||||||
|
.querySelectorAll(`[data-bind]`);
|
||||||
if (parts.includes(`tableSelect`)) {
|
for (const input of elements) {
|
||||||
this.element
|
input.addEventListener(`change`, this.#bindListener.bind(this));
|
||||||
.querySelector(`[data-application-part="tableSelect"] [data-bind]`)
|
|
||||||
?.addEventListener(`change`, this.#bindListener.bind(this));
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -60,6 +58,10 @@ export class StatsViewer extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
this.#prepareTableSelectContext(ctx);
|
this.#prepareTableSelectContext(ctx);
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
case `dataFilters`: {
|
||||||
|
this.#prepareDataFiltersContext(ctx);
|
||||||
|
break;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
if (import.meta.env.DEV) {
|
if (import.meta.env.DEV) {
|
||||||
|
|
@ -99,6 +101,18 @@ export class StatsViewer extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
ctx.subtables = subtableList;
|
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
|
* @param {Event} event
|
||||||
*/
|
*/
|
||||||
|
|
@ -108,6 +122,7 @@ export class StatsViewer extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
|
|
||||||
const binding = data.bind;
|
const binding = data.bind;
|
||||||
if (!binding || !Object.hasOwn(this, binding)) {
|
if (!binding || !Object.hasOwn(this, binding)) {
|
||||||
|
Logger.debug(`Skipping change for element with binding "${binding}"`);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string | number} selected
|
* @param {string | number | string[] | number[]} selected
|
||||||
* @param {Array<Option | string>} opts
|
* @param {Array<Option | string>} opts
|
||||||
* @param {any} meta
|
* @param {any} meta
|
||||||
*/
|
*/
|
||||||
export function options(selected, opts) {
|
export function options(selected, opts) {
|
||||||
selected = Handlebars.escapeExpression(selected);
|
if (!Array.isArray(selected)) {
|
||||||
|
selected = [selected];
|
||||||
|
};
|
||||||
|
// selected = selected.map(Handlebars.escapeExpression);
|
||||||
const htmlOptions = [];
|
const htmlOptions = [];
|
||||||
|
|
||||||
for (let opt of opts) {
|
for (let opt of opts) {
|
||||||
|
|
@ -22,7 +25,7 @@ export function options(selected, opts) {
|
||||||
htmlOptions.push(
|
htmlOptions.push(
|
||||||
`<option
|
`<option
|
||||||
value="${opt.value}"
|
value="${opt.value}"
|
||||||
${selected === opt.value ? `selected` : ``}
|
${selected.includes(opt.value) ? `selected` : ``}
|
||||||
${opt.disabled ? `disabled` : ``}
|
${opt.disabled ? `disabled` : ``}
|
||||||
>
|
>
|
||||||
${ opt.label }
|
${ opt.label }
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,9 @@
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
}
|
}
|
||||||
|
[data-application-part="dataFilters"] {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,11 @@
|
||||||
<div>
|
<div>
|
||||||
Data Filters
|
<div>
|
||||||
|
Extra Controls
|
||||||
|
</div>
|
||||||
|
{{!-- This currently doesn't support any placeholders :( --}}
|
||||||
|
<multi-select
|
||||||
|
data-bind="_selectedUsers"
|
||||||
|
>
|
||||||
|
{{ st-options selectedUsers users }}
|
||||||
|
</multi-select>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue