From 5e9d98a8af55a72d48dd1eec290f880fdbcb44a6 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Tue, 17 Sep 2024 14:27:55 +0000 Subject: [PATCH] Bug 37930: [DO NOT PUSH] Alternate concept Alternative patch taking into account feedback in comment 5 on the bug. This patch removes the authorised values store and migrates the methods to the main store. Authorised values are now added into the module specific store and replaced on module load with the actual values To test I've added a console log of the values in the store to the AgreementsList component so apply all patches on the bug and then navigate to the agreements table in ERM. The module will throw errors as I haven't been through and changed all the instances where we would need to swap the AV store for the ERM store (there are a lot of instances and this is just a proof of concept for discussion for now). Check that the logged values are as expected. If you have the Vue devtools you'll be able to see the store values and check them directly in there --- .../js/vue/components/ERM/AgreementsList.vue | 3 + .../prog/js/vue/components/ERM/Main.vue | 13 ++--- .../intranet-tmpl/prog/js/vue/modules/erm.ts | 3 - .../intranet-tmpl/prog/js/vue/stores/erm.js | 50 +++++++++++++++++ .../intranet-tmpl/prog/js/vue/stores/main.js | 55 +++++++++++++++++++ 5 files changed, 113 insertions(+), 11 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue index 0b3fc2aa822..a22e14819af 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue @@ -75,6 +75,9 @@ export default { const { setConfirmationDialog, setMessage } = inject("mainStore") + const { authorisedValues } = inject("ERMStore") + console.log(authorisedValues) + const table = ref() const filters = reactive({ diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Main.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Main.vue index beabf6e96c2..a43b063599d 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Main.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Main.vue @@ -41,26 +41,23 @@ export default { setup() { const vendorStore = inject("vendorStore") - const AVStore = inject("AVStore") - const { initialiseAVStore } = AVStore - const mainStore = inject("mainStore") - const { loading, loaded, setError } = mainStore + const { loading, loaded, setError, loadAuthorisedValues } = mainStore const ERMStore = inject("ERMStore") - const { config } = storeToRefs(ERMStore) + const { config, authorisedValues } = storeToRefs(ERMStore) return { vendorStore, - AVStore, ERMStore, config, setError, loading, loaded, - initialiseAVStore, + loadAuthorisedValues, + authorisedValues, } }, data() { @@ -80,7 +77,7 @@ export default { }, error => {} ) - this.initialiseAVStore("erm").then(() => { + this.loadAuthorisedValues(this.authorisedValues).then(() => { this.loaded() this.initialized = true }) 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 26ecaba18f7..4dcca91eddc 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/modules/erm.ts +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/modules/erm.ts @@ -21,7 +21,6 @@ import { routes as routesDef } from "../routes/erm"; import { useMainStore } from "../stores/main"; import { useVendorStore } from "../stores/vendors"; -import { useAVStore } from "../stores/authorisedValues/authorised-values"; import { useERMStore } from "../stores/erm"; import { useNavigationStore } from "../stores/navigation"; import { useReportsStore } from "../stores/usage-reports"; @@ -30,7 +29,6 @@ import i18n from "../i18n"; const pinia = createPinia(); const mainStore = useMainStore(pinia); -const AVStore = useAVStore(pinia); const navigationStore = useNavigationStore(pinia); const routes = navigationStore.setRoutes(routesDef); @@ -52,7 +50,6 @@ const rootComponent = app app.config.unwrapInjectedRef = true; app.provide("vendorStore", useVendorStore(pinia)); app.provide("mainStore", mainStore); -app.provide("AVStore", AVStore); app.provide("navigationStore", navigationStore); const ERMStore = useERMStore(pinia); app.provide("ERMStore", ERMStore); diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/erm.js b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/erm.js index 3570499eadd..6e8b13074d0 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/erm.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/erm.js @@ -8,5 +8,55 @@ export const useERMStore = defineStore("erm", { ERMProviders: [], }, }, + authorisedValues: { + av_agreement_statuses: "ERM_AGREEMENT_STATUS", + av_agreement_closure_reasons: "ERM_AGREEMENT_CLOSURE_REASON", + av_agreement_renewal_priorities: "ERM_AGREEMENT_RENEWAL_PRIORITY", + av_user_roles: "ERM_USER_ROLES", + av_license_types: "ERM_LICENSE_TYPE", + av_license_statuses: "ERM_LICENSE_STATUS", + av_agreement_license_statuses: "ERM_AGREEMENT_LICENSE_STATUS", + av_agreement_license_location: "ERM_AGREEMENT_LICENSE_LOCATION", + av_package_types: "ERM_PACKAGE_TYPE", + av_package_content_types: "ERM_PACKAGE_CONTENT_TYPE", + av_title_publication_types: "ERM_TITLE_PUBLICATION_TYPE", + av_report_types: "ERM_REPORT_TYPES", + av_platform_reports_metrics: "ERM_PLATFORM_REPORTS_METRICS", + av_database_reports_metrics: "ERM_DATABASE_REPORTS_METRICS", + av_title_reports_metrics: "ERM_TITLE_REPORTS_METRICS", + av_item_reports_metrics: "ERM_ITEM_REPORTS_METRICS", + av_agreement_relationships: [ + { value: "supersedes", description: __("supersedes") }, + { + value: "is-superseded-by", + description: __("is superseded by"), + }, + { + value: "provides_post-cancellation_access_for", + description: __("provides post-cancellation access for"), + }, + { + value: "has-post-cancellation-access-in", + description: __("has post-cancellation access in"), + }, + { + value: "tracks_demand-driven_acquisitions_for", + description: __("tracks demand-driven acquisitions for"), + }, + { + value: "has-demand-driven-acquisitions-in", + description: __("has demand-driven acquisitions in"), + }, + { + value: "has_backfile_in", + description: __("has backfile in"), + }, + { + value: "has_frontfile_in", + description: __("has frontfile in"), + }, + { value: "related_to", description: __("related to") }, + ], + }, }), }); diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js index 7a0c9e65166..97963b28a2b 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js @@ -1,4 +1,5 @@ import { defineStore } from "pinia"; +import { APIClient } from "../fetch/api-client.js"; export const useMainStore = defineStore("main", { state: () => ({ @@ -90,6 +91,60 @@ export const useMainStore = defineStore("main", { loaded() { this._is_loading = false; }, + get_lib_from_av(arr_name, av) { + if (this[arr_name] === undefined) { + console.warn( + "The authorised value category for '%s' is not defined.".format( + arr_name + ) + ); + return; + } + let o = this[arr_name].find(e => e.value == av); + return o ? o.description : av; + }, + map_av_dt_filter(arr_name) { + return this[arr_name].map(e => { + e["_id"] = e["value"]; + e["_str"] = e["description"]; + return e; + }); + }, + async loadAuthorisedValues(authorisedValues) { + console.log(authorisedValues); + const AVsToFetch = Object.keys(authorisedValues).reduce( + (acc, avKey) => { + if (Array.isArray(authorisedValues[avKey])) return acc; + acc[avKey] = authorisedValues[avKey]; + return acc; + }, + {} + ); + + const AVCatArray = Object.keys(AVsToFetch).map(avCat => { + return '"' + AVsToFetch[avCat] + '"'; + }); + + const promises = []; + const AVClient = APIClient.authorised_values; + promises.push( + AVClient.values + .getCategoriesWithValues(AVCatArray) + .then(AVCategories => { + Object.entries(AVsToFetch).forEach( + ([AVName, AVCat]) => { + const AVMatch = AVCategories.find( + element => element.category_name == AVCat + ); + authorisedValues[AVName] = + AVMatch.authorised_values; + } + ); + }) + ); + + return Promise.all(promises); + }, }, getters: { error() { -- 2.39.3 (Apple Git-146)