Mercurial > gemma
diff client/src/components/ImportStretches.vue @ 1930:1aa864cccddc
define stretches: converted to vuex
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Mon, 21 Jan 2019 11:57:03 +0100 |
parents | 0059aa870a39 |
children | d1b7b1c70410 |
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"),