code review changes

This commit is contained in:
SimonGschnell
2024-08-01 11:49:14 +02:00
parent 3641047963
commit 6fcc8cf7e8
6 changed files with 124 additions and 166 deletions
@@ -52,10 +52,6 @@ class Bookmark extends FHCAPI_Controller
{
$bookmarks = $this->BookmarkModel->loadWhere(["uid"=>$this->uid]);
if(isError($bookmarks)){
$this->terminateWithError(getError($bookmarks));
}
$bookmarks = $this->getDataOrTerminateWithError($bookmarks);
$this->terminateWithSuccess($bookmarks);
@@ -68,32 +64,20 @@ class Bookmark extends FHCAPI_Controller
*/
public function delete($bookmark_id)
{
if(!isset($bookmark_id)) $this->terminateWithError("missing required parameters");
$bookmark = $this->BookmarkModel->load($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");
$this->_outputAuthError(['delete' => ['admin:rw']]);
}
}
@@ -104,22 +88,17 @@ class Bookmark extends FHCAPI_Controller
*/
public function insert()
{
// form validation
$this->load->library('form_validation');
$this->form_validation->set_rules('url', 'URL', 'required|valid_url|max_length[511]');
$this->form_validation->set_rules('title', 'Title', 'required|max_length[255]');
if($this->form_validation->run() == FALSE) $this->terminateWithValidationErrors($this->form_validation->error_array());
$url = $this->input->post('url',true);
$title = $this->input->post('title',true);
$tag = $this->input->post('tag',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->BookmarkModel->insert(['uid'=>$this->uid, 'url'=>$url, 'title'=>$title,'tag'=>$tag, 'insertvon'=>$this->uid, 'updateamum'=>NULL, 'updatevon'=>NULL]);
$insert_into_result = $this->getDataOrTerminateWithError($insert_into_result);
+7 -13
View File
@@ -1,33 +1,27 @@
export default {
getBookmarks: function (uid) {
getBookmarks: function () {
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) {
delete: 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}`
,{}
);
},
insertBookmark: function ({url, title, tag}) {
insert: 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,
,{
url: url,
title: title,
tag: tag}
tag: tag
}
);
},
}
+2 -3
View File
@@ -1,6 +1,5 @@
import FhcDashboard from '../../components/Dashboard/Dashboard.js';
import Phrasen from "../../plugin/Phrasen.js"
import FhcAlert from "../../plugin/FhcAlert.js"
import Phrasen from "../../plugin/Phrasen.js";
const app = Vue.createApp({
data: () => ({
@@ -11,5 +10,5 @@ const app = Vue.createApp({
}
});
app.config.unwrapInjectedRef = true;
app.use(Phrasen).use(FhcAlert);
app.use(Phrasen);
app.mount('#content');
+95 -104
View File
@@ -2,107 +2,98 @@ import BsModal from "../Bootstrap/Modal.js";
import CachedWidgetLoader from "../../composables/Dashboard/CachedWidgetLoader.js";
export default {
components: {
BsModal
},
data: () => ({
component: '',
arguments: null,
target: false,
widget: null,
tmpConfig: {},
isLoading: false,
hasConfig: true,
sharedData: null
}),
emits: [
"change",
"remove",
"dragstart",
"resizestart",
],
props: [
"id",
"config",
"width",
"height",
"custom",
"hidden",
"editMode",
"loading"
],
computed: {
isResizeable() {
if (!this.widget)
return false;
return this.widget.setup.width.max || this.widget.setup.height.max;
},
ready() {
return this.component && this.arguments !== null
},
widgetHasFooter(){
return this.widget?.setup?.name == "Bookmark" ? false : true;
},
},
methods: {
mouseDown(e) {
this.target = e.target;
},
startDrag(e) {
if (this.$refs.dragHandle.contains(this.target)) {
this.$emit('dragstart', e);
} else if (this.isResizeable && this.$refs.resizeHandle.contains(this.target)) {
if (this.isResizeable)
this.$emit('resizestart', e);
else
e.preventDefault();
} else {
e.preventDefault();
}
},
openConfig() {
this.tmpConfig = {...this.arguments};
this.$refs.config.show();
},
setConfig(hasConfig) {
this.hasConfig = hasConfig;
},
changeConfig() {
this.isLoading = true;
let config = {...this.tmpConfig};
this.sendChangeConfig(config);
},
changeConfigManually() {
let config = {...this.arguments};
this.sendChangeConfig(config);
},
sendChangeConfig(config) {
for (var k in config) {
if (this.widget.arguments[k] == config[k]) {
delete config[k];
}
}
this.$emit('change', config);
}
},
watch: {
config() {
this.arguments = {...this.widget.arguments, ...this.config};
this.tmpConfig = {...this.arguments};
this.$refs.config.hide();
this.isLoading = false;
}
},
async created() {
this.widget = await CachedWidgetLoader.loadWidget(this.id);
let component = (await import('../' + this.widget.setup.file)).default;
this.$options.components['widget' + this.widget.widget_id] = component;
this.component = 'widget' + this.widget.widget_id;
this.arguments = {...this.widget.arguments, ...this.config};
this.tmpConfig = {...this.arguments};
},
template: /*html*/`
components: {
BsModal,
},
data: () => ({
component: "",
arguments: null,
target: false,
widget: null,
tmpConfig: {},
isLoading: false,
hasConfig: true,
sharedData: null,
}),
emits: ["change", "remove", "dragstart", "resizestart"],
props: [
"id",
"config",
"width",
"height",
"custom",
"hidden",
"editMode",
"loading",
],
computed: {
isResizeable() {
if (!this.widget) return false;
return this.widget.setup.width.max || this.widget.setup.height.max;
},
ready() {
return this.component && this.arguments !== null;
},
},
methods: {
mouseDown(e) {
this.target = e.target;
},
startDrag(e) {
if (this.$refs.dragHandle.contains(this.target)) {
this.$emit("dragstart", e);
} else if (
this.isResizeable &&
this.$refs.resizeHandle.contains(this.target)
) {
if (this.isResizeable) this.$emit("resizestart", e);
else e.preventDefault();
} else {
e.preventDefault();
}
},
openConfig() {
this.tmpConfig = { ...this.arguments };
this.$refs.config.show();
},
setConfig(hasConfig) {
this.hasConfig = hasConfig;
},
changeConfig() {
this.isLoading = true;
let config = { ...this.tmpConfig };
this.sendChangeConfig(config);
},
changeConfigManually() {
let config = { ...this.arguments };
this.sendChangeConfig(config);
},
sendChangeConfig(config) {
for (var k in config) {
if (this.widget.arguments[k] == config[k]) {
delete config[k];
}
}
this.$emit("change", config);
},
},
watch: {
config() {
this.arguments = { ...this.widget.arguments, ...this.config };
this.tmpConfig = { ...this.arguments };
this.$refs.config.hide();
this.isLoading = false;
},
},
async created() {
this.widget = await CachedWidgetLoader.loadWidget(this.id);
let component = (await import("../" + this.widget.setup.file)).default;
this.$options.components["widget" + this.widget.widget_id] = component;
this.component = "widget" + this.widget.widget_id;
this.arguments = { ...this.widget.arguments, ...this.config };
this.tmpConfig = { ...this.arguments };
},
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>
@@ -132,7 +123,7 @@ export default {
<component v-if="ready && !isLoading" :is="component" v-model:shared-data="sharedData" :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-if="widgetHasFooter" v-slot:footer>
<template v-if="!widget?.setup?.hideFooter" 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>
@@ -140,5 +131,5 @@ export default {
<div v-if="editMode && isResizeable" class="card-footer d-flex justify-content-end p-0">
<span drag-action="resize" class="col-auto px-1 cursor-nw-resize"><i class="fa-solid fa-up-right-and-down-left-from-center mirror-x"></i></span>
</div>
</div>`
}
</div>`,
};
+10 -15
View File
@@ -5,7 +5,6 @@ export default {
data: () => ({
title_input: "",
url_input: "",
isPhrasenLoaded: false,
}),
mixins: [AbstractWidget],
computed: {
@@ -37,16 +36,16 @@ export default {
},
addLink() {
this.$fhcApi.factory.bookmark
.insertBookmark({
.insert({
tag: this.config.tag,
title: this.title_input,
url: this.url_input,
})
.then((res) => res.data)
.then((result) => {
this.$fhcAlert.alertInfo("bookmark added");
this.$fhcAlert.alertInfo(this.$p.t("bookmark", "bookmarkAdded"));
})
.catch();
.catch(this.$fhcAlert.handleSystemError);
// reset the values for the title and url inputs
this.title_input = "";
@@ -58,7 +57,7 @@ export default {
async removeLink(bookmark_id) {
await this.confirmDelete();
this.$fhcApi.factory.bookmark
.deleteBookmark(bookmark_id)
.delete(bookmark_id)
.then((res) => res.data)
.then((result) => {
this.$fhcAlert.alertInfo(this.$p.t("bookmark", "bookmarkDeleted"));
@@ -69,12 +68,6 @@ export default {
this.fetchBookmarks();
},
},
created() {
this.$p.loadCategory("bookmark").then(() => {
this.isPhrasenLoaded = true;
});
},
async mounted() {
await this.fetchBookmarks();
},
@@ -95,10 +88,12 @@ export default {
<!-- todo: widgetTag ?? -->
<template v-if="shared">
<header><b>{{ tagName }}</b></header>
<div v-if="!emptyBookmarks" v-for="link in shared" :key="link.id" class="d-flex mt-2">
<a target="_blank" :href="link.url"><i class="fa fa-solid fa-arrow-up-right-from-square"></i> {{ link.title }}</a>
<a class="ms-auto" href="#" @click.prevent="removeLink(link.bookmark_id)" v-show="configMode"><i class="fa fa-regular fa-trash-can"></i></a>
</div>
<template v-if="!emptyBookmarks">
<div v-for="link in shared" :key="link.id" class="d-flex mt-2">
<a target="_blank" :href="link.url"><i class="fa fa-solid fa-arrow-up-right-from-square"></i> {{ link.title }}</a>
<a class="ms-auto" href="#" @click.prevent="removeLink(link.bookmark_id)" v-show="configMode"><i class="fa fa-regular fa-trash-can"></i></a>
</div>
</template>
<div v-else class="d-flex mt-2">
<span>{{$p.t('bookmark','emptyBookmarks')}}</span>
</div>
@@ -8,7 +8,7 @@ if (!$result = @$db->db_query("SELECT to_regclass('dashboard.tbl_bookmark')"))
bookmark_id BIGINT PRIMARY KEY,
uid VARCHAR(255) NOT NULL,
url VARCHAR(511) NOT NULL,
title VARCHAR(255) NULL,
title VARCHAR(255) NOT NULL,
tag VARCHAR(255) NULL,
insertamum TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
insertvon VARCHAR(255) NULL REFERENCES public.tbl_benutzer(uid),