Skip to content
Snippets Groups Projects
Commit add98bae authored by Timothee P's avatar Timothee P :sunflower:
Browse files

fix conflict in feature_detail with validation

parents 56f8a9e1 27e2424d
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,7 @@ export default new Vuex.Store({ ...@@ -30,6 +30,7 @@ export default new Vuex.Store({
map map
}, },
state: { state: {
error: null,
logged: false, logged: false,
user: false, user: false,
configuration:null, configuration:null,
...@@ -43,6 +44,9 @@ export default new Vuex.Store({ ...@@ -43,6 +44,9 @@ export default new Vuex.Store({
}, },
mutations: { mutations: {
error(state, data) {
return state.error = data
},
SET_PROJECTS(state, projects) { SET_PROJECTS(state, projects) {
state.projects = projects; state.projects = projects;
}, },
...@@ -125,15 +129,23 @@ export default new Vuex.Store({ ...@@ -125,15 +129,23 @@ export default new Vuex.Store({
password: payload.password, password: payload.password,
}) })
.then((response) => { .then((response) => {
commit('error', null)
if (response && response.status === 200) { if (response && response.status === 200) {
// * use stored previous route to go back after login if page not open on login at first // * 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); commit("SET_USER", response.data.user);
router.push(routerHistory[routerHistory.length - 1] || "/") router.push(routerHistory[routerHistory.length - 1] || "/")
dispatch("GET_USER_LEVEL_PROJECTS"); dispatch("GET_USER_LEVEL_PROJECTS");
} }
}) })
.catch(() => { .catch((error) => {
if (error.response.status === 403)
commit('error', error.response.data.detail)
commit("SET_USER", false); commit("SET_USER", false);
}); });
} }
......
const axios = require("axios"); const axios = require("axios");
//import router from '../../router' import router from '../../router'
const feature = { const feature = {
...@@ -93,19 +93,31 @@ const feature = { ...@@ -93,19 +93,31 @@ const feature = {
.put(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}features/${state.form.feature_id}/`, geojson) .put(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}features/${state.form.feature_id}/`, geojson)
.then((response) => { .then((response) => {
if (response.status === 200 && response.data) { 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) => { .catch((error) => {
throw error; throw error;
}); });
} else { } else {
axios axios
.post(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}features/`, geojson) .post(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}features/`, geojson)
.then((response) => { .then((response) => {
if (response.status === 201 && response.data) { if (response.status === 201 && response.data) {
console.log(response, response.data)
dispatch("SEND_ATTACHMENTS", response.data.id) 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) => { .catch((error) => {
......
...@@ -77,6 +77,7 @@ const feature_type = { ...@@ -77,6 +77,7 @@ const feature_type = {
async SEND_FEATURE_TYPE({ state, getters, rootGetters }, requestType) { async SEND_FEATURE_TYPE({ state, getters, rootGetters }, requestType) {
const data = { const data = {
'title': state.form.title.value, 'title': state.form.title.value,
'title_optional': state.form.title_optional.value,
'geom_type': state.form.geom_type.value, 'geom_type': state.form.geom_type.value,
'color': state.form.color.value, 'color': state.form.color.value,
'colors_style': state.form.colors_style.value, 'colors_style': state.form.colors_style.value,
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
> >
<!-- Feature Fields --> <!-- Feature Fields -->
<div class="two fields"> <div class="two fields">
<div class="required field"> <div :class="field_title">
<label :for="form.title.id_for_label">{{ form.title.label }}</label> <label :for="form.title.id_for_label">{{ form.title.label }}</label>
<input <input
type="text" type="text"
...@@ -320,6 +320,15 @@ export default { ...@@ -320,6 +320,15 @@ export default {
]), ]),
...mapGetters("feature_type", ["feature_type"]), ...mapGetters("feature_type", ["feature_type"]),
field_title() {
if (this.feature_type) {
if (this.feature_type.title_optional) {
return "field";
}
}
return "required field";
},
currentRouteName() { currentRouteName() {
return this.$route.name; return this.$route.name;
}, },
...@@ -524,23 +533,40 @@ export default { ...@@ -524,23 +533,40 @@ export default {
return isValid; return isValid;
}, },
goBackToProject(message) {
this.$router.push({
name: "project_detail",
params: {
slug: this.$store.state.project_slug,
message,
},
});
},
postForm() { postForm() {
if ( let is_valid = true;
this.checkFormTitle() && if (!this.feature_type.title_optional) {
this.checkFormGeom() && is_valid =
this.checkAddedForm() this.checkFormTitle() &&
) { this.checkFormGeom() &&
this.checkAddedForm();
} else {
is_valid = this.checkFormGeom() && this.checkAddedForm();
}
if (is_valid) {
this.$store.dispatch("feature/SEND_FEATURE", this.currentRouteName); this.$store.dispatch("feature/SEND_FEATURE", this.currentRouteName);
} }
}, },
//* ************* MAP *************** *//
onFeatureTypeLoaded() { onFeatureTypeLoaded() {
var geomLeaflet = { var geomLeaflet = {
point: "circlemarker", point: "circlemarker",
linestring: "polyline", linestring: "polyline",
polygon: "polygon", polygon: "polygon",
}; };
// console.log(this.feature_type)
var geomType = this.feature_type.geom_type; var geomType = this.feature_type.geom_type;
var drawConfig = { var drawConfig = {
polygon: false, polygon: false,
......
...@@ -71,6 +71,16 @@ ...@@ -71,6 +71,16 @@
<!-- {{ form.color.errors }} --> <!-- {{ form.color.errors }} -->
</div> </div>
</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 --> <!-- //* s'affiche après sélection d'option de type liste dans type de champ -->
<div <div
...@@ -207,6 +217,13 @@ export default { ...@@ -207,6 +217,13 @@ export default {
html_name: "title", html_name: "title",
value: null, value: null,
}, },
title_optional: {
errors: null,
id_for_label: "title_optional",
html_name: "title_optional",
label: "Titre du signalement optionnel",
value: false,
},
geom_type: { geom_type: {
id_for_label: "geom_type", id_for_label: "geom_type",
label: "Type de géométrie", label: "Type de géométrie",
...@@ -322,6 +339,7 @@ export default { ...@@ -322,6 +339,7 @@ export default {
this.$store.commit("feature_type/UPDATE_FORM", { this.$store.commit("feature_type/UPDATE_FORM", {
color: this.form.color, color: this.form.color,
title: this.form.title, title: this.form.title,
title_optional: this.form.title_optional,
geom_type: this.form.geom_type, geom_type: this.form.geom_type,
colors_style: this.form.colors_style, colors_style: this.form.colors_style,
}); });
......
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
<script> <script>
import { mapState } from "vuex";
export default { export default {
name: "Login", name: "Login",
...@@ -76,6 +77,7 @@ export default { ...@@ -76,6 +77,7 @@ export default {
}; };
}, },
computed: { computed: {
...mapState(["error"]),
LOGO_PATH:function () { LOGO_PATH:function () {
return this.$store.state.configuration.VUE_APP_LOGO_PATH; return this.$store.state.configuration.VUE_APP_LOGO_PATH;
}, },
...@@ -87,11 +89,19 @@ export default { ...@@ -87,11 +89,19 @@ export default {
}, },
}, },
methods: { methods: {
login() { async login() {
this.$store.dispatch("LOGIN", { this.$store.dispatch("LOGIN", {
username: this.username_value, username: this.username_value,
password: this.password_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
});
}, },
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment