changeset 1784:724758455a4e v2-preview20190111

Submit Approved Gaugemeasurements data to backend.
author Sascha Wilde <wilde@intevation.de>
date Fri, 11 Jan 2019 19:46:21 +0100
parents 8fd132b9cdbd
children 614c6c766691
files client/src/components/ImportApprovedGaugeMeasurement.vue
diffstat 1 files changed, 26 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/ImportApprovedGaugeMeasurement.vue	Fri Jan 11 18:32:59 2019 +0100
+++ b/client/src/components/ImportApprovedGaugeMeasurement.vue	Fri Jan 11 19:46:21 2019 +0100
@@ -17,7 +17,7 @@
             <div class="flex-column w-100">
               <div class="custom-file">
               <input
-                accept=".zip"
+                accept=".csv"
                 type="file"
                 @change="fileSelected"
                 class="custom-file-input"
@@ -65,7 +65,8 @@
  * Thomas Junk <thomas.junk@intevation.de>
  */
 
-import { displayInfo } from "@/lib/errors.js";
+import { HTTP } from "@/lib/http";
+import { displayError, displayInfo } from "@/lib/errors.js";
 
 export default {
   name: "importapprovedgaugemeasurements",
@@ -84,10 +85,29 @@
       this.uploadFile = files[0];
     },
     submit() {
-      displayInfo({
-        title: this.$gettext("Import"),
-        message: this.$gettext("under construction")
-      });
+      if (!this.uploadFile) return;
+      let formData = new FormData();
+      formData.append("approvedgm", this.uploadFile);
+      HTTP.post("/imports/approvedgm", formData, {
+        headers: {
+          "X-Gemma-Auth": localStorage.getItem("token"),
+          "Content-Type": "multipart/form-data"
+        }
+      })
+        .then(() => {
+          displayInfo({
+            title: this.$gettext("Import"),
+            message: this.$gettext("Starting import of Approved Gauge Measurements")
+          });
+          this.initialState();
+        })
+        .catch(error => {
+          const { status, data } = error.response;
+          displayError({
+            title: this.$gettext("Backend Error"),
+            message: `${status}: ${data.message || data}`
+          });
+        });
     }
   },
   components: {