Mercurial > gemma
changeset 1930:1aa864cccddc
define stretches: converted to vuex
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Mon, 21 Jan 2019 11:57:03 +0100 |
parents | f538d9a23329 |
children | 8fb1b1a8ea85 |
files | client/src/components/ImportStretches.vue client/src/store/imports.js |
diffstat | 2 files changed, 25 insertions(+), 54 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/components/ImportStretches.vue Mon Jan 21 11:44:31 2019 +0100 +++ b/client/src/components/ImportStretches.vue Mon Jan 21 11:57:03 2019 +0100 @@ -225,7 +225,6 @@ * Thomas Junk <thomas.junk@intevation.de> */ import { mapState, mapGetters } from "vuex"; -import { HTTP } from "@/lib/http"; import { displayError, displayInfo } from "@/lib/errors.js"; export default { @@ -257,13 +256,13 @@ }, mounted() { this.edit = false; - this.$store.dispatch("imports/loadStretches").catch(error => { - const { status, data } = error.response; - displayError({ - title: this.$gettext("Backend Error"), - message: `${status}: ${data.message || data}` - }); - }); + // this.$store.dispatch("imports/loadStretches").catch(error => { + // const { status, data } = error.response; + // displayError({ + // title: this.$gettext("Backend Error"), + // message: `${status}: ${data.message || data}` + // }); + // }); }, methods: { clean() { @@ -321,55 +320,28 @@ }, save() { this.validate(); - const stretch = { - id: this.id, - funktion: this.funktion, - startrhm: this.startrhm, - endrhm: this.endrhm, - objbn: this.objbn, - nobjbn: this.nobjbn, - countryCode: this.countryCode, - date_info: this.date_info, - source: this.source + const data = { + name: this.id, + from: this.startrhm, + to: this.endrhm, + "source-organization": this.source, + "date-info": this.date_info, + objnam: this.objbn, + nobjnam: this.nobjbn, + countries: this.countryCode.split(",") }; - //-- The following code does not work... [sw] - // this.$store.commit("imports/addStretch", stretch); - - // this.$store.dispatch("imports/addStretch", stretch).catch(error => { - // const { status, data } = error.response; - // displayError({ - // title: this.$gettext("Backend Error"), - // message: `${status}: ${data.message || data}` - // }); - // }); - - // so here the quick dirty and working version: [sw] - const data = { - name: stretch.id, - from: stretch.startrhm, - to: stretch.endrhm, - source_organization: stretch.source, - date_info: stretch.date_info, - objnam: stretch.objnam, - nobjnam: stretch.nobjnam, - countries: stretch.countryCode.split() - }; - HTTP.post("/imports/stretch", data, { - headers: { - "X-Gemma-Auth": localStorage.getItem("token"), - "Content-Type": "multipart/form-data" - } - }) + this.$store + .dispatch("imports/saveStretch", data) .then(() => { displayInfo({ title: this.$gettext("Import"), - message: this.$gettext( - "Starting import of stretch" - ) + message: this.$gettext("Starting import of stretch") }); - this.initialState(); + this.clean(); + this.edit = false; }) .catch(error => { + console.log(error); const { status, data } = error.response; displayError({ title: this.$gettext("Backend Error"),
--- a/client/src/store/imports.js Mon Jan 21 11:44:31 2019 +0100 +++ b/client/src/store/imports.js Mon Jan 21 11:57:03 2019 +0100 @@ -219,9 +219,9 @@ }, actions: { loadStretches({ commit }) { - throw new Error("Not active"); + throw new Error("Endpoint not activated!"); return new Promise((resolve, reject) => { - HTTP.get("/imports/stretches", { + HTTP.get("/imports/stretch", { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { @@ -234,9 +234,8 @@ }); }, saveStretch({ commit }, stretch) { - throw new Error("Not active"); return new Promise((resolve, reject) => { - HTTP.post("/imports/stretches", stretch, { + HTTP.post("/imports/stretch", stretch, { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => {