Mercurial > gemma
view 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 source
/* This is Free Software under GNU Affero General Public License v >= 3.0 * without warranty, see README.md and license for details. * * SPDX-License-Identifier: AGPL-3.0-or-later * License-Filename: LICENSES/AGPL-3.0.txt * * Copyright (C) 2018 by via donau * – Österreichische Wasserstraßen-Gesellschaft mbH * Software engineering by Intevation GmbH * * Author(s): * Thomas Junk <thomas.junk@intevation.de> */ import { HTTP } from "@/lib/http"; import Vue from "vue"; /* eslint-disable no-unused-vars */ /* eslint-disable no-unreachable */ const STATES = { NEEDSAPPROVAL: "pending", APPROVED: "accepted", REJECTED: "declined" }; const IMPORTTYPES = { BOTTLENECK: "bottleneck" }; const SCHEDULES = { DAILY: "daily", MONTHLY: "monthly" }; const IMPORTTYPEKIND = { bottleneck: "bn", fairwayawailability: "fa", gaugemeasurement: "ga", waterwayaxis: "wx" }; const KINDIMPORTTYPE = { bn: "bottleneck", fa: "fairwayawailability", ga: "gaugemeasurement", wx: "waterwayaxis" }; const initializeCurrentSchedule = () => { return { id: null, importType: null, schedule: null, import_: null, importSource: null, eMailNotification: false, scheduled: false, easyCron: true, cronstring: null, cronMode: "", minutes: null, month: null, hour: null, day: null, dayOfMonth: null, simple: null, url: null, insecure: false }; }; // initial state const init = () => { return { imports: [], staging: [], schedules: [], importScheduleDetailVisible: false, currentSchedule: initializeCurrentSchedule(), importToReview: null }; }; const imports = { init, namespaced: true, state: init(), mutations: { clearCurrentSchedule: state => { state.currentSchedule = initializeCurrentSchedule(); }, setImportScheduleDetailInvisible: state => { state.importScheduleDetailVisible = false; }, setImportScheduleDetailVisible: state => { state.importScheduleDetailVisible = true; }, setSchedules: (state, schedules) => { state.schedules = schedules; }, setImports: (state, imports) => { state.imports = imports; }, setStaging: (state, staging) => { const enriched = staging.map(x => { return { ...x, status: STATES.NEEDSAPPROVAL }; }); state.staging = enriched; }, setImportToReview: (state, id) => { if (!isNaN(parseFloat(id)) && isFinite(id)) { state.importToReview = id; } }, toggleApproval: (state, change) => { const { id, newStatus } = change; const stagedResult = state.staging.find(e => { return e.id === id; }); if (stagedResult.status === newStatus) { stagedResult.status = STATES.NEEDSAPPROVAL; } 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, { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { resolve(response); }) .catch(error => { reject(error); }); }); }, 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) => { HTTP.post("imports/config", data, { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { resolve(response); }) .catch(error => { reject(error); }); }); }, loadSchedules({ commit }) { return new Promise((resolve, reject) => { HTTP.get("/imports/config", { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { commit("setSchedules", response.data); resolve(response); }) .catch(error => { reject(error); }); }); }, triggerImport({ commit }, { type, data }) { return new Promise((resolve, reject) => { HTTP.post("imports/" + type, data, { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { resolve(response); }) .catch(error => { reject(error); }); }); }, getImports({ commit }) { return new Promise((resolve, reject) => { HTTP.get("/imports", { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { commit("setImports", response.data.imports); resolve(response); }) .catch(error => { reject(error); }); }); }, getStaging({ commit }) { return new Promise((resolve, reject) => { HTTP.get("/imports?states=pending", { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { commit("setStaging", response.data.imports); resolve(response); }) .catch(error => { reject(error); }); }); } } }; export { imports, STATES, SCHEDULES, IMPORTTYPES, IMPORTTYPEKIND };