Mercurial > gemma
diff client/src/store/imports.js @ 1731:8dd7452929ca
WIP: edit scheduled imports
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Wed, 09 Jan 2019 13:57:36 +0100 |
parents | b24a54c684bd |
children | 549337e6facd |
line wrap: on
line diff
--- 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 }) {