From 8a8c18b82dd3c8c70fcf1eeb4486da05de1e5a67 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Thu, 17 Oct 2024 11:08:05 +0000 Subject: [PATCH] Bug 37930: Restore AV store to hold methods --- .../prog/js/vue/components/ERM/Main.vue | 34 ++++--- .../intranet-tmpl/prog/js/vue/modules/erm.ts | 3 + .../prog/js/vue/stores/authorised-values.js | 88 +++++++++---------- .../intranet-tmpl/prog/js/vue/stores/main.js | 54 ------------ 4 files changed, 60 insertions(+), 119 deletions(-) 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 b3c61e6c9a4..a57c85cc2c0 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,9 +41,12 @@ export default { setup() { const vendorStore = inject("vendorStore") + const AVStore = inject("AVStore") + const { loadAuthorisedValues } = AVStore + const mainStore = inject("mainStore") - const { loading, loaded, setError, loadAuthorisedValues } = mainStore + const { loading, loaded, setError } = mainStore const ERMStore = inject("ERMStore") @@ -86,24 +89,19 @@ export default { } const client = APIClient.erm - client.config - .get() - .then(config => { - this.config = config - if (this.config.settings.ERMModule != 1) { - return this.setError( - this.$__( - 'The e-resource management module is disabled, turn on ERMModule to use it' - ), - false - ) - } - return fetch_config() - }) - .then(() => { + client.config.get().then(config => { + this.config = config + if (this.config.settings.ERMModule != 1) { this.loaded() - this.initialized = true - }) + return this.setError( + this.$__( + 'The e-resource management module is disabled, turn on ERMModule to use it' + ), + false + ) + } + return fetch_config() + }) }, methods: { async filterProviders(navigationTree) { 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 4dcca91eddc..683527607d9 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/modules/erm.ts +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/modules/erm.ts @@ -24,6 +24,7 @@ import { useVendorStore } from "../stores/vendors"; import { useERMStore } from "../stores/erm"; import { useNavigationStore } from "../stores/navigation"; import { useReportsStore } from "../stores/usage-reports"; +import { useAVStore } from "../stores/authorised-values"; import i18n from "../i18n"; const pinia = createPinia(); @@ -55,6 +56,8 @@ const ERMStore = useERMStore(pinia); app.provide("ERMStore", ERMStore); const reportsStore = useReportsStore(pinia); app.provide("reportsStore", reportsStore); +const AVStore = useAVStore(pinia); +app.provide("AVStore", AVStore); app.mount("#erm"); diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised-values.js b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised-values.js index ef77373d689..e4df2c2f032 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised-values.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised-values.js @@ -1,51 +1,11 @@ import { defineStore } from "pinia"; +import { APIClient } from "../fetch/api-client.js"; export const useAVStore = defineStore("authorised_values", { - state: () => ({ - av_agreement_statuses: [], - av_agreement_closure_reasons: [], - av_agreement_renewal_priorities: [], - av_user_roles: [], - av_license_types: [], - av_license_statuses: [], - av_agreement_license_statuses: [], - av_agreement_license_location: [], - 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") }, - ], - av_package_types: [], - av_package_content_types: [], - av_title_publication_types: [], - av_notforloan: [], - av_report_types: [], - av_platform_reports_metrics: [], - av_database_reports_metrics: [], - av_title_reports_metrics: [], - av_item_reports_metrics: [], - }), + state: () => ({}), actions: { - get_lib_from_av(arr_name, av) { - if (this[arr_name] === undefined) { + get_lib_from_av(array, av) { + if (array === undefined) { console.warn( "The authorised value category for '%s' is not defined.".format( arr_name @@ -53,15 +13,49 @@ export const useAVStore = defineStore("authorised_values", { ); return; } - let o = this[arr_name].find(e => e.value == av); + let o = array.find(e => e.value == av); return o ? o.description : av; }, - map_av_dt_filter(arr_name) { - return this[arr_name].map(e => { + map_av_dt_filter(array) { + return array.map(e => { e["_id"] = e["value"]; e["_str"] = e["description"]; return e; }); }, + async loadAuthorisedValues(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); + }, }, }); 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 97963b28a2b..d35245720c7 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js @@ -91,60 +91,6 @@ 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)