From edcc260b7bb3454152e06ccc13112df6ac05a8b2 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 24 Jul 2023 15:12:45 -0600 Subject: [PATCH] WIP on caching static option file and searching it client-side Get it working in nextmatch --- .../etemplate/Et2Select/Et2SelectReadonly.ts | 24 ++++++++++++------- .../etemplate/et2_extension_customfields.ts | 2 +- api/js/etemplate/et2_extension_nextmatch.ts | 2 +- api/src/Etemplate/Widget/Customfields.php | 10 ++++++-- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/api/js/etemplate/Et2Select/Et2SelectReadonly.ts b/api/js/etemplate/Et2Select/Et2SelectReadonly.ts index 79323edd18..e47d5b11dd 100644 --- a/api/js/etemplate/Et2Select/Et2SelectReadonly.ts +++ b/api/js/etemplate/Et2Select/Et2SelectReadonly.ts @@ -46,7 +46,8 @@ li { return { ...super.properties, value: String, - select_options: {type: Array} + select_options: {type: Array}, + searchUrl: String // Used for options from file } } @@ -64,12 +65,16 @@ li { public async getUpdateComplete() { - const result = await super.getUpdateComplete(); if(this.__fetchComplete) { + const response = await super.getUpdateComplete(); await this.__fetchComplete; + return response; + } + else + { + return super.getUpdateComplete(); } - return result; } protected find_select_options(_attrs) @@ -81,13 +86,14 @@ li { } // Cache options from file - if(_attrs.searchUrl && _attrs.searchUrl.includes(".json") && this.__fetchComplete == null) + if(this.searchUrl && this.searchUrl.includes(".json") && this.__fetchComplete == null) { - this.__fetchComplete = StaticOptions.cached_from_file(this, _attrs.searchUrl).then(options => - { - this.select_options = options; - this.requestUpdate(); - }); + this.__fetchComplete = StaticOptions.cached_from_file(this, this.searchUrl) + .then(options => + { + this.select_options = options; + this.requestUpdate(); + }); } } diff --git a/api/js/etemplate/et2_extension_customfields.ts b/api/js/etemplate/et2_extension_customfields.ts index 3aef1872af..4769446566 100644 --- a/api/js/etemplate/et2_extension_customfields.ts +++ b/api/js/etemplate/et2_extension_customfields.ts @@ -617,7 +617,7 @@ export class et2_customfields_list extends et2_valueWidget implements et2_IDetac if(field.values && field.values["@"]) { // Options are in a list stored in a file - attrs.searchUrl = this.egw().webserverUrl + '/webdav.php' + field.values["@"]; + attrs.searchUrl = field.values["@"]; } return true; } diff --git a/api/js/etemplate/et2_extension_nextmatch.ts b/api/js/etemplate/et2_extension_nextmatch.ts index c9b658b4ac..bb041f6510 100644 --- a/api/js/etemplate/et2_extension_nextmatch.ts +++ b/api/js/etemplate/et2_extension_nextmatch.ts @@ -4196,7 +4196,7 @@ export class et2_nextmatch_customfields extends et2_customfields_list implements }; if(field.values["@"]) { - attrs.searchUrl = this.egw().webserverUrl + '/webdav.php' + field.values["@"]; + attrs.searchUrl = field.values["@"]; } widget = loadWebComponent( field.type == 'select-account' ? 'et2-nextmatch-header-account' : "et2-nextmatch-header-filter", diff --git a/api/src/Etemplate/Widget/Customfields.php b/api/src/Etemplate/Widget/Customfields.php index 6a2e48b4a7..15bd691af8 100644 --- a/api/src/Etemplate/Widget/Customfields.php +++ b/api/src/Etemplate/Widget/Customfields.php @@ -245,9 +245,15 @@ class Customfields extends Transformer if (!empty($data['values'])) { // Full URL for options from file - if(!empty($data['values']['@'])) + if(!empty($data['values']['@']) && strpos($data['values']['@'], '/') == 0 && !str_contains($data['values']['@'], 'webdav.php') && + $stat = Api\Vfs::stat($data['values']['@']) + ) { - $fields[$data['name']]['values']['@'] = Api\Framework::link(Api\Vfs::download_url($data['values']['@'])); + + $data['values']['@'] = $fields[$data['name']]['values']['@'] = Api\Framework::link( + Api\Vfs::download_url($data['values']['@']), + ['download' => $stat['mtime']] + ); } Select::fix_encoded_options($data['values']); }