Lines 1-51
Link Here
|
1 |
import { defineStore } from "pinia"; |
1 |
import { defineStore } from "pinia"; |
|
|
2 |
import { APIClient } from "../fetch/api-client.js"; |
2 |
|
3 |
|
3 |
export const useAVStore = defineStore("authorised_values", { |
4 |
export const useAVStore = defineStore("authorised_values", { |
4 |
state: () => ({ |
5 |
state: () => ({}), |
5 |
av_agreement_statuses: [], |
|
|
6 |
av_agreement_closure_reasons: [], |
7 |
av_agreement_renewal_priorities: [], |
8 |
av_user_roles: [], |
9 |
av_license_types: [], |
10 |
av_license_statuses: [], |
11 |
av_agreement_license_statuses: [], |
12 |
av_agreement_license_location: [], |
13 |
av_agreement_relationships: [ |
14 |
{ value: "supersedes", description: __("supersedes") }, |
15 |
{ value: "is-superseded-by", description: __("is superseded by") }, |
16 |
{ |
17 |
value: "provides_post-cancellation_access_for", |
18 |
description: __("provides post-cancellation access for"), |
19 |
}, |
20 |
{ |
21 |
value: "has-post-cancellation-access-in", |
22 |
description: __("has post-cancellation access in"), |
23 |
}, |
24 |
{ |
25 |
value: "tracks_demand-driven_acquisitions_for", |
26 |
description: __("tracks demand-driven acquisitions for"), |
27 |
}, |
28 |
{ |
29 |
value: "has-demand-driven-acquisitions-in", |
30 |
description: __("has demand-driven acquisitions in"), |
31 |
}, |
32 |
{ value: "has_backfile_in", description: __("has backfile in") }, |
33 |
{ value: "has_frontfile_in", description: __("has frontfile in") }, |
34 |
{ value: "related_to", description: __("related to") }, |
35 |
], |
36 |
av_package_types: [], |
37 |
av_package_content_types: [], |
38 |
av_title_publication_types: [], |
39 |
av_notforloan: [], |
40 |
av_report_types: [], |
41 |
av_platform_reports_metrics: [], |
42 |
av_database_reports_metrics: [], |
43 |
av_title_reports_metrics: [], |
44 |
av_item_reports_metrics: [], |
45 |
}), |
46 |
actions: { |
6 |
actions: { |
47 |
get_lib_from_av(arr_name, av) { |
7 |
get_lib_from_av(array, av) { |
48 |
if (this[arr_name] === undefined) { |
8 |
if (array === undefined) { |
49 |
console.warn( |
9 |
console.warn( |
50 |
"The authorised value category for '%s' is not defined.".format( |
10 |
"The authorised value category for '%s' is not defined.".format( |
51 |
arr_name |
11 |
arr_name |
Lines 53-67
export const useAVStore = defineStore("authorised_values", {
Link Here
|
53 |
); |
13 |
); |
54 |
return; |
14 |
return; |
55 |
} |
15 |
} |
56 |
let o = this[arr_name].find(e => e.value == av); |
16 |
let o = array.find(e => e.value == av); |
57 |
return o ? o.description : av; |
17 |
return o ? o.description : av; |
58 |
}, |
18 |
}, |
59 |
map_av_dt_filter(arr_name) { |
19 |
map_av_dt_filter(array) { |
60 |
return this[arr_name].map(e => { |
20 |
return array.map(e => { |
61 |
e["_id"] = e["value"]; |
21 |
e["_id"] = e["value"]; |
62 |
e["_str"] = e["description"]; |
22 |
e["_str"] = e["description"]; |
63 |
return e; |
23 |
return e; |
64 |
}); |
24 |
}); |
65 |
}, |
25 |
}, |
|
|
26 |
async loadAuthorisedValues(authorisedValues) { |
27 |
const AVsToFetch = Object.keys(authorisedValues).reduce( |
28 |
(acc, avKey) => { |
29 |
if (Array.isArray(authorisedValues[avKey])) return acc; |
30 |
acc[avKey] = authorisedValues[avKey]; |
31 |
return acc; |
32 |
}, |
33 |
{} |
34 |
); |
35 |
|
36 |
const AVCatArray = Object.keys(AVsToFetch).map(avCat => { |
37 |
return '"' + AVsToFetch[avCat] + '"'; |
38 |
}); |
39 |
|
40 |
const promises = []; |
41 |
const AVClient = APIClient.authorised_values; |
42 |
promises.push( |
43 |
AVClient.values |
44 |
.getCategoriesWithValues(AVCatArray) |
45 |
.then(AVCategories => { |
46 |
Object.entries(AVsToFetch).forEach( |
47 |
([AVName, AVCat]) => { |
48 |
const AVMatch = AVCategories.find( |
49 |
element => element.category_name == AVCat |
50 |
); |
51 |
authorisedValues[AVName] = |
52 |
AVMatch.authorised_values; |
53 |
} |
54 |
); |
55 |
}) |
56 |
); |
57 |
|
58 |
return Promise.all(promises); |
59 |
}, |
66 |
}, |
60 |
}, |
67 |
}); |
61 |
}); |