From 90c433443face506c1af1ab90a36ce95a1f620a4 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Tue, 13 Jun 2023 13:55:40 +0100 Subject: [PATCH] accounts: filter by string field, general search string fields can now be searched by with the ":" syntax, also added back a better general search, that supports essentially all string fields, including Jellyfin ID. --- ts/modules/accounts.ts | 50 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/ts/modules/accounts.ts b/ts/modules/accounts.ts index a79ca62..6724a86 100644 --- a/ts/modules/accounts.ts +++ b/ts/modules/accounts.ts @@ -459,6 +459,20 @@ class user implements User { this._label.classList.add("chip", "~gray", "mr-2"); } } + + matchesSearch = (query: string): boolean => { + return ( + this.name.includes(query) || + this.label.includes(query) || + this.discord.includes(query) || + this.email.includes(query) || + this.id.includes(query) || + this.label.includes(query) || + this.matrix.includes(query) || + this.telegram.includes(query) + ); + } + private _checkEvent = new CustomEvent("accountCheckEvent"); private _uncheckEvent = new CustomEvent("accountUncheckEvent"); @@ -778,6 +792,20 @@ export class accountsList { search = (query: String): string[] => { console.log("called!"); const queries: { [field: string]: { name: string, getter: string, bool: boolean, string: boolean, date: boolean }} = { + "id": { + name: "Jellyfin ID", + getter: "id", + bool: false, + string: true, + date: false + }, + "label": { + name: "Label", + getter: "label", + bool: true, + string: true, + date: false + }, "admin": { name: "Admin", getter: "admin", @@ -846,7 +874,16 @@ export class accountsList { query = query.toLowerCase(); let result: string[] = [...this._ordering]; console.log("initial:", result); - if (!(query.includes(":"))) return result; + if (!(query.includes(":"))) { + let cachedResult = [...result]; + for (let id of cachedResult) { + const u = this._users[id]; + if (!u.matchesSearch(query as string)) { + result.splice(result.indexOf(id), 1); + } + } + return result; + } // const words = query.split(" "); let words: string[] = []; @@ -915,9 +952,14 @@ export class accountsList { } } if (queryFormat.string) { - - // FIXME: STRING SEARCH FOR FIELD - // FIXME: SUBTRACT FROM RESULT + let cachedResult = [...result]; + for (let id of cachedResult) { + const u = this._users[id]; + const value = Object.getOwnPropertyDescriptor(user.prototype, queryFormat.getter).get.call(u); + if (!(value.includes(split[1]))) { + result.splice(result.indexOf(id), 1); + } + } continue; } if (queryFormat.date) {