From 8c00158d04e409d03bc0114ee54c60540fff4991 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 22 Apr 2025 09:52:07 +0200 Subject: [PATCH 1/2] refactor(Dashboard Database data structure): changes how the data for the dashboard is structured in the database, instead of having a global widgets property, each section has its own widgets property where additional properties like description can be stored --- application/controllers/dashboard/Config.php | 12 ++++++------ application/libraries/dashboard/DashboardLib.php | 15 ++++++++------- public/js/apps/DashboardAdmin.js | 3 ++- public/js/components/Dashboard/Admin/Presets.js | 3 +-- public/js/components/Dashboard/Dashboard.js | 12 ++++++------ public/js/components/Dashboard/Section.js | 8 ++++---- public/js/components/Drop/Grid.js | 2 +- 7 files changed, 28 insertions(+), 27 deletions(-) diff --git a/application/controllers/dashboard/Config.php b/application/controllers/dashboard/Config.php index 2c0cf5fca..f6db9509f 100644 --- a/application/controllers/dashboard/Config.php +++ b/application/controllers/dashboard/Config.php @@ -65,7 +65,7 @@ class Config extends Auth_Controller $preset_decoded = json_decode($preset->preset, true); - $this->DashboardLib->addWidgetsToWidgets($preset_decoded['widgets'], $dashboard_kurzbz, $funktion_kurzbz, $input->widgets); + $this->DashboardLib->addWidgetsToWidgets($preset_decoded, $dashboard_kurzbz, $funktion_kurzbz, $input->widgets); $preset->preset = json_encode($preset_decoded); @@ -92,7 +92,7 @@ class Config extends Auth_Controller } $preset_decoded = json_decode($preset->preset, true); - if (!$this->DashboardLib->removeWidgetFromWidgets($preset_decoded['widgets'], $funktion_kurzbz, $widgetid)) + if (!$this->DashboardLib->removeWidgetFromWidgets($preset_decoded, $funktion_kurzbz, $widgetid)) { http_response_code(404); $this->terminateWithJsonError('widgetid ' . $widgetid . ' not found'); @@ -119,7 +119,7 @@ class Config extends Auth_Controller $override_decoded = json_decode($override->override, true); - $this->DashboardLib->addWidgetsToWidgets($override_decoded['widgets'], $dashboard_kurzbz, $funktion_kurzbz, $input->widgets); + $this->DashboardLib->addWidgetsToWidgets($override_decoded, $dashboard_kurzbz, $funktion_kurzbz, $input->widgets); $override->override = json_encode($override_decoded); @@ -148,7 +148,7 @@ class Config extends Auth_Controller $override_decoded = json_decode($override->override, true); - if (!$this->DashboardLib->removeWidgetFromWidgets($override_decoded['widgets'], $funktion_kurzbz, $widgetid)) + if (!$this->DashboardLib->removeWidgetFromWidgets($override_decoded, $funktion_kurzbz, $widgetid)) { http_response_code(404); $this->terminateWithJsonError('widgetid ' . $widgetid . ' not found'); @@ -202,10 +202,10 @@ class Config extends Auth_Controller if ($conf) { $preset = json_decode($conf->preset, true); - if (!isset($preset['widgets']) || !isset($preset['widgets'][$funktion])) + if (!isset($preset[$funktion]) || !isset($preset[$funktion]['widgets'])) $result[$funktion] = []; else - $result[$funktion] = $preset['widgets'][$funktion]; + $result[$funktion] = $preset[$funktion]['widgets']; } else $result[$funktion] = []; diff --git a/application/libraries/dashboard/DashboardLib.php b/application/libraries/dashboard/DashboardLib.php index edea7c310..72072f657 100644 --- a/application/libraries/dashboard/DashboardLib.php +++ b/application/libraries/dashboard/DashboardLib.php @@ -107,7 +107,7 @@ class DashboardLib $emptyoverride = new stdClass(); $emptyoverride->dashboard_id = $dashboard->dashboard_id; $emptyoverride->uid = $uid; - $emptyoverride->override = '{"widgets": {"' . self::USEROVERRIDE_SECTION . '": {}}}'; + $emptyoverride->override = '{"' . self::USEROVERRIDE_SECTION . '": {"widgets":{}}}}'; return $emptyoverride; } @@ -127,7 +127,7 @@ class DashboardLib $emptypreset->dashboard_id = $dashboard->dashboard_id; $emptypreset->funktion_kurzbz = $funktion_kurzbz; $section = ($funktion_kurzbz !== null) ? $funktion_kurzbz : self::SECTION_IF_FUNKTION_KURZBZ_IS_NULL; - $emptypreset->preset = '{"widgets": {"' . $section . '": {}}}'; + $emptypreset->preset = '{"' . $section . '": { "widgets" : {}}}'; return $emptypreset; } @@ -206,21 +206,22 @@ class DashboardLib public function addWidgetToWidgets(&$widgets, $section, $widget, $widgetid) { $section = ($section !== null) ? $section : self::SECTION_IF_FUNKTION_KURZBZ_IS_NULL; - if (!isset($widgets[$section]) || !is_array($widgets[$section])) + if (!isset($widgets[$section]) || !isset($widgets[$section]["widgets"]) || !is_array($widgets[$section])) { $widgets[$section] = array(); + $widgets[$section]["widgets"] = array(); } - $widgets[$section][$widgetid] = $widget; + $widgets[$section]["widgets"][$widgetid] = $widget; } public function removeWidgetFromWidgets(&$widgets, $section, $widgetid) { $section = ($section !== null) ? $section : self::SECTION_IF_FUNKTION_KURZBZ_IS_NULL; - if (isset($widgets[$section]) && isset($widgets[$section][$widgetid])) + if (isset($widgets[$section]) && isset($widgets[$section]["widgets"][$widgetid])) { - unset($widgets[$section][$widgetid]); - if(empty($widgets[$section]) && $section !== self::USEROVERRIDE_SECTION) { + unset($widgets[$section]["widgets"][$widgetid]); + if(empty($widgets[$section]["widgets"]) && $section !== self::USEROVERRIDE_SECTION) { unset($widgets[$section]); } return true; diff --git a/public/js/apps/DashboardAdmin.js b/public/js/apps/DashboardAdmin.js index 1f3e831c8..05b438798 100644 --- a/public/js/apps/DashboardAdmin.js +++ b/public/js/apps/DashboardAdmin.js @@ -1,5 +1,6 @@ import {CoreNavigationCmpt} from '../components/navigation/Navigation.js'; import DashboardAdmin from '../components/Dashboard/Admin.js'; +import Phrases from "../plugin/Phrasen.js" Vue.createApp({ name: 'DashboardAdminApp', @@ -12,4 +13,4 @@ Vue.createApp({ }, mounted() { } -}).mount('#main'); \ No newline at end of file +}).use(Phrases).mount('#main'); \ No newline at end of file diff --git a/public/js/components/Dashboard/Admin/Presets.js b/public/js/components/Dashboard/Admin/Presets.js index fa8f65970..8d6a07803 100644 --- a/public/js/components/Dashboard/Admin/Presets.js +++ b/public/js/components/Dashboard/Admin/Presets.js @@ -42,7 +42,7 @@ export default { funktion_kurzbz: section_name, widgets: [widget] }).then(result => { - let newId = Object.keys(result.data.retval.data.widgets[section_name]).pop(); + let newId = Object.keys(result.data.retval.data[section_name].widgets).pop(); widget.id = newId; widget.custom = 1; this.sections.forEach(section => { @@ -126,7 +126,6 @@ export default { }}).then(res => { if (this.tmpLoading !== funktionen.join('###')) return; // NOTE(chris): prevent race condition - for (var section in res.data.retval) { let widgets = []; for (var wid in res.data.retval[section]) { diff --git a/public/js/components/Dashboard/Dashboard.js b/public/js/components/Dashboard/Dashboard.js index e6f26d169..046edf920 100644 --- a/public/js/components/Dashboard/Dashboard.js +++ b/public/js/components/Dashboard/Dashboard.js @@ -70,7 +70,7 @@ export default { funktion_kurzbz: section_name, widgets: [widget] }).then(result => { - let newId = Object.keys(result.data.retval.data.widgets[section_name]).pop(); + let newId = Object.keys(result.data.retval.data[section_name].widgets).pop(); widget.id = newId; this.sections.forEach(section => { if (section.name == section_name) { @@ -159,13 +159,13 @@ export default { axios.get(this.apiurl + '/Config', {params:{ db: this.dashboard }}).then(res => { - for (var name in res.data.retval.widgets) { + for (var name in res.data.retval) { let widgets = []; let remove = []; - for (var wid in res.data.retval.widgets[name]) { - res.data.retval.widgets[name][wid].id = wid; - if (res.data.retval.widgets[name][wid].custom || res.data.retval.widgets[name][wid].preset) - widgets.push(res.data.retval.widgets[name][wid]); + for (var wid in res.data.retval[name].widgets) { + res.data.retval[name].widgets[wid].id = wid; + if (res.data.retval[name].widgets[wid].custom || res.data.retval[name].widgets[wid].preset) + widgets.push(res.data.retval[name].widgets[wid]); else remove.push(wid); } diff --git a/public/js/components/Dashboard/Section.js b/public/js/components/Dashboard/Section.js index 4a2a4eaaa..5c4b82206 100644 --- a/public/js/components/Dashboard/Section.js +++ b/public/js/components/Dashboard/Section.js @@ -14,8 +14,8 @@ export default { }, inject: { widgetsSetup:{ - type: Object, - default: {}, + type: Array, + default: [], }, adminMode: { type: Boolean, @@ -188,7 +188,7 @@ export default { }); }, template: ` -

+

{{name}}:

@@ -208,7 +208,7 @@ export default { :config="item.config" :custom="item.custom" :hidden="item.hidden" - :editMode="editMode" + :editMode="editModeIsActive" :place="item.place[gridWidth]" :setup="computedWidgetsSetup[item.widget]" @change="saveConfig($event, item)" diff --git a/public/js/components/Drop/Grid.js b/public/js/components/Drop/Grid.js index 4b4b181d3..396af5901 100644 --- a/public/js/components/Drop/Grid.js +++ b/public/js/components/Drop/Grid.js @@ -609,7 +609,7 @@ export default { Date: Tue, 22 Apr 2025 11:40:58 +0200 Subject: [PATCH 2/2] update(Dashboard Section description): adds phrases for the description of general/custom/other sections --- .../libraries/dashboard/DashboardLib.php | 2 +- public/js/components/Dashboard/Dashboard.js | 3 +- public/js/components/Dashboard/Section.js | 27 ++++- system/phrasesupdate.php | 104 +++++++++++++++++- 4 files changed, 130 insertions(+), 6 deletions(-) diff --git a/application/libraries/dashboard/DashboardLib.php b/application/libraries/dashboard/DashboardLib.php index 72072f657..7aab6b949 100644 --- a/application/libraries/dashboard/DashboardLib.php +++ b/application/libraries/dashboard/DashboardLib.php @@ -127,7 +127,7 @@ class DashboardLib $emptypreset->dashboard_id = $dashboard->dashboard_id; $emptypreset->funktion_kurzbz = $funktion_kurzbz; $section = ($funktion_kurzbz !== null) ? $funktion_kurzbz : self::SECTION_IF_FUNKTION_KURZBZ_IS_NULL; - $emptypreset->preset = '{"' . $section . '": { "widgets" : {}}}'; + $emptypreset->preset = '{"' . $section . '": { "widgets" : {}},"custom": { "widgets" : {}}}'; return $emptypreset; } diff --git a/public/js/components/Dashboard/Dashboard.js b/public/js/components/Dashboard/Dashboard.js index 046edf920..005551570 100644 --- a/public/js/components/Dashboard/Dashboard.js +++ b/public/js/components/Dashboard/Dashboard.js @@ -143,7 +143,7 @@ export default { } }, created() { - + this.$p.loadCategory('dashboard'); axios.get(this.apiurl + '/Widget/getWidgetsForDashboard', { params: { db: this.dashboard @@ -175,6 +175,7 @@ export default { }); remove.forEach(wid => this.widgetRemove(name, wid)); } + this.sections = this.sections.sort((section1, section2) => section2.widgets.length - section1.widgets.length); }).catch(err => console.error('ERROR:', err)); }, async beforeMount() { diff --git a/public/js/components/Dashboard/Section.js b/public/js/components/Dashboard/Section.js index 5c4b82206..17c2ac004 100644 --- a/public/js/components/Dashboard/Section.js +++ b/public/js/components/Dashboard/Section.js @@ -93,8 +93,29 @@ export default { }, methods: { + sectionNameTranslation(){ + switch(this.name){ + case "general": + return this.$p.t('dashboard',this.name); + break; + case "custom": + return this.$p.t('dashboard',this.name); + break; + default: + return this.name; + break; + } + }, showSectionInformation(){ - SectionModal.popup(`this is the information for the section ${name}`); + if (this.name == "general"){ + SectionModal.popup(this.$p.t('dashboard', 'dashboardGeneralSectionDescription')); + } + else if(this.name == "custom"){ + SectionModal.popup(this.$p.t('dashboard', 'dashboardCustomSectionDescription')); + } + else{ + SectionModal.popup(this.$p.t('dashboard', 'dashboardSectionDescription', [this.name])); + } }, handleConfigOpened() { this.configOpened = true @@ -188,9 +209,9 @@ export default { }); }, template: ` -

+

- {{name}}: + {{sectionNameTranslation()}}:

diff --git a/system/phrasesupdate.php b/system/phrasesupdate.php index 01f0427b6..dd874ddff 100644 --- a/system/phrasesupdate.php +++ b/system/phrasesupdate.php @@ -38354,6 +38354,106 @@ array( ) ), // ### STUDIENGANG_INFORMATIONEN PHRASEN ENDE + array( + 'app' => 'core', + 'category' => 'dashboard', + 'phrase' => 'general', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'Allgemein', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'General', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'dashboard', + 'phrase' => 'custom', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'Benutzerdefiniert', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'Custom', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'dashboard', + 'phrase' => 'dashboardGeneralSectionDescription', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'Hier befinden sich die vordefinierten Widgets', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'Here are the predefined widgets', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'dashboard', + 'phrase' => 'dashboardCustomSectionDescription', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'Hier befinden sich die Widgets Ihrer persönlichen Anpassungen', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'Here are the widgets of your personal cutomizations', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), + array( + 'app' => 'core', + 'category' => 'dashboard', + 'phrase' => 'dashboardSectionDescription', + 'insertvon' => 'system', + 'phrases' => array( + array( + 'sprache' => 'German', + 'text' => 'Hier befinden sich die Widgets der {0} Funktion', + 'description' => '', + 'insertvon' => 'system' + ), + array( + 'sprache' => 'English', + 'text' => 'Here are the widgets of the {0} function', + 'description' => '', + 'insertvon' => 'system' + ) + ) + ), // CIS4 phrases from legacy code end array( 'app' => 'core', @@ -38414,7 +38514,9 @@ array( 'insertvon' => 'system' ) ) - ) + ), + + );