changeset 1921:0059aa870a39 v2

Hotfixed stretch import.
author Sascha Wilde <wilde@intevation.de>
date Fri, 18 Jan 2019 20:26:21 +0100
parents 3dca0ee97da6
children e06cdc5ef4e5
files client/src/components/ImportStretches.vue client/yarn.lock
diffstat 2 files changed, 47 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/ImportStretches.vue	Fri Jan 18 20:02:55 2019 +0100
+++ b/client/src/components/ImportStretches.vue	Fri Jan 18 20:26:21 2019 +0100
@@ -225,7 +225,8 @@
  * Thomas Junk <thomas.junk@intevation.de>
  */
 import { mapState, mapGetters } from "vuex";
-import { displayInfo } from "@/lib/errors.js";
+import { HTTP } from "@/lib/http";
+import { displayError, displayInfo } from "@/lib/errors.js";
 
 export default {
   name: "importstretches",
@@ -256,14 +257,13 @@
   },
   mounted() {
     this.edit = false;
-    // uncomment when backend is there
-    // this.$store.dispatch("imports/loadStretches").catch(error => {
-    //   const { status, data } = error.response;
-    //   displayError({
-    //     title: this.$gettext("Backend Error"),
-    //     message: `${status}: ${data.message || data}`
-    //   });
-    // });
+    this.$store.dispatch("imports/loadStretches").catch(error => {
+      const { status, data } = error.response;
+      displayError({
+        title: this.$gettext("Backend Error"),
+        message: `${status}: ${data.message || data}`
+      });
+    });
   },
   methods: {
     clean() {
@@ -308,7 +308,6 @@
         "startrhm",
         "endrhm",
         "objbn",
-        "nobjbn",
         "date_info",
         "source"
       ];
@@ -333,8 +332,9 @@
         date_info: this.date_info,
         source: this.source
       };
-      this.$store.commit("imports/addStretch", stretch);
-      // uncomment when backend is there
+      //-- The following code does not work... [sw]
+      // this.$store.commit("imports/addStretch", stretch);
+
       // this.$store.dispatch("imports/addStretch", stretch).catch(error => {
       //   const { status, data } = error.response;
       //   displayError({
@@ -342,11 +342,40 @@
       //     message: `${status}: ${data.message || data}`
       //   });
       // });
-      this.edit = false;
-      displayInfo({
-        title: this.$gettext("Sections"),
-        message: this.$gettext("Not implemented!")
-      });
+
+      // so here the quick dirty and working version:  [sw]
+      const data = {
+        name: stretch.id,
+        from: stretch.startrhm,
+        to: stretch.endrhm,
+        source_organization: stretch.source,
+        date_info: stretch.date_info,
+        objnam: stretch.objnam,
+        nobjnam: stretch.nobjnam,
+        countries: stretch.countryCode.split()
+      };
+      HTTP.post("/imports/stretch", data, {
+        headers: {
+          "X-Gemma-Auth": localStorage.getItem("token"),
+          "Content-Type": "multipart/form-data"
+        }
+      })
+        .then(() => {
+          displayInfo({
+            title: this.$gettext("Import"),
+            message: this.$gettext(
+              "Starting import of stretch"
+            )
+          });
+          this.initialState();
+        })
+        .catch(error => {
+          const { status, data } = error.response;
+          displayError({
+            title: this.$gettext("Backend Error"),
+            message: `${status}: ${data.message || data}`
+          });
+        });
     }
   },
   watch: {
--- a/client/yarn.lock	Fri Jan 18 20:02:55 2019 +0100
+++ b/client/yarn.lock	Fri Jan 18 20:26:21 2019 +0100
@@ -4530,7 +4530,7 @@
     loader-utils "^1.0.2"
     schema-utils "^1.0.0"
 
-"file-saver@github:eligrey/FileSaver.js#1.3.8":
+file-saver@eligrey/FileSaver.js#1.3.8:
   version "1.3.8"
   resolved "https://codeload.github.com/eligrey/FileSaver.js/tar.gz/e865e37af9f9947ddcced76b549e27dc45c1cb2e"