View | Details | Raw Unified | Return to bug 37930
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue (-2 / +2 lines)
Lines 200-207 import { storeToRefs } from "pinia" Link Here
200
200
201
export default {
201
export default {
202
    setup() {
202
    setup() {
203
        const mainStore = inject("mainStore")
203
        const ERMStore = inject("ERMStore")
204
        const { authorisedValues } = storeToRefs(mainStore)
204
        const { authorisedValues } = storeToRefs(ERMStore)
205
205
206
        return {
206
        return {
207
            authorisedValues,
207
            authorisedValues,
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsList.vue (-6 / +3 lines)
Lines 72-83 export default { Link Here
72
        const vendorStore = inject("vendorStore")
72
        const vendorStore = inject("vendorStore")
73
        const { vendors } = storeToRefs(vendorStore)
73
        const { vendors } = storeToRefs(vendorStore)
74
74
75
        const {
75
        const { setConfirmationDialog, setMessage } = inject("mainStore")
76
            setConfirmationDialog,
76
77
            setMessage,
77
        const { get_lib_from_av, map_av_dt_filter } = inject("ERMStore")
78
            get_lib_from_av,
79
            map_av_dt_filter,
80
        } = inject("mainStore")
81
78
82
        const table = ref()
79
        const table = ref()
83
80
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Main.vue (-22 / +18 lines)
Lines 43-53 export default { Link Here
43
43
44
        const mainStore = inject("mainStore")
44
        const mainStore = inject("mainStore")
45
45
46
        const { loading, loaded, setError, loadAuthorisedValues } = mainStore
46
        const { loading, loaded, setError } = mainStore
47
47
48
        const ERMStore = inject("ERMStore")
48
        const ERMStore = inject("ERMStore")
49
49
50
        const { config, authorisedValues } = storeToRefs(ERMStore)
50
        const { config, authorisedValues } = storeToRefs(ERMStore)
51
        const { loadAuthorisedValues } = ERMStore
51
52
52
        return {
53
        return {
53
            vendorStore,
54
            vendorStore,
Lines 70-77 export default { Link Here
70
        this.loading()
71
        this.loading()
71
72
72
        const fetch_config = () => {
73
        const fetch_config = () => {
73
            let promises = []
74
75
            const acq_client = APIClient.acquisition
74
            const acq_client = APIClient.acquisition
76
            acq_client.vendors.getAll().then(
75
            acq_client.vendors.getAll().then(
77
                vendors => {
76
                vendors => {
Lines 79-110 export default { Link Here
79
                },
78
                },
80
                error => {}
79
                error => {}
81
            )
80
            )
82
            this.loadAuthorisedValues(this.authorisedValues).then(() => {
81
            this.loadAuthorisedValues(
82
                this.authorisedValues,
83
                this.ERMStore
84
            ).then(() => {
83
                this.loaded()
85
                this.loaded()
84
                this.initialized = true
86
                this.initialized = true
85
            })
87
            })
86
        }
88
        }
87
89
88
        const client = APIClient.erm
90
        const client = APIClient.erm
89
        client.config
91
        client.config.get().then(config => {
90
            .get()
92
            this.config = config
91
            .then(config => {
93
            if (this.config.settings.ERMModule != 1) {
92
                this.config = config
93
                if (this.config.settings.ERMModule != 1) {
94
                    this.loaded()
95
                    return this.setError(
96
                        this.$__(
97
                            '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'
98
                        ),
99
                        false
100
                    )
101
                }
102
                return fetch_config()
103
            })
104
            .then(() => {
105
                this.loaded()
94
                this.loaded()
106
                this.initialized = true
95
                return this.setError(
107
            })
96
                    this.$__(
97
                        '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'
98
                    ),
99
                    false
100
                )
101
            }
102
            return fetch_config()
103
        })
108
    },
104
    },
109
    methods: {
105
    methods: {
110
        async filterProviders(navigationTree) {
106
        async filterProviders(navigationTree) {
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/composables/authorisedValues.js (+50 lines)
Line 0 Link Here
1
import { APIClient } from "../fetch/api-client.js";
2
3
export const get_lib_from_av_handler = (arr_name, av, store) => {
4
    if (store.authorisedValues[arr_name] === undefined) {
5
        console.warn(
6
            "The authorised value category for '%s' is not defined.".format(
7
                arr_name
8
            )
9
        );
10
        return;
11
    }
12
    let o = store.authorisedValues[arr_name].find(e => e.value == av);
13
    return o ? o.description : av;
14
};
15
export const map_av_dt_filter_handler = (arr_name, store) => {
16
    return store.authorisedValues[arr_name].map(e => {
17
        e["_id"] = e["value"];
18
        e["_str"] = e["description"];
19
        return e;
20
    });
21
};
22
export const loadAuthorisedValues = async (authorisedValues, targetStore) => {
23
    const AVsToFetch = Object.keys(authorisedValues).reduce((acc, avKey) => {
24
        if (Array.isArray(authorisedValues[avKey])) return acc;
25
        acc[avKey] = authorisedValues[avKey];
26
        return acc;
27
    }, {});
28
29
    const AVCatArray = Object.keys(AVsToFetch).map(avCat => {
30
        return '"' + AVsToFetch[avCat] + '"';
31
    });
32
33
    const promises = [];
34
    const AVClient = APIClient.authorised_values;
35
    promises.push(
36
        AVClient.values
37
            .getCategoriesWithValues(AVCatArray)
38
            .then(AVCategories => {
39
                Object.entries(AVsToFetch).forEach(([AVName, AVCat]) => {
40
                    const AVMatch = AVCategories.find(
41
                        element => element.category_name == AVCat
42
                    );
43
                    targetStore.authorisedValues[AVName] =
44
                        AVMatch.authorised_values;
45
                });
46
            })
47
    );
48
49
    return Promise.all(promises);
50
};
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised-values.js (-67 lines)
Lines 1-67 Link Here
1
import { defineStore } from "pinia";
2
3
export const useAVStore = defineStore("authorised_values", {
4
    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: {
47
        get_lib_from_av(arr_name, av) {
48
            if (this[arr_name] === undefined) {
49
                console.warn(
50
                    "The authorised value category for '%s' is not defined.".format(
51
                        arr_name
52
                    )
53
                );
54
                return;
55
            }
56
            let o = this[arr_name].find(e => e.value == av);
57
            return o ? o.description : av;
58
        },
59
        map_av_dt_filter(arr_name) {
60
            return this[arr_name].map(e => {
61
                e["_id"] = e["value"];
62
                e["_str"] = e["description"];
63
                return e;
64
            });
65
        },
66
    },
67
});
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/erm.js (+14 lines)
Lines 1-4 Link Here
1
import { defineStore } from "pinia";
1
import { defineStore } from "pinia";
2
import {
3
    loadAuthorisedValues,
4
    get_lib_from_av_handler,
5
    map_av_dt_filter_handler,
6
} from "../composables/authorisedValues";
2
7
3
export const useERMStore = defineStore("erm", {
8
export const useERMStore = defineStore("erm", {
4
    state: () => ({
9
    state: () => ({
Lines 59-62 export const useERMStore = defineStore("erm", { Link Here
59
            ],
64
            ],
60
        },
65
        },
61
    }),
66
    }),
67
    actions: {
68
        loadAuthorisedValues,
69
        get_lib_from_av(arr_name, av) {
70
            return get_lib_from_av_handler(arr_name, av, this);
71
        },
72
        map_av_dt_filter(arr_name) {
73
            return map_av_dt_filter_handler(arr_name, this);
74
        },
75
    },
62
});
76
});
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js (-55 lines)
Lines 1-5 Link Here
1
import { defineStore } from "pinia";
1
import { defineStore } from "pinia";
2
import { APIClient } from "../fetch/api-client.js";
3
2
4
export const useMainStore = defineStore("main", {
3
export const useMainStore = defineStore("main", {
5
    state: () => ({
4
    state: () => ({
Lines 92-150 export const useMainStore = defineStore("main", { Link Here
92
        loaded() {
91
        loaded() {
93
            this._is_loading = false;
92
            this._is_loading = false;
94
        },
93
        },
95
        get_lib_from_av(arr_name, av) {
96
            if (this.authorisedValues[arr_name] === undefined) {
97
                console.warn(
98
                    "The authorised value category for '%s' is not defined.".format(
99
                        arr_name
100
                    )
101
                );
102
                return;
103
            }
104
            let o = this.authorisedValues[arr_name].find(e => e.value == av);
105
            return o ? o.description : av;
106
        },
107
        map_av_dt_filter(arr_name) {
108
            return this.authorisedValues[arr_name].map(e => {
109
                e["_id"] = e["value"];
110
                e["_str"] = e["description"];
111
                return e;
112
            });
113
        },
114
        async loadAuthorisedValues(authorisedValues) {
115
            const AVsToFetch = Object.keys(authorisedValues).reduce(
116
                (acc, avKey) => {
117
                    if (Array.isArray(authorisedValues[avKey])) return acc;
118
                    acc[avKey] = authorisedValues[avKey];
119
                    return acc;
120
                },
121
                {}
122
            );
123
124
            const AVCatArray = Object.keys(AVsToFetch).map(avCat => {
125
                return '"' + AVsToFetch[avCat] + '"';
126
            });
127
128
            const promises = [];
129
            const AVClient = APIClient.authorised_values;
130
            promises.push(
131
                AVClient.values
132
                    .getCategoriesWithValues(AVCatArray)
133
                    .then(AVCategories => {
134
                        Object.entries(AVsToFetch).forEach(
135
                            ([AVName, AVCat]) => {
136
                                const AVMatch = AVCategories.find(
137
                                    element => element.category_name == AVCat
138
                                );
139
                                this.authorisedValues[AVName] =
140
                                    AVMatch.authorised_values;
141
                            }
142
                        );
143
                    })
144
            );
145
146
            return Promise.all(promises);
147
        },
148
    },
94
    },
149
    getters: {
95
    getters: {
150
        error() {
96
        error() {
151
- 

Return to bug 37930