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

(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementLicenses.vue (-1 / +1 lines)
Lines 117-123 export default { Link Here
117
    },
117
    },
118
    beforeCreate() {
118
    beforeCreate() {
119
        const client = APIClient.erm
119
        const client = APIClient.erm
120
        client.licenses.getAll.then(
120
        client.licenses.getAll().then(
121
            licenses => {
121
            licenses => {
122
                this.licenses = licenses
122
                this.licenses = licenses
123
                this.initialized = true
123
                this.initialized = true
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackageAgreements.vue (-10 / +21 lines)
Lines 36-42 Link Here
36
36
37
<script>
37
<script>
38
import AgreementsList from "./AgreementsList.vue"
38
import AgreementsList from "./AgreementsList.vue"
39
import { createPackage, editPackage } from "../../fetch/erm.js"
39
import { APIClient } from "../../fetch/api-client.js"
40
import { setWarning, removeMessages } from "../../messages"
40
import { setWarning, removeMessages } from "../../messages"
41
41
42
export default {
42
export default {
Lines 71-84 export default { Link Here
71
                )
71
                )
72
            ) {
72
            ) {
73
                erm_package.package_agreements.push({ agreement_id })
73
                erm_package.package_agreements.push({ agreement_id })
74
                const client = APIClient.erm
74
                if (this.erm_package.koha_internal_id) {
75
                if (this.erm_package.koha_internal_id) {
75
                    editPackage(erm_package).then(() => {
76
                    client.localPackages.update(erm_package, package_id).then(
76
                        this.$emit("refresh-agreements")
77
                        success => {
77
                    })
78
                            this.$emit("refresh-agreements")
79
                        },
80
                        error => {}
81
                    )
78
                } else {
82
                } else {
79
                    createPackage(erm_package).then(() => {
83
                    client.localPackages.create(erm_package).then(
80
                        this.$emit("refresh-agreements")
84
                        success => {
81
                    })
85
                            this.$emit("refresh-agreements")
86
                        },
87
                        error => {}
88
                    )
82
                }
89
                }
83
            } else {
90
            } else {
84
                setWarning(
91
                setWarning(
Lines 90-99 export default { Link Here
90
        },
97
        },
91
        deleteAgreement(counter) {
98
        deleteAgreement(counter) {
92
            let erm_package = this.serializeAgreement()
99
            let erm_package = this.serializeAgreement()
100
            const client = APIClient.erm
93
            erm_package.package_agreements.splice(counter, 1)
101
            erm_package.package_agreements.splice(counter, 1)
94
            editPackage(erm_package).then(() => {
102
            client.localPackages.update(erm_package, package_id).then(
95
                this.$emit("refresh-agreements")
103
                success => {
96
            })
104
                    this.$emit("refresh-agreements")
105
                },
106
                error => {}
107
            )
97
        },
108
        },
98
    },
109
    },
99
    props: {
110
    props: {
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOPackagesList.vue (-3 / +13 lines)
Lines 62-68 Link Here
62
<script>
62
<script>
63
import { inject, createVNode, render } from "vue"
63
import { inject, createVNode, render } from "vue"
64
import { storeToRefs } from "pinia"
64
import { storeToRefs } from "pinia"
65
import { fetchLocalPackageCount } from "./../../fetch/erm.js"
65
import { APIClient } from "../../fetch/api-client.js"
66
import {
66
import {
67
    useDataTable,
67
    useDataTable,
68
    build_url_params,
68
    build_url_params,
Lines 136-143 export default { Link Here
136
                .DataTable()
136
                .DataTable()
137
                .draw()
137
                .draw()
138
            if (this.erm_providers.includes("local")) {
138
            if (this.erm_providers.includes("local")) {
139
                this.local_count_packages = await fetchLocalPackageCount(
139
                const client = APIClient.erm
140
                    this.filters
140
                const query = filters
141
                    ? {
142
                          "me.name": { like: "%" + filters.package_name + "%" },
143
                          ...(filters.content_type
144
                              ? { "me.content_type": filters.content_type }
145
                              : {}),
146
                      }
147
                    : {}
148
                client.localPackages.count(query).then(
149
                    count => (this.local_count_packages = count),
150
                    error => {}
141
                )
151
                )
142
            }
152
            }
143
        },
153
        },
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsEBSCOTitlesList.vue (-3 / +27 lines)
Lines 66-72 Link Here
66
<script>
66
<script>
67
import { inject, createVNode, render } from "vue"
67
import { inject, createVNode, render } from "vue"
68
import { storeToRefs } from "pinia"
68
import { storeToRefs } from "pinia"
69
import { fetchLocalTitleCount } from "./../../fetch/erm.js"
69
import { APIClient } from "../../fetch/api-client.js"
70
import {
70
import {
71
    useDataTable,
71
    useDataTable,
72
    build_url_params,
72
    build_url_params,
Lines 140-147 export default { Link Here
140
                    .DataTable()
140
                    .DataTable()
141
                    .draw()
141
                    .draw()
142
                if (this.erm_providers.includes("local")) {
142
                if (this.erm_providers.includes("local")) {
143
                    this.local_title_count = await fetchLocalTitleCount(
143
                    const client = APIClient.erm
144
                        this.filters
144
145
                    const q = filters
146
                        ? {
147
                              ...(this.filters.publication_title
148
                                  ? {
149
                                        "me.publication_title": {
150
                                            like:
151
                                                "%" +
152
                                                this.filters.publication_title +
153
                                                "%",
154
                                        },
155
                                    }
156
                                  : {}),
157
                              ...(this.filters.publication_type
158
                                  ? {
159
                                        "me.publication_type":
160
                                            this.filters.publication_type,
161
                                    }
162
                                  : {}),
163
                          }
164
                        : undefined
165
166
                    client.localTitles.count(q).then(
167
                        count => (this.local_title_count = count),
168
                        error => {}
145
                    )
169
                    )
146
                }
170
                }
147
            } else {
171
            } else {
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormAdd.vue (-25 / +35 lines)
Lines 88-99 Link Here
88
import { inject } from "vue"
88
import { inject } from "vue"
89
import EHoldingsPackageAgreements from "./EHoldingsLocalPackageAgreements.vue"
89
import EHoldingsPackageAgreements from "./EHoldingsLocalPackageAgreements.vue"
90
import { setMessage, setError, setWarning } from "../../messages"
90
import { setMessage, setError, setWarning } from "../../messages"
91
import {
91
import { APIClient } from "../../fetch/api-client.js"
92
    fetchLocalPackage,
93
    createPackage,
94
    editPackage,
95
    checkError,
96
} from "../../fetch/erm.js"
97
import { storeToRefs } from "pinia"
92
import { storeToRefs } from "pinia"
98
93
99
export default {
94
export default {
Lines 137-146 export default { Link Here
137
        })
132
        })
138
    },
133
    },
139
    methods: {
134
    methods: {
140
        async getPackage(package_id) {
135
        getPackage(package_id) {
141
            const erm_package = await fetchLocalPackage(package_id)
136
            const client = APIClient.erm
142
            this.erm_package = erm_package
137
            client.localPackages.get(package_id).then(
143
            this.initialized = true
138
                erm_package => {
139
                    this.erm_package = erm_package
140
                    this.initialized = true
141
                },
142
                error => {}
143
            )
144
        },
144
        },
145
        checkForm(erm_package) {
145
        checkForm(erm_package) {
146
            let errors = []
146
            let errors = []
Lines 168-195 export default { Link Here
168
                return false
168
                return false
169
            }
169
            }
170
170
171
            if (erm_package.package_id) {
171
            let package_id = erm_package.package_id
172
                editPackage(erm_package).then(response => {
172
            delete erm_package.package_id
173
                    if (response && response.status == 200) {
173
            delete erm_package.resources
174
            delete erm_package.vendor
175
            delete erm_package.resources_count
176
            delete erm_package.is_selected
177
178
            erm_package.package_agreements = erm_package.package_agreements.map(
179
                ({ package_id, agreement, ...keepAttrs }) => keepAttrs
180
            )
181
182
            const client = APIClient.erm
183
            if (package_id) {
184
                client.localPackages.update(erm_package, package_id).then(
185
                    success => {
186
                        setMessage(this.$__("Package updated"))
174
                        this.$router.push(
187
                        this.$router.push(
175
                            "/cgi-bin/koha/erm/eholdings/local/packages"
188
                            "/cgi-bin/koha/erm/eholdings/local/packages"
176
                        )
189
                        )
177
                        setMessage(this.$__("Package updated"))
190
                    },
178
                    } else if (response) {
191
                    error => {}
179
                        setError(response.message || response.statusText)
192
                )
180
                    }
181
                })
182
            } else {
193
            } else {
183
                createPackage(erm_package).then(response => {
194
                client.localPackages.create(erm_package).then(
184
                    if (response && response.status == 201) {
195
                    success => {
196
                        setMessage(this.$__("Package created"))
185
                        this.$router.push(
197
                        this.$router.push(
186
                            "/cgi-bin/koha/erm/eholdings/local/packages"
198
                            "/cgi-bin/koha/erm/eholdings/local/packages"
187
                        )
199
                        )
188
                        setMessage(this.$__("Package created"))
200
                    },
189
                    } else if (response) {
201
                    error => {}
190
                        setError(response.message || response.statusText)
202
                )
191
                    }
192
                })
193
            }
203
            }
194
        },
204
        },
195
    },
205
    },
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormConfirmDelete.vue (-31 / +19 lines)
Lines 31-38 Link Here
31
</template>
31
</template>
32
32
33
<script>
33
<script>
34
import { fetchLocalPackage, checkError } from "../../fetch/erm.js"
35
import { setMessage, setError } from "../../messages"
34
import { setMessage, setError } from "../../messages"
35
import { APIClient } from "../../fetch/api-client.js"
36
36
37
export default {
37
export default {
38
    data() {
38
    data() {
Lines 47-86 export default { Link Here
47
        })
47
        })
48
    },
48
    },
49
    methods: {
49
    methods: {
50
        async getPackage(package_id) {
50
        getPackage(package_id) {
51
            const erm_package = await fetchLocalPackage(package_id)
51
            const client = APIClient.erm
52
            this.erm_package = erm_package
52
            client.localPackages.get(package_id).then(
53
            this.initialized = true
53
                erm_package => {
54
                    this.erm_package = erm_package
55
                    this.initialized = true
56
                },
57
                error => {}
58
            )
54
        },
59
        },
55
        onSubmit(e) {
60
        onSubmit(e) {
56
            e.preventDefault()
61
            e.preventDefault()
57
62
            const client = APIClient.erm
58
            let apiUrl =
63
            client.localPackages.delete(this.erm_package.package_id).then(
59
                "/api/v1/erm/eholdings/local/packages/" +
64
                success => {
60
                this.erm_package.package_id
65
                    setMessage(this.$__("Package deleted"))
61
66
                    this.$router.push(
62
            const options = {
67
                        "/cgi-bin/koha/erm/eholdings/local/packages"
63
                method: "DELETE",
68
                    )
64
                headers: {
65
                    "Content-Type": "application/json;charset=utf-8",
66
                },
69
                },
67
            }
70
                error => {}
68
71
            )
69
            fetch(apiUrl, options)
70
                .then(response => checkError(response, 1))
71
                .then(response => {
72
                    if (response.status == 204) {
73
                        setMessage(this.$__("Package deleted"))
74
                        this.$router.push(
75
                            "/cgi-bin/koha/erm/eholdings/local/packages"
76
                        )
77
                    } else {
78
                        setError(response.message || response.statusText)
79
                    }
80
                })
81
                .catch(error => {
82
                    setError(error)
83
                })
84
        },
72
        },
85
    },
73
    },
86
    name: "EHoldingsLocalPackagesFormConfirmDelete",
74
    name: "EHoldingsLocalPackagesFormConfirmDelete",
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesList.vue (-3 / +9 lines)
Lines 21-27 Link Here
21
import Toolbar from "./EHoldingsLocalPackagesToolbar.vue"
21
import Toolbar from "./EHoldingsLocalPackagesToolbar.vue"
22
import { inject, createVNode, render } from "vue"
22
import { inject, createVNode, render } from "vue"
23
import { storeToRefs } from "pinia"
23
import { storeToRefs } from "pinia"
24
import { fetchLocalPackageCount } from "../../fetch/erm.js"
24
import { APIClient } from "../../fetch/api-client.js"
25
import { useDataTable } from "../../composables/datatables"
25
import { useDataTable } from "../../composables/datatables"
26
26
27
export default {
27
export default {
Lines 59-66 export default { Link Here
59
    },
59
    },
60
    methods: {
60
    methods: {
61
        async getPackageCount() {
61
        async getPackageCount() {
62
            this.package_count = await fetchLocalPackageCount()
62
            const client = APIClient.erm
63
            this.initialized = true
63
            await client.localPackages.count().then(
64
                count => {
65
                    this.package_count = count
66
                    this.initialized = true
67
                },
68
                error => {}
69
            )
64
        },
70
        },
65
        show_package: function (package_id) {
71
        show_package: function (package_id) {
66
            this.$router.push(
72
            this.$router.push(
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesShow.vue (-5 / +10 lines)
Lines 106-112 Link Here
106
<script>
106
<script>
107
import { inject } from "vue"
107
import { inject } from "vue"
108
import EHoldingsPackageTitlesList from "./EHoldingsLocalPackageTitlesList.vue"
108
import EHoldingsPackageTitlesList from "./EHoldingsLocalPackageTitlesList.vue"
109
import { fetchLocalPackage } from "../../fetch/erm.js"
109
import { APIClient } from "../../fetch/api-client.js"
110
110
111
export default {
111
export default {
112
    setup() {
112
    setup() {
Lines 145-154 export default { Link Here
145
        this.erm_package = this.getPackage(to.params.package_id)
145
        this.erm_package = this.getPackage(to.params.package_id)
146
    },
146
    },
147
    methods: {
147
    methods: {
148
        async getPackage(package_id) {
148
        getPackage(package_id) {
149
            const erm_package = await fetchLocalPackage(package_id)
149
            const client = APIClient.erm
150
            this.erm_package = erm_package
150
            client.localPackages.get(package_id).then(
151
            this.initialized = true
151
                erm_package => {
152
                    this.erm_package = erm_package
153
                    this.initialized = true
154
                },
155
                error => {}
156
            )
152
        },
157
        },
153
    },
158
    },
154
    components: {
159
    components: {
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalResourcesShow.vue (-5 / +10 lines)
Lines 96-102 Link Here
96
96
97
<script>
97
<script>
98
import { inject } from "vue"
98
import { inject } from "vue"
99
import { fetchLocalResource } from "../../fetch/erm.js"
99
import { APIClient } from "../../fetch/api-client.js"
100
import { storeToRefs } from "pinia"
100
import { storeToRefs } from "pinia"
101
export default {
101
export default {
102
    setup() {
102
    setup() {
Lines 134-143 export default { Link Here
134
        this.resource = this.getResource(to.params.resource_id)
134
        this.resource = this.getResource(to.params.resource_id)
135
    },
135
    },
136
    methods: {
136
    methods: {
137
        async getResource(resource_id) {
137
        getResource(resource_id) {
138
            const resource = await fetchLocalResource(resource_id)
138
            const client = APIClient.erm
139
            this.resource = resource
139
            client.localResources.get(resource_id).then(
140
            this.initialized = true
140
                resource => {
141
                    this.resource = resource
142
                    this.initialized = true
143
                },
144
                error => {}
145
            )
141
        },
146
        },
142
    },
147
    },
143
    name: "EHoldingsLocalResourcesShow",
148
    name: "EHoldingsLocalResourcesShow",
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAdd.vue (-42 / +31 lines)
Lines 388-394 Link Here
388
import { inject } from "vue"
388
import { inject } from "vue"
389
import EHoldingsTitlesFormAddResources from "./EHoldingsLocalTitlesFormAddResources.vue"
389
import EHoldingsTitlesFormAddResources from "./EHoldingsLocalTitlesFormAddResources.vue"
390
import { setMessage, setError, setWarning } from "../../messages"
390
import { setMessage, setError, setWarning } from "../../messages"
391
import { fetchLocalTitle, checkError } from "../../fetch/erm.js"
391
import { APIClient } from "../../fetch/api-client.js"
392
import { storeToRefs } from "pinia"
392
import { storeToRefs } from "pinia"
393
393
394
export default {
394
export default {
Lines 450-459 export default { Link Here
450
        })
450
        })
451
    },
451
    },
452
    methods: {
452
    methods: {
453
        async getTitle(title_id) {
453
        getTitle(title_id) {
454
            const title = await fetchLocalTitle(title_id)
454
            const client = APIClient.erm
455
            this.title = title
455
            client.localTitles.get(title_id).then(
456
            this.initialized = true
456
                title => {
457
                    this.title = title
458
                    this.initialized = true
459
                },
460
                error => {}
461
            )
457
        },
462
        },
458
        checkForm(title) {
463
        checkForm(title) {
459
            let errors = []
464
            let errors = []
Lines 481-493 export default { Link Here
481
            if (!this.checkForm(title)) {
486
            if (!this.checkForm(title)) {
482
                return false
487
                return false
483
            }
488
            }
484
            let apiUrl = "/api/v1/erm/eholdings/local/titles"
485
489
486
            let method = "POST"
490
            let title_id = title.title_id
487
            if (title.title_id) {
488
                method = "PUT"
489
                apiUrl += "/" + title.title_id
490
            }
491
            delete title.title_id
491
            delete title.title_id
492
            delete title.biblio_id
492
            delete title.biblio_id
493
493
Lines 497-535 export default { Link Here
497
                delete e.resource_id
497
                delete e.resource_id
498
            })
498
            })
499
499
500
            const options = {
500
            const client = APIClient.erm
501
                method: method,
501
            if (title_id) {
502
                body: JSON.stringify(title),
502
                client.localTitles.update(title, title_id).then(
503
                headers: {
503
                    success => {
504
                    "Content-Type": "application/json;charset=utf-8",
504
                        setMessage(this.$__("Title updated"))
505
                },
505
                        this.$router.push(
506
            }
506
                            "/cgi-bin/koha/erm/eholdings/local/titles"
507
507
                        )
508
            fetch(apiUrl, options)
509
                .then(response => checkError(response, 1))
510
                .then(
511
                    response => {
512
                        if (response && response.status == 200) {
513
                            this.$router.push(
514
                                "/cgi-bin/koha/erm/eholdings/local/titles"
515
                            )
516
                            setMessage(this.$__("Title updated"))
517
                        } else if (response && response.status == 201) {
518
                            this.$router.push(
519
                                "/cgi-bin/koha/erm/eholdings/local/titles"
520
                            )
521
                            setMessage(this.$__("Title created"))
522
                        } else if (response) {
523
                            setError(response.message || response.statusText)
524
                        }
525
                    },
508
                    },
526
                    error => {
509
                    error => {}
527
                        setError(error)
528
                    }
529
                )
510
                )
530
                .catch(e => {
511
            } else {
531
                    console.log(e)
512
                client.localTitles.create(title).then(
532
                })
513
                    success => {
514
                        setMessage(this.$__("Title created"))
515
                        this.$router.push(
516
                            "/cgi-bin/koha/erm/eholdings/local/titles"
517
                        )
518
                    },
519
                    error => {}
520
                )
521
            }
533
        },
522
        },
534
    },
523
    },
535
    components: { EHoldingsTitlesFormAddResources },
524
    components: { EHoldingsTitlesFormAddResources },
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormAddResources.vue (-2 / +9 lines)
Lines 95-101 Link Here
95
import { inject } from "vue"
95
import { inject } from "vue"
96
import flatPickr from "vue-flatpickr-component"
96
import flatPickr from "vue-flatpickr-component"
97
import { storeToRefs } from "pinia"
97
import { storeToRefs } from "pinia"
98
import { fetchLocalPackages } from "../../fetch/erm.js"
98
import { APIClient } from "../../fetch/api-client.js"
99
99
100
export default {
100
export default {
101
    setup() {
101
    setup() {
Lines 110-116 export default { Link Here
110
        }
110
        }
111
    },
111
    },
112
    beforeCreate() {
112
    beforeCreate() {
113
        fetchLocalPackages().then(packages => (this.packages = packages))
113
        const client = APIClient.erm
114
        client.localPackages.getAll().then(
115
            packages => {
116
                this.packages = packages
117
                this.initialized = true
118
            },
119
            error => {}
120
        )
114
    },
121
    },
115
    methods: {
122
    methods: {
116
        addPackage() {
123
        addPackage() {
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormConfirmDelete.vue (-9 / +14 lines)
Lines 8-14 Link Here
8
                    <ol>
8
                    <ol>
9
                        <li>
9
                        <li>
10
                            {{ $__("Title") }}:
10
                            {{ $__("Title") }}:
11
                            {{ eholding.publication_title }}
11
                            {{ title.publication_title }}
12
                        </li>
12
                        </li>
13
                    </ol>
13
                    </ol>
14
                </fieldset>
14
                </fieldset>
Lines 31-62 Link Here
31
</template>
31
</template>
32
32
33
<script>
33
<script>
34
import { fetchLocalTitle, checkError } from "../../fetch/erm.js"
34
import { APIClient } from "../../fetch/api-client.js"
35
import { setMessage, setError } from "../../messages"
35
import { setMessage, setError } from "../../messages"
36
36
37
export default {
37
export default {
38
    data() {
38
    data() {
39
        return {
39
        return {
40
            eholding: {},
40
            title: {},
41
            initialized: false,
41
            initialized: false,
42
        }
42
        }
43
    },
43
    },
44
    beforeRouteEnter(to, from, next) {
44
    beforeRouteEnter(to, from, next) {
45
        next(vm => {
45
        next(vm => {
46
            vm.getEHolding(to.params.title_id)
46
            vm.getTitle(to.params.title_id)
47
        })
47
        })
48
    },
48
    },
49
    methods: {
49
    methods: {
50
        async getEHolding(title_id) {
50
        getTitle(title_id) {
51
            const eholding = await fetchLocalTitle(title_id)
51
            const client = APIClient.erm
52
            this.eholding = eholding
52
            client.localTitles.get(title_id).then(
53
            this.initialized = true
53
                title => {
54
                    this.title = title
55
                    this.initialized = true
56
                },
57
                error => {}
58
            )
54
        },
59
        },
55
        onSubmit(e) {
60
        onSubmit(e) {
56
            e.preventDefault()
61
            e.preventDefault()
57
62
58
            let apiUrl =
63
            let apiUrl =
59
                "/api/v1/erm/eholdings/local/titles/" + this.eholding.title_id
64
                "/api/v1/erm/eholdings/local/titles/" + this.title.title_id
60
65
61
            const options = {
66
            const options = {
62
                method: "DELETE",
67
                method: "DELETE",
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesFormImport.vue (-8 / +13 lines)
Lines 23-32 Link Here
23
</template>
23
</template>
24
24
25
<script>
25
<script>
26
import { setMessage, setError, setWarning } from "../../messages"
26
import { setError } from "../../messages"
27
import { createVNode, render } from "vue"
27
import { createVNode, render } from "vue"
28
import { APIClient } from "../../fetch/api-client.js"
28
import { useDataTable } from "../../composables/datatables"
29
import { useDataTable } from "../../composables/datatables"
29
import { checkError, fetchLocalPackages } from "../../fetch/erm.js"
30
30
31
export default {
31
export default {
32
    setup() {
32
    setup() {
Lines 46-57 export default { Link Here
46
        }
46
        }
47
    },
47
    },
48
    beforeCreate() {
48
    beforeCreate() {
49
        fetchLocalPackages().then(packages => {
49
        const client = APIClient.erm
50
            this.packages = packages
50
        client.localPackages.getAll().then(
51
            if (this.packages.length) {
51
            packages => {
52
                this.package_id = packages[0].package_id
52
                this.packages = packages
53
            }
53
                if (this.packages.length) {
54
        })
54
                    this.package_id = packages[0].package_id
55
                }
56
                this.initialized = true
57
            },
58
            error => {}
59
        )
55
    },
60
    },
56
    methods: {
61
    methods: {
57
        import_from_list: async function (list_id) {
62
        import_from_list: async function (list_id) {
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesList.vue (-3 / +9 lines)
Lines 21-27 Link Here
21
import Toolbar from "./EHoldingsLocalTitlesToolbar.vue"
21
import Toolbar from "./EHoldingsLocalTitlesToolbar.vue"
22
import { inject, createVNode, render } from "vue"
22
import { inject, createVNode, render } from "vue"
23
import { storeToRefs } from "pinia"
23
import { storeToRefs } from "pinia"
24
import { fetchLocalTitleCount } from "../../fetch/erm.js"
24
import { APIClient } from "../../fetch/api-client.js"
25
import { useDataTable } from "../../composables/datatables"
25
import { useDataTable } from "../../composables/datatables"
26
26
27
export default {
27
export default {
Lines 58-65 export default { Link Here
58
    },
58
    },
59
    methods: {
59
    methods: {
60
        async getTitleCount() {
60
        async getTitleCount() {
61
            this.title_count = await fetchLocalTitleCount()
61
            const client = APIClient.erm
62
            this.initialized = true
62
            await client.localTitles.count().then(
63
                count => {
64
                    this.title_count = count
65
                    this.initialized = true
66
                },
67
                error => {}
68
            )
63
        },
69
        },
64
        show_title: function (title_id) {
70
        show_title: function (title_id) {
65
            this.$router.push(
71
            this.$router.push(
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesShow.vue (-5 / +11 lines)
Lines 258-264 Link Here
258
<script>
258
<script>
259
import { inject } from "vue"
259
import { inject } from "vue"
260
import EHoldingsTitlePackagesList from "./EHoldingsLocalTitlePackagesList.vue"
260
import EHoldingsTitlePackagesList from "./EHoldingsLocalTitlePackagesList.vue"
261
import { fetchLocalTitle } from "../../fetch/erm.js"
261
import { APIClient } from "../../fetch/api-client.js"
262
262
export default {
263
export default {
263
    setup() {
264
    setup() {
264
        const AVStore = inject("AVStore")
265
        const AVStore = inject("AVStore")
Lines 311-320 export default { Link Here
311
        this.title = this.getTitle(to.params.title_id)
312
        this.title = this.getTitle(to.params.title_id)
312
    },
313
    },
313
    methods: {
314
    methods: {
314
        async getTitle(title_id) {
315
        getTitle(title_id) {
315
            const title = await fetchLocalTitle(title_id)
316
            const client = APIClient.erm
316
            this.title = title
317
            client.localTitles.get(title_id).then(
317
            this.initialized = true
318
                title => {
319
                    this.title = title
320
                    this.initialized = true
321
                },
322
                error => {}
323
            )
318
        },
324
        },
319
    },
325
    },
320
    components: {
326
    components: {
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js (-1 / +98 lines)
Lines 46-52 export class ERMAPIClient extends HttpClient { Link Here
46
                    endpoint: "licenses/" + id,
46
                    endpoint: "licenses/" + id,
47
                    headers: {
47
                    headers: {
48
                        "x-koha-embed":
48
                        "x-koha-embed":
49
                        "user_roles,user_roles.patron,vendor,documents"
49
                            "user_roles,user_roles.patron,vendor,documents",
50
                    },
50
                    },
51
                }),
51
                }),
52
            getAll: (query) =>
52
            getAll: (query) =>
Lines 72-77 export class ERMAPIClient extends HttpClient { Link Here
72
                }),
72
                }),
73
        };
73
        };
74
    }
74
    }
75
76
    get localPackages() {
77
        return {
78
            get: (id) =>
79
                this.get({
80
                    endpoint: "eholdings/local/packages/" + id,
81
                    headers: {
82
                        "x-koha-embed":
83
                            "package_agreements,package_agreements.agreement,resources+count,vendor",
84
                    },
85
                }),
86
            getAll: (query) =>
87
                this.get({
88
                    endpoint:
89
                        "eholdings/local/packages?" + (query || "_per_page=-1"),
90
                    headers: {
91
                        "x-koha-embed": "resources+count,vendor.name",
92
                    },
93
                }),
94
            delete: (id) =>
95
                this.delete({
96
                    endpoint: "eholdings/local/packages/" + id,
97
                }),
98
            create: (local_package) =>
99
                this.post({
100
                    endpoint: "eholdings/local/packages",
101
                    body: local_package,
102
                }),
103
            update: (local_package, id) =>
104
                this.put({
105
                    endpoint: "eholdings/local/packages/" + id,
106
                    body: local_package,
107
                }),
108
            count: (query = {}) =>
109
                this.count({
110
                    endpoint:
111
                        "eholdings/local/packages?" +
112
                        new URLSearchParams({
113
                            _page: 1,
114
                            _per_page: 1,
115
                            ...(query && { q: JSON.stringify(query) }),
116
                        }),
117
                }),
118
        };
119
    }
120
121
    get localTitles() {
122
        return {
123
            get: (id) =>
124
                this.get({
125
                    endpoint: "eholdings/local/titles/" + id,
126
                    headers: {
127
                        "x-koha-embed": "resources,resources.package",
128
                    },
129
                }),
130
            getAll: (query) =>
131
                this.get({
132
                    endpoint: "eholdings/local/titles?" + (query || "_per_page=-1"),
133
                }),
134
            delete: (id) =>
135
                this.delete({
136
                    endpoint: "eholdings/local/titles/" + id,
137
                }),
138
            create: (local_package) =>
139
                this.post({
140
                    endpoint: "eholdings/local/titles",
141
                    body: local_package,
142
                }),
143
            update: (local_package, id) =>
144
                this.put({
145
                    endpoint: "eholdings/local/titles/" + id,
146
                    body: local_package,
147
                }),
148
            count: (query = {}) =>
149
                this.count({
150
                    endpoint:
151
                        "eholdings/local/titles?" +
152
                        new URLSearchParams({
153
                            _page: 1,
154
                            _per_page: 1,
155
                            ...(query && { q: JSON.stringify(query) }),
156
                        }),
157
                }),
158
        };
159
    }
160
161
    get localResources() {
162
        return {
163
            get: (id) =>
164
                this.get({
165
                    endpoint: "eholdings/local/resources/" + id,
166
                    headers: {
167
                        "x-koha-embed": "title,package,vendor",
168
                    },
169
                }),
170
        };
171
    }
75
}
172
}
76
173
77
export default ERMAPIClient;
174
export default ERMAPIClient;
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm.js (-97 lines)
Lines 2-41 import { setError } from "../messages"; Link Here
2
2
3
//TODO: all of these functions should be deleted and reimplemented in the components using ERMAPIClient
3
//TODO: all of these functions should be deleted and reimplemented in the components using ERMAPIClient
4
4
5
const _createEditPackage = function (method, erm_package) {
6
    let apiUrl = "/api/v1/erm/eholdings/local/packages";
7
8
    if (method == "PUT") {
9
        apiUrl += "/" + erm_package.package_id;
10
    }
11
    delete erm_package.package_id;
12
    delete erm_package.resources;
13
    delete erm_package.vendor;
14
    delete erm_package.resources_count;
15
    delete erm_package.is_selected;
16
17
    erm_package.package_agreements = erm_package.package_agreements.map(
18
        ({ package_id, agreement, ...keepAttrs }) => keepAttrs
19
    );
20
21
    const options = {
22
        method: method,
23
        body: JSON.stringify(erm_package),
24
        headers: {
25
            "Content-Type": "application/json;charset=utf-8",
26
        },
27
    };
28
29
    return myFetch(apiUrl, options, 1);
30
};
31
32
export const createPackage = function (erm_package) {
33
    return _createEditPackage("POST", erm_package);
34
};
35
export const editPackage = function (erm_package) {
36
    return _createEditPackage("PUT", erm_package);
37
};
38
39
const _fetchPackage = function (apiUrl, package_id) {
5
const _fetchPackage = function (apiUrl, package_id) {
40
    if (!package_id) return;
6
    if (!package_id) return;
41
    return myFetch(apiUrl, {
7
    return myFetch(apiUrl, {
Lines 45-54 const _fetchPackage = function (apiUrl, package_id) { Link Here
45
        },
11
        },
46
    });
12
    });
47
};
13
};
48
export const fetchLocalPackage = function (package_id) {
49
    const apiUrl = "/api/v1/erm/eholdings/local/packages/" + package_id;
50
    return _fetchPackage(apiUrl, package_id);
51
};
52
export const fetchEBSCOPackage = function (package_id) {
14
export const fetchEBSCOPackage = function (package_id) {
53
    const apiUrl = "/api/v1/erm/eholdings/ebsco/packages/" + package_id;
15
    const apiUrl = "/api/v1/erm/eholdings/ebsco/packages/" + package_id;
54
    return _fetchPackage(apiUrl, package_id);
16
    return _fetchPackage(apiUrl, package_id);
Lines 61-94 export const _fetchPackages = function (apiUrl) { Link Here
61
        },
23
        },
62
    });
24
    });
63
};
25
};
64
export const fetchLocalPackages = function () {
65
    const apiUrl = "/api/v1/erm/eholdings/local/packages?_per_page=-1";
66
    return _fetchPackages(apiUrl);
67
};
68
export const fetchEBSCOPackages = function () {
26
export const fetchEBSCOPackages = function () {
69
    const apiUrl = "/api/v1/erm/eholdings/ebsco/packages";
27
    const apiUrl = "/api/v1/erm/eholdings/ebsco/packages";
70
    return _fetchPackages(apiUrl);
28
    return _fetchPackages(apiUrl);
71
};
29
};
72
30
73
export const fetchLocalPackageCount = function (filters) {
74
    const q = filters
75
        ? {
76
              "me.name": { like: "%" + filters.package_name + "%" },
77
              ...(filters.content_type
78
                  ? { "me.content_type": filters.content_type }
79
                  : {}),
80
          }
81
        : {};
82
83
    const params = {
84
        _page: 1,
85
        _per_page: 1,
86
        q: JSON.stringify(q),
87
    };
88
    var apiUrl = "/api/v1/erm/eholdings/local/packages";
89
    return myFetchTotal(apiUrl + "?" + new URLSearchParams(params));
90
};
91
92
export const _fetchTitle = function (apiUrl, title_id) {
31
export const _fetchTitle = function (apiUrl, title_id) {
93
    if (!title_id) return;
32
    if (!title_id) return;
94
    return myFetch(apiUrl, {
33
    return myFetch(apiUrl, {
Lines 97-135 export const _fetchTitle = function (apiUrl, title_id) { Link Here
97
        },
36
        },
98
    });
37
    });
99
};
38
};
100
export const fetchLocalTitle = function (title_id) {
101
    const apiUrl = "/api/v1/erm/eholdings/local/titles/" + title_id;
102
    return _fetchTitle(apiUrl, title_id);
103
};
104
export const fetchEBSCOTitle = function (title_id) {
39
export const fetchEBSCOTitle = function (title_id) {
105
    const apiUrl = "/api/v1/erm/eholdings/ebsco/titles/" + title_id;
40
    const apiUrl = "/api/v1/erm/eholdings/ebsco/titles/" + title_id;
106
    return _fetchTitle(apiUrl, title_id);
41
    return _fetchTitle(apiUrl, title_id);
107
};
42
};
108
43
109
export const fetchLocalTitleCount = function (filters) {
110
    const q = filters
111
        ? {
112
              ...(filters.publication_title
113
                  ? {
114
                        "me.publication_title": {
115
                            like: "%" + filters.publication_title + "%",
116
                        },
117
                    }
118
                  : {}),
119
              ...(filters.publication_type
120
                  ? { "me.publication_type": filters.publication_type }
121
                  : {}),
122
          }
123
        : undefined;
124
    const params = {
125
        _page: 1,
126
        _per_page: 1,
127
        ...(q ? { q: JSON.stringify(q) } : {}),
128
    };
129
    var apiUrl = "/api/v1/erm/eholdings/local/titles";
130
    return myFetchTotal(apiUrl + "?" + new URLSearchParams(params));
131
};
132
133
export const _fetchResource = function (apiUrl, resource_id) {
44
export const _fetchResource = function (apiUrl, resource_id) {
134
    if (!resource_id) return;
45
    if (!resource_id) return;
135
    return myFetch(apiUrl, {
46
    return myFetch(apiUrl, {
Lines 138-147 export const _fetchResource = function (apiUrl, resource_id) { Link Here
138
        },
49
        },
139
    });
50
    });
140
};
51
};
141
export const fetchLocalResource = function (resource_id) {
142
    const apiUrl = "/api/v1/erm/eholdings/local/resources/" + resource_id;
143
    return _fetchResource(apiUrl, resource_id);
144
};
145
export const fetchEBSCOResource = function (resource_id) {
52
export const fetchEBSCOResource = function (resource_id) {
146
    const apiUrl = "/api/v1/erm/eholdings/ebsco/resources/" + resource_id;
53
    const apiUrl = "/api/v1/erm/eholdings/ebsco/resources/" + resource_id;
147
    return _fetchResource(apiUrl, resource_id);
54
    return _fetchResource(apiUrl, resource_id);
Lines 151-160 export const _fetchResources = async function (apiUrl) { Link Here
151
    return await myFetch(apiUrl);
58
    return await myFetch(apiUrl);
152
};
59
};
153
60
154
export const fetchLocalResources = function () {
155
    const apiUrl = "/api/v1/erm/eholdings/local/resources";
156
    return _fetchResources(apiUrl);
157
};
158
export const fetchEBSCOResources = function () {
61
export const fetchEBSCOResources = function () {
159
    const apiUrl = "/api/v1/erm/eholdings/ebsco/resources";
62
    const apiUrl = "/api/v1/erm/eholdings/ebsco/resources";
160
    return _fetchResources(apiUrl);
63
    return _fetchResources(apiUrl);
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js (-4 / +2 lines)
Lines 72-88 class HttpClient { Link Here
72
72
73
    count(params = {}) {
73
    count(params = {}) {
74
        let res;
74
        let res;
75
        this._fetchJSON(params.endpoint, params.headers, 1).then(
75
        return this._fetchJSON(params.endpoint, params.headers, {}, 1).then(
76
            (response) => {
76
            (response) => {
77
                if (response) {
77
                if (response) {
78
                    res = response.headers.get("X-Total-Count");
78
                    return response.headers.get("X-Total-Count");
79
                }
79
                }
80
            },
80
            },
81
            (error) => {
81
            (error) => {
82
                setError(error.toString());
82
                setError(error.toString());
83
            }
83
            }
84
        );
84
        );
85
        return res;
86
    }
85
    }
87
86
88
    checkError(response, return_response = 0) {
87
    checkError(response, return_response = 0) {
89
- 

Return to bug 32939