Et2VfsSelectDialog: Include total results and "# more..." indicator

This commit is contained in:
nathan 2024-02-21 10:14:03 -07:00
parent e35947875b
commit b5179cac22
3 changed files with 34 additions and 2 deletions

View File

@ -46,6 +46,10 @@ export default css`
margin-top: auto; margin-top: auto;
} }
.vfs_select__listbox .more {
text-align: center;
}
.vfs_select__mimefilter { .vfs_select__mimefilter {
flex: 0 0; flex: 0 0;
} }

View File

@ -133,6 +133,7 @@ export class Et2VfsSelectDialog extends Et2InputWidget(LitElement) implements Se
protected _searchTimeout : number; protected _searchTimeout : number;
protected _searchPromise : Promise<FileInfo[]> = Promise.resolve([]); protected _searchPromise : Promise<FileInfo[]> = Promise.resolve([]);
private static SEARCH_TIMEOUT : number = 500; private static SEARCH_TIMEOUT : number = 500;
private _total_result_count : number = 0;
// Still need some server-side info // Still need some server-side info
protected _serverContent : Promise<any> = Promise.resolve({}); protected _serverContent : Promise<any> = Promise.resolve({});
@ -331,6 +332,7 @@ export class Et2VfsSelectDialog extends Et2InputWidget(LitElement) implements Se
// Stop timeout timer // Stop timeout timer
clearTimeout(this._searchTimeout); clearTimeout(this._searchTimeout);
this._total_result_count = 0;
this.searching = true; this.searching = true;
this.requestUpdate("searching"); this.requestUpdate("searching");
@ -376,6 +378,10 @@ export class Et2VfsSelectDialog extends Et2InputWidget(LitElement) implements Se
this._pathWritable = results.writable; this._pathWritable = results.writable;
this.requestUpdate("_pathWritable"); this.requestUpdate("_pathWritable");
} }
if(typeof results.total !== "undefined")
{
this._total_result_count = results.total;
}
this.helpText = results?.message ?? ""; this.helpText = results?.message ?? "";
this._fileList = results?.files ?? []; this._fileList = results?.files ?? [];
@ -841,7 +847,9 @@ export class Et2VfsSelectDialog extends Et2InputWidget(LitElement) implements Se
@dblclick=${this.handleFileDoubleClick} @dblclick=${this.handleFileDoubleClick}
></et2-vfs-select-row>`; ></et2-vfs-select-row>`;
} }
)}` )}
${until(this.moreResultsTemplate(), nothing)}
`
}`; }`;
}); });
return html` return html`
@ -860,6 +868,23 @@ export class Et2VfsSelectDialog extends Et2InputWidget(LitElement) implements Se
</div>`; </div>`;
} }
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`
<div class="more">${more}</div>` : nothing}`;
});
}
protected mimeOptionsTemplate() protected mimeOptionsTemplate()
{ {
return html``; return html``;

View File

@ -636,11 +636,13 @@ class Vfs extends File
$files = []; $files = [];
} }
} }
$response['total'] = $content['total'] ?? count($response['files']);
foreach($files as $path) foreach($files as $path)
{ {
if(is_string($path) && $path == $content['path'] || is_array($path) && $path['path'] == $content['path']) if(is_string($path) && $path == $content['path'] || is_array($path) && $path['path'] == $content['path'])
{ {
// remove directory itself // remove directory itself
$response['total']--;
continue; continue;
} }
$name = $path['name'] ?? Api\Vfs::basename($path); $name = $path['name'] ?? Api\Vfs::basename($path);
@ -660,7 +662,7 @@ class Vfs extends File
Json\Response::get()->data($response); Json\Response::get()->data($response);
} }
private static function filesFromVfs($search, $params) private static function filesFromVfs($search, &$params)
{ {
$vfs_options = array( $vfs_options = array(
'dirsontop' => true, 'dirsontop' => true,
@ -688,6 +690,7 @@ class Vfs extends File
$vfs_options['limit'] = (int)$params['num_rows']; $vfs_options['limit'] = (int)$params['num_rows'];
} }
$files = Api\Vfs::find($params['path'], $vfs_options); $files = Api\Vfs::find($params['path'], $vfs_options);
$params['total'] = Api\Vfs::$find_total;
return array_merge($dirs, $files); return array_merge($dirs, $files);
} }