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 {
-
+
diff --git a/public/js/components/DashboardWidget/Url.js b/public/js/components/DashboardWidget/Url.js
index 23631c88c..11502abe4 100755
--- a/public/js/components/DashboardWidget/Url.js
+++ b/public/js/components/DashboardWidget/Url.js
@@ -3,7 +3,10 @@ import AbstractWidget from './Abstract';
export default {
name: 'WidgetsUrl',
data: () => ({
- links: null
+ links: null,
+ title_input: '',
+ url_input: '',
+ isPhrasenLoaded: false,
}),
mixins: [
AbstractWidget
@@ -22,27 +25,50 @@ export default {
})
.catch();
},
- addLink(){
- let linkId = this.links.length;
-
- this.links.push({
- id: linkId,
- tag: this.config.tag,
- title: this.title,
- url: this.url
- })
+ async confirmDelete() {
+ if (await this.$fhcAlert.confirmDelete() === false)
+ return;
},
- removeLink(bookmark_id){
+ addLink(){
+ //let linkId = this.links.length;
+
+ this.$fhcApi.factory.bookmark.insertBookmark({
+ tag: this.config.tag,
+ title: this.title_input,
+ url: this.url_input
+ })
+ .then(res => res.data)
+ .then(result => {
+ this.$fhcAlert.alertInfo("bookmark added");
+ })
+ .catch();
+
+ // reset the values for the title and url inputs
+ this.title_input = '';
+ this.url_input = '';
+
+ // refetch the bookmarks to see the updates
+ this.fetchBookmarks();
+
+ },
+ async removeLink(bookmark_id){
+ await this.confirmDelete();
this.$fhcApi.factory.bookmark.deleteBookmark(bookmark_id)
.then(res => res.data)
.then(result => {
this.$fhcAlert.alertInfo(this.$p.t('bookmark','bookmarkDeleted'));
})
.catch();
+
+ // refetch the bookmarks to see the updates
+ this.fetchBookmarks();
}
},
created() {
+ this.$p.loadCategory('bookmark').then(()=>{
+ this.isPhrasenLoaded = true;
+ })
//this.links = TEST_LINKS;
// this.links = TEST_KEINE_LINKS;
},
@@ -56,9 +82,9 @@ export default {
{{$p.t('bookmark','newLink')}}
-
-
-
+
+
+
diff --git a/system/dbupdate_3.4/41134_bookmark_dashboardWidget.php b/system/dbupdate_3.4/41134_bookmark_dashboardWidget.php
index dc3919730..28171367c 100644
--- a/system/dbupdate_3.4/41134_bookmark_dashboardWidget.php
+++ b/system/dbupdate_3.4/41134_bookmark_dashboardWidget.php
@@ -1,42 +1,44 @@
db_query("SELECT to_regclass('dashboard.tbl_bookmark')"))
+{
+ $qry = "BEGIN TRANSACTION;
- CREATE TABLE IF NOT EXISTS dashboard.tbl_bookmark(
- bookmark_id BIGINT PRIMARY KEY,
- uid VARCHAR(255) NOT NULL,
- url VARCHAR(511) NOT NULL,
- title VARCHAR(255) NULL,
- tag VARCHAR(255) NULL,
- insertamum TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
- insertvon VARCHAR(255) NULL REFERENCES public.tbl_benutzer(uid),
- updateamum TIMESTAMP NULL,
- updatevon VARCHAR(255) NULL REFERENCES public.tbl_benutzer(uid)
- );
+ CREATE TABLE IF NOT EXISTS dashboard.tbl_bookmark(
+ bookmark_id BIGINT PRIMARY KEY,
+ uid VARCHAR(255) NOT NULL,
+ url VARCHAR(511) NOT NULL,
+ title VARCHAR(255) NULL,
+ tag VARCHAR(255) NULL,
+ insertamum TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
+ insertvon VARCHAR(255) NULL REFERENCES public.tbl_benutzer(uid),
+ updateamum TIMESTAMP NULL,
+ updatevon VARCHAR(255) NULL REFERENCES public.tbl_benutzer(uid)
+ );
- ALTER TABLE dashboard.tbl_bookmark ADD CONSTRAINT tbl_bookmark_fk FOREIGN KEY(uid) REFERENCES public.tbl_benutzer(uid);
+ ALTER TABLE dashboard.tbl_bookmark ADD CONSTRAINT tbl_bookmark_fk FOREIGN KEY(uid) REFERENCES public.tbl_benutzer(uid);
- CREATE SEQUENCE IF NOT EXISTS dashboard.tbl_bookmark_sequence
- AS BIGINT
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- START WITH 1
- CACHE 1
- OWNED BY dashboard.tbl_bookmark.bookmark_id;
+ CREATE SEQUENCE IF NOT EXISTS dashboard.tbl_bookmark_sequence
+ AS BIGINT
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ START WITH 1
+ CACHE 1
+ OWNED BY dashboard.tbl_bookmark.bookmark_id;
- ALTER TABLE dashboard.tbl_bookmark ALTER COLUMN bookmark_id SET DEFAULT nextval('dashboard.tbl_bookmark_sequence ');
+ ALTER TABLE dashboard.tbl_bookmark ALTER COLUMN bookmark_id SET DEFAULT nextval('dashboard.tbl_bookmark_sequence ');
- GRANT SELECT, INSERT, UPDATE, DELETE ON dashboard.tbl_bookmark TO vilesci;
- GRANT SELECT, INSERT, UPDATE, DELETE ON dashboard.tbl_bookmark TO web;
- GRANT SELECT, UPDATE ON dashboard.tbl_bookmark_sequence TO vilesci;
- GRANT SELECT, UPDATE ON dashboard.tbl_bookmark_sequence TO web;
+ GRANT SELECT, INSERT, UPDATE, DELETE ON dashboard.tbl_bookmark TO vilesci;
+ GRANT SELECT, INSERT, UPDATE, DELETE ON dashboard.tbl_bookmark TO web;
+ GRANT SELECT, UPDATE ON dashboard.tbl_bookmark_sequence TO vilesci;
+ GRANT SELECT, UPDATE ON dashboard.tbl_bookmark_sequence TO web;
- COMMIT TRANSACTION;";
-
-if (!$db->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';
+ COMMIT TRANSACTION;";
+ if (!$db->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';
+}