mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-06-27 05:11:41 +02:00
WIP on caching static option file and searching it client-side
Avoid type error in CalendarOwner
This commit is contained in:
parent
748673522c
commit
f04b25089a
@ -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,19 +1215,7 @@ 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);
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add in remote results
|
|
||||||
* @param results
|
|
||||||
* @protected
|
|
||||||
*/
|
|
||||||
protected processRemoteResults(results)
|
|
||||||
{
|
{
|
||||||
// If results have a total included, pull it out.
|
// If results have a total included, pull it out.
|
||||||
// It will cause errors if left in the results
|
// It will cause errors if left in the results
|
||||||
@ -1240,6 +1226,19 @@ export const Et2WithSearchMixin = <T extends Constructor<LitElement>>(superclass
|
|||||||
delete results.total;
|
delete results.total;
|
||||||
}
|
}
|
||||||
let entries = cleanSelectOptions(results);
|
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(entries, totalResults = 0)
|
||||||
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user