# HG changeset patch # User Thomas Junk # Date 1547038656 -3600 # Node ID 8dd7452929ca10e3162ea581e21e504c83b86d82 # Parent 7c54babe10f7f8f59c9ee68e46a994047079fe2e WIP: edit scheduled imports diff -r 7c54babe10f7 -r 8dd7452929ca client/src/components/importschedule/Importschedule.vue --- 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 @@ @@ -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") } diff -r 7c54babe10f7 -r 8dd7452929ca client/src/components/importschedule/Importscheduledetail.vue --- 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"); diff -r 7c54babe10f7 -r 8dd7452929ca client/src/store/imports.js --- 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 }) {