From b5179cac228a33e9ce19ec452b321c75502d5ea9 Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 21 Feb 2024 10:14:03 -0700 Subject: [PATCH] Et2VfsSelectDialog: Include total results and "# more..." indicator --- .../etemplate/Et2Vfs/Et2VfsSelect.styles.ts | 4 +++ api/js/etemplate/Et2Vfs/Et2VfsSelectDialog.ts | 27 ++++++++++++++++++- api/src/Etemplate/Widget/Vfs.php | 5 +++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/api/js/etemplate/Et2Vfs/Et2VfsSelect.styles.ts b/api/js/etemplate/Et2Vfs/Et2VfsSelect.styles.ts index a75ff301da..8a06b7f3fc 100644 --- a/api/js/etemplate/Et2Vfs/Et2VfsSelect.styles.ts +++ b/api/js/etemplate/Et2Vfs/Et2VfsSelect.styles.ts @@ -46,6 +46,10 @@ export default css` margin-top: auto; } + .vfs_select__listbox .more { + text-align: center; + } + .vfs_select__mimefilter { flex: 0 0; } diff --git a/api/js/etemplate/Et2Vfs/Et2VfsSelectDialog.ts b/api/js/etemplate/Et2Vfs/Et2VfsSelectDialog.ts index 3d05a27f0d..d8be91664e 100644 --- a/api/js/etemplate/Et2Vfs/Et2VfsSelectDialog.ts +++ b/api/js/etemplate/Et2Vfs/Et2VfsSelectDialog.ts @@ -133,6 +133,7 @@ export class Et2VfsSelectDialog extends Et2InputWidget(LitElement) implements Se protected _searchTimeout : number; protected _searchPromise : Promise = Promise.resolve([]); private static SEARCH_TIMEOUT : number = 500; + private _total_result_count : number = 0; // Still need some server-side info protected _serverContent : Promise = Promise.resolve({}); @@ -331,6 +332,7 @@ export class Et2VfsSelectDialog extends Et2InputWidget(LitElement) implements Se // Stop timeout timer clearTimeout(this._searchTimeout); + this._total_result_count = 0; this.searching = true; this.requestUpdate("searching"); @@ -376,6 +378,10 @@ export class Et2VfsSelectDialog extends Et2InputWidget(LitElement) implements Se this._pathWritable = results.writable; this.requestUpdate("_pathWritable"); } + if(typeof results.total !== "undefined") + { + this._total_result_count = results.total; + } this.helpText = results?.message ?? ""; this._fileList = results?.files ?? []; @@ -841,7 +847,9 @@ export class Et2VfsSelectDialog extends Et2InputWidget(LitElement) implements Se @dblclick=${this.handleFileDoubleClick} >`; } - )}` + )} + ${until(this.moreResultsTemplate(), nothing)} + ` }`; }); return html` @@ -860,6 +868,23 @@ export class Et2VfsSelectDialog extends Et2InputWidget(LitElement) implements Se `; } + protected async moreResultsTemplate() + { + if(this._total_result_count <= 0 || !this._searchPromise || !this._listNode) + { + return nothing; + } + return this._searchPromise.then(() => + { + const moreCount = this._total_result_count - this._fileList.length; + const more = this.egw().lang("%1 more...", moreCount); + + return html`${moreCount > 0 ? + html` +
${more}
` : nothing}`; + }); + } + protected mimeOptionsTemplate() { return html``; diff --git a/api/src/Etemplate/Widget/Vfs.php b/api/src/Etemplate/Widget/Vfs.php index deb81bef2a..47a57fbdc1 100644 --- a/api/src/Etemplate/Widget/Vfs.php +++ b/api/src/Etemplate/Widget/Vfs.php @@ -636,11 +636,13 @@ class Vfs extends File $files = []; } } + $response['total'] = $content['total'] ?? count($response['files']); foreach($files as $path) { if(is_string($path) && $path == $content['path'] || is_array($path) && $path['path'] == $content['path']) { // remove directory itself + $response['total']--; continue; } $name = $path['name'] ?? Api\Vfs::basename($path); @@ -660,7 +662,7 @@ class Vfs extends File Json\Response::get()->data($response); } - private static function filesFromVfs($search, $params) + private static function filesFromVfs($search, &$params) { $vfs_options = array( 'dirsontop' => true, @@ -688,6 +690,7 @@ class Vfs extends File $vfs_options['limit'] = (int)$params['num_rows']; } $files = Api\Vfs::find($params['path'], $vfs_options); + $params['total'] = Api\Vfs::$find_total; return array_merge($dirs, $files); }