Bugzilla – Attachment 176721 Details for
Bug 37930
Change how we handle authorised values in Vue
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37930: Move AV code to a dedicated file
Bug-37930-Move-AV-code-to-a-dedicated-file.patch (text/plain), 13.51 KB, created by
Matt Blenkinsop
on 2025-01-17 11:37:21 UTC
(
hide
)
Description:
Bug 37930: Move AV code to a dedicated file
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2025-01-17 11:37:21 UTC
Size:
13.51 KB
patch
obsolete
>From e66a00352947d7de9bc7bcd2a6fb68cd38b71d03 Mon Sep 17 00:00:00 2001 >From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >Date: Thu, 16 Jan 2025 15:42:56 +0000 >Subject: [PATCH] Bug 37930: Move AV code to a dedicated file > >--- > .../vue/components/ERM/AgreementsFormAdd.vue | 4 +- > .../js/vue/components/ERM/AgreementsList.vue | 9 +-- > .../prog/js/vue/components/ERM/Main.vue | 40 +++++------ > .../js/vue/composables/authorisedValues.js | 50 ++++++++++++++ > .../prog/js/vue/stores/authorised-values.js | 67 ------------------- > .../intranet-tmpl/prog/js/vue/stores/erm.js | 14 ++++ > .../intranet-tmpl/prog/js/vue/stores/main.js | 54 --------------- > 7 files changed, 87 insertions(+), 151 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/composables/authorisedValues.js > delete mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised-values.js > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue >index 02c9ef53b05..d37adb6d37b 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue >@@ -200,8 +200,8 @@ import { storeToRefs } from "pinia" > > export default { > setup() { >- const mainStore = inject("mainStore") >- const { authorisedValues } = storeToRefs(mainStore) >+ const ERMStore = inject("ERMStore") >+ const { authorisedValues } = storeToRefs(ERMStore) > > return { > authorisedValues, >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 5443a5f40d2..c1934e6daf9 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 >@@ -72,12 +72,9 @@ export default { > const vendorStore = inject("vendorStore") > const { vendors } = storeToRefs(vendorStore) > >- const { >- setConfirmationDialog, >- setMessage, >- get_lib_from_av, >- map_av_dt_filter, >- } = inject("mainStore") >+ const { setConfirmationDialog, setMessage } = inject("mainStore") >+ >+ const { get_lib_from_av, map_av_dt_filter } = inject("ERMStore") > > const table = ref() > >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 45cb6d97033..9cbb5482f45 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 >@@ -43,11 +43,12 @@ export default { > > const mainStore = inject("mainStore") > >- const { loading, loaded, setError, loadAuthorisedValues } = mainStore >+ const { loading, loaded, setError } = mainStore > > const ERMStore = inject("ERMStore") > > const { config, authorisedValues } = storeToRefs(ERMStore) >+ const { loadAuthorisedValues } = ERMStore > > return { > vendorStore, >@@ -70,8 +71,6 @@ export default { > this.loading() > > const fetch_config = () => { >- let promises = [] >- > const acq_client = APIClient.acquisition > acq_client.vendors.getAll().then( > vendors => { >@@ -79,32 +78,29 @@ export default { > }, > error => {} > ) >- this.loadAuthorisedValues(this.authorisedValues).then(() => { >+ this.loadAuthorisedValues( >+ this.authorisedValues, >+ this.ERMStore >+ ).then(() => { > this.loaded() > this.initialized = true > }) > } > > const client = APIClient.erm >- client.config >- .get() >- .then(config => { >- this.config = config >- if (this.config.settings.ERMModule != 1) { >- this.loaded() >- return this.setError( >- this.$__( >- "The e-resource management module is disabled, turn on <a href='/cgi-bin/koha/admin/preferences.pl?tab=&op=search&searchfield=ERMModule'>ERMModule</a> 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 <a href="/cgi-bin/koha/admin/preferences.pl?tab=&op=search&searchfield=ERMModule">ERMModule</a> to use it' >+ ), >+ false >+ ) >+ } >+ return fetch_config() >+ }) > }, > methods: { > async filterProviders(navigationTree) { >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/composables/authorisedValues.js b/koha-tmpl/intranet-tmpl/prog/js/vue/composables/authorisedValues.js >new file mode 100644 >index 00000000000..3bfdb9ac305 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/composables/authorisedValues.js >@@ -0,0 +1,50 @@ >+import { APIClient } from "../fetch/api-client.js"; >+ >+export const get_lib_from_av_handler = (arr_name, av, store) => { >+ if (store.authorisedValues[arr_name] === undefined) { >+ console.warn( >+ "The authorised value category for '%s' is not defined.".format( >+ arr_name >+ ) >+ ); >+ return; >+ } >+ let o = store.authorisedValues[arr_name].find(e => e.value == av); >+ return o ? o.description : av; >+}; >+export const map_av_dt_filter_handler = (arr_name, store) => { >+ return store.authorisedValues[arr_name].map(e => { >+ e["_id"] = e["value"]; >+ e["_str"] = e["description"]; >+ return e; >+ }); >+}; >+export const loadAuthorisedValues = async (authorisedValues, targetStore) => { >+ 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 >+ ); >+ targetStore.authorisedValues[AVName] = >+ AVMatch.authorised_values; >+ }); >+ }) >+ ); >+ >+ return Promise.all(promises); >+}; >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 >deleted file mode 100644 >index ef77373d689..00000000000 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised-values.js >+++ /dev/null >@@ -1,67 +0,0 @@ >-import { defineStore } from "pinia"; >- >-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: [], >- }), >- actions: { >- 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; >- }); >- }, >- }, >-}); >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 6e8b13074d0..244501ea158 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/erm.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/erm.js >@@ -1,4 +1,9 @@ > import { defineStore } from "pinia"; >+import { >+ loadAuthorisedValues, >+ get_lib_from_av_handler, >+ map_av_dt_filter_handler, >+} from "../composables/authorisedValues"; > > export const useERMStore = defineStore("erm", { > state: () => ({ >@@ -59,4 +64,13 @@ export const useERMStore = defineStore("erm", { > ], > }, > }), >+ actions: { >+ loadAuthorisedValues, >+ get_lib_from_av(arr_name, av) { >+ return get_lib_from_av_handler(arr_name, av, this); >+ }, >+ map_av_dt_filter(arr_name) { >+ return map_av_dt_filter_handler(arr_name, this); >+ }, >+ }, > }); >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 97daf68301f..3334101a62f 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js >@@ -1,5 +1,4 @@ > import { defineStore } from "pinia"; >-import { APIClient } from "../fetch/api-client.js"; > > export const useMainStore = defineStore("main", { > state: () => ({ >@@ -92,59 +91,6 @@ export const useMainStore = defineStore("main", { > loaded() { > this._is_loading = false; > }, >- get_lib_from_av(arr_name, av) { >- if (this.authorisedValues[arr_name] === undefined) { >- console.warn( >- "The authorised value category for '%s' is not defined.".format( >- arr_name >- ) >- ); >- return; >- } >- let o = this.authorisedValues[arr_name].find(e => e.value == av); >- return o ? o.description : av; >- }, >- map_av_dt_filter(arr_name) { >- return this.authorisedValues[arr_name].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 >- ); >- this.authorisedValues[AVName] = >- AVMatch.authorised_values; >- } >- ); >- }) >- ); >- >- return Promise.all(promises); >- }, > }, > getters: { > error() { >-- >2.48.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 37930
:
171556
|
171557
|
171558
|
171628
|
172863
|
172864
|
172865
|
172886
|
172887
|
172888
|
172979
|
173069
|
176677
|
176678
|
176679
|
176719
|
176720
|
176721
|
176722
|
176830
|
178248
|
178249
|
178250
|
178251