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> |