From 10fc2390f6c79937695c9a77a1bd544f80c27805 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 14 Mar 2023 13:56:59 -0600 Subject: [PATCH] Home: Pull favorite list live client-side Also IDE now understands we can't call abstract __construct --- home/inc/class.home_birthday_portlet.inc.php | 17 ++++++------ home/inc/class.home_favorite_portlet.inc.php | 15 +--------- home/inc/class.home_legacy_portlet.inc.php | 1 - home/inc/class.home_link_portlet.inc.php | 2 -- home/inc/class.home_list_portlet.inc.php | 2 -- home/inc/class.home_note_portlet.inc.php | 2 -- home/inc/class.home_weather_portlet.inc.php | 2 -- home/js/Et2PortletFavorite.ts | 29 ++++++++++++++++++++ 8 files changed, 38 insertions(+), 32 deletions(-) diff --git a/home/inc/class.home_birthday_portlet.inc.php b/home/inc/class.home_birthday_portlet.inc.php index 077219eabe..810bbb9b14 100644 --- a/home/inc/class.home_birthday_portlet.inc.php +++ b/home/inc/class.home_birthday_portlet.inc.php @@ -32,7 +32,6 @@ use EGroupware\Api\Etemplate; public function __construct(Array &$context = array(), &$need_reload = false) { unset($need_reload); // not used, but required by function signature - if (false) parent::__construct(); $this->context = $context; } @@ -177,15 +176,15 @@ use EGroupware\Api\Etemplate; $properties = parent::get_properties(); $properties[] = array( - 'name' => 'days', - 'type' => 'listbox', - 'label' => '', - 'default' => 3, + 'name' => 'days', + 'type' => 'et2-selectbox', + 'label' => '', + 'default' => 3, 'select_options' => array( - 1 => lang('Yes, for today and tomorrow'), - 3 => lang('Yes, for the next three days'), - 7 => lang('Yes, for the next week'), - 14=> lang('Yes, for the next two weeks'), + 1 => lang('Yes, for today and tomorrow'), + 3 => lang('Yes, for the next three days'), + 7 => lang('Yes, for the next week'), + 14 => lang('Yes, for the next two weeks'), ), ); return $properties; diff --git a/home/inc/class.home_favorite_portlet.inc.php b/home/inc/class.home_favorite_portlet.inc.php index 278440742c..14eb15125f 100644 --- a/home/inc/class.home_favorite_portlet.inc.php +++ b/home/inc/class.home_favorite_portlet.inc.php @@ -59,8 +59,6 @@ class home_favorite_portlet extends home_portlet */ public function __construct(Array &$context = array(), &$need_reload = false) { - if (false) parent::__construct(); - // Process dropped data (Should be [appname => , id => ]) into something useable if($context['dropped_data']) { @@ -235,18 +233,7 @@ class home_favorite_portlet extends home_portlet public function get_properties() { $properties = parent::get_properties(); - $favorites = Framework\Favorites::get_favorites($this->context['appname']); - $favorite_list = array(); - foreach($favorites as $id => $favorite) - { - if($favorite) - { - $favorite_list[] = array( - 'value' => $id, - 'label' => $favorite['name'] - ); - } - } + $favorite = array( 'label' => lang('Favorite'), 'name' => 'favorite', diff --git a/home/inc/class.home_legacy_portlet.inc.php b/home/inc/class.home_legacy_portlet.inc.php index 8800500402..1cb002749b 100644 --- a/home/inc/class.home_legacy_portlet.inc.php +++ b/home/inc/class.home_legacy_portlet.inc.php @@ -35,7 +35,6 @@ class home_legacy_portlet extends home_portlet public function __construct(array &$context = array(), &$need_reload = false) { unset($need_reload); // not used, but required by function signature - if (false) parent::__construct(); $this->context = $context; diff --git a/home/inc/class.home_link_portlet.inc.php b/home/inc/class.home_link_portlet.inc.php index dc4b68f30f..83bff2a42c 100644 --- a/home/inc/class.home_link_portlet.inc.php +++ b/home/inc/class.home_link_portlet.inc.php @@ -51,8 +51,6 @@ class home_link_portlet extends home_portlet */ public function __construct(Array &$context = array(), &$need_reload = false) { - if (false) parent::__construct(); - // Process dropped data into something useable if($context['dropped_data']) { diff --git a/home/inc/class.home_list_portlet.inc.php b/home/inc/class.home_list_portlet.inc.php index 13a432f298..2a1500196d 100644 --- a/home/inc/class.home_list_portlet.inc.php +++ b/home/inc/class.home_list_portlet.inc.php @@ -40,8 +40,6 @@ class home_list_portlet extends home_portlet */ public function __construct(Array &$context = array(), &$need_reload = false) { - if (false) parent::__construct(); - if(!is_array($context['list'])) $context['list'] = array(); // Process dropped data (Should be GUIDs) into something useable diff --git a/home/inc/class.home_note_portlet.inc.php b/home/inc/class.home_note_portlet.inc.php index 280dc11448..72eeb5e495 100644 --- a/home/inc/class.home_note_portlet.inc.php +++ b/home/inc/class.home_note_portlet.inc.php @@ -32,8 +32,6 @@ class home_note_portlet extends home_portlet */ public function __construct(Array &$context = array(), &$need_reload = false) { - if (false) parent::__construct(); - // Title not set for new widgets created via context menu if(!$context['title']) { diff --git a/home/inc/class.home_weather_portlet.inc.php b/home/inc/class.home_weather_portlet.inc.php index 91c5ad97de..35b5529a28 100644 --- a/home/inc/class.home_weather_portlet.inc.php +++ b/home/inc/class.home_weather_portlet.inc.php @@ -35,8 +35,6 @@ class home_weather_portlet extends home_portlet */ public function __construct(Array &$context = array(), &$need_reload = false) { - if (false) parent::__construct(); - // City not set for new widgets created via context menu if(!$context['city']) { diff --git a/home/js/Et2PortletFavorite.ts b/home/js/Et2PortletFavorite.ts index 09d304931e..5851729d73 100644 --- a/home/js/Et2PortletFavorite.ts +++ b/home/js/Et2PortletFavorite.ts @@ -2,6 +2,8 @@ import {Et2Portlet} from "../../api/js/etemplate/Et2Portlet/Et2Portlet"; import {classMap, css, html} from "@lion/core"; import shoelace from "../../api/js/etemplate/Styles/shoelace"; import {etemplate2} from "../../api/js/etemplate/etemplate2"; +import type {SelectOption} from "../../api/js/etemplate/Et2Select/FindSelectOptions"; +import {Et2Favorites} from "../../api/js/etemplate/Et2Favorites/Et2Favorites"; export class Et2PortletFavorite extends Et2Portlet { @@ -34,6 +36,33 @@ export class Et2PortletFavorite extends Et2Portlet this.classList.add("header_hidden"); } + /** + * Get a list of user-configurable properties + * @returns {[{name : string, type : string, select_options? : [SelectOption]}]} + */ + get portletProperties() : { name : string, type : string, label : string, select_options? : SelectOption[] }[] + { + // Default blank filter + let favorites = [ + {value: 'blank', label: this.egw().lang("No filters")} + ]; + + // Load favorites + let preferences : any = this.egw().preference("*", this.settings.appname); + for(let pref_name in preferences) + { + if(pref_name.indexOf(Et2Favorites.PREFIX) == 0 && typeof preferences[pref_name] == 'object') + { + let name = pref_name.substr(Et2Favorites.PREFIX.length); + favorites.push({value: name, label: preferences[pref_name]['name']}); + } + } + return [ + ...super.portletProperties, + {name: "favorite", type: "et2-select", label: "Favorite", select_options: favorites} + ] + } + headerTemplate() { const hidden = this.classList.contains("header_hidden");