From 6fcc8cf7e845915fc861b9e497865ef148b11545 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Thu, 1 Aug 2024 11:49:14 +0200 Subject: [PATCH] code review changes --- .../controllers/api/frontend/v1/Bookmark.php | 39 +--- public/js/api/bookmark.js | 20 +- public/js/apps/Dashboard/Fhc.js | 5 +- public/js/components/Dashboard/Item.js | 199 +++++++++--------- public/js/components/DashboardWidget/Url.js | 25 +-- .../41134_bookmark_dashboardWidget.php | 2 +- 6 files changed, 124 insertions(+), 166 deletions(-) diff --git a/application/controllers/api/frontend/v1/Bookmark.php b/application/controllers/api/frontend/v1/Bookmark.php index 9fb8a6519..a811843ce 100644 --- a/application/controllers/api/frontend/v1/Bookmark.php +++ b/application/controllers/api/frontend/v1/Bookmark.php @@ -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); diff --git a/public/js/api/bookmark.js b/public/js/api/bookmark.js index 5c99a4010..30e49d50d 100644 --- a/public/js/api/bookmark.js +++ b/public/js/api/bookmark.js @@ -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 + } ); }, } \ No newline at end of file diff --git a/public/js/apps/Dashboard/Fhc.js b/public/js/apps/Dashboard/Fhc.js index 824f03bd2..a20bb5b64 100755 --- a/public/js/apps/Dashboard/Fhc.js +++ b/public/js/apps/Dashboard/Fhc.js @@ -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'); diff --git a/public/js/components/Dashboard/Item.js b/public/js/components/Dashboard/Item.js index 67b814946..42608899d 100755 --- a/public/js/components/Dashboard/Item.js +++ b/public/js/components/Dashboard/Item.js @@ -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*/ `
@@ -132,7 +123,7 @@ export default {
-