From 50b2334e5cbe76005c72ed275a3c031b3b2b05db Mon Sep 17 00:00:00 2001 From: Harald Bamberger Date: Wed, 13 Aug 2025 10:38:30 +0200 Subject: [PATCH 1/3] work in progess, calc tabs title suffix when component is not rendered --- .../api/frontend/v1/stv/Config.php | 3 ++- public/js/components/Notiz/Notiz.js | 3 +++ public/js/components/Tabs.js | 22 ++++++++++++++++--- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/application/controllers/api/frontend/v1/stv/Config.php b/application/controllers/api/frontend/v1/stv/Config.php index 935928c81..a6a66e670 100644 --- a/application/controllers/api/frontend/v1/stv/Config.php +++ b/application/controllers/api/frontend/v1/stv/Config.php @@ -68,7 +68,8 @@ class Config extends FHCAPI_Controller 'title' => $this->p->t('stv', 'tab_notes'), 'component' => './Stv/Studentenverwaltung/Details/Notizen.js', 'config' => $config['notes'], - 'showSuffix' => $showSuffix && ($config['notes']['showCountNotes'] ?? false) + 'showSuffix' => $showSuffix && ($config['notes']['showCountNotes'] ?? false), + 'suffixhelper' => APP_ROOT . 'public/js/components/Stv/Studentenverwaltung/Details/Notizen/NotizenSuffixHelper.js' ]; $result['contact'] = [ diff --git a/public/js/components/Notiz/Notiz.js b/public/js/components/Notiz/Notiz.js index ab4230681..03e3d0c4a 100644 --- a/public/js/components/Notiz/Notiz.js +++ b/public/js/components/Notiz/Notiz.js @@ -517,6 +517,9 @@ export default { }); }) .catch(this.$fhcAlert.handleSystemError); + }, + getSuffix() { + return '(bhtest)'; } }, created() { diff --git a/public/js/components/Tabs.js b/public/js/components/Tabs.js index 349fcf01c..e52c724b3 100644 --- a/public/js/components/Tabs.js +++ b/public/js/components/Tabs.js @@ -67,9 +67,9 @@ export default { } }, methods: { - handleTabClick: function(index) { + handleTabClick: function (e) { let keys = Object.keys(this.tabs); - this.change(keys[index]); + this.change(keys[e.index]); }, change(key) { this.$emit("change", key) @@ -108,8 +108,24 @@ export default { title: Vue.computed(() => item.title || key), config: item.config, key, - value + value, + suffixhelper: null }; + + const fetchhelper = async function (tab, item) { + if (!item.showSuffix) + return null; + + const mod = await import(item.suffixhelper); + tab.suffixhelper = mod.getSuffix; + // TODO call suffixhelper with modelValue - but modelValue not defined in this scope + /* + tab.suffixhelper(modelValue).then((response) => { + tab.value.suffix = response.data; + }); + */ + }; + fetchhelper(tabs[key], item); } if (Array.isArray(config)) From d4f5a7c92f8d9948b1fa07502d923cfb9443d0f7 Mon Sep 17 00:00:00 2001 From: Harald Bamberger Date: Wed, 13 Aug 2025 16:37:28 +0200 Subject: [PATCH 2/3] add missing helper js file --- .../Details/Notizen/NotizenSuffixHelper.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 public/js/components/Stv/Studentenverwaltung/Details/Notizen/NotizenSuffixHelper.js diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Notizen/NotizenSuffixHelper.js b/public/js/components/Stv/Studentenverwaltung/Details/Notizen/NotizenSuffixHelper.js new file mode 100644 index 000000000..4fef188eb --- /dev/null +++ b/public/js/components/Stv/Studentenverwaltung/Details/Notizen/NotizenSuffixHelper.js @@ -0,0 +1,8 @@ +import ApiNotizPerson from '../../../../../api/factory/notiz/person.js'; + +export async function getSuffix(modelValue) { + const response = await this.$api + .call(ApiNotizPerson.getCountNotes(modelValue.person_id)); + const suffix = ' (' + response.data + ')'; + return suffix; +} \ No newline at end of file From 1092463beb20c520500b2cdac16c2d40970c6738 Mon Sep 17 00:00:00 2001 From: Harald Bamberger Date: Thu, 14 Aug 2025 15:23:42 +0200 Subject: [PATCH 3/3] show count of notes in tab title --- .../api/frontend/v1/stv/Config.php | 5 +- public/js/components/Notiz/Notiz.js | 24 +--------- .../Studentenverwaltung/Details/Notizen.js | 8 +--- public/js/components/Tabs.js | 47 ++++++++++--------- .../Details/Notizen/NotizenSuffixHelper.js | 6 +-- 5 files changed, 33 insertions(+), 57 deletions(-) rename public/js/{components => helpers}/Stv/Studentenverwaltung/Details/Notizen/NotizenSuffixHelper.js (55%) diff --git a/application/controllers/api/frontend/v1/stv/Config.php b/application/controllers/api/frontend/v1/stv/Config.php index a6a66e670..2fb436384 100644 --- a/application/controllers/api/frontend/v1/stv/Config.php +++ b/application/controllers/api/frontend/v1/stv/Config.php @@ -63,13 +63,12 @@ class Config extends FHCAPI_Controller 'config' => $config['details'] ]; - $showSuffix = $config['notes']['showCountNotes'] ?? false; $result['notes'] = [ 'title' => $this->p->t('stv', 'tab_notes'), 'component' => './Stv/Studentenverwaltung/Details/Notizen.js', 'config' => $config['notes'], - 'showSuffix' => $showSuffix && ($config['notes']['showCountNotes'] ?? false), - 'suffixhelper' => APP_ROOT . 'public/js/components/Stv/Studentenverwaltung/Details/Notizen/NotizenSuffixHelper.js' + 'showSuffix' => ($config['notes']['showCountNotes'] ?? false), + 'suffixhelper' => APP_ROOT . 'public/js/helpers/Stv/Studentenverwaltung/Details/Notizen/NotizenSuffixHelper.js' ]; $result['contact'] = [ diff --git a/public/js/components/Notiz/Notiz.js b/public/js/components/Notiz/Notiz.js index 03e3d0c4a..58168fbc7 100644 --- a/public/js/components/Notiz/Notiz.js +++ b/public/js/components/Notiz/Notiz.js @@ -295,8 +295,7 @@ export default { showType_id: false, showId: false, showLastupdate: false - }, - newCount: null + } } }, methods: { @@ -368,7 +367,6 @@ export default { .catch(this.$fhcAlert.handleSystemError) .finally(() => { window.scrollTo(0, 0); - this.getCountNotes(); }); }, deleteNotiz(notiz_id) { @@ -383,7 +381,6 @@ export default { .catch(this.$fhcAlert.handleSystemError) .finally(() => { window.scrollTo(0, 0); - this.getCountNotes(); }); }, loadNotiz(notiz_id) { @@ -427,7 +424,6 @@ export default { .catch(this.$fhcAlert.handleSystemError) .finally(() => { window.scrollTo(0, 0); - this.getCountNotes(); }); }, reload() { @@ -505,21 +501,6 @@ export default { const columnToShow = "show" + column.charAt(0).toUpperCase() + column.slice(1); this.showVariables[columnToShow] = true; }); - }, - getCountNotes(){ - return this.$api - .call(this.endpoint.getCountNotes(this.id)) - .then( - result => { - this.newCount = result.data; - this.$nextTick(() => { - this.$emit('updateCount', this.newCount); - }); - }) - .catch(this.$fhcAlert.handleSystemError); - }, - getSuffix() { - return '(bhtest)'; } }, created() { @@ -530,9 +511,6 @@ export default { if (this.showTinyMce) { await this.initTinyMCE(); } - this.$nextTick(() => { - this.getCountNotes(); - }); }, watch: { //watcher für Tinymce-Textfeld diff --git a/public/js/components/Stv/Studentenverwaltung/Details/Notizen.js b/public/js/components/Stv/Studentenverwaltung/Details/Notizen.js index 6d7033012..ea6776dce 100644 --- a/public/js/components/Stv/Studentenverwaltung/Details/Notizen.js +++ b/public/js/components/Stv/Studentenverwaltung/Details/Notizen.js @@ -16,12 +16,6 @@ export default { countNotiz: '' }; }, - methods: { - updateCountNotes(countNew){ - this.headerSuffix = "(" + countNew + ")"; - this.$emit('update:suffix', this.headerSuffix); - } - }, template: `
@@ -37,7 +31,7 @@ export default { show-document show-tiny-mce :visibleColumns="['titel','text','verfasser','bearbeiter','dokumente']" - @updateCount="updateCountNotes" + @reload="$emit('update:suffix')" > diff --git a/public/js/components/Tabs.js b/public/js/components/Tabs.js index e52c724b3..aedd5c1c9 100644 --- a/public/js/components/Tabs.js +++ b/public/js/components/Tabs.js @@ -14,7 +14,7 @@ export default { emits: [ 'update:modelValue', 'change', - 'changed', + 'changed' ], props: { config: { @@ -109,23 +109,8 @@ export default { config: item.config, key, value, - suffixhelper: null + suffixhelper: item.suffixhelper ?? null }; - - const fetchhelper = async function (tab, item) { - if (!item.showSuffix) - return null; - - const mod = await import(item.suffixhelper); - tab.suffixhelper = mod.getSuffix; - // TODO call suffixhelper with modelValue - but modelValue not defined in this scope - /* - tab.suffixhelper(modelValue).then((response) => { - tab.value.suffix = response.data; - }); - */ - }; - fetchhelper(tabs[key], item); } if (Array.isArray(config)) @@ -141,15 +126,35 @@ export default { } this.tabs = tabs; }, - updateSuffix(event) { - if (this.currentTab?.value) { - this.currentTab.value.suffix = event; + updateSuffix() { + this.getTabSuffix(this.currentTab); + }, + async getTabSuffix(tab) { + if (!tab.value.showSuffix) { + return; } + + if (tab.suffixhelper !== null) { + const suffixhelper = await import(tab.suffixhelper); + const suffix = await suffixhelper.getSuffix(this.$api, this.modelValue); + tab.value.suffix = suffix; + } else { + tab.value.suffix = ''; + } + }, + getTabSuffixes() { + Object.entries(this.tabs).forEach(([key, item]) => this.getTabSuffix(item)); } }, created() { this.initConfig(this.config); }, + mounted() { + this.getTabSuffixes(); + }, + updated() { + this.getTabSuffixes(); + }, template: `