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 {
-