Bugzilla – Attachment 171556 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: Add a method to initialise the AV store
Bug-37930-Add-a-method-to-initialise-the-AV-store.patch (text/plain), 10.50 KB, created by
Matt Blenkinsop
on 2024-09-16 15:31:39 UTC
(
hide
)
Description:
Bug 37930: Add a method to initialise the AV store
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2024-09-16 15:31:39 UTC
Size:
10.50 KB
patch
obsolete
>From fec8c5ca628604014e9d28e076ff9044f9b1d244 Mon Sep 17 00:00:00 2001 >From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >Date: Mon, 16 Sep 2024 15:27:17 +0000 >Subject: [PATCH] Bug 37930: Add a method to initialise the AV store > >This patch adds a method to initialise the authorised values in a vue app. It will automatically load authorised values into the app and store them in the authorised values store based on the entries in a matrix file. The intent behind this is to make adding authorised values into a Vue app much simpler and more DRY, especially when creating a new vue app. You will just need to add your app into the avMatrix.js file and add a call to the initialisation method in your app. >--- > .../prog/js/vue/stores/authorised-values.js | 67 -------------- > .../authorisedValues/authorised-values.js | 74 ++++++++++++++++ > .../vue/stores/authorisedValues/avMatrix.js | 88 +++++++++++++++++++ > 3 files changed, 162 insertions(+), 67 deletions(-) > delete mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised-values.js > create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorisedValues/authorised-values.js > create mode 100644 koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorisedValues/avMatrix.js > >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/authorisedValues/authorised-values.js b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorisedValues/authorised-values.js >new file mode 100644 >index 00000000000..6da22387a7d >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorisedValues/authorised-values.js >@@ -0,0 +1,74 @@ >+import { defineStore } from "pinia"; >+import { APIClient } from "../../fetch/api-client.js"; >+import { avMatrix } from "./avMatrix.js"; >+ >+export const useAVStore = defineStore("authorised_values", { >+ state: () => ({ >+ ...Object.keys(avMatrix).reduce((acc, moduleKey) => { >+ const moduleValues = Object.keys(avMatrix[moduleKey]).reduce( >+ (acc, avKey) => { >+ acc[avKey] = avMatrix[moduleKey][avKey].values; >+ return acc; >+ }, >+ {} >+ ); >+ >+ return { ...acc, ...moduleValues }; >+ }, {}), >+ }), >+ 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; >+ }); >+ }, >+ async initialiseAVStore(module) { >+ const authorisedValues = Object.keys(avMatrix[module]).reduce( >+ (acc, avKey) => { >+ if (!avMatrix[module][avKey].name) return acc; >+ acc[avKey] = avMatrix[module][avKey]; >+ return acc; >+ }, >+ {} >+ ); >+ >+ const AVCatArray = Object.keys(authorisedValues).map(avCat => { >+ return '"' + authorisedValues[avCat].name + '"'; >+ }); >+ >+ const promises = []; >+ const AVClient = APIClient.authorised_values; >+ promises.push( >+ AVClient.values >+ .getCategoriesWithValues(AVCatArray) >+ .then(AVCategories => { >+ Object.entries(authorisedValues).forEach( >+ ([AVName, AVCat]) => { >+ const AVMatch = AVCategories.find( >+ element => >+ element.category_name == AVCat.name >+ ); >+ this[AVName] = AVMatch.authorised_values; >+ } >+ ); >+ }) >+ ); >+ >+ return Promise.all(promises); >+ }, >+ }, >+}); >diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorisedValues/avMatrix.js b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorisedValues/avMatrix.js >new file mode 100644 >index 00000000000..aee7461fb63 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorisedValues/avMatrix.js >@@ -0,0 +1,88 @@ >+export const avMatrix = { >+ erm: { >+ av_agreement_statuses: { name: "ERM_AGREEMENT_STATUS", values: [] }, >+ av_agreement_closure_reasons: { >+ name: "ERM_AGREEMENT_CLOSURE_REASON", >+ values: [], >+ }, >+ av_agreement_renewal_priorities: { >+ name: "ERM_AGREEMENT_RENEWAL_PRIORITY", >+ values: [], >+ }, >+ av_user_roles: { name: "ERM_USER_ROLES", values: [] }, >+ av_license_types: { name: "ERM_LICENSE_TYPE", values: [] }, >+ av_license_statuses: { name: "ERM_LICENSE_STATUS", values: [] }, >+ av_agreement_license_statuses: { >+ name: "ERM_AGREEMENT_LICENSE_STATUS", >+ values: [], >+ }, >+ av_agreement_license_location: { >+ name: "ERM_AGREEMENT_LICENSE_LOCATION", >+ values: [], >+ }, >+ av_package_types: { name: "ERM_PACKAGE_TYPE", values: [] }, >+ av_package_content_types: { >+ name: "ERM_PACKAGE_CONTENT_TYPE", >+ values: [], >+ }, >+ av_title_publication_types: { >+ name: "ERM_TITLE_PUBLICATION_TYPE", >+ values: [], >+ }, >+ av_report_types: { name: "ERM_REPORT_TYPES", values: [] }, >+ av_platform_reports_metrics: { >+ name: "ERM_PLATFORM_REPORTS_METRICS", >+ values: [], >+ }, >+ av_database_reports_metrics: { >+ name: "ERM_DATABASE_REPORTS_METRICS", >+ values: [], >+ }, >+ av_title_reports_metrics: { >+ name: "ERM_TITLE_REPORTS_METRICS", >+ values: [], >+ }, >+ av_item_reports_metrics: { >+ name: "ERM_ITEM_REPORTS_METRICS", >+ values: [], >+ }, >+ av_agreement_relationships: { >+ name: null, >+ values: [ >+ { 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") }, >+ ], >+ }, >+ }, >+ preservation: { >+ av_notforloan: { name: "NOT_LOAN", values: [] }, >+ }, >+}; >-- >2.39.3 (Apple Git-146)
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
|
180243
|
180244
|
180245
|
180246
|
180689
|
180698
|
180699
|
180700
|
180701
|
180767
|
180768
|
180769
|
180770
|
180771
|
180772
|
180773
|
180774
|
180775