From d2ac478c7245c48bd26a747a15bf0c878d53952b Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Fri, 4 Aug 2023 11:55:59 +0000 Subject: [PATCH] Bug 34417: Add routeClass to routes and api call This patch adds a class to match the route to the API call and ensure that no items with the same property (e.g. license.name and agreement.name) can lead to incorrect breadcrumbs. Code is also moved into the get() request function to reduce the number of times it is called --- .../prog/js/vue/fetch/erm-api-client.js | 4 +++ .../prog/js/vue/fetch/http-client.js | 32 +++++++++++-------- .../intranet-tmpl/prog/js/vue/modules/erm.ts | 22 ++++++++++++- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js index 0acdcac5a4..d918e6c1d6 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js @@ -25,6 +25,7 @@ export class ERMAPIClient extends HttpClient { "x-koha-embed": "periods,user_roles,user_roles.patron,agreement_licenses,agreement_licenses.license,agreement_relationships,agreement_relationships.related_agreement,documents,agreement_packages,agreement_packages.package,vendor", }, + class: 'agreement' }), getAll: query => this.getAll({ @@ -67,6 +68,7 @@ export class ERMAPIClient extends HttpClient { "x-koha-embed": "user_roles,user_roles.patron,vendor,documents", }, + class: 'license' }), getAll: query => this.getAll({ @@ -112,6 +114,7 @@ export class ERMAPIClient extends HttpClient { "x-koha-embed": "package_agreements,package_agreements.agreement,resources+count,vendor", }, + class: 'local_package' }), getAll: query => this.getAll({ @@ -156,6 +159,7 @@ export class ERMAPIClient extends HttpClient { headers: { "x-koha-embed": "resources,resources.package", }, + class: 'local_title' }), delete: id => this.delete({ diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js index 807db61039..74436dda18 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js @@ -42,26 +42,30 @@ class HttpClient { if (error) throw Error(error); - const navigationStore = useNavigationStore() - const { current } = navigationStore - current.forEach(route => { - const { title, path } = route.meta.self - if(title && title.dynamic && res[title.identifier]) { - navigationStore.setBreadcrumbParameter({ - breadcrumbText: res[title.identifier], - path: path - }) - } - }) - return res; } - get(params = {}) { - return this._fetchJSON(params.endpoint, params.headers, { + async get(params = {}) { + const res = await this._fetchJSON(params.endpoint, params.headers, { ...params.options, method: "GET", }); + + const navigationStore = useNavigationStore() + const { current } = navigationStore + if(current && current.slice(-1)[0].routeClass === params.class) { + current.forEach(route => { + const { title, path } = route.meta.self + if(title && title.dynamic && res[title.identifier]) { + navigationStore.setBreadcrumbParameter({ + breadcrumbText: res[title.identifier], + path: path + }) + } + }) + } + + return res } getAll(params = {}) { diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/modules/erm.ts b/koha-tmpl/intranet-tmpl/prog/js/vue/modules/erm.ts index f8391a091f..5141b0ff51 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/modules/erm.ts +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/modules/erm.ts @@ -60,7 +60,17 @@ app.mount("#erm"); const { removeMessages } = mainStore; router.beforeEach((to, from) => { - navigationStore.setCurrent(to.matched) + let matchedRoutes = [] + if (to.path.match(/\/erm\/agreements/)) { + matchedRoutes = _setRouteClass(to.matched, 'agreement') + } else if (to.path.match(/\/erm\/licenses/)) { + matchedRoutes = _setRouteClass(to.matched, 'license') + } else if (to.path.match(/\/erm\/eholdings\/local\/packages/)) { + matchedRoutes = _setRouteClass(to.matched, 'local_package') + } else if (to.path.match(/\/erm\/eholdings\/local\/titles/)) { + matchedRoutes = _setRouteClass(to.matched, 'local_title') + } + navigationStore.setCurrent(matchedRoutes) navigationStore.setParams(to.params || {}) navigationStore.setBreadcrumbParameter({}) removeMessages(); // This will actually flag the messages as displayed already @@ -81,3 +91,13 @@ router.afterEach((to, from) => { node.click(); } }); + +const _setRouteClass = (routes: Array, routeClass: string) => { + const classedRoutes = routes.map(route => { + return { + ...route, + routeClass + } + }) + return classedRoutes +} -- 2.37.1 (Apple Git-137.1)