mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-24 00:43:20 +01:00
WIP on caching static option file and searching it client-side
Avoid type error in CalendarOwner
This commit is contained in:
parent
2c919d4318
commit
e00582b5f9
@ -1133,11 +1133,11 @@ export const Et2WithSearchMixin = <T extends Constructor<LitElement>>(superclass
|
||||
* @param {string} search
|
||||
* @protected
|
||||
*/
|
||||
protected remoteSearch(search : string, options : object)
|
||||
protected remoteSearch(search : string, options : object) : Promise<SelectOption[]>
|
||||
{
|
||||
if(!this.searchUrl)
|
||||
{
|
||||
return Promise.resolve();
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
// Check our URL: JSON file or URL?
|
||||
@ -1149,10 +1149,8 @@ export const Et2WithSearchMixin = <T extends Constructor<LitElement>>(superclass
|
||||
else
|
||||
{
|
||||
// Fire off the query to the server
|
||||
let promise = this.remoteQuery(search, options);
|
||||
return this.remoteQuery(search, options);
|
||||
}
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1162,7 +1160,7 @@ export const Et2WithSearchMixin = <T extends Constructor<LitElement>>(superclass
|
||||
* @param {object} options
|
||||
* @protected
|
||||
*/
|
||||
protected jsonQuery(search : string, options : object)
|
||||
protected jsonQuery(search : string, options : object) : Promise<SelectOption[]>
|
||||
{
|
||||
// Get the file
|
||||
const controller = new AbortController();
|
||||
@ -1204,7 +1202,7 @@ export const Et2WithSearchMixin = <T extends Constructor<LitElement>>(superclass
|
||||
* @returns {any}
|
||||
* @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
|
||||
let sendOptions = {
|
||||
@ -1212,29 +1210,30 @@ export const Et2WithSearchMixin = <T extends Constructor<LitElement>>(superclass
|
||||
...options
|
||||
}
|
||||
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);
|
||||
return result;
|
||||
// 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);
|
||||
this.processRemoteResults(entries, total);
|
||||
return entries;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add in remote results
|
||||
* @param results
|
||||
* @param totalResults If there are more results than were returned, total number of matches
|
||||
* @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;
|
||||
|
||||
if(entries.length == 0)
|
||||
@ -1283,12 +1282,12 @@ export const Et2WithSearchMixin = <T extends Constructor<LitElement>>(superclass
|
||||
})
|
||||
.then(() =>
|
||||
{
|
||||
if(total && total > resultCount)
|
||||
if(totalResults && totalResults > resultCount)
|
||||
{
|
||||
// More results available that were not sent
|
||||
let count = document.createElement("span")
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user