diff --git a/lang/admin/en-us.json b/lang/admin/en-us.json index d420ee8..6638176 100644 --- a/lang/admin/en-us.json +++ b/lang/admin/en-us.json @@ -137,8 +137,8 @@ "filters": "Filters", "clickToRemoveFilter": "Click to remove this filter.", "clearSearch": "Clear search", - "searchAll": "Search all", - "searchAllRecords": "Search all records (on server)", + "searchAll": "Search/sort all", + "searchAllRecords": "Search/sort all records (on server)", "actions": "Actions", "searchOptions": "Search Options", "matchText": "Match Text", diff --git a/ts/modules/accounts.ts b/ts/modules/accounts.ts index fd642d7..de96b94 100644 --- a/ts/modules/accounts.ts +++ b/ts/modules/accounts.ts @@ -1188,7 +1188,7 @@ export class accountsList extends PaginatedList { const headerNames: string[] = ["username", "access-jfa", "email", "telegram", "matrix", "discord", "expiry", "last-active", "referrals"]; const headerGetters: string[] = ["name", "accounts_admin", "email", "telegram", "matrix", "discord", "expiry", "last_active", "referrals_enabled"]; for (let i = 0; i < headerNames.length; i++) { - const header: HTMLTableHeaderCellElement = document.querySelector(".accounts-header-" + headerNames[i]) as HTMLTableHeaderCellElement; + const header: HTMLTableCellElement = document.querySelector(".accounts-header-" + headerNames[i]) as HTMLTableCellElement; if (header !== null) { this._columns[headerGetters[i]] = new Column(header, headerGetters[i], Object.getOwnPropertyDescriptor(user.prototype, headerGetters[i]).get); } @@ -1219,10 +1219,9 @@ export class accountsList extends PaginatedList { } else { this.setVisibility(this._search.ordering, true); this._search.setNotFoundPanelVisibility(false); - this._search.setServerSearchButtonsDisabled( - event.detail == this._c.defaultSortField && this._columns[event.detail].ascending == this._c.defaultSortAscending - ); } + this._search.inServerSearch = false; + this.autoSetServerSearchButtonsDisabled(); this._search.showHideSearchOptionsHeader(); }); @@ -2116,14 +2115,14 @@ type Getter = () => GetterReturnType; // When list is refreshed, accountList calls method of the specific Column and re-orders accordingly. // Listen for broadcast event from others, check its not us by comparing the header className in the message, then hide the arrow icon class Column { - private _header: HTMLTableHeaderCellElement; + private _header: HTMLTableCellElement; private _name: string; private _headerContent: string; private _getter: Getter; private _ascending: boolean; private _active: boolean; - constructor(header: HTMLTableHeaderCellElement, name: string, getter: Getter) { + constructor(header: HTMLTableCellElement, name: string, getter: Getter) { this._header = header; this._name = name; this._headerContent = this._header.textContent; diff --git a/ts/modules/list.ts b/ts/modules/list.ts index 2335a2c..b3f0d8a 100644 --- a/ts/modules/list.ts +++ b/ts/modules/list.ts @@ -128,14 +128,13 @@ export abstract class PaginatedList { if (v) { this._c.loadAllButton.classList.add("unfocused"); this._c.loadMoreButton.textContent = window.lang.strings("noMoreResults"); - this._search.setServerSearchButtonsDisabled(this._search.inServerSearch); this._c.loadMoreButton.disabled = true; } else { this._c.loadMoreButton.textContent = window.lang.strings("loadMore"); this._c.loadMoreButton.disabled = false; - this._search.setServerSearchButtonsDisabled(false); this._c.loadAllButton.classList.remove("unfocused"); } + this.autoSetServerSearchButtonsDisabled(); } protected _previousVisibleItemCount = 0; @@ -171,17 +170,30 @@ export abstract class PaginatedList { this._c.refreshButton.onclick = () => this.reload(); } + autoSetServerSearchButtonsDisabled = () => { + const serverSearchSortChanged = this._search.inServerSearch && (this._searchParams.sortByField != this._search.sortField || this._searchParams.ascending != this._search.ascending); + if (this._search.inServerSearch) { + if (serverSearchSortChanged) { + this._search.setServerSearchButtonsDisabled(false); + } else { + this._search.setServerSearchButtonsDisabled(this.lastPage); + } + return; + } + if (!this._search.inSearch && this._search.sortField == this._c.defaultSortField && this._search.ascending == this._c.defaultSortAscending) { + this._search.setServerSearchButtonsDisabled(true); + return; + } + this._search.setServerSearchButtonsDisabled(false); + } + initSearch = (searchConfig: SearchConfiguration) => { const previousCallback = searchConfig.onSearchCallback; searchConfig.onSearchCallback = (newItems: boolean, loadAll: boolean) => { // if (this._search.inSearch && !this.lastPage) this._c.loadAllButton.classList.remove("unfocused"); // else this._c.loadAllButton.classList.add("unfocused"); - - if (this._search.sortField == this._c.defaultSortField && this._search.ascending == this._c.defaultSortAscending) { - this._search.setServerSearchButtonsDisabled(!this._search.inSearch) - } else { - this._search.setServerSearchButtonsDisabled(false) - } + + this.autoSetServerSearchButtonsDisabled(); // FIXME: Figure out why this makes sense and make it clearer. if ((this._visible.length < this._c.itemsPerPage && this._counter.loaded < this._c.maxItemsLoadedForSearch && !this.lastPage) || loadAll) { @@ -205,7 +217,7 @@ export abstract class PaginatedList { if (previousServerSearch) previousServerSearch(params, newSearch); }; searchConfig.clearServerSearch = () => { - console.log("Clearing server search"); + console.trace("Clearing server search"); this._page = 0; this.reload(); } diff --git a/ts/modules/search.ts b/ts/modules/search.ts index 46bb7fa..d27c4d7 100644 --- a/ts/modules/search.ts +++ b/ts/modules/search.ts @@ -420,18 +420,16 @@ export class Search { // Returns a list of identifiers (used as keys in items, values in ordering). searchParsed = (searchTerms: string[], queries: Query[]): string[] => { let result: string[] = [...this._ordering]; - // If we're in a server search already, the results are (probably) already correct. - if (this.inServerSearch) { - let hasLocalOnlyQueries = false; - for (const q of queries) { - if (q.localOnly) { - hasLocalOnlyQueries = true; - break; - } - } - if (!hasLocalOnlyQueries) return result; - // Continue on if really necessary - } + // If we didn't care about rendering the query cards, we could run this to (maybe) return early. + // if (this.inServerSearch) { + // let hasLocalOnlyQueries = false; + // for (const q of queries) { + // if (q.localOnly) { + // hasLocalOnlyQueries = true; + // break; + // } + // } + // } // Normal searches can be evaluated by the server, so skip this if we've already ran one. if (!this.inServerSearch) {