changeset 1889:b6d0460b069d

define stretches: Now with store-backend At present added stretches are stored in vuex. In addition to that, logic for persistence is provided but is currently commented out.
author Thomas Junk <thomas.junk@intevation.de>
date Fri, 18 Jan 2019 10:04:55 +0100
parents 45197e7a7ad3
children b1b0db195cc5
files client/src/components/ImportStretches.vue client/src/store/imports.js
diffstat 2 files changed, 59 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/ImportStretches.vue	Fri Jan 18 09:47:05 2019 +0100
+++ b/client/src/components/ImportStretches.vue	Fri Jan 18 10:04:55 2019 +0100
@@ -231,7 +231,6 @@
   name: "importstretches",
   data() {
     return {
-      stretches: [],
       edit: false,
       id: "",
       funktion: "",
@@ -257,6 +256,14 @@
   },
   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}`
+    //   });
+    // });
   },
   methods: {
     clean() {
@@ -315,7 +322,7 @@
     },
     save() {
       this.validate();
-      this.stretches.push({
+      const stretch = {
         id: this.id,
         funktion: this.funktion,
         startrhm: this.startrhm,
@@ -325,7 +332,16 @@
         countryCode: this.countryCode,
         date_info: this.date_info,
         source: this.source
-      });
+      };
+      this.$store.commit("imports/addStretch", stretch);
+      // uncomment when backend is there
+      // this.$store.dispatch("imports/addStretch", stretch).catch(error => {
+      //   const { status, data } = error.response;
+      //   displayError({
+      //     title: this.$gettext("Backend Error"),
+      //     message: `${status}: ${data.message || data}`
+      //   });
+      // });
       this.edit = false;
       displayInfo({
         title: this.$gettext("Sections"),
@@ -352,7 +368,8 @@
   },
   computed: {
     ...mapState("map", ["identifiedFeatures", "currentMeasurement"]),
-    ...mapGetters("user", ["isSysAdmin"])
+    ...mapGetters("user", ["isSysAdmin"]),
+    ...mapState("imports", ["stretches"])
   }
 };
 </script>
--- a/client/src/store/imports.js	Fri Jan 18 09:47:05 2019 +0100
+++ b/client/src/store/imports.js	Fri Jan 18 10:04:55 2019 +0100
@@ -97,6 +97,7 @@
 // initial state
 const init = () => {
   return {
+    stretches: [],
     imports: [],
     staging: [],
     schedules: [],
@@ -111,6 +112,13 @@
   namespaced: true,
   state: init(),
   mutations: {
+    setStretches: (state, stretches) => {
+      state.stretches = stretches;
+    },
+    // only for prototype purposes delete after real backend is active
+    addStretch: (state, stretch) => {
+      state.stretches.push(stretch);
+    },
     clearCurrentSchedule: state => {
       state.currentSchedule = initializeCurrentSchedule();
     },
@@ -210,6 +218,36 @@
     }
   },
   actions: {
+    loadStretches({ commit }) {
+      throw new Error("Not active");
+      return new Promise((resolve, reject) => {
+        HTTP.get("/imports/stretches", {
+          headers: { "X-Gemma-Auth": localStorage.getItem("token") }
+        })
+          .then(response => {
+            commit("setStretches", response.data);
+            resolve(response);
+          })
+          .catch(error => {
+            reject(error);
+          });
+      });
+    },
+    saveStretch({ commit }, stretch) {
+      throw new Error("Not active");
+      return new Promise((resolve, reject) => {
+        HTTP.post("/imports/stretches", stretch, {
+          headers: { "X-Gemma-Auth": localStorage.getItem("token") }
+        })
+          .then(response => {
+            commit("setStretches", response.data);
+            resolve(response);
+          })
+          .catch(error => {
+            reject(error);
+          });
+      });
+    },
     loadSchedule({ commit }, id) {
       return new Promise((resolve, reject) => {
         HTTP.get("/imports/config/" + id, {