1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-23 01:20:11 +00:00

accounts: filter by string field, general search

string fields can now be searched by with the "<field>:<value>" syntax,
also added back a better general search, that supports essentially all
string fields, including Jellyfin ID.
This commit is contained in:
Harvey Tindall 2023-06-13 13:55:40 +01:00
parent 8a37663c89
commit 90c433443f
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2

View File

@ -459,6 +459,20 @@ class user implements User {
this._label.classList.add("chip", "~gray", "mr-2"); 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 _checkEvent = new CustomEvent("accountCheckEvent");
private _uncheckEvent = new CustomEvent("accountUncheckEvent"); private _uncheckEvent = new CustomEvent("accountUncheckEvent");
@ -778,6 +792,20 @@ export class accountsList {
search = (query: String): string[] => { search = (query: String): string[] => {
console.log("called!"); console.log("called!");
const queries: { [field: string]: { name: string, getter: string, bool: boolean, string: boolean, date: boolean }} = { 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": { "admin": {
name: "Admin", name: "Admin",
getter: "admin", getter: "admin",
@ -846,7 +874,16 @@ export class accountsList {
query = query.toLowerCase(); query = query.toLowerCase();
let result: string[] = [...this._ordering]; let result: string[] = [...this._ordering];
console.log("initial:", result); 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(" "); // const words = query.split(" ");
let words: string[] = []; let words: string[] = [];
@ -915,9 +952,14 @@ export class accountsList {
} }
} }
if (queryFormat.string) { if (queryFormat.string) {
let cachedResult = [...result];
// FIXME: STRING SEARCH FOR FIELD for (let id of cachedResult) {
// FIXME: SUBTRACT FROM RESULT 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; continue;
} }
if (queryFormat.date) { if (queryFormat.date) {