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

(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesKBARTImport.vue (+124 lines)
Line 0 Link Here
1
<template>
2
    <h2>{{ $__("Import from a KBART file") }}</h2>
3
    <div class="page-section" id="files">
4
        <form @submit="addDocument($event)" class="file_upload">
5
            <label>{{ $__("File") }}:</label>
6
            <div class="file_information">
7
                <span v-if="!file.filename">
8
                    {{ $__("Select a file") }}
9
                    <input
10
                        type="file"
11
                        @change="selectFile($event)"
12
                        :id="`import_file`"
13
                        :name="`import_file`"
14
                    />
15
                </span>
16
                <ol>
17
                    <li v-show="file.filename">
18
                        {{ $__("File name") }}:
19
                        <span>{{ file.filename }}</span>
20
                    </li>
21
                    <li v-show="file.file_type">
22
                        {{ $__("File type") }}:
23
                        <span>{{ file.file_type }}</span>
24
                    </li>
25
                </ol>
26
            </div>
27
            <fieldset class="action">
28
                <ButtonSubmit />
29
                <a @click="clearForm($event)" role="button" class="cancel">{{
30
                    $__("Clear form")
31
                }}</a>
32
            </fieldset>
33
        </form>
34
    </div>
35
</template>
36
37
<script>
38
import ButtonSubmit from "../ButtonSubmit.vue"
39
import { APIClient } from "../../fetch/api-client.js"
40
import { setMessage, setWarning } from "../../messages"
41
42
export default {
43
    data() {
44
        return {
45
            file: {
46
                filename: null,
47
                file_content: null,
48
            },
49
        }
50
    },
51
    methods: {
52
        selectFile(e) {
53
            let files = e.target.files
54
            if (!files) return
55
            let file = files[0]
56
            const reader = new FileReader()
57
            reader.onload = e => this.loadFile(file.name, e.target.result)
58
            reader.readAsBinaryString(file)
59
        },
60
        loadFile(filename, content) {
61
            this.file.filename = filename
62
            this.file.file_content = btoa(content)
63
        },
64
        addDocument(e) {
65
            e.preventDefault()
66
            const client = APIClient.erm
67
            client.localTitles.import_kbart(this.file).then(
68
                success => {
69
                    let message = ""
70
                    if (success.job_ids) {
71
                        if (success.job_ids.length > 1) {
72
                            message += this.__(
73
                                "<li>Your file was too large to process in one job, the file has been split into %s jobs to meet the maximum size limits.</li>"
74
                            ).format(success.job_ids.length)
75
                        }
76
                        success.job_ids.forEach((job, i) => {
77
                            message += this.$__(
78
                                '<li>Job for uploaded file %s has been queued, <a href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=%s" target="_blank">click here</a> to check its progress.</li>'
79
                            ).format(i + 1, job)
80
                        })
81
                        setMessage(message, true)
82
                    }
83
                    if (success.invalid_columns) {
84
                        message +=
85
                            "<p>Invalid columns were detected in your report, please check the list below:</p>"
86
                        success.invalid_columns.forEach(column => {
87
                            message += this.$__(
88
                                `<li style="font-weight: normal; font-size: medium;">%s</li>`
89
                            ).format(column)
90
                        })
91
                        message +=
92
                            '<p style="margin-top: 1em;">Below is a list of columns allowed in a KBART phase II report:</p>'
93
                        success.valid_columns.forEach(column => {
94
                            message += this.$__(
95
                                `<li style="font-weight: normal; font-size: medium;">%s</li>`
96
                            ).format(column)
97
                        })
98
                        setWarning(message)
99
                    }
100
                },
101
                error => {}
102
            )
103
        },
104
        clearForm(e) {
105
            e.preventDefault()
106
            this.file = {
107
                filename: null,
108
                file_type: null,
109
                file_content: null,
110
            }
111
        },
112
    },
113
    components: {
114
        ButtonSubmit,
115
    },
116
    name: "EHoldingsLocalTitlesKBARTImport",
117
}
118
</script>
119
120
<style scoped>
121
label {
122
    margin: 0px 10px 0px 0px;
123
}
124
</style>
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalTitlesList.vue (+17 lines)
Lines 102-107 export default { Link Here
102
                },
102
                },
103
            },
103
            },
104
            cannot_search: false,
104
            cannot_search: false,
105
            toolbar_options: [
106
                {
107
                    to: "EHoldingsLocalTitlesFormAdd",
108
                    icon: "plus",
109
                    button_title: this.$__("New title"),
110
                },
111
                {
112
                    to: "EHoldingsLocalTitlesFormImport",
113
                    icon: "plus",
114
                    button_title: this.$__("Import from list"),
115
                },
116
                {
117
                    to: "EHoldingsLocalTitlesKBARTImport",
118
                    icon: "plus",
119
                    button_title: this.$__("Import from KBART file"),
120
                },
121
            ],
105
        }
122
        }
106
    },
123
    },
107
    beforeRouteEnter(to, from, next) {
124
    beforeRouteEnter(to, from, next) {
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/erm-api-client.js (+5 lines)
Lines 189-194 export class ERMAPIClient extends HttpClient { Link Here
189
                    endpoint: "eholdings/local/titles/import",
189
                    endpoint: "eholdings/local/titles/import",
190
                    body,
190
                    body,
191
                }),
191
                }),
192
            import_kbart: body =>
193
                this.post({
194
                    endpoint: "eholdings/local/titles/import_kbart",
195
                    body,
196
                }),
192
        };
197
        };
193
    }
198
    }
194
199
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/routes/erm.js (-1 / +9 lines)
Lines 7-12 import AgreementsFormAdd from "../components/ERM/AgreementsFormAdd.vue"; Link Here
7
import EHoldingsLocalPackagesFormAdd from "../components/ERM/EHoldingsLocalPackagesFormAdd.vue";
7
import EHoldingsLocalPackagesFormAdd from "../components/ERM/EHoldingsLocalPackagesFormAdd.vue";
8
import EHoldingsLocalTitlesFormAdd from "../components/ERM/EHoldingsLocalTitlesFormAdd.vue";
8
import EHoldingsLocalTitlesFormAdd from "../components/ERM/EHoldingsLocalTitlesFormAdd.vue";
9
import EHoldingsLocalTitlesFormImport from "../components/ERM/EHoldingsLocalTitlesFormImport.vue";
9
import EHoldingsLocalTitlesFormImport from "../components/ERM/EHoldingsLocalTitlesFormImport.vue";
10
import EHoldingsLocalTitlesKBARTImport from "../components/ERM/EHoldingsLocalTitlesKBARTImport.vue";
10
import EHoldingsLocalPackagesList from "../components/ERM/EHoldingsLocalPackagesList.vue";
11
import EHoldingsLocalPackagesList from "../components/ERM/EHoldingsLocalPackagesList.vue";
11
import EHoldingsLocalPackagesShow from "../components/ERM/EHoldingsLocalPackagesShow.vue";
12
import EHoldingsLocalPackagesShow from "../components/ERM/EHoldingsLocalPackagesShow.vue";
12
import EHoldingsLocalResourcesShow from "../components/ERM/EHoldingsLocalResourcesShow.vue";
13
import EHoldingsLocalResourcesShow from "../components/ERM/EHoldingsLocalResourcesShow.vue";
Lines 200-205 export const routes = [ Link Here
200
                                        ),
201
                                        ),
201
                                        title: $__("Import from a list"),
202
                                        title: $__("Import from a list"),
202
                                    },
203
                                    },
204
                                    {
205
                                        path: "kbart-import",
206
                                        name: "EHoldingsLocalTitlesKBARTImport",
207
                                        component: markRaw(
208
                                            EHoldingsLocalTitlesKBARTImport
209
                                        ),
210
                                        title: $__("Import from a KBART file"),
211
                                    },
203
                                    {
212
                                    {
204
                                        path: "/cgi-bin/koha/erm/eholdings/local/resources/:resource_id",
213
                                        path: "/cgi-bin/koha/erm/eholdings/local/resources/:resource_id",
205
                                        name: "EHoldingsLocalResourcesShow",
214
                                        name: "EHoldingsLocalResourcesShow",
206
- 

Return to bug 34788