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({
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);
});
}
......
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) => {
......
......@@ -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,
......
......@@ -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,
......
......@@ -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,
});
......
......@@ -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
});
},
},
......
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