From 5798e960a2d0d1952c55ba52e73ad65b8d1f3558 Mon Sep 17 00:00:00 2001 From: chfhtw Date: Mon, 27 Apr 2026 09:37:17 +0200 Subject: [PATCH] Use config update for widgets as intended instead of a proprietary solution --- .../controllers/api/frontend/v1/Bookmark.php | 139 ------------------ .../models/dashboard/Bookmark_model.php | 63 -------- public/js/api/factory/widget/bookmark.js | 25 ---- public/js/components/DashboardWidget/Url.js | 100 +++---------- 4 files changed, 17 insertions(+), 310 deletions(-) diff --git a/application/controllers/api/frontend/v1/Bookmark.php b/application/controllers/api/frontend/v1/Bookmark.php index 4482159db..e152907b3 100644 --- a/application/controllers/api/frontend/v1/Bookmark.php +++ b/application/controllers/api/frontend/v1/Bookmark.php @@ -33,10 +33,6 @@ class Bookmark extends FHCAPI_Controller 'update' => self::PERM_LOGGED, 'changeOrder' => self::PERM_LOGGED, 'getAllBookmarkTags' => self::PERM_LOGGED, - 'getTagFilter' => self::PERM_LOGGED, - 'addAndUpdateTagFilter' => self::PERM_LOGGED, - 'isInOverride' => self::PERM_LOGGED, - 'addWidgetToOverride' => self::PERM_LOGGED, ]); $this->load->model('dashboard/Bookmark_model', 'BookmarkModel'); @@ -188,140 +184,5 @@ class Bookmark extends FHCAPI_Controller $this->terminateWithSuccess(current($bookmarks)); } - - /** - * get all tagFilter of a certain bookmark widget - * @access public - * @return void - */ - public function getTagFilter($widgetId, $sectionName) - { - $result = $this->BookmarkModel->getTagFilter($widgetId, $this->uid, $sectionName); - $data = $this->getDataOrTerminateWithError($result); - - $this->terminateWithSuccess(current($data)); - } - /** - * get all tagFilter of a certain bookmark widget - * @access public - * @return void - */ - public function addAndUpdateTagFilter($widgetId, $sectionName) - { - $tags = $this->input->post('tags',true); - if (is_array($tags)) - { - $tags = json_encode($tags); - } - $result = $this->BookmarkModel->addAndUpdateTagFilter($widgetId, $this->uid, $sectionName, $tags); - - $data = $this->getDataOrTerminateWithError($result); - - $this->terminateWithSuccess($data); - } - - /** - * checks if a widget has already an entry in the benutzeroverride - * @access public - * @return void - */ - public function isInOverride($widgetId, $sectionName) - { - $result = $this->BookmarkModel->checkOrAddToOverride($widgetId, $this->uid, $sectionName); - - $data = getData($result); - if(!$data) - $this->terminateWithSuccess([false, 0]); - - $id = current($data)->widgetid; - $id = trim($id, '"'); - - if ($id != $widgetId) - $this->terminateWithSuccess([false, 1]); - else - $this->terminateWithSuccess([true, null]); - } - /** - * adds widget benutzeroverride - * @access public - * @return void - */ - public function addWidgetToOverride($widgetId, $sectionName, $mode, $x, $y, $h, $w) - { - $this->load->library('dashboard/DashboardLib', null, 'DashboardLib'); - $dashboard_kurzbz = "CIS"; - $structure = [ - "custom" => [ - "widgets" => [] - ], - "general" => [ - "widgets" => [ - $widgetId => [ - "widget" => 3, - "config" => new stdClass(), - "place" => [ - "3" => [ - "x" => $x, - "y" => $y, - "w" => $w, - "h" => $h - ] - ], - "widgetid" => $widgetId, - "custom" => 1, - "id" => "insertByBookmarkwidget" - ] - ] - ] - ]; - $jsonOverrideNew = json_encode($structure, JSON_UNESCAPED_UNICODE); - - //no existing benutzeroverride - if($mode == 0) - { - $override = $this->DashboardLib->getOverrideOrCreateEmptyOverride($dashboard_kurzbz, $this->uid); - - $override->override = $jsonOverrideNew; - - $result = $this->DashboardLib->insertOrUpdateOverride($override); - - $this->terminateWithSuccess($result); - - } - //benutzeroverride existing, but widget not included - elseif($mode == 1) - { - $overrideExisting = $this->DashboardLib->getOverrideOrCreateEmptyOverride($dashboard_kurzbz, $this->uid); - $override = json_decode($overrideExisting->override, true); // decode as Array - - $newWidget = [ - "widget" => 3, - "config" => new stdClass(), - "place" => [ - "3" => [ - "x" => $x, - "y" => $y, - "w" => $w, - "h" => $h - ] - ], - "widgetid" => $widgetId, - "custom" => 1, - "id" => "insertByBookmarkwidget" - ]; - - $override['general']['widgets'][$widgetId] = $newWidget; - - $jsonOverrideUpdated = json_encode($override, JSON_UNESCAPED_UNICODE); - $overrideExisting->override = $jsonOverrideUpdated; - - $result = $this->DashboardLib->insertOrUpdateOverride($overrideExisting); - - $this->terminateWithSuccess($result); - } - else - $this->terminateWithError("Error: no known mode"); - } - } diff --git a/application/models/dashboard/Bookmark_model.php b/application/models/dashboard/Bookmark_model.php index 931fe7064..8c70faf04 100644 --- a/application/models/dashboard/Bookmark_model.php +++ b/application/models/dashboard/Bookmark_model.php @@ -28,67 +28,4 @@ class Bookmark_model extends DB_Model return $this->execQuery($qry, array('uid' => $uid)); } - - /** - * Get Overrides of given uid and funktion_kurzbz and widget_id - * @param integer $widget_id - * @param string $uid - * @param string $funktion_kurzbz - * @return array - */ - public function getTagFilter($widgetId, $uid, $funktion_kurzbz) - { - $qry = " SELECT override -> '" . $funktion_kurzbz . "'-> 'widgets'-> '" . $widgetId . "'-> 'config' -> 'tags' AS tags FROM dashboard.tbl_dashboard_benutzer_override WHERE uid = '" . $uid . "';"; - - return $this->execQuery($qry); - } - - /* - * updates Tagfilter - * checks and changes type of config - * if config == array -> change to object - */ - public function addAndUpdateTagFilter($widgetId, $uid, $funktion_kurzbz, $tags) - { - $params = [ - $funktion_kurzbz, $widgetId, - $funktion_kurzbz, $widgetId, - $funktion_kurzbz, $widgetId, - $funktion_kurzbz, $widgetId, - $tags, - $uid - ]; - - $qry = " - UPDATE dashboard.tbl_dashboard_benutzer_override - SET override = jsonb_set( - -- check if config is object - jsonb_set( - COALESCE(override, '{}'::jsonb), - format('{%s,widgets,%s,config}', ?, ?)::text[], - CASE - WHEN jsonb_typeof(override #> format('{%s,widgets,%s,config}', ?, ?)::text[]) = 'array' - THEN '{}'::jsonb - ELSE COALESCE((override #> format('{%s,widgets,%s,config}', ?, ?)::text[])::jsonb, '{}'::jsonb) - END, - true - ), - -- insert tags - format('{%s,widgets,%s,config,tags}', ?, ?)::text[], - ?::jsonb, - true - ) - WHERE uid = ? - "; - - return $this->execQuery($qry, $params); - } - - public function checkOrAddToOverride($widgetId, $uid, $funktion_kurzbz) - { - $params = [$funktion_kurzbz, $widgetId, $uid]; - $qry = " SELECT override -> '" . $funktion_kurzbz . "'-> 'widgets'-> '" . $widgetId . "'-> 'widgetid' as widgetid FROM dashboard.tbl_dashboard_benutzer_override WHERE uid = '" . $uid . "';"; - - return $this->execQuery($qry, $params); - } } diff --git a/public/js/api/factory/widget/bookmark.js b/public/js/api/factory/widget/bookmark.js index 9379b42b2..3f034fee6 100644 --- a/public/js/api/factory/widget/bookmark.js +++ b/public/js/api/factory/widget/bookmark.js @@ -54,30 +54,5 @@ export default { method: 'get', url: '/api/frontend/v1/Bookmark/getAllBookmarkTags' }; - }, - getTagFilter(widgetId, sectionName){ - return { - method: 'get', - url: `/api/frontend/v1/Bookmark/getTagFilter/${widgetId}/${sectionName}` - }; - }, - addTagFilter(widgetId, sectionName, tags){ - return { - method: 'post', - url: `/api/frontend/v1/Bookmark/addAndUpdateTagFilter/${widgetId}/${sectionName}`, - params: { tags } - }; - }, - isInOverride(widgetId, sectionName){ - return { - method: 'post', - url: `/api/frontend/v1/Bookmark/isInOverride/${widgetId}/${sectionName}` - }; - }, - addWidgetToOverride(widgetId, sectionName, mode, x, y, h, w){ - return { - method: 'post', - url: `/api/frontend/v1/Bookmark/addWidgetToOverride/${widgetId}/${sectionName}/${mode}/${x}/${y}/${h}/${w}`, - }; } }; \ No newline at end of file diff --git a/public/js/components/DashboardWidget/Url.js b/public/js/components/DashboardWidget/Url.js index 3ecc8c1b6..d3b275cff 100644 --- a/public/js/components/DashboardWidget/Url.js +++ b/public/js/components/DashboardWidget/Url.js @@ -197,12 +197,11 @@ export default { .catch(this.$fhcAlert.handleSystemError); }, filterBookmarksByTags(bookmarks) { - const filter = this.filter; - if (!filter || filter.length === 0 || filter == "[]") return bookmarks; - - return bookmarks.filter(b => { - const tags = JSON.parse(b.tag || "[]"); - return tags.some(tag => filter.includes(tag)); + if (!this.config.tags || !this.config.tags.length) + return bookmarks; + return bookmarks.filter(bookmark => { + const tags = JSON.parse(bookmark.tag || "[]"); + return tags.some(tag => this.config.tags.includes(tag)); }); }, sortDown(bookmark_id){ @@ -281,81 +280,19 @@ export default { }) .catch(this.$fhcAlert.handleSystemError); }, - openFilterModal(){ + openFilterModal() { + if (this.config.tags && this.config.tags.length) + this.selectedFilters = this.prepareTag(this.config.tags); + else + this.selectedFilters = []; this.$refs.filterModal.show(); }, - async handleAddingTagFilter(widgetId){ - - const result = await this.isInOverride(widgetId); - - if (!result) { - return; - } - const [status, reason] = result; - - if (status) { - this.addTagFilter(widgetId); - } else { - this.addWidgetToOverride(widgetId, reason); - } - }, - addTagFilter(widgetId){ - this.$api - .call(ApiBookmark.addTagFilter(widgetId, this.sectionName, this.filterInput)) - .then((res) => res.data) - .then((result) => { - this.$fhcAlert.alertInfo(this.$p.t("bookmark", "filterUpdated")); - this.$refs.filterModal.hide(); - this.getTagFilter(this.widgetId); - - this.$nextTick(() => { - this.getAllBookmarkTags(); - }); - this.fetchBookmarks(); - }) - .catch(this.$fhcAlert.handleSystemError); - }, - async isInOverride(widgetId) { - try { - const res = await this.$api.call(ApiBookmark.isInOverride(widgetId, this.sectionName)); - const result = res.data; - return result; - } catch (err) { - this.$fhcAlert.handleSystemError(err); - return null; - } - }, - addWidgetToOverride(widgetId, reason){ - this.$api - .call(ApiBookmark.addWidgetToOverride( - widgetId, - this.sectionName, - reason, - this.item_data.x, - this.item_data.y, - this.item_data.h, - this.item_data.w - )) - .then((res) => res.data) - .then((result) => { - this.addTagFilter(widgetId); - }) - .catch(this.$fhcAlert.handleSystemError); - }, - getTagFilter(widget_id) { - this.$api - .call(ApiBookmark.getTagFilter(widget_id, this.sectionName)) - .then((res) => res.data) - .then((result) => { - const rawTags = result.tags; // string - this.filter = rawTags; - if(rawTags != null) { - this.rawTagsParsed = JSON.parse(rawTags); - this.selectedFilters = this.prepareTag(this.rawTagsParsed); - } - this.fetchBookmarks(); - }) - .catch(this.$fhcAlert.handleSystemError); + async handleAddingTagFilter(widgetId) { + this.config.tags = [ ...this.filterInput ]; + this.$emit('change'); + this.sharedFiltered = this.filterBookmarksByTags(this.shared); + this.$fhcAlert.alertInfo(this.$p.t("bookmark", "filterUpdated")); + this.$refs.filterModal.hide(); }, search(event) { const query = event.query ?? ""; @@ -372,9 +309,6 @@ export default { }, }, async mounted() { - if(this.widgetId) { - this.getTagFilter(this.widgetId); - } await this.fetchBookmarks(); this.getAllBookmarkTags(); }, @@ -394,7 +328,7 @@ export default { {{ $p.t('bookmark', 'newLink') }}