Skip to content

Commit

Permalink
* All apps: limit number of loaded links to 20 and showing a load mor…
Browse files Browse the repository at this point in the history
…e button, if more are available
  • Loading branch information
ralfbecker committed Sep 24, 2024
1 parent a151367 commit 3fbf2e9
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 56 deletions.
124 changes: 71 additions & 53 deletions api/js/etemplate/Et2Link/Et2LinkString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import {css, html, LitElement, PropertyValues, render, TemplateResult} from "lit";
import {until} from "lit/directives/until.js";
import {Et2Widget} from "../Et2Widget/Et2Widget";
import {Et2Link, LinkInfo} from "./Et2Link";
import {LinkInfo} from "./Et2Link";
import {et2_IDetachedDOM} from "../et2_core_interfaces";
import {property} from "lit/decorators/property.js";
import {customElement} from "lit/decorators/custom-element.js";

/**
* Display a list of entries in a comma separated list
Expand All @@ -25,6 +27,7 @@ import {et2_IDetachedDOM} from "../et2_core_interfaces";
*/

// @ts-ignore TypeScript says there's something wrong with types
@customElement('et2-link-string')
export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetachedDOM
{

Expand Down Expand Up @@ -62,52 +65,52 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
}


static get properties()
{
return {
...super.properties,
/**
* Specify the application for all the entries, so you only need to specify the entry ID
*/
application: {
type: String,
reflect: true,
},
/**
* Application entry ID
*/
entryId: {
type: String,
reflect: true
},
/**
* Application filter
* Set to an appname or comma separated list of applications to show only linked entries from those
* applications
*/
onlyApp: {
type: String
},
/**
* Type filter
* Sub-type key to list only entries of that type
*/
linkType: {
type: String
},

// Show links that are marked as deleted, being held for purge
showDeleted: {type: Boolean},

/**
* Pass value as an object, will be parsed to set application & entryId
*/
value: {
type: Object,
reflect: false
}
}
}
/**
* Specify the application for all the entries, so you only need to specify the entry ID
*/
@property({ type: String, reflect: true })
application;

/**
* Application entry ID
*/
@property({type: String, reflect: true})
entryId;

/**
* Application filter
* Set to an appname or comma separated list of applications to show only linked entries from those
* applications
*/
@property({type: String})
onlyApp;

/**
* Type filter
* Sub-type key to list only entries of that type
*/
@property({type: String})
linkType;

/**
* Show links that are marked as deleted, being held for purge
*/
@property({type: Boolean})
showDeleted = false;

/**
* Pass value as an object, will be parsed to set application & entryId
*/
@property({type: Object})
value;

/**
* Number of application-links to load (file-links are always fully loaded currently)
*
* If number is exceeded, a "Load more links ..." button is displayed, which will load the double amount of links each time clicked
*/
@property({type: Number})
limit = 20;

protected _link_list : LinkInfo[];
protected _loadingPromise : Promise<LinkInfo[]>;
Expand All @@ -116,7 +119,6 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
{
super();
this._link_list = []
this.__showDeleted = false;
}

async getUpdateComplete()
Expand Down Expand Up @@ -228,6 +230,21 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
<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>`;
}

/**
* Render that we're waiting for data
* @returns {TemplateResult}
Expand Down Expand Up @@ -256,7 +273,7 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
links.forEach((link) =>
{
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));
})

Expand Down Expand Up @@ -290,8 +307,11 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
to_app: this.application,
to_id: this.entryId,
only_app: this.onlyApp,
show_deleted: this.showDeleted
show_deleted: this.showDeleted,
limit: this.limit
};
this.limit *= 2; // double number of loaded links on next call

if(this._loadingPromise)
{
// Already waiting
Expand Down Expand Up @@ -333,6 +353,4 @@ export class Et2LinkString extends Et2Widget(LitElement) implements et2_IDetache
this[k] = _values[k];
}
}
};

customElements.define("et2-link-string", Et2LinkString);
}
2 changes: 1 addition & 1 deletion api/lang/egw_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
%1 email addresses inserted common de %1 E-Mail-Adressen eingefügt.
%1 email(s) added into %2 common de %1 E-Mail-Adresse(n) in %2 hinzugefügt
%1 etemplates deleted common de %1 eTemplate(s) gelöscht
%1 etemplates for application '%2' dumped to '%3' common de %1 eTemplate(s) für die Anwendung '%2' nach '%3' geschrieben
%1 etemplates found common de %1 eTemplate(s) gefunden.
%1 file common de %1 Datei
%1 is not executable by the webserver !!! common de %1 ist nicht ausführbar durch den Webserver!
Expand Down Expand Up @@ -819,6 +818,7 @@ list members common de Mitglieder anzeigen
list of files linked to the current record preferences de Liste der Dokumente, die zu dem aktuellen Datensatz gehören.
lithuania common de LITAUEN
load common de Daten werden geladen
load more links ... common de Weitere Verknüpfungen laden ...
load this template into the editor common de Lädt diese Template zum Bearbeiten
loading common de Lade
local common de Lokal
Expand Down
1 change: 1 addition & 0 deletions api/lang/egw_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ list members common en List members
list of files linked to the current record preferences en List of files linked to the current record
lithuania common en LITHUANIA
load common en Load
load more links ... common en Load more links ...
load this template into the editor common en Load template to the editor
loading common en Loading
local common en Local
Expand Down
12 changes: 11 additions & 1 deletion api/src/Etemplate/Widget/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ public static function ajax_link_list($value)
$app = $value['to_app'];
$id = $value['to_id'];

$links = Api\Link::get_links($app, $id, $value['only_app'], 'link_lastmod DESC', true, $value['show_deleted']);
$links = Api\Link::get_links($app, $id, $value['only_app'] ?? '', 'link_lastmod DESC', true, $value['show_deleted'], $value['limit'] ?? null);
$limit_exceeded = !empty($value['limit']) && Api\Link::$limit_exceeded;
$only_links = [];
if($value['only_app'])
{
Expand Down Expand Up @@ -243,6 +244,15 @@ public static function ajax_link_list($value)
$link['help'] = lang('Remove this link (not the entry itself)');
}
}
if ($limit_exceeded)
{
$links[] = [
'app' => 'exceeded',
'id' => 'exceeded',
'title' => lang('Load more links ...'),
'icon' => 'box-arrow-down',
];
}

$response = Api\Json\Response::get();
// Strip keys, unneeded and cause index problems on the client side
Expand Down
4 changes: 3 additions & 1 deletion api/src/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ static function get_links($app, $id, $only_app='', $order='link_lastmod DESC',$c
return $ids;
}
$ids = Link\Storage::get_links($app, $id, $only_app, $order, $deleted, $limit);
$limit_exceeded = self::$limit_exceeded;
if (empty($only_app) || $only_app == self::VFS_APPNAME ||
($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME))
{
Expand All @@ -533,7 +534,7 @@ static function get_links($app, $id, $only_app='', $order='link_lastmod DESC',$c
//echo "ids=<pre>"; print_r($ids); echo "</pre>\n";
if ($cache_titles)
{
// agregate links by app
// aggregate links by app
$app_ids = array();
foreach($ids as $link)
{
Expand All @@ -553,6 +554,7 @@ static function get_links($app, $id, $only_app='', $order='link_lastmod DESC',$c
}
reset($ids);
}
self::$limit_exceeded = $limit_exceeded;
return $ids;
}

Expand Down

0 comments on commit 3fbf2e9

Please sign in to comment.