From 0b80976cb38088bfbdf1c1a93a0bfda298729963 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Tue, 24 Jun 2025 15:03:09 +0100 Subject: [PATCH] Bug 38201: Allow the breadcrumb to be dynamic in the show component Signed-off-by: Michaela Sieber Signed-off-by: Jonathan Druart Signed-off-by: Lucas Gass --- .../prog/js/vue/composables/base-resource.js | 3 +++ .../intranet-tmpl/prog/js/vue/routes/erm.js | 2 +- .../prog/js/vue/stores/navigation.js | 24 +++++++++++++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/composables/base-resource.js b/koha-tmpl/intranet-tmpl/prog/js/vue/composables/base-resource.js index ab6140561a..44de86eb70 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/composables/base-resource.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/composables/base-resource.js @@ -9,6 +9,8 @@ export function useBaseResource(instancedResource) { const route = useRoute(); const { setConfirmationDialog, setMessage, setError, setWarning } = inject("mainStore"); + const navigationStore = inject("navigationStore"); + const { breadcrumbMetadata } = storeToRefs(navigationStore); const moduleStoreUtils = {}; if (instancedResource.moduleStore) { @@ -363,6 +365,7 @@ export function useBaseResource(instancedResource) { //TODO: Rename this 'resource' to 'fetchedResource'. Needs to also be renamed in ResourceFormAdd and ResourceShow // This is to make it clear that this is the fetchedResource (data), not the resource component class componentData.resource.value = resource; + breadcrumbMetadata.value = resource; if (componentData.instancedResource.afterResourceFetch) { componentData.instancedResource.afterResourceFetch( componentData, diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/routes/erm.js b/koha-tmpl/intranet-tmpl/prog/js/vue/routes/erm.js index 6452d6a788..09d3e90e41 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/routes/erm.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/routes/erm.js @@ -49,7 +49,7 @@ export const routes = [ path: ":agreement_id", name: "AgreementsShow", component: markRaw(ResourceWrapper), - title: $__("Show agreement"), + title: $__("Show {name}"), }, { path: "add", diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/navigation.js b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/navigation.js index 0f06174540..646e5f2ca5 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/navigation.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/navigation.js @@ -14,6 +14,7 @@ export const useNavigationStore = defineStore("navigation", () => { params: {}, from: null, query: {}, + breadcrumbMetadata: null, }); const actions = { setRoutes(routesDef) { @@ -79,7 +80,8 @@ export const useNavigationStore = defineStore("navigation", () => { return _buildFromCurrentMatches( store.current, store.routeState, - store.params + store.params, + store.breadcrumbMetadata ); return _getBaseElements(store.routeState); @@ -111,7 +113,8 @@ export const useNavigationStore = defineStore("navigation", () => { function _buildFromCurrentMatches( currentMatches, routeState, - params + params, + breadcrumbMetadata ) { return [ { @@ -119,7 +122,7 @@ export const useNavigationStore = defineStore("navigation", () => { icon: null, children: null, }, - ..._mapMatches(currentMatches, params), + ..._mapMatches(currentMatches, params, breadcrumbMetadata), ]; } @@ -140,7 +143,7 @@ export const useNavigationStore = defineStore("navigation", () => { return match.path; } - function _mapMatches(currentMatches, params) { + function _mapMatches(currentMatches, params, breadcrumbMetadata) { const matches = currentMatches .filter(match => _isBaseOrNotStub(match.meta.self)) .filter(match => _isEmptyNode(match.meta.self)) @@ -158,13 +161,24 @@ export const useNavigationStore = defineStore("navigation", () => { }); } const breadcrumbInfo = { - ...match.meta.self, + ...self, icon: null, ...(externalPath ? { href: path, path: null } : { path }), children: null, }; + if ( + breadcrumbMetadata && + /(?:{([^}]+)})/.test(self.title) + ) { + breadcrumbInfo.title = self.title.replaceAll( + /(?:{([^}]+)})/g, + (match, paramName) => { + return breadcrumbMetadata[paramName]; + } + ); + } return breadcrumbInfo; }); return matches;