Koha/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised-values.js
Jonathan Druart 5d8c6a36b8
Bug 32983: ERM - Retrieve AVs from an endpoint
Bug 32981 let us retrieve the authorised values from a REST API route,
instead of injecting them from the template. Let us that for the ERM module!

Test plan:
You will notice a "Loading" screen when refreshing the ERM module
Then you should not notice any other UI changes. Dropdown list should be
populated like before this patch.

Some technical notes:
I am expecting this to be slower than before, but it feels better to use
a REST API route to retrieve the AV
Future improvement will be to lazy load the AVs, to speed up the landing
page. However it needs more changes, and this gets big enough.
I would like to see a follow-up that move the code from ERM/Main.vue to
the authorised value store (I've failed at that), but that should
certainly be done after the lazy loading is implemented anyway)

Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2023-03-02 14:46:09 -03:00

61 lines
2.2 KiB
JavaScript

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: [],
}),
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;
});
},
},
});