mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-06-26 12:51:52 +02:00
Revert "Fix link-string in nextmatch did not show values" as no more links shown :(
This reverts commit 2c07840e95c6348da3b8b861e8b5e10aa3aefe7e.^
This commit is contained in:
parent
64f03a21fd
commit
7128486d7e
@ -10,14 +10,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import {css, html, LitElement, nothing, PropertyValues, render, TemplateResult} from "lit";
|
import {css, html, LitElement, PropertyValues, render, TemplateResult} from "lit";
|
||||||
import {until} from "lit/directives/until.js";
|
import {until} from "lit/directives/until.js";
|
||||||
import {Et2Widget} from "../Et2Widget/Et2Widget";
|
import {Et2Widget} from "../Et2Widget/Et2Widget";
|
||||||
import {LinkInfo} from "./Et2Link";
|
import {LinkInfo} from "./Et2Link";
|
||||||
import {et2_IDetachedDOM} from "../et2_core_interfaces";
|
import {et2_IDetachedDOM} from "../et2_core_interfaces";
|
||||||
import {property} from "lit/decorators/property.js";
|
import {property} from "lit/decorators/property.js";
|
||||||
import {customElement} from "lit/decorators/custom-element.js";
|
import {customElement} from "lit/decorators/custom-element.js";
|
||||||
import {repeat} from "lit/directives/repeat.js";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a list of entries in a comma separated list
|
* Display a list of entries in a comma separated list
|
||||||
@ -43,26 +42,22 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
|
|||||||
padding: 0px;
|
padding: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
et2-link, et2-link::part(base), et2-description {
|
::slotted(*) {
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
|
|
||||||
et2-link::part(icon) {
|
::slotted(*):hover {
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
et2-link:hover {
|
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* CSS for child elements */
|
/* CSS for child elements */
|
||||||
|
|
||||||
et2-link::part(title):after {
|
::slotted(*):after {
|
||||||
content: ", "
|
content: ", "
|
||||||
}
|
}
|
||||||
|
|
||||||
et2-link:last-child::part(title):after {
|
::slotted(*:last-child):after {
|
||||||
content: initial;
|
content: initial;
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
@ -117,14 +112,13 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
|
|||||||
@property({type: Number})
|
@property({type: Number})
|
||||||
limit = 20;
|
limit = 20;
|
||||||
|
|
||||||
protected _totalResults : number = 0;
|
protected _link_list : LinkInfo[];
|
||||||
protected _link_list : LinkInfo[] = [];
|
protected _loadingPromise : Promise<LinkInfo[]>;
|
||||||
protected _loadingPromise : Promise<LinkInfo[]> = Promise.resolve([]);
|
|
||||||
protected _loading = false;
|
|
||||||
|
|
||||||
constructor()
|
constructor()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
this._link_list = []
|
||||||
}
|
}
|
||||||
|
|
||||||
async getUpdateComplete()
|
async getUpdateComplete()
|
||||||
@ -150,12 +144,6 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
|
|||||||
public set_value(_value : string | { to_app : string, to_id : string } | LinkInfo[])
|
public set_value(_value : string | { to_app : string, to_id : string } | LinkInfo[])
|
||||||
{
|
{
|
||||||
this._link_list = [];
|
this._link_list = [];
|
||||||
if(typeof _value["total"] !== "undefined")
|
|
||||||
{
|
|
||||||
this._totalResults = _value["total"];
|
|
||||||
delete _value["total"];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(typeof _value == "object" && !Array.isArray(_value) && !_value.to_app && this.application)
|
if(typeof _value == "object" && !Array.isArray(_value) && !_value.to_app && this.application)
|
||||||
{
|
{
|
||||||
_value.to_app = this.application;
|
_value.to_app = this.application;
|
||||||
@ -167,12 +155,7 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
|
|||||||
{
|
{
|
||||||
this.application = _value.to_app;
|
this.application = _value.to_app;
|
||||||
this.entryId = _value.to_id;
|
this.entryId = _value.to_id;
|
||||||
|
|
||||||
// Let update complete finish first, if it's not done yet
|
|
||||||
this.updateComplete.then(() =>
|
|
||||||
{
|
|
||||||
this.get_links();
|
this.get_links();
|
||||||
})
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,9 +166,9 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
|
|||||||
ids.forEach((id) => (<LinkInfo[]>this._link_list).push(<LinkInfo>{app: this.application, id: id}));
|
ids.forEach((id) => (<LinkInfo[]>this._link_list).push(<LinkInfo>{app: this.application, id: id}));
|
||||||
}
|
}
|
||||||
// List of LinkInfo
|
// List of LinkInfo
|
||||||
else if(Array.isArray(_value) || typeof _value[0] == "object")
|
else if(Array.isArray(_value))
|
||||||
{
|
{
|
||||||
this._link_list = <LinkInfo[]>Object.values(_value);
|
this._link_list = _value;
|
||||||
}
|
}
|
||||||
// List of LinkInfo stuffed into to_id - entry is not yet saved
|
// List of LinkInfo stuffed into to_id - entry is not yet saved
|
||||||
else if(_value.to_id && typeof _value.to_id !== "string")
|
else if(_value.to_id && typeof _value.to_id !== "string")
|
||||||
@ -196,7 +179,8 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
|
|||||||
this._link_list.push(<LinkInfo>_value.to_id[key]);
|
this._link_list.push(<LinkInfo>_value.to_id[key]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.requestUpdate();
|
this._addLinks(this._link_list);
|
||||||
|
super.requestUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public updated(changedProperties : PropertyValues)
|
public updated(changedProperties : PropertyValues)
|
||||||
@ -216,21 +200,20 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
|
|||||||
{
|
{
|
||||||
// This shows loading template until loadingPromise resolves, then shows _listTemplate
|
// This shows loading template until loadingPromise resolves, then shows _listTemplate
|
||||||
return html`
|
return html`
|
||||||
${until(this._loadingPromise?.then(res =>
|
${this._loadingPromise ? until(
|
||||||
|
this._loadingPromise?.then(res =>
|
||||||
{
|
{
|
||||||
return this._listTemplate();
|
this._listTemplate();
|
||||||
}),
|
}),
|
||||||
this._loadingTemplate()
|
this._loadingTemplate()
|
||||||
)}
|
) : this._listTemplate()}
|
||||||
${until(this.moreResultsTemplate(), nothing)}
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _listTemplate()
|
protected _listTemplate()
|
||||||
{
|
{
|
||||||
return html`
|
return html`
|
||||||
${repeat(this._link_list, l => l.link_id, this._linkTemplate)}
|
<slot></slot>`;
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -244,9 +227,22 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
|
|||||||
{
|
{
|
||||||
const id = typeof link.id === "string" ? link.id : link.link_id;
|
const id = typeof link.id === "string" ? link.id : link.link_id;
|
||||||
return html`
|
return html`
|
||||||
<et2-link part="link" class="et2_link"
|
<et2-link app="${link.app}" entryId="${id}" .value=${link} ._parent=${this}></et2-link>`;
|
||||||
app="${link.app}" entryId="${id}" .value=${link} ._parent=${this}
|
}
|
||||||
></et2-link>`;
|
|
||||||
|
/**
|
||||||
|
* Render "more links available"
|
||||||
|
*
|
||||||
|
* @param link
|
||||||
|
* @returns {TemplateResult}
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
protected _moreAvailableTemplate(link : LinkInfo) : TemplateResult
|
||||||
|
{
|
||||||
|
return html`
|
||||||
|
<et2-button image="${link.icon}" label="${link.title}" .onclick="${() => {
|
||||||
|
this.get_links();
|
||||||
|
}}" ._parent=${this} slot="link_exceeded"></et2-button>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -256,27 +252,7 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
|
|||||||
*/
|
*/
|
||||||
protected _loadingTemplate() : TemplateResult
|
protected _loadingTemplate() : TemplateResult
|
||||||
{
|
{
|
||||||
return html`
|
return html`loading...`;
|
||||||
<div class="search__loading">
|
|
||||||
<sl-spinner></sl-spinner>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async moreResultsTemplate()
|
|
||||||
{
|
|
||||||
if(this._totalResults <= 0 || !this._loadingPromise)
|
|
||||||
{
|
|
||||||
return nothing;
|
|
||||||
}
|
|
||||||
return this._loadingPromise.then(() =>
|
|
||||||
{
|
|
||||||
const moreCount = this._totalResults - this._link_list.length;
|
|
||||||
const more = html`
|
|
||||||
<et2-description statustext="${this.egw().lang("%1 more...", moreCount)}">...
|
|
||||||
</et2-description>`;
|
|
||||||
return html`${moreCount > 0 ? more : nothing}`;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -288,7 +264,6 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
|
|||||||
*/
|
*/
|
||||||
protected _addLinks(links : LinkInfo[])
|
protected _addLinks(links : LinkInfo[])
|
||||||
{
|
{
|
||||||
return;
|
|
||||||
// Remove anything there right now
|
// Remove anything there right now
|
||||||
while(this.lastChild)
|
while(this.lastChild)
|
||||||
{
|
{
|
||||||
@ -298,7 +273,7 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
|
|||||||
links.forEach((link) =>
|
links.forEach((link) =>
|
||||||
{
|
{
|
||||||
let temp = document.createElement("div");
|
let temp = document.createElement("div");
|
||||||
render(this._linkTemplate(link), temp);
|
render(link.app === 'exceeded' ? this._moreAvailableTemplate(link) : this._linkTemplate(link), temp);
|
||||||
temp.childNodes.forEach((node) => this.appendChild(node));
|
temp.childNodes.forEach((node) => this.appendChild(node));
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -322,15 +297,8 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
|
|||||||
* Called internally to fetch the list. May be called externally to trigger a refresh if a link is added.
|
* Called internally to fetch the list. May be called externally to trigger a refresh if a link is added.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public get_links(not_saved_links? : LinkInfo[], offset = 0)
|
public get_links(not_saved_links? : LinkInfo[])
|
||||||
{
|
{
|
||||||
if(this._loading)
|
|
||||||
{
|
|
||||||
// Already waiting
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._loading = true;
|
|
||||||
|
|
||||||
if(typeof not_saved_links === "undefined")
|
if(typeof not_saved_links === "undefined")
|
||||||
{
|
{
|
||||||
not_saved_links = [];
|
not_saved_links = [];
|
||||||
@ -340,31 +308,31 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
|
|||||||
to_id: this.entryId,
|
to_id: this.entryId,
|
||||||
only_app: this.onlyApp,
|
only_app: this.onlyApp,
|
||||||
show_deleted: this.showDeleted,
|
show_deleted: this.showDeleted,
|
||||||
limit: [offset, /* num_rows: */this.limit]
|
limit: this.limit
|
||||||
};
|
};
|
||||||
|
this.limit *= 2; // double number of loaded links on next call
|
||||||
|
|
||||||
|
if(this._loadingPromise)
|
||||||
|
{
|
||||||
|
// Already waiting
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this._loadingPromise = <Promise<LinkInfo[]>>(this.egw().jsonq('EGroupware\\Api\\Etemplate\\Widget\\Link::ajax_link_list', [_value]))
|
this._loadingPromise = <Promise<LinkInfo[]>>(this.egw().jsonq('EGroupware\\Api\\Etemplate\\Widget\\Link::ajax_link_list', [_value]))
|
||||||
.then(_value =>
|
.then(_value =>
|
||||||
{
|
{
|
||||||
if(typeof _value.total)
|
if(_value && Array.isArray(_value))
|
||||||
{
|
{
|
||||||
this._totalResults = _value.total;
|
for(let link of <LinkInfo[]>_value)
|
||||||
delete _value.total;
|
|
||||||
}
|
|
||||||
if(_value)
|
|
||||||
{
|
{
|
||||||
for(let link of <LinkInfo[]>Object.values(_value))
|
if(!not_saved_links.some(l => l.app == link.app && l.id == link.id))
|
||||||
{
|
{
|
||||||
// Avoid duplicates, files are always sent
|
not_saved_links.push(link);
|
||||||
if(!not_saved_links.some(l => l.app == link.app && l.id == link.id) &&
|
|
||||||
!this._link_list.some(l => l.app == link.app && l.id == link.id))
|
|
||||||
{
|
|
||||||
this._link_list.push(link);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._loading = false;
|
this._addLinks(not_saved_links);
|
||||||
this.requestUpdate();
|
this._loadingPromise = null;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,7 +351,6 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
|
|||||||
for(let k in _values)
|
for(let k in _values)
|
||||||
{
|
{
|
||||||
this[k] = _values[k];
|
this[k] = _values[k];
|
||||||
this.requestUpdate(k);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user