comparison client/src/components/importconfiguration/types/ApprovedGaugeMeasurement.vue @ 2978:d6dd158b8071 unified_import

unified_import: reorganizing files
author Thomas Junk <thomas.junk@intevation.de>
date Tue, 09 Apr 2019 13:42:44 +0200
parents client/src/components/importconfiguration/ImportApprovedGaugeMeasurement.vue@2a29bf8776d0
children 1b8bb4f89227
comparison
equal deleted inserted replaced
2977:ab26fb7a76f6 2978:d6dd158b8071
1 <template>
2 <div>
3 <div class="d-flex flex-column text-left w-25">
4 <label class="text-nowrap" for="originator">
5 <small class="text-muted"
6 >{{ $options.ORIGINATOR }} / {{ $options.FROM }}</small
7 >
8 </label>
9 <input
10 type="text"
11 v-model="originator"
12 class="form-control"
13 id="originator"
14 />
15 <span class="text-left text-danger">
16 <small v-if="!originator">
17 <translate>Please enter an originator</translate>
18 </small>
19 </span>
20 </div>
21 <div class="mt-4 flex-column w-100">
22 <div class="custom-file">
23 <input
24 accept=".csv"
25 type="file"
26 @change="fileSelected"
27 class="custom-file-input"
28 id="uploadFile"
29 />
30 <label class="pointer custom-file-label" for="uploadFile">
31 {{ uploadLabel }}
32 </label>
33 </div>
34 </div>
35 <div class="d-flex flex-row-reverse w-100 mt-3">
36 <button :key="1" @click="back()" class="btn btn-warning">
37 Back
38 </button>
39 <button
40 :key="2"
41 type="submit"
42 @click="submit"
43 class="shadow-sm btn btn-info submit-button mr-3"
44 >
45 <translate>Submit</translate>
46 </button>
47 </div>
48 </div>
49 </template>
50
51 <script>
52 /* This is Free Software under GNU Affero General Public License v >= 3.0
53 * without warranty, see README.md and license for details.
54 *
55 * SPDX-License-Identifier: AGPL-3.0-or-later
56 * License-Filename: LICENSES/AGPL-3.0.txt
57 *
58 * Copyright (C) 2018 by via donau
59 * – Österreichische Wasserstraßen-Gesellschaft mbH
60 * Software engineering by Intevation GmbH
61 *
62 * Author(s):
63 * Thomas Junk <thomas.junk@intevation.de>
64 */
65
66 import { HTTP } from "@/lib/http";
67 import { displayError, displayInfo } from "@/lib/errors.js";
68 import app from "@/main";
69
70 export default {
71 name: "importapprovedgaugemeasurements",
72 data() {
73 return {
74 disableUploadButton: false,
75 uploadLabel: this.$gettext("choose file to upload"),
76 uploadFile: null,
77 originator: "viadonau"
78 };
79 },
80 computed: {
81 importGaugmeasurmentLabel() {
82 return this.$gettext("Import approved gaugemeasurements");
83 }
84 },
85 methods: {
86 back() {
87 this.uploadLabel = this.$gettext("choose file to upload");
88 this.uploadFile = null;
89 this.originator = "viadonau";
90 this.$store.commit("importschedule/setListMode");
91 },
92 fileSelected(e) {
93 const files = e.target.files || e.dataTransfer.files;
94 if (!files) return;
95 this.uploadLabel = files[0].name;
96 this.uploadFile = files[0];
97 },
98 submit() {
99 if (!this.originator || !this.uploadFile) return;
100 let formData = new FormData();
101 formData.append("agm", this.uploadFile);
102 formData.append("originator", this.originator);
103 HTTP.post("/imports/agm", formData, {
104 headers: {
105 "X-Gemma-Auth": localStorage.getItem("token"),
106 "Content-Type": "multipart/form-data"
107 }
108 })
109 .then(() => {
110 displayInfo({
111 title: this.$gettext("Import"),
112 message: this.$gettext(
113 "Starting import of Approved Gauge Measurements"
114 )
115 });
116 this.back();
117 })
118 .catch(error => {
119 const { status, data } = error.response;
120 displayError({
121 title: this.$gettext("Backend Error"),
122 message: `${status}: ${data.message || data}`
123 });
124 });
125 }
126 },
127 ORIGINATOR: app.$gettext("originator"),
128 FROM: app.$gettext("from")
129 };
130 </script>
131
132 <style lang="scss" scoped></style>