Mercurial > gemma
changeset 2033:431f97fd873b unify_imports
importschedule: extracted to separate store
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Fri, 25 Jan 2019 11:09:21 +0100 |
parents | 15db4fb07af4 |
children | cc3ad4aa9b2f |
files | client/src/components/importschedule/Importschedule.vue client/src/components/importschedule/Importscheduledetail.vue client/src/store/imports.js client/src/store/index.js |
diffstat | 4 files changed, 36 insertions(+), 269 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/components/importschedule/Importschedule.vue Fri Jan 25 10:15:53 2019 +0100 +++ b/client/src/components/importschedule/Importschedule.vue Fri Jan 25 11:09:21 2019 +0100 @@ -138,9 +138,9 @@ methods: { editSchedule(id) { this.$store - .dispatch("imports/loadSchedule", id) + .dispatch("importschedule/loadSchedule", id) .then(() => { - this.$store.commit("imports/setImportScheduleDetailVisible"); + this.$store.commit("importschedule/setImportScheduleDetailVisible"); }) .catch(error => { const { status, data } = error.response; @@ -170,7 +170,7 @@ }); }, getSchedules() { - this.$store.dispatch("imports/loadSchedules").catch(error => { + this.$store.dispatch("importschedule/loadSchedules").catch(error => { const { status, data } = error.response; displayError({ title: this.$gettext("Backend Error"), @@ -179,12 +179,12 @@ }); }, newImport() { - this.$store.commit("imports/setImportScheduleDetailVisible"); + this.$store.commit("importschedule/setImportScheduleDetailVisible"); }, deleteSchedule(index) { if (this.importScheduleDetailVisible) return; this.$store - .dispatch("imports/deleteSchedule", index) + .dispatch("importschedule/deleteSchedule", index) .then(() => { this.getSchedules(); displayInfo({ @@ -203,7 +203,7 @@ }, computed: { ...mapState("application", ["showSidebar"]), - ...mapState("imports", ["schedules", "importScheduleDetailVisible"]), + ...mapState("importschedule", ["schedules", "importScheduleDetailVisible"]), activeStyle() { const color = this.importScheduleDetailVisible ? "#aeaeae" : "#000000"; return { color: color };
--- a/client/src/components/importschedule/Importscheduledetail.vue Fri Jan 25 10:15:53 2019 +0100 +++ b/client/src/components/importschedule/Importscheduledetail.vue Fri Jan 25 11:09:21 2019 +0100 @@ -382,7 +382,7 @@ IMPORTTYPES, IMPORTTYPEKIND, initializeCurrentSchedule -} from "@/store/imports.js"; +} from "@/store/importschedule"; import { mapState } from "vuex"; import { displayInfo, displayError } from "@/lib/errors.js"; import app from "@/main.js"; @@ -488,7 +488,10 @@ } }, computed: { - ...mapState("imports", ["importScheduleDetailVisible", "currentSchedule"]), + ...mapState("importschedule", [ + "importScheduleDetailVisible", + "currentSchedule" + ]), dialogLabel() { if (this.id) return this.$gettext("Import") + " " + this.id; return this.$gettext("New Import"); @@ -667,7 +670,7 @@ } this.triggerActive = false; this.$store - .dispatch("imports/triggerImport", { type: this.import_, data }) + .dispatch("importschedule/triggerImport", { type: this.import_, data }) .then(response => { const { id } = response.data; displayInfo({ @@ -747,7 +750,7 @@ data["send-email"] = this.eMailNotification; if (!this.id) { this.$store - .dispatch("imports/saveCurrentSchedule", data) + .dispatch("importschedule/saveCurrentSchedule", data) .then(response => { const { id } = response.data; displayInfo({ @@ -755,13 +758,15 @@ 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}` + this.$store + .dispatch("importschedule/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; @@ -772,7 +777,7 @@ }); } else { this.$store - .dispatch("imports/updateCurrentSchedule", { + .dispatch("importschedule/updateCurrentSchedule", { data: data, id: this.id }) @@ -783,13 +788,15 @@ 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}` + this.$store + .dispatch("importschedule/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; @@ -801,8 +808,8 @@ } }, closeDetailview() { - this.$store.commit("imports/clearCurrentSchedule"); - this.$store.commit("imports/setImportScheduleDetailInvisible"); + this.$store.commit("importschedule/clearCurrentSchedule"); + this.$store.commit("importschedule/setImportScheduleDetailInvisible"); } } };
--- a/client/src/store/imports.js Fri Jan 25 10:15:53 2019 +0100 +++ b/client/src/store/imports.js Fri Jan 25 11:09:21 2019 +0100 @@ -13,7 +13,6 @@ */ import { HTTP } from "@/lib/http"; -import Vue from "vue"; import { WFS } from "ol/format.js"; import { equalTo as equalToFilter } from "ol/format/filter.js"; @@ -25,86 +24,12 @@ 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: 1, - minWidth: null, - maxWidth: null, - depth: null, - sourceOrganization: null - }; -}; - // initial state const init = () => { return { stretches: [], imports: [], staging: [], - schedules: [], - importScheduleDetailVisible: false, - currentSchedule: initializeCurrentSchedule(), importToReview: null }; }; @@ -117,18 +42,6 @@ setStretches: (state, stretches) => { state.stretches = stretches; }, - 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; }, @@ -153,66 +66,6 @@ } 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: { @@ -264,95 +117,6 @@ }); }); }, - 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", { @@ -384,11 +148,4 @@ } }; -export { - imports, - STATES, - SCHEDULES, - IMPORTTYPES, - IMPORTTYPEKIND, - initializeCurrentSchedule -}; +export { imports, STATES };
--- a/client/src/store/index.js Fri Jan 25 10:15:53 2019 +0100 +++ b/client/src/store/index.js Fri Jan 25 11:09:21 2019 +0100 @@ -22,6 +22,7 @@ import fairwayprofile from "./fairway"; import bottlenecks from "./bottlenecks"; import { imports } from "./imports"; +import { importschedule } from "./importschedule"; Vue.use(Vuex); @@ -32,6 +33,7 @@ application: application.init(), fairwayprofile: fairwayprofile.init(), imports: imports.init(), + importschedule: importschedule.init(), bottlenecks: bottlenecks.init(), map: map.init(), user: user.init(), @@ -43,6 +45,7 @@ application, fairwayprofile, imports, + importschedule, bottlenecks, map, user,