WIP on caching static option file and searching it client-side

Avoid type error in CalendarOwner
This commit is contained in:
nathan 2023-07-24 08:51:27 -06:00
parent 748673522c
commit f04b25089a

View File

@ -1138,11 +1138,11 @@ export const Et2WithSearchMixin = <T extends Constructor<LitElement>>(superclass
* @param {string} search * @param {string} search
* @protected * @protected
*/ */
protected remoteSearch(search : string, options : object) protected remoteSearch(search : string, options : object) : Promise<SelectOption[]>
{ {
if(!this.searchUrl) if(!this.searchUrl)
{ {
return Promise.resolve(); return Promise.resolve([]);
} }
// Check our URL: JSON file or URL? // Check our URL: JSON file or URL?
@ -1154,10 +1154,8 @@ export const Et2WithSearchMixin = <T extends Constructor<LitElement>>(superclass
else else
{ {
// Fire off the query to the server // Fire off the query to the server
let promise = this.remoteQuery(search, options); return this.remoteQuery(search, options);
} }
return promise;
} }
/** /**
@ -1167,7 +1165,7 @@ export const Et2WithSearchMixin = <T extends Constructor<LitElement>>(superclass
* @param {object} options * @param {object} options
* @protected * @protected
*/ */
protected jsonQuery(search : string, options : object) protected jsonQuery(search : string, options : object) : Promise<SelectOption[]>
{ {
// Get the file // Get the file
const controller = new AbortController(); const controller = new AbortController();
@ -1209,7 +1207,7 @@ export const Et2WithSearchMixin = <T extends Constructor<LitElement>>(superclass
* @returns {any} * @returns {any}
* @protected * @protected
*/ */
protected remoteQuery(search : string, options : object) protected remoteQuery(search : string, options : object) : Promise<SelectOption[]>
{ {
// Include a limit, even if options don't, to avoid massive lists breaking the UI // Include a limit, even if options don't, to avoid massive lists breaking the UI
let sendOptions = { let sendOptions = {
@ -1217,29 +1215,30 @@ export const Et2WithSearchMixin = <T extends Constructor<LitElement>>(superclass
...options ...options
} }
return this.egw().request(this.egw().link(this.egw().ajaxUrl(this.egw().decodePath(this.searchUrl)), return this.egw().request(this.egw().link(this.egw().ajaxUrl(this.egw().decodePath(this.searchUrl)),
{query: search, ...sendOptions}), [search, sendOptions]).then((result) => {query: search, ...sendOptions}), [search, sendOptions]).then((results) =>
{ {
this.processRemoteResults(result); // If results have a total included, pull it out.
return result; // It will cause errors if left in the results
let total = null;
if(typeof results.total !== "undefined")
{
total = results.total;
delete results.total;
}
let entries = cleanSelectOptions(results);
this.processRemoteResults(entries, total);
return entries;
}); });
} }
/** /**
* Add in remote results * Add in remote results
* @param results * @param results
* @param totalResults If there are more results than were returned, total number of matches
* @protected * @protected
*/ */
protected processRemoteResults(results) protected processRemoteResults(entries, totalResults = 0)
{ {
// If results have a total included, pull it out.
// It will cause errors if left in the results
let total = null;
if(typeof results.total !== "undefined")
{
total = results.total;
delete results.total;
}
let entries = cleanSelectOptions(results);
let resultCount = entries.length; let resultCount = entries.length;
if(entries.length == 0) if(entries.length == 0)
@ -1288,12 +1287,12 @@ export const Et2WithSearchMixin = <T extends Constructor<LitElement>>(superclass
}) })
.then(() => .then(() =>
{ {
if(total && total > resultCount) if(totalResults && totalResults > resultCount)
{ {
// More results available that were not sent // More results available that were not sent
let count = document.createElement("span") let count = document.createElement("span")
count.classList.add("remote"); count.classList.add("remote");
count.textContent = this.egw().lang("%1 more...", total - resultCount); count.textContent = this.egw().lang("%1 more...", totalResults - resultCount);
target.appendChild(count); target.appendChild(count);
} }
}); });