From 284cf711fd45deff4be46f2d0d34be33a5ad7e5a Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 30 Jul 2024 11:26:22 +0200 Subject: [PATCH 1/8] adds the sql scripts to create dashboard.tbl_bookmark and dashboard.tbl_bookmark_sequence --- system/dbupdate_3.4.php | 3 ++ .../41134_bookmark_dashboardWidget.php | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 system/dbupdate_3.4/41134_bookmark_dashboardWidget.php diff --git a/system/dbupdate_3.4.php b/system/dbupdate_3.4.php index b3c070095..17487b5d3 100755 --- a/system/dbupdate_3.4.php +++ b/system/dbupdate_3.4.php @@ -58,6 +58,7 @@ require_once('dbupdate_3.4/25999_cis4_cms.php'); require_once('dbupdate_3.4/36530_bis_internationsalisierung_codextabelle_neuerungen.php'); require_once('dbupdate_3.4/34543_ux_template.php'); require_once('dbupdate_3.4/17513_Entwicklungsteam.php'); +require_once('dbupdate_3.4/41134_bookmark_dashboardWidget.php'); @@ -410,6 +411,8 @@ $tabellen=array( "wawi.tbl_rechnungsbetrag" => array("rechnungsbetrag_id","rechnung_id","mwst","betrag","bezeichnung","ext_id"), "wawi.tbl_aufteilung" => array("aufteilung_id","bestellung_id","oe_kurzbz","anteil","insertamum","insertvon","updateamum","updatevon"), "wawi.tbl_aufteilung_default" => array("aufteilung_id","kostenstelle_id","oe_kurzbz","anteil","insertamum","insertvon","updateamum","updatevon"), + "dashboard.tbl_bookmark" => array("bookmark_id","uid","url","title","tag","insertamum","insertvon","updateamum","updatevon"), + ); $tabs=array_keys($tabellen); diff --git a/system/dbupdate_3.4/41134_bookmark_dashboardWidget.php b/system/dbupdate_3.4/41134_bookmark_dashboardWidget.php new file mode 100644 index 000000000..dc3919730 --- /dev/null +++ b/system/dbupdate_3.4/41134_bookmark_dashboardWidget.php @@ -0,0 +1,42 @@ +db_query($qry)) + echo 'error occurred during tbl_bookmark creation: ' . $db->db_last_error() . '
'; + else + echo '
dashboard.tbl_bookmark and dashboard.tbl_bookmark_sequence was created'; + + From 39574c1b3a1f8454bfaaa9647679e42baee7768a Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 30 Jul 2024 15:27:24 +0200 Subject: [PATCH 2/8] adds delete endpoint for the dashboard bookmark widget --- .../controllers/api/frontend/v1/Bookmark.php | 99 +++++++++++++++++++ .../models/dashboard/Bookmark_model.php | 57 +++++++++++ public/js/api/bookmark.js | 21 ++++ public/js/api/fhcapifactory.js | 2 + public/js/apps/Dashboard/Fhc.js | 3 + public/js/components/DashboardWidget/Url.js | 67 ++++++++++--- system/phrasesupdate.php | 65 +++++++++++- 7 files changed, 300 insertions(+), 14 deletions(-) create mode 100644 application/controllers/api/frontend/v1/Bookmark.php create mode 100644 application/models/dashboard/Bookmark_model.php create mode 100644 public/js/api/bookmark.js diff --git a/application/controllers/api/frontend/v1/Bookmark.php b/application/controllers/api/frontend/v1/Bookmark.php new file mode 100644 index 000000000..c18afc751 --- /dev/null +++ b/application/controllers/api/frontend/v1/Bookmark.php @@ -0,0 +1,99 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +class Bookmark extends FHCAPI_Controller +{ + + /** + * Object initialization + */ + public function __construct() + { + parent::__construct([ + 'getBookmarks' => self::PERM_LOGGED, + 'delete' => self::PERM_LOGGED, + ]); + + $this->load->model('dashboard/Bookmark_model', 'BookmarkModel'); + + $this->uid = getAuthUID(); + $this->pid = getAuthPersonID(); + + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + + /** + * gets the bookmarks associated to a user + * @access public + * @return void + */ + public function getBookmarks() + { + $bookmarks = $this->BookmarkModel->getAll($this->uid); + + if(isError($bookmarks)){ + $this->terminateWithError(getError($bookmarks)); + } + + $bookmarks = $this->getDataOrTerminateWithError($bookmarks); + + $this->terminateWithSuccess($bookmarks); + } + + /** + * deletes bookmark from associated user + * @access public + * @return void + */ + public function delete($bookmark_id) + { + if(!isset($bookmark_id)) $this->terminateWithError("missing required parameters"); + + $bookmark = $this->BookmarkModel->get($bookmark_id); + + if(isError($bookmark)){ + $this->terminateWithError(getError($bookmark)); + } + + $bookmark = current($this->getDataOrTerminateWithError($bookmark)); + + // only delete bookmark if the user is the owner of the bookmark + $this->load->library('PermissionLib'); + + if($bookmark->uid == $this->uid || $this->permissionlib->isBerechtigt('admin')){ + + $delete_result = $this->BookmarkModel->delete($bookmark_id); + + if(isError($delete_result)){ + $this->terminateWithError(getError($delete_result)); + } + + $delete_result = $this->getDataOrTerminateWithError($delete_result); + + $this->terminateWithSuccess($delete_result); + }else{ + $this->terminateWithError("You are not authorized to delete this bookmark"); + } + } +} + diff --git a/application/models/dashboard/Bookmark_model.php b/application/models/dashboard/Bookmark_model.php new file mode 100644 index 000000000..3b44d055c --- /dev/null +++ b/application/models/dashboard/Bookmark_model.php @@ -0,0 +1,57 @@ +dbTable = 'dashboard.tbl_bookmark'; + $this->pk = 'bookmark_id'; + } + + + /** + * Get Bookmarks of UID. + * @param string user uid + * @return array + */ + public function getAll($uid) + { + return $this->execReadOnlyQuery(" + SELECT * + FROM dashboard.tbl_bookmark + WHERE uid = ? + ",[$uid]); + } + + /** + * Gets Bookmark by bookmark_id. + * @param int $bookmark_id + * @return array + */ + public function get($bookmark_id) + { + return $this->execReadOnlyQuery(" + SELECT * + FROM dashboard.tbl_bookmark + WHERE bookmark_id = ? + ",[$bookmark_id]); + } + + /** + * Gets Bookmark by bookmark_id. + * @param int $bookmark_id + * @return array + */ + public function delete($bookmark_id) + { + return $this->execReadOnlyQuery(" + DELETE + FROM dashboard.tbl_bookmark + WHERE bookmark_id = ? + ",[$bookmark_id]); + } +} diff --git a/public/js/api/bookmark.js b/public/js/api/bookmark.js new file mode 100644 index 000000000..6a6b3c309 --- /dev/null +++ b/public/js/api/bookmark.js @@ -0,0 +1,21 @@ +export default { + + getBookmarks: function (uid) { + return this.$fhcApi.get( + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/api/frontend/v1/Bookmark/getBookmarks` + ,{} + ); + }, + + deleteBookmark: function (bookmark_id) { + + return this.$fhcApi.get( + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/api/frontend/v1/Bookmark/delete/${bookmark_id}` + ,{} + ); + }, +} \ No newline at end of file diff --git a/public/js/api/fhcapifactory.js b/public/js/api/fhcapifactory.js index 73ce0dd7f..99f154992 100644 --- a/public/js/api/fhcapifactory.js +++ b/public/js/api/fhcapifactory.js @@ -22,6 +22,7 @@ import filter from "./filter.js"; import studstatus from "./studstatus.js"; import profil from "./profil.js"; import profilUpdate from "./profilUpdate.js"; +import bookmark from "./bookmark.js"; export default { search, @@ -31,4 +32,5 @@ export default { studstatus, profil, profilUpdate, + bookmark, }; diff --git a/public/js/apps/Dashboard/Fhc.js b/public/js/apps/Dashboard/Fhc.js index ebcbb4b78..824f03bd2 100755 --- a/public/js/apps/Dashboard/Fhc.js +++ b/public/js/apps/Dashboard/Fhc.js @@ -1,4 +1,6 @@ import FhcDashboard from '../../components/Dashboard/Dashboard.js'; +import Phrasen from "../../plugin/Phrasen.js" +import FhcAlert from "../../plugin/FhcAlert.js" const app = Vue.createApp({ data: () => ({ @@ -9,4 +11,5 @@ const app = Vue.createApp({ } }); app.config.unwrapInjectedRef = true; +app.use(Phrasen).use(FhcAlert); app.mount('#content'); diff --git a/public/js/components/DashboardWidget/Url.js b/public/js/components/DashboardWidget/Url.js index f374b7ed8..23631c88c 100755 --- a/public/js/components/DashboardWidget/Url.js +++ b/public/js/components/DashboardWidget/Url.js @@ -3,7 +3,7 @@ import AbstractWidget from './Abstract'; export default { name: 'WidgetsUrl', data: () => ({ - links: [] + links: null }), mixins: [ AbstractWidget @@ -14,6 +14,14 @@ export default { } }, methods: { + async fetchBookmarks(){ + await this.$fhcApi.factory.bookmark.getBookmarks() + .then(res => res.data) + .then(result => { + this.links = result; + }) + .catch(); + }, addLink(){ let linkId = this.links.length; @@ -24,37 +32,70 @@ export default { url: this.url }) }, - removeLink(linkId){ - let indexToRemove = this.links.findIndex((obj => obj.id === linkId)); - this.links.splice(indexToRemove, 1); + removeLink(bookmark_id){ + this.$fhcApi.factory.bookmark.deleteBookmark(bookmark_id) + .then(res => res.data) + .then(result => { + this.$fhcAlert.alertInfo(this.$p.t('bookmark','bookmarkDeleted')); + }) + .catch(); } }, + created() { - this.links = TEST_LINKS; + //this.links = TEST_LINKS; // this.links = TEST_KEINE_LINKS; }, - template: ` + async mounted(){ + await this.fetchBookmarks(); + }, + template: /*html*/`
-
Neuer Link

+
{{$p.t('bookmark','newLink')}}

- +
-
{{ widgetTag }}
- + + +
` } + +/* +Link JSON structure: +{ + "bookmark_id": number, + "uid": string, + "url": string, + "title": string, + "tag": string, + "insertamum": "2024-07-30 14:33:03.699318", + "insertvon": null, + "updateamum": null, + "updatevon": null +} +*/ + + const TEST_KEINE_LINKS = []; const TEST_LINKS = [ { diff --git a/system/phrasesupdate.php b/system/phrasesupdate.php index 8dc1d163f..688023295 100755 --- a/system/phrasesupdate.php +++ b/system/phrasesupdate.php @@ -27489,7 +27489,70 @@ array( 'insertvon' => 'system' ) ) - ) + ), + // BOOKMARK PHRASEN ---------------------------------------------------------------------- + array( + 'app' => 'core', + 'category' => 'bookmark', + 'phrase' => 'newLink', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'Neuer Link', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'New Link', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'bookmark', + 'phrase' => 'saveLink', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'Link speichern', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'Save link', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'bookmark', + 'phrase' => 'bookmarkDeleted', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'Link gelöscht', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'Link deleted', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + + ); From c2be0a4790d3eb0fb411382ec3443b16497a1e72 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Wed, 31 Jul 2024 12:41:03 +0200 Subject: [PATCH 3/8] adds content to Url.js --- .../controllers/api/frontend/v1/Bookmark.php | 35 +++++++++- .../models/dashboard/Bookmark_model.php | 41 +----------- public/js/api/bookmark.js | 12 ++++ public/js/components/Dashboard/Item.js | 10 ++- public/js/components/DashboardWidget/Url.js | 54 +++++++++++---- .../41134_bookmark_dashboardWidget.php | 66 ++++++++++--------- 6 files changed, 127 insertions(+), 91 deletions(-) diff --git a/application/controllers/api/frontend/v1/Bookmark.php b/application/controllers/api/frontend/v1/Bookmark.php index c18afc751..9fb8a6519 100644 --- a/application/controllers/api/frontend/v1/Bookmark.php +++ b/application/controllers/api/frontend/v1/Bookmark.php @@ -29,6 +29,7 @@ class Bookmark extends FHCAPI_Controller parent::__construct([ 'getBookmarks' => self::PERM_LOGGED, 'delete' => self::PERM_LOGGED, + 'insert' => self::PERM_LOGGED, ]); $this->load->model('dashboard/Bookmark_model', 'BookmarkModel'); @@ -49,7 +50,7 @@ class Bookmark extends FHCAPI_Controller */ public function getBookmarks() { - $bookmarks = $this->BookmarkModel->getAll($this->uid); + $bookmarks = $this->BookmarkModel->loadWhere(["uid"=>$this->uid]); if(isError($bookmarks)){ $this->terminateWithError(getError($bookmarks)); @@ -69,7 +70,7 @@ class Bookmark extends FHCAPI_Controller { if(!isset($bookmark_id)) $this->terminateWithError("missing required parameters"); - $bookmark = $this->BookmarkModel->get($bookmark_id); + $bookmark = $this->BookmarkModel->load($bookmark_id); if(isError($bookmark)){ $this->terminateWithError(getError($bookmark)); @@ -95,5 +96,35 @@ class Bookmark extends FHCAPI_Controller $this->terminateWithError("You are not authorized to delete this bookmark"); } } + + /** + * inserts new bookmark into the bookmark table + * @access public + * @return void + */ + public function insert() + { + $url = $this->input->post('url',true); + $title = $this->input->post('title',true); + $tag = $this->input->post('tag',true); + + // set the parameters to null if they are not present in the request payload + if($title == FALSE) $title = NULL; + if($tag == FALSE) $tag = NULL; + + if(!isset($url))$this->terminateWithError("missing required parameters"); + + $insert_into_result = $this->BookmarkModel->execReadOnlyQuery(" + INSERT INTO dashboard.tbl_bookmark (uid, url, title,tag, insertvon, updateamum, updatevon) VALUES (?,?,?,?,?,NULL,NULL);",[$this->uid,$url,$title,$tag,$this->uid]); + + if(isError($insert_into_result)){ + $this->terminateWithError(getError($insert_into_result)); + } + + $insert_into_result = $this->getDataOrTerminateWithError($insert_into_result); + + $this->terminateWithSuccess($insert_into_result); + + } } diff --git a/application/models/dashboard/Bookmark_model.php b/application/models/dashboard/Bookmark_model.php index 3b44d055c..5efacc26b 100644 --- a/application/models/dashboard/Bookmark_model.php +++ b/application/models/dashboard/Bookmark_model.php @@ -13,45 +13,6 @@ class Bookmark_model extends DB_Model } - /** - * Get Bookmarks of UID. - * @param string user uid - * @return array - */ - public function getAll($uid) - { - return $this->execReadOnlyQuery(" - SELECT * - FROM dashboard.tbl_bookmark - WHERE uid = ? - ",[$uid]); - } + - /** - * Gets Bookmark by bookmark_id. - * @param int $bookmark_id - * @return array - */ - public function get($bookmark_id) - { - return $this->execReadOnlyQuery(" - SELECT * - FROM dashboard.tbl_bookmark - WHERE bookmark_id = ? - ",[$bookmark_id]); - } - - /** - * Gets Bookmark by bookmark_id. - * @param int $bookmark_id - * @return array - */ - public function delete($bookmark_id) - { - return $this->execReadOnlyQuery(" - DELETE - FROM dashboard.tbl_bookmark - WHERE bookmark_id = ? - ",[$bookmark_id]); - } } diff --git a/public/js/api/bookmark.js b/public/js/api/bookmark.js index 6a6b3c309..5c99a4010 100644 --- a/public/js/api/bookmark.js +++ b/public/js/api/bookmark.js @@ -18,4 +18,16 @@ export default { ,{} ); }, + + insertBookmark: function ({url, title, tag}) { + + return this.$fhcApi.post( + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/api/frontend/v1/Bookmark/insert` + ,{url: url, + title: title, + tag: tag} + ); + }, } \ No newline at end of file diff --git a/public/js/components/Dashboard/Item.js b/public/js/components/Dashboard/Item.js index 43e03ebc7..10c436047 100755 --- a/public/js/components/Dashboard/Item.js +++ b/public/js/components/Dashboard/Item.js @@ -38,9 +38,13 @@ export default { }, ready() { return this.component && this.arguments !== null - } + }, + widgetHasFooter(){ + return this.widget?.setup?.name == "Bookmark" ? false : true; + }, }, methods: { + mouseDown(e) { this.target = e.target; }, @@ -97,7 +101,7 @@ export default { this.arguments = {...this.widget.arguments, ...this.config}; this.tmpConfig = {...this.arguments}; }, - template: ` + template: /*html*/`
@@ -127,7 +131,7 @@ export default {
-