search: fix "search all" button disabling logic, more

just a few more general fixes. Also changed the "Search all" button to
say "Search/sort all".
This commit is contained in:
Harvey Tindall
2025-05-26 17:28:09 +01:00
parent ef253de56b
commit 699cbee240
4 changed files with 38 additions and 29 deletions
+2 -2
View File
@@ -137,8 +137,8 @@
"filters": "Filters", "filters": "Filters",
"clickToRemoveFilter": "Click to remove this filter.", "clickToRemoveFilter": "Click to remove this filter.",
"clearSearch": "Clear search", "clearSearch": "Clear search",
"searchAll": "Search all", "searchAll": "Search/sort all",
"searchAllRecords": "Search all records (on server)", "searchAllRecords": "Search/sort all records (on server)",
"actions": "Actions", "actions": "Actions",
"searchOptions": "Search Options", "searchOptions": "Search Options",
"matchText": "Match Text", "matchText": "Match Text",
+5 -6
View File
@@ -1188,7 +1188,7 @@ export class accountsList extends PaginatedList {
const headerNames: string[] = ["username", "access-jfa", "email", "telegram", "matrix", "discord", "expiry", "last-active", "referrals"]; 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"]; const headerGetters: string[] = ["name", "accounts_admin", "email", "telegram", "matrix", "discord", "expiry", "last_active", "referrals_enabled"];
for (let i = 0; i < headerNames.length; i++) { 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) { if (header !== null) {
this._columns[headerGetters[i]] = new Column(header, headerGetters[i], Object.getOwnPropertyDescriptor(user.prototype, headerGetters[i]).get); 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 { } else {
this.setVisibility(this._search.ordering, true); this.setVisibility(this._search.ordering, true);
this._search.setNotFoundPanelVisibility(false); 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(); 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. // 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 // 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 { class Column {
private _header: HTMLTableHeaderCellElement; private _header: HTMLTableCellElement;
private _name: string; private _name: string;
private _headerContent: string; private _headerContent: string;
private _getter: Getter; private _getter: Getter;
private _ascending: boolean; private _ascending: boolean;
private _active: boolean; private _active: boolean;
constructor(header: HTMLTableHeaderCellElement, name: string, getter: Getter) { constructor(header: HTMLTableCellElement, name: string, getter: Getter) {
this._header = header; this._header = header;
this._name = name; this._name = name;
this._headerContent = this._header.textContent; this._headerContent = this._header.textContent;
+21 -9
View File
@@ -128,14 +128,13 @@ export abstract class PaginatedList {
if (v) { if (v) {
this._c.loadAllButton.classList.add("unfocused"); this._c.loadAllButton.classList.add("unfocused");
this._c.loadMoreButton.textContent = window.lang.strings("noMoreResults"); this._c.loadMoreButton.textContent = window.lang.strings("noMoreResults");
this._search.setServerSearchButtonsDisabled(this._search.inServerSearch);
this._c.loadMoreButton.disabled = true; this._c.loadMoreButton.disabled = true;
} else { } else {
this._c.loadMoreButton.textContent = window.lang.strings("loadMore"); this._c.loadMoreButton.textContent = window.lang.strings("loadMore");
this._c.loadMoreButton.disabled = false; this._c.loadMoreButton.disabled = false;
this._search.setServerSearchButtonsDisabled(false);
this._c.loadAllButton.classList.remove("unfocused"); this._c.loadAllButton.classList.remove("unfocused");
} }
this.autoSetServerSearchButtonsDisabled();
} }
protected _previousVisibleItemCount = 0; protected _previousVisibleItemCount = 0;
@@ -171,17 +170,30 @@ export abstract class PaginatedList {
this._c.refreshButton.onclick = () => this.reload(); 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) => { initSearch = (searchConfig: SearchConfiguration) => {
const previousCallback = searchConfig.onSearchCallback; const previousCallback = searchConfig.onSearchCallback;
searchConfig.onSearchCallback = (newItems: boolean, loadAll: boolean) => { searchConfig.onSearchCallback = (newItems: boolean, loadAll: boolean) => {
// if (this._search.inSearch && !this.lastPage) this._c.loadAllButton.classList.remove("unfocused"); // if (this._search.inSearch && !this.lastPage) this._c.loadAllButton.classList.remove("unfocused");
// else this._c.loadAllButton.classList.add("unfocused"); // else this._c.loadAllButton.classList.add("unfocused");
if (this._search.sortField == this._c.defaultSortField && this._search.ascending == this._c.defaultSortAscending) { this.autoSetServerSearchButtonsDisabled();
this._search.setServerSearchButtonsDisabled(!this._search.inSearch)
} else {
this._search.setServerSearchButtonsDisabled(false)
}
// FIXME: Figure out why this makes sense and make it clearer. // 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) { 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); if (previousServerSearch) previousServerSearch(params, newSearch);
}; };
searchConfig.clearServerSearch = () => { searchConfig.clearServerSearch = () => {
console.log("Clearing server search"); console.trace("Clearing server search");
this._page = 0; this._page = 0;
this.reload(); this.reload();
} }
+10 -12
View File
@@ -420,18 +420,16 @@ export class Search {
// Returns a list of identifiers (used as keys in items, values in ordering). // Returns a list of identifiers (used as keys in items, values in ordering).
searchParsed = (searchTerms: string[], queries: Query[]): string[] => { searchParsed = (searchTerms: string[], queries: Query[]): string[] => {
let result: string[] = [...this._ordering]; let result: string[] = [...this._ordering];
// If we're in a server search already, the results are (probably) already correct. // If we didn't care about rendering the query cards, we could run this to (maybe) return early.
if (this.inServerSearch) { // if (this.inServerSearch) {
let hasLocalOnlyQueries = false; // let hasLocalOnlyQueries = false;
for (const q of queries) { // for (const q of queries) {
if (q.localOnly) { // if (q.localOnly) {
hasLocalOnlyQueries = true; // hasLocalOnlyQueries = true;
break; // break;
} // }
} // }
if (!hasLocalOnlyQueries) return result; // }
// Continue on if really necessary
}
// Normal searches can be evaluated by the server, so skip this if we've already ran one. // Normal searches can be evaluated by the server, so skip this if we've already ran one.
if (!this.inServerSearch) { if (!this.inServerSearch) {