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

(-)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/authorisedValues/authorised-values.js (+74 lines)
Line 0 Link Here
1
import { defineStore } from "pinia";
2
import { APIClient } from "../../fetch/api-client.js";
3
import { avMatrix } from "./avMatrix.js";
4
5
export const useAVStore = defineStore("authorised_values", {
6
    state: () => ({
7
        ...Object.keys(avMatrix).reduce((acc, moduleKey) => {
8
            const moduleValues = Object.keys(avMatrix[moduleKey]).reduce(
9
                (acc, avKey) => {
10
                    acc[avKey] = avMatrix[moduleKey][avKey].values;
11
                    return acc;
12
                },
13
                {}
14
            );
15
16
            return { ...acc, ...moduleValues };
17
        }, {}),
18
    }),
19
    actions: {
20
        get_lib_from_av(arr_name, av) {
21
            if (this[arr_name] === undefined) {
22
                console.warn(
23
                    "The authorised value category for '%s' is not defined.".format(
24
                        arr_name
25
                    )
26
                );
27
                return;
28
            }
29
            let o = this[arr_name].find(e => e.value == av);
30
            return o ? o.description : av;
31
        },
32
        map_av_dt_filter(arr_name) {
33
            return this[arr_name].map(e => {
34
                e["_id"] = e["value"];
35
                e["_str"] = e["description"];
36
                return e;
37
            });
38
        },
39
        async initialiseAVStore(module) {
40
            const authorisedValues = Object.keys(avMatrix[module]).reduce(
41
                (acc, avKey) => {
42
                    if (!avMatrix[module][avKey].name) return acc;
43
                    acc[avKey] = avMatrix[module][avKey];
44
                    return acc;
45
                },
46
                {}
47
            );
48
49
            const AVCatArray = Object.keys(authorisedValues).map(avCat => {
50
                return '"' + authorisedValues[avCat].name + '"';
51
            });
52
53
            const promises = [];
54
            const AVClient = APIClient.authorised_values;
55
            promises.push(
56
                AVClient.values
57
                    .getCategoriesWithValues(AVCatArray)
58
                    .then(AVCategories => {
59
                        Object.entries(authorisedValues).forEach(
60
                            ([AVName, AVCat]) => {
61
                                const AVMatch = AVCategories.find(
62
                                    element =>
63
                                        element.category_name == AVCat.name
64
                                );
65
                                this[AVName] = AVMatch.authorised_values;
66
                            }
67
                        );
68
                    })
69
            );
70
71
            return Promise.all(promises);
72
        },
73
    },
74
});
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/authorisedValues/avMatrix.js (-1 / +88 lines)
Line 0 Link Here
0
- 
1
export const avMatrix = {
2
    erm: {
3
        av_agreement_statuses: { name: "ERM_AGREEMENT_STATUS", values: [] },
4
        av_agreement_closure_reasons: {
5
            name: "ERM_AGREEMENT_CLOSURE_REASON",
6
            values: [],
7
        },
8
        av_agreement_renewal_priorities: {
9
            name: "ERM_AGREEMENT_RENEWAL_PRIORITY",
10
            values: [],
11
        },
12
        av_user_roles: { name: "ERM_USER_ROLES", values: [] },
13
        av_license_types: { name: "ERM_LICENSE_TYPE", values: [] },
14
        av_license_statuses: { name: "ERM_LICENSE_STATUS", values: [] },
15
        av_agreement_license_statuses: {
16
            name: "ERM_AGREEMENT_LICENSE_STATUS",
17
            values: [],
18
        },
19
        av_agreement_license_location: {
20
            name: "ERM_AGREEMENT_LICENSE_LOCATION",
21
            values: [],
22
        },
23
        av_package_types: { name: "ERM_PACKAGE_TYPE", values: [] },
24
        av_package_content_types: {
25
            name: "ERM_PACKAGE_CONTENT_TYPE",
26
            values: [],
27
        },
28
        av_title_publication_types: {
29
            name: "ERM_TITLE_PUBLICATION_TYPE",
30
            values: [],
31
        },
32
        av_report_types: { name: "ERM_REPORT_TYPES", values: [] },
33
        av_platform_reports_metrics: {
34
            name: "ERM_PLATFORM_REPORTS_METRICS",
35
            values: [],
36
        },
37
        av_database_reports_metrics: {
38
            name: "ERM_DATABASE_REPORTS_METRICS",
39
            values: [],
40
        },
41
        av_title_reports_metrics: {
42
            name: "ERM_TITLE_REPORTS_METRICS",
43
            values: [],
44
        },
45
        av_item_reports_metrics: {
46
            name: "ERM_ITEM_REPORTS_METRICS",
47
            values: [],
48
        },
49
        av_agreement_relationships: {
50
            name: null,
51
            values: [
52
                { value: "supersedes", description: __("supersedes") },
53
                {
54
                    value: "is-superseded-by",
55
                    description: __("is superseded by"),
56
                },
57
                {
58
                    value: "provides_post-cancellation_access_for",
59
                    description: __("provides post-cancellation access for"),
60
                },
61
                {
62
                    value: "has-post-cancellation-access-in",
63
                    description: __("has post-cancellation access in"),
64
                },
65
                {
66
                    value: "tracks_demand-driven_acquisitions_for",
67
                    description: __("tracks demand-driven acquisitions for"),
68
                },
69
                {
70
                    value: "has-demand-driven-acquisitions-in",
71
                    description: __("has demand-driven acquisitions in"),
72
                },
73
                {
74
                    value: "has_backfile_in",
75
                    description: __("has backfile in"),
76
                },
77
                {
78
                    value: "has_frontfile_in",
79
                    description: __("has frontfile in"),
80
                },
81
                { value: "related_to", description: __("related to") },
82
            ],
83
        },
84
    },
85
    preservation: {
86
        av_notforloan: { name: "NOT_LOAN", values: [] },
87
    },
88
};

Return to bug 37930