From 43873af7bc14a3345f3b0ee02d8ede6876297e9d Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 14 Apr 2023 10:28:16 -0600 Subject: [PATCH] Add implicit preference to remember user's last sort order. Sort stored in favorites override this when the favorite is used. --- api/js/etemplate/et2_extension_nextmatch.ts | 4 ++++ api/src/Etemplate/Widget/Nextmatch.php | 22 +++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/api/js/etemplate/et2_extension_nextmatch.ts b/api/js/etemplate/et2_extension_nextmatch.ts index cc638698d6..fc5c277947 100644 --- a/api/js/etemplate/et2_extension_nextmatch.ts +++ b/api/js/etemplate/et2_extension_nextmatch.ts @@ -4347,6 +4347,10 @@ export class et2_nextmatch_sortheader extends et2_nextmatch_header implements et { // Send default sort mode if not sorted, otherwise send undefined to calculate this.nextmatch.sortBy(this.id, this.sortmode == "none" ? !(this.options.sortmode.toUpperCase() == "DESC") : undefined); + + // Update sort preference + this.egw().set_preference(this.nextmatch._get_appname(), this.nextmatch.options.template + "_sort", this.nextmatch.activeFilters["sort"]); + return true; } diff --git a/api/src/Etemplate/Widget/Nextmatch.php b/api/src/Etemplate/Widget/Nextmatch.php index 526c112eeb..e370919795 100644 --- a/api/src/Etemplate/Widget/Nextmatch.php +++ b/api/src/Etemplate/Widget/Nextmatch.php @@ -120,7 +120,7 @@ class Nextmatch extends Etemplate\Widget $value = self::get_array(self::$request->content, $form_name, true); $value['start'] = 0; - if(!array_key_exists('num_rows',$value)) + if(!array_key_exists('num_rows', $value)) { $value['num_rows'] = self::INITIAL_ROWS; } @@ -129,24 +129,30 @@ class Nextmatch extends Etemplate\Widget $send_value = $value; - list($app) = explode('.',$value['get_rows']); - if (empty($GLOBALS['egw_info']['apps'][$app])) + list($app) = explode('.', $value['get_rows']); + if(empty($GLOBALS['egw_info']['apps'][$app])) { - list($app) = explode('.',$this->attrs['template']); + list($app) = explode('.', $this->attrs['template']); + } + + // Check for sort preference. We only apply this on first load so it can be changed + if($GLOBALS['egw_info']['user']['preferences'][$app][$this->attrs['template'] . "_sort"]) + { + $send_value['sort'] = $GLOBALS['egw_info']['user']['preferences'][$app][$this->attrs['template'] . "_sort"]; } // Check for a favorite in URL - if (!empty($_GET['favorite']) && !empty($value['favorites'])) + if(!empty($_GET['favorite']) && !empty($value['favorites'])) { - $safe_name = preg_replace('/[^A-Za-z0-9-_]/','_',strip_tags($_GET['favorite'])); - $pref_name = "favorite_" .$safe_name; + $safe_name = preg_replace('/[^A-Za-z0-9-_]/', '_', strip_tags($_GET['favorite'])); + $pref_name = "favorite_" . $safe_name; // Do some easy applying of filters server side $favorite = $GLOBALS['egw_info']['user']['preferences'][$app][$pref_name]; if(!$favorite && $_GET['favorite'] == 'blank') { // Have to go through each of these - foreach(array('search','cat_id','filter','filter2') as $filter) + foreach(array('search', 'cat_id', 'filter', 'filter2') as $filter) { $send_value[$filter] = ''; }