changeset 1731:8dd7452929ca

WIP: edit scheduled imports
author Thomas Junk <thomas.junk@intevation.de>
date Wed, 09 Jan 2019 13:57:36 +0100
parents 7c54babe10f7
children 73aab5f9a934
files client/src/components/importschedule/Importschedule.vue client/src/components/importschedule/Importscheduledetail.vue client/src/store/imports.js
diffstat 3 files changed, 129 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/importschedule/Importschedule.vue	Wed Jan 09 13:11:09 2019 +0100
+++ b/client/src/components/importschedule/Importschedule.vue	Wed Jan 09 13:57:36 2019 +0100
@@ -57,6 +57,7 @@
                   </td>
                   <td>
                     <font-awesome-icon
+                      @click="editSchedule(schedule.id)"
                       icon="pencil-alt"
                       fixed-width
                     ></font-awesome-icon>
@@ -130,6 +131,20 @@
     this.getSchedules();
   },
   methods: {
+    editSchedule(id) {
+      this.$store
+        .dispatch("imports/loadSchedule", id)
+        .then(() => {
+          this.$store.commit("imports/setImportScheduleDetailVisible");
+        })
+        .catch(error => {
+          const { status, data } = error.response;
+          displayError({
+            title: this.$gettext("Backend Error"),
+            message: `${status}: ${data.message || data}`
+          });
+        });
+    },
     triggerManualImport(id) {
       HTTP.get("/imports/config/" + id, {
         headers: { "X-Gemma-Auth": localStorage.getItem("token") }
--- a/client/src/components/importschedule/Importscheduledetail.vue	Wed Jan 09 13:11:09 2019 +0100
+++ b/client/src/components/importschedule/Importscheduledetail.vue	Wed Jan 09 13:57:36 2019 +0100
@@ -363,6 +363,7 @@
       eMailNotification: false,
       scheduled: false,
       easyCron: true,
+      cronstring: null,
       cronMode: "",
       minutes: null,
       month: null,
@@ -420,7 +421,7 @@
     this.initialize();
   },
   watch: {
-    currentSchedule() {
+    importScheduleDetailVisible() {
       this.initialize();
     },
     cronString() {
@@ -549,30 +550,60 @@
         default:
           break;
       }
-      this.$store
-        .dispatch("imports/saveCurrentSchedule", data)
-        .then(response => {
-          const { id } = response.data;
-          displayInfo({
-            title: this.$gettext("Import"),
-            message: this.$gettext("Saved import: #") + id
-          });
-          this.closeDetailview();
-          this.$store.dispatch("imports/loadSchedules").catch(error => {
+      if (!this.id) {
+        this.$store
+          .dispatch("imports/saveCurrentSchedule", data)
+          .then(response => {
+            const { id } = response.data;
+            displayInfo({
+              title: this.$gettext("Import"),
+              message: this.$gettext("Saved import: #") + id
+            });
+            this.closeDetailview();
+            this.$store.dispatch("imports/loadSchedules").catch(error => {
+              const { status, data } = error.response;
+              displayError({
+                title: this.gettext("Backend Error"),
+                message: `${status}: ${data.message || data}`
+              });
+            });
+          })
+          .catch(error => {
             const { status, data } = error.response;
             displayError({
-              title: this.gettext("Backend Error"),
+              title: this.$gettext("Backend Error"),
               message: `${status}: ${data.message || data}`
             });
           });
-        })
-        .catch(error => {
-          const { status, data } = error.response;
-          displayError({
-            title: this.$gettext("Backend Error"),
-            message: `${status}: ${data.message || data}`
+      } else {
+        this.$store
+          .dispatch("imports/updateCurrentSchedule", {
+            data: data,
+            id: this.id
+          })
+          .then(response => {
+            const { id } = response.data;
+            displayInfo({
+              title: this.$gettext("Import"),
+              message: this.$gettext("update import: #") + id
+            });
+            this.closeDetailview();
+            this.$store.dispatch("imports/loadSchedules").catch(error => {
+              const { status, data } = error.response;
+              displayError({
+                title: this.gettext("Backend Error"),
+                message: `${status}: ${data.message || data}`
+              });
+            });
+          })
+          .catch(error => {
+            const { status, data } = error.response;
+            displayError({
+              title: this.$gettext("Backend Error"),
+              message: `${status}: ${data.message || data}`
+            });
           });
-        });
+      }
     },
     closeDetailview() {
       this.$store.commit("imports/clearCurrentSchedule");
--- a/client/src/store/imports.js	Wed Jan 09 13:11:09 2019 +0100
+++ b/client/src/store/imports.js	Wed Jan 09 13:57:36 2019 +0100
@@ -13,6 +13,7 @@
  */
 
 import { HTTP } from "@/lib/http";
+import Vue from "vue";
 
 /* eslint-disable no-unused-vars */
 /* eslint-disable no-unreachable */
@@ -38,6 +39,13 @@
   waterwayaxis: "wx"
 };
 
+const KINDIMPORTTYPE = {
+  bn: "bottleneck",
+  fa: "fairwayawailability",
+  ga: "gaugemeasurement",
+  wx: "waterwayaxis"
+};
+
 const initializeCurrentSchedule = () => {
   return {
     id: null,
@@ -48,6 +56,7 @@
     eMailNotification: false,
     scheduled: false,
     easyCron: true,
+    cronstring: null,
     cronMode: "",
     minutes: null,
     month: null,
@@ -113,9 +122,38 @@
       } else {
         stagedResult.status = newStatus;
       }
+    },
+    unmarshallCurrentSchedule: (state, payload) => {
+      const { kind, id, cron, url } = payload;
+      const eMailNotification = payload["send-email"];
+      Vue.set(state.currentSchedule, "import_", KINDIMPORTTYPE[kind]);
+      Vue.set(state.currentSchedule, "id", id);
+      if (cron) {
+        Vue.set(state.currentSchedule, "cronstring", cron);
+      }
+      if (eMailNotification) {
+        Vue.set(state.currentSchedule, "eMailNotification", eMailNotification);
+      }
+      if (url) {
+        Vue.set(state.currentSchedule, "url", url);
+      }
     }
   },
   actions: {
+    loadSchedule({ commit }, id) {
+      return new Promise((resolve, reject) => {
+        HTTP.get("/imports/config/" + id, {
+          headers: { "X-Gemma-Auth": localStorage.getItem("token") }
+        })
+          .then(response => {
+            commit("unmarshallCurrentSchedule", response.data);
+            resolve(response);
+          })
+          .catch(error => {
+            reject(error);
+          });
+      });
+    },
     deleteSchedule({ commit }, id) {
       return new Promise((resolve, reject) => {
         HTTP.delete("imports/config/" + id, {
@@ -131,35 +169,35 @@
           });
       });
     },
+    updateCurrentSchedule({ commit }, payload) {
+      const { data, id } = payload;
+      return new Promise((resolve, reject) => {
+        HTTP.patch("imports/config/" + id, data, {
+          headers: {
+            "X-Gemma-Auth": localStorage.getItem("token")
+          }
+        })
+          .then(response => {
+            resolve(response);
+          })
+          .catch(error => {
+            reject(error);
+          });
+      });
+    },
     saveCurrentSchedule({ commit }, data) {
       return new Promise((resolve, reject) => {
-        const create = true;
-        if (create) {
-          HTTP.post("imports/config", data, {
-            headers: {
-              "X-Gemma-Auth": localStorage.getItem("token")
-            }
+        HTTP.post("imports/config", data, {
+          headers: {
+            "X-Gemma-Auth": localStorage.getItem("token")
+          }
+        })
+          .then(response => {
+            resolve(response);
           })
-            .then(response => {
-              resolve(response);
-            })
-            .catch(error => {
-              reject(error);
-            });
-        } else {
-          const { id } = data;
-          HTTP.patch("imports/config/" + id, data, {
-            headers: {
-              "X-Gemma-Auth": localStorage.getItem("token")
-            }
-          })
-            .then(response => {
-              resolve(response);
-            })
-            .catch(error => {
-              reject(error);
-            });
-        }
+          .catch(error => {
+            reject(error);
+          });
       });
     },
     loadSchedules({ commit }) {