Mercurial > gemma
view client/src/store/imports.js @ 1921:0059aa870a39 v2
Hotfixed stretch import.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Fri, 18 Jan 2019 20:26:21 +0100 |
parents | b6d0460b069d |
children | 1aa864cccddc |
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", WATERWAYAXIS: "waterwayaxis", GAUGEMEASUREMENT: "gaugemeasurement", FAIRWAYAVAILABILITY: "fairwayavailability", WATERWAYAREA: "waterwayarea", FAIRWAYDIMENSION: "fairwaydimension", WATERWAYGAUGES: "waterwaygauges", DISTANCEMARKSVIRTUAL: "distancemarksvirtual" }; const SCHEDULES = { DAILY: "daily", MONTHLY: "monthly" }; const IMPORTTYPEKIND = { bottleneck: "bn", fairwayavailability: "fa", gaugemeasurement: "gm", waterwayaxis: "wx", waterwayarea: "wa", fairwaydimension: "fd", waterwaygauges: "wg", distancemarksvirtual: "dmv" }; const KINDIMPORTTYPE = { bn: "bottleneck", fa: "fairwayavailability", gm: "gaugemeasurement", wx: "waterwayaxis", wa: "waterwayarea", fd: "fairwaydimension", wg: "waterwaygauge", dmv: "distancemarksvirtual" }; const initializeCurrentSchedule = () => { return { id: null, importType: null, schedule: null, import_: null, importSource: null, eMailNotification: false, scheduled: false, easyCron: true, cronString: "* * * * ", cronMode: "", minutes: null, month: null, hour: null, day: null, dayOfMonth: null, simple: null, url: null, insecure: false, triggerActive: true, featureType: null, sortBy: null, username: "", password: "", LOS: null, minWidth: null, maxWidth: null, depth: null, sourceOrganization: null }; }; // initial state const init = () => { return { stretches: [], imports: [], staging: [], schedules: [], importScheduleDetailVisible: false, currentSchedule: initializeCurrentSchedule(), importToReview: null }; }; const imports = { init, 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(); }, 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, attributes } = 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, "scheduled", true); Vue.set(state.currentSchedule, "easyCron", false); Vue.set(state.currentSchedule, "cronString", cron); } if (eMailNotification) { Vue.set(state.currentSchedule, "eMailNotification", eMailNotification); } if (url) { Vue.set(state.currentSchedule, "url", url); } if (attributes) { let { insecure, username, password, los, depth } = attributes; let sortBy = attributes["sort-by"]; let minWidth = attributes["min-width"]; let maxWidth = attributes["max-width"]; let sourceOrganization = attributes["source-organization"]; const featureType = attributes["feature-type"]; insecure = insecure == "true"; if (insecure) { Vue.set(state.currentSchedule, "insecure", insecure); } if (featureType) { Vue.set(state.currentSchedule, "featureType", featureType); } if (sortBy) { Vue.set(state.currentSchedule, "sortBy", sortBy); } if (username) { Vue.set(state.currentSchedule, "username", username); } if (password) { Vue.set(state.currentSchedule, "password", password); } if (los) { Vue.set(state.currentSchedule, "LOS", los); } if (minWidth) { Vue.set(state.currentSchedule, "minWidth", minWidth); } if (maxWidth) { Vue.set(state.currentSchedule, "maxWidth", maxWidth); } if (depth) { Vue.set(state.currentSchedule, "depth", depth); } if (sourceOrganization) { Vue.set( state.currentSchedule, "sourceOrganization", sourceOrganization ); } } } }, 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, { 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, initializeCurrentSchedule };