From 37dffbba19b9a105806c775e0042e10698a93fb6 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 5 Nov 2024 11:32:02 +0100 Subject: [PATCH] fix(Dashboard widget Url): adds validation method for both input fields and fixes confirm delete dialog --- public/js/components/DashboardWidget/Url.js | 84 +++++++++++++------ system/dbupdate_3.4.php | 2 +- ... => 41134_C4_bookmark_dashboardWidget.php} | 39 +++++++-- system/phrasesupdate.php | 20 +++++ 4 files changed, 109 insertions(+), 36 deletions(-) rename system/dbupdate_3.4/{41134_bookmark_dashboardWidget.php => 41134_C4_bookmark_dashboardWidget.php} (64%) diff --git a/public/js/components/DashboardWidget/Url.js b/public/js/components/DashboardWidget/Url.js index 8dabf7b4c..c3ad0c810 100644 --- a/public/js/components/DashboardWidget/Url.js +++ b/public/js/components/DashboardWidget/Url.js @@ -5,7 +5,10 @@ export default { data: () => ({ title_input: "", url_input: "", - invalidURL: false, + validation:{ + invalidURL: false, + invalidTitel:false, + } }), mixins: [AbstractWidget], computed: { @@ -23,28 +26,37 @@ export default { }, }, methods: { + isValidationSuccessfull(){ + // validate the input fields + if (this.title_input.length === 0) { + this.$fhcAlert.alertError(this.$p.t("bookmark", "invalidTitel")); + this.validation.invalidTitel = true; + } + if (!URL.canParse(this.url_input)) { + this.$fhcAlert.alertError(this.$p.t("bookmark", "invalidUrl")); + this.validation.invalidURL = true; + } + + return !Object.values(this.validation).some(value => value === true); + }, async fetchBookmarks() { await this.$fhcApi.factory.bookmark .getBookmarks() .then((res) => res.data) .then((result) => { - this.shared = result; - }) + this.shared = result; + }) .catch(this.$fhcAlert.handleSystemError); }, - async confirmDelete() { - if ((await this.$fhcAlert.confirmDelete()) === false) return; - }, addLink() { // reset is-invalid css on url input field - this.invalidURL = false; - - if(!URL.canParse(this.url_input)) - { - this.$fhcAlert.alertError(this.$p.t("bookmark", "invalidUrl")); - this.invalidURL = true; - return; + for(let key of Object.keys(this.validation)){ + this.validation[key] = false; } + + // early return if validation failed + if (!this.isValidationSuccessfull()) return; + this.$fhcApi.factory.bookmark .insert({ tag: this.config.tag, @@ -54,28 +66,30 @@ export default { .then((res) => res.data) .then((result) => { this.$fhcAlert.alertInfo(this.$p.t("bookmark", "bookmarkAdded")); + // refetch the bookmarks to see the updates + this.fetchBookmarks(); }) .catch(this.$fhcAlert.handleSystemError); // 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 + let isConfirmed = await this.$fhcAlert.confirmDelete(); + + // early return if the confirm dialog was not confirmed + if(!isConfirmed) return; + + this.$fhcApi.factory.bookmark .delete(bookmark_id) .then((res) => res.data) .then((result) => { this.$fhcAlert.alertInfo(this.$p.t("bookmark", "bookmarkDeleted")); + // refetch the bookmarks to see the updates + this.fetchBookmarks(); }) .catch(this.$fhcAlert.handleSystemError); - - // refetch the bookmarks to see the updates - this.fetchBookmarks(); }, }, async mounted() { @@ -92,11 +106,22 @@ export default {
{{$p.t('bookmark','newLink')}}

- - -
- {{$p.t("bookmark", "invalidUrl")}}. +
+ + +
+ {{$p.t("bookmark", "invalidTitel")}}. +
+ +
+ + +
+ {{$p.t("bookmark", "invalidUrl")}}. +
+
+
@@ -107,8 +132,13 @@ export default {
{{ tagName }}
diff --git a/system/dbupdate_3.4.php b/system/dbupdate_3.4.php index aab8d1134..2f4f38608 100644 --- a/system/dbupdate_3.4.php +++ b/system/dbupdate_3.4.php @@ -59,7 +59,7 @@ require_once('dbupdate_3.4/25999_cis4_cms.php'); require_once('dbupdate_3.4/36530_bis_internationsalisierung_codextabelle_neuerungen.php'); require_once('dbupdate_3.4/34543_ux_template.php'); require_once('dbupdate_3.4/17513_Entwicklungsteam.php'); -require_once('dbupdate_3.4/41134_bookmark_dashboardWidget.php'); +require_once('dbupdate_3.4/41134_C4_bookmark_dashboardWidget.php'); require_once('dbupdate_3.4/28575_softwarebereitstellung.php'); require_once('dbupdate_3.4/41150_oe-pfad_db_view.php'); require_once('dbupdate_3.4/44031_stv_favorites.php'); diff --git a/system/dbupdate_3.4/41134_bookmark_dashboardWidget.php b/system/dbupdate_3.4/41134_C4_bookmark_dashboardWidget.php similarity index 64% rename from system/dbupdate_3.4/41134_bookmark_dashboardWidget.php rename to system/dbupdate_3.4/41134_C4_bookmark_dashboardWidget.php index ebcdeba91..c54b4c2ca 100644 --- a/system/dbupdate_3.4/41134_bookmark_dashboardWidget.php +++ b/system/dbupdate_3.4/41134_C4_bookmark_dashboardWidget.php @@ -2,8 +2,11 @@ if (!$result = @$db->db_query("SELECT to_regclass('dashboard.tbl_bookmark')")) { - $qry = "BEGIN TRANSACTION; - + if (!$db->db_query("BEGIN;")) + { + echo 'wasnt able to start transaction for 41134_C4_bookmark_dashboardWidget: ' . $db->db_last_error() . '
'; + } + $qry = " CREATE TABLE IF NOT EXISTS dashboard.tbl_bookmark( bookmark_id BIGINT PRIMARY KEY, uid VARCHAR(255) NOT NULL, @@ -33,12 +36,32 @@ if (!$result = @$db->db_query("SELECT to_regclass('dashboard.tbl_bookmark')")) 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'; - + { + // Rollback + if (!$db->db_query("ROLLBACK;")) + { + echo 'wasnt able to rollback: ' . $db->db_last_error() . '
'; + } + else + { + echo 'ROLLED BACK 41134_C4_bookmark_dashboardWidget
'; + } + echo 'error occurred during tbl_bookmark creation: ' . $db->db_last_error() . '
'; + } + else + { + // Commit + if (!$db->db_query("COMMIT;")) + { + echo 'wasnt able to commit: ' . $db->db_last_error() . '
'; + } + else + { + echo 'COMMITED 41134_C4_bookmark_dashboardWidget
'; + } + echo '
dashboard.tbl_bookmark and dashboard.tbl_bookmark_sequence was created'; + } } diff --git a/system/phrasesupdate.php b/system/phrasesupdate.php index d90cd362a..9fcc8f489 100644 --- a/system/phrasesupdate.php +++ b/system/phrasesupdate.php @@ -31524,6 +31524,26 @@ array( ) ) ), + array( + 'app' => 'core', + 'category' => 'bookmark', + 'phrase' => 'invalidTitel', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'Ungültiger Titel', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'Invalid title', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), array( 'app' => 'core', 'category' => 'global',