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

(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/Main.vue (-18 / +16 lines)
Lines 41-49 export default { Link Here
41
    setup() {
41
    setup() {
42
        const vendorStore = inject("vendorStore")
42
        const vendorStore = inject("vendorStore")
43
43
44
        const AVStore = inject("AVStore")
45
        const { loadAuthorisedValues } = AVStore
46
44
        const mainStore = inject("mainStore")
47
        const mainStore = inject("mainStore")
45
48
46
        const { loading, loaded, setError, loadAuthorisedValues } = mainStore
49
        const { loading, loaded, setError } = mainStore
47
50
48
        const ERMStore = inject("ERMStore")
51
        const ERMStore = inject("ERMStore")
49
52
Lines 86-109 export default { Link Here
86
        }
89
        }
87
90
88
        const client = APIClient.erm
91
        const client = APIClient.erm
89
        client.config
92
        client.config.get().then(config => {
90
            .get()
93
            this.config = config
91
            .then(config => {
94
            if (this.config.settings.ERMModule != 1) {
92
                this.config = config
93
                if (this.config.settings.ERMModule != 1) {
94
                    return this.setError(
95
                        this.$__(
96
                            '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'
97
                        ),
98
                        false
99
                    )
100
                }
101
                return fetch_config()
102
            })
103
            .then(() => {
104
                this.loaded()
95
                this.loaded()
105
                this.initialized = true
96
                return this.setError(
106
            })
97
                    this.$__(
98
                        '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'
99
                    ),
100
                    false
101
                )
102
            }
103
            return fetch_config()
104
        })
107
    },
105
    },
108
    methods: {
106
    methods: {
109
        async filterProviders(navigationTree) {
107
        async filterProviders(navigationTree) {
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/modules/erm.ts (+3 lines)
Lines 24-29 import { useVendorStore } from "../stores/vendors"; Link Here
24
import { useERMStore } from "../stores/erm";
24
import { useERMStore } from "../stores/erm";
25
import { useNavigationStore } from "../stores/navigation";
25
import { useNavigationStore } from "../stores/navigation";
26
import { useReportsStore } from "../stores/usage-reports";
26
import { useReportsStore } from "../stores/usage-reports";
27
import { useAVStore } from "../stores/authorised-values";
27
import i18n from "../i18n";
28
import i18n from "../i18n";
28
29
29
const pinia = createPinia();
30
const pinia = createPinia();
Lines 55-60 const ERMStore = useERMStore(pinia); Link Here
55
app.provide("ERMStore", ERMStore);
56
app.provide("ERMStore", ERMStore);
56
const reportsStore = useReportsStore(pinia);
57
const reportsStore = useReportsStore(pinia);
57
app.provide("reportsStore", reportsStore);
58
app.provide("reportsStore", reportsStore);
59
const AVStore = useAVStore(pinia);
60
app.provide("AVStore", AVStore);
58
61
59
app.mount("#erm");
62
app.mount("#erm");
60
63
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorised-values.js (-47 / +41 lines)
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
});
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/main.js (-55 lines)
Lines 91-150 export const useMainStore = defineStore("main", { Link Here
91
        loaded() {
91
        loaded() {
92
            this._is_loading = false;
92
            this._is_loading = false;
93
        },
93
        },
94
        get_lib_from_av(arr_name, av) {
95
            if (this[arr_name] === undefined) {
96
                console.warn(
97
                    "The authorised value category for '%s' is not defined.".format(
98
                        arr_name
99
                    )
100
                );
101
                return;
102
            }
103
            let o = this[arr_name].find(e => e.value == av);
104
            return o ? o.description : av;
105
        },
106
        map_av_dt_filter(arr_name) {
107
            return this[arr_name].map(e => {
108
                e["_id"] = e["value"];
109
                e["_str"] = e["description"];
110
                return e;
111
            });
112
        },
113
        async loadAuthorisedValues(authorisedValues) {
114
            console.log(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
                                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