diff --git a/src/store/index.js b/src/store/index.js index faebe1b6157cbcb4a4d572b2edc5be1135af5d9c..ce5d58e6a11272cec3d59b600a3ef15b6c968558 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -30,6 +30,7 @@ export default new Vuex.Store({ map }, state: { + error: null, logged: false, user: false, configuration:null, @@ -43,6 +44,9 @@ export default new Vuex.Store({ }, mutations: { + error(state, data) { + return state.error = data + }, SET_PROJECTS(state, projects) { state.projects = projects; }, @@ -125,15 +129,23 @@ export default new Vuex.Store({ password: payload.password, }) .then((response) => { + commit('error', null) if (response && response.status === 200) { // * use stored previous route to go back after login if page not open on login at first - const routerHistory = router.options.routerHistory[0].name !== "login" ? router.options.routerHistory : "/" + let routerHistory = '' + if (router.options.routerHistory[0] != undefined){ + routerHistory = router.options.routerHistory[0].name !== "login" ? router.options.routerHistory : "/" + } else { + routerHistory = "/" + } commit("SET_USER", response.data.user); router.push(routerHistory[routerHistory.length - 1] || "/") dispatch("GET_USER_LEVEL_PROJECTS"); } }) - .catch(() => { + .catch((error) => { + if (error.response.status === 403) + commit('error', error.response.data.detail) commit("SET_USER", false); }); } diff --git a/src/store/modules/feature.js b/src/store/modules/feature.js index df638cf266dfce9e82646000d260747c0adbc853..fd9ee2833a5d85f36bf828c538cf948cb6bff8a2 100644 --- a/src/store/modules/feature.js +++ b/src/store/modules/feature.js @@ -1,5 +1,5 @@ const axios = require("axios"); -//import router from '../../router' +import router from '../../router' const feature = { @@ -93,19 +93,31 @@ const feature = { .put(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}features/${state.form.feature_id}/`, geojson) .then((response) => { if (response.status === 200 && response.data) { - console.log(response, response.data) + router.push({ + name: "project_detail", + params: { + slug: rootState.project_slug, + message: "Le signalement a été mis à jour", + }, + }); } }) .catch((error) => { throw error; }); - } else { - axios + } else { + axios .post(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}features/`, geojson) .then((response) => { if (response.status === 201 && response.data) { - console.log(response, response.data) dispatch("SEND_ATTACHMENTS", response.data.id) + router.push({ + name: "project_detail", + params: { + slug: rootState.project_slug, + message: "Le signalement a été crée", + }, + }); } }) .catch((error) => { diff --git a/src/store/modules/feature_type.js b/src/store/modules/feature_type.js index 1f0ced836f3359f7db4a331bba40fe3bc1c202b7..e8986cb11c20e7c50a568a2a94e4707f7f77193b 100644 --- a/src/store/modules/feature_type.js +++ b/src/store/modules/feature_type.js @@ -77,6 +77,7 @@ const feature_type = { async SEND_FEATURE_TYPE({ state, getters, rootGetters }, requestType) { const data = { 'title': state.form.title.value, + 'title_optional': state.form.title_optional.value, 'geom_type': state.form.geom_type.value, 'color': state.form.color.value, 'colors_style': state.form.colors_style.value, diff --git a/src/views/feature/Feature_edit.vue b/src/views/feature/Feature_edit.vue index e4d5c62ce0ec448bf8c2fcc677b446e5056a636d..c13fb8bfeb046d852fde7a6f9c5d7e4c653b490f 100644 --- a/src/views/feature/Feature_edit.vue +++ b/src/views/feature/Feature_edit.vue @@ -19,7 +19,7 @@ > <!-- Feature Fields --> <div class="two fields"> - <div class="required field"> + <div :class="field_title"> <label :for="form.title.id_for_label">{{ form.title.label }}</label> <input type="text" @@ -320,6 +320,15 @@ export default { ]), ...mapGetters("feature_type", ["feature_type"]), + field_title() { + if (this.feature_type) { + if (this.feature_type.title_optional) { + return "field"; + } + } + return "required field"; + }, + currentRouteName() { return this.$route.name; }, @@ -524,23 +533,40 @@ export default { return isValid; }, + goBackToProject(message) { + this.$router.push({ + name: "project_detail", + params: { + slug: this.$store.state.project_slug, + message, + }, + }); + }, + postForm() { - if ( - this.checkFormTitle() && - this.checkFormGeom() && - this.checkAddedForm() - ) { + let is_valid = true; + if (!this.feature_type.title_optional) { + is_valid = + this.checkFormTitle() && + this.checkFormGeom() && + this.checkAddedForm(); + } else { + is_valid = this.checkFormGeom() && this.checkAddedForm(); + } + + if (is_valid) { this.$store.dispatch("feature/SEND_FEATURE", this.currentRouteName); } }, + //* ************* MAP *************** *// + onFeatureTypeLoaded() { var geomLeaflet = { point: "circlemarker", linestring: "polyline", polygon: "polygon", }; - // console.log(this.feature_type) var geomType = this.feature_type.geom_type; var drawConfig = { polygon: false, diff --git a/src/views/feature_type/Feature_type_edit.vue b/src/views/feature_type/Feature_type_edit.vue index 50aa59cad812c431491a02fda2f8e651b62f5a36..af4f1bb3af32c801c6e2525cfcb350b4725dda71 100644 --- a/src/views/feature_type/Feature_type_edit.vue +++ b/src/views/feature_type/Feature_type_edit.vue @@ -71,6 +71,16 @@ <!-- {{ form.color.errors }} --> </div> </div> + <div class="field"> + <div class="ui checkbox"> + <input + :name="form.title_optional.html_name" + v-model="form.title_optional.value" + type="checkbox" + /> + <label>{{form.title_optional.label}}</label> + </div> + </div> <!-- //* s'affiche après sélection d'option de type liste dans type de champ --> <div @@ -207,6 +217,13 @@ export default { html_name: "title", value: null, }, + title_optional: { + errors: null, + id_for_label: "title_optional", + html_name: "title_optional", + label: "Titre du signalement optionnel", + value: false, + }, geom_type: { id_for_label: "geom_type", label: "Type de géométrie", @@ -322,6 +339,7 @@ export default { this.$store.commit("feature_type/UPDATE_FORM", { color: this.form.color, title: this.form.title, + title_optional: this.form.title_optional, geom_type: this.form.geom_type, colors_style: this.form.colors_style, }); diff --git a/src/views/registration/Login.vue b/src/views/registration/Login.vue index 05d38bd0338eef467e39ed8b6647911635d3684f..470d00f3be470f1e4d7b8e989439019d89ba2b92 100644 --- a/src/views/registration/Login.vue +++ b/src/views/registration/Login.vue @@ -62,6 +62,7 @@ <script> +import { mapState } from "vuex"; export default { name: "Login", @@ -76,6 +77,7 @@ export default { }; }, computed: { + ...mapState(["error"]), LOGO_PATH:function () { return this.$store.state.configuration.VUE_APP_LOGO_PATH; }, @@ -87,11 +89,19 @@ export default { }, }, methods: { - login() { + async login() { this.$store.dispatch("LOGIN", { username: this.username_value, password: this.password_value, - }); + }) + .then(() => { + if (this.error != null){ + this.form.errors = "Les informations d'identification sont incorrectes."; + } + }) + .catch(() => { + this.form.errors = this.error + }); }, },