mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-19 16:02:15 +00:00
adds content to Url.js
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}
|
||||
);
|
||||
},
|
||||
}
|
||||
@@ -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*/`
|
||||
<div v-if="loading">
|
||||
<div class="d-flex justify-content-center align-items-center h-100">
|
||||
<i class="fa-solid fa-spinner fa-pulse fa-3x"></i>
|
||||
@@ -127,7 +131,7 @@ export default {
|
||||
<component v-if="ready && !isLoading" :is="component" :config="tmpConfig" @change="changeConfig" :configMode="true"></component>
|
||||
<div v-else class="text-center"><i class="fa-solid fa-spinner fa-pulse fa-3x"></i></div>
|
||||
</template>
|
||||
<template v-slot:footer>
|
||||
<template v-if="widgetHasFooter" v-slot:footer>
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
||||
<button type="button" class="btn btn-primary" @click="changeConfig">Save changes</button>
|
||||
</template>
|
||||
|
||||
@@ -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 {
|
||||
|
||||
<header><b>{{$p.t('bookmark','newLink')}}</b></header><br>
|
||||
<div>
|
||||
<input class="form-control form-control-sm" placeholder="Titel" type="text" v-model="title" name="title" maxlength="50" required>
|
||||
<input class="form-control form-control-sm mt-2" type="url" placeholder="URL" v-model="url" name="url" required>
|
||||
<button class="btn btn-outline-secondary btn-sm w-100 mt-2" @click="addLink()" type="button">{{$p.t('bookmark','saveLink')}}</button>
|
||||
<input class="form-control form-control-sm" placeholder="Titel" type="text" v-model="title_input" name="title" maxlength="50" required>
|
||||
<input class="form-control form-control-sm mt-2" type="url" placeholder="URL" v-model="url_input" name="url" required>
|
||||
<button class="btn btn-outline-secondary btn-sm w-100 mt-2" @click="addLink" type="button">{{$p.t('bookmark','saveLink')}}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,42 +1,44 @@
|
||||
<?php
|
||||
|
||||
$qry = "BEGIN TRANSACTION;
|
||||
if (!$result = @$db->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 '<strong>error occurred during tbl_bookmark creation: ' . $db->db_last_error() . '</strong><br>';
|
||||
else
|
||||
echo '<br>dashboard.tbl_bookmark and dashboard.tbl_bookmark_sequence was created';
|
||||
COMMIT TRANSACTION;";
|
||||
|
||||
if (!$db->db_query($qry))
|
||||
echo '<strong>error occurred during tbl_bookmark creation: ' . $db->db_last_error() . '</strong><br>';
|
||||
else
|
||||
echo '<br>dashboard.tbl_bookmark and dashboard.tbl_bookmark_sequence was created';
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user