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

empty feature and extra_form at feature editon/creation

parent a0657d4b
No related branches found
No related tags found
No related merge requests found
......@@ -58,6 +58,9 @@ const feature = {
SET_EXTRA_FORM(state, extra_form) {
state.extra_form = extra_form;
},
CLEAR_EXTRA_FORM(state) {
state.extra_form = [];
},
ADD_ATTACHMENT_FORM(state, attachmentFormset) {
state.attachmentFormset = [...state.attachmentFormset, attachmentFormset];
},
......@@ -109,7 +112,7 @@ const feature = {
rootState.cancellableSearchRequest[rootState.cancellableSearchRequest.length - 1];
currentRequestCancelToken.cancel();
}
const cancelToken = axios.CancelToken.source();
commit('SET_CANCELLABLE_SEARCH_REQUEST', cancelToken, { root: true });
commit("SET_FEATURES", []);
......@@ -121,10 +124,10 @@ const feature = {
url = url.concat('', `${url.includes('?') ? '&' : '?'}title__contains=${search}`);
}
if (limit) {
url =url.concat('', `${url.includes('?') ? '&' : '?'}limit=${limit}`);
url = url.concat('', `${url.includes('?') ? '&' : '?'}limit=${limit}`);
}
return axios
.get(url , { cancelToken: cancelToken.token })
.get(url, { cancelToken: cancelToken.token })
.then((response) => {
if (response.status === 200 && response.data) {
const features = response.data.features;
......@@ -137,19 +140,19 @@ const feature = {
throw error;
});
},
GET_PROJECT_FEATURE({ commit, rootState }, { project_slug, feature_id }) {
GET_PROJECT_FEATURE({ commit, rootState }, { project_slug, feature_id }) {
if (rootState.cancellableSearchRequest.length > 0) {
const currentRequestCancelToken =
rootState.cancellableSearchRequest[rootState.cancellableSearchRequest.length - 1];
currentRequestCancelToken.cancel();
}
const cancelToken = axios.CancelToken.source();
commit('SET_CANCELLABLE_SEARCH_REQUEST', cancelToken, { root: true });
commit("SET_CURRENT_FEATURE", null);
let url = `${rootState.configuration.VUE_APP_DJANGO_API_BASE}projects/${project_slug}/feature/?id=${feature_id}`;
return axios
.get(url , { cancelToken: cancelToken.token })
.get(url, { cancelToken: cancelToken.token })
.then((response) => {
if (response.status === 200 && response.data.features) {
const feature = response.data.features[0];
......
......@@ -367,7 +367,7 @@ export default {
return this.$route.name;
},
feature () {
feature() {
return this.$store.state.feature.current_feature;
},
......@@ -563,7 +563,10 @@ export default {
return {
...field,
//* add value field to extra forms from feature_type and existing values if feature is defined
value: feature ? findCurrentValue(field.label) : null,
value:
feature && feature.feature_data
? findCurrentValue(field.label)
: null,
};
});
this.$store.commit("feature/SET_EXTRA_FORM", extraForm);
......@@ -999,6 +1002,10 @@ export default {
"feature_type/SET_CURRENT_FEATURE_TYPE_SLUG",
this.$route.params.slug_type_signal
);
//* empty previous feature data, not emptying by itself since it doesn't update by itself anymore
if (this.currentRouteName === "ajouter-signalement") {
this.$store.commit("feature/SET_CURRENT_FEATURE", []);
}
if (this.$route.params.slug_signal) {
this.getFeatureAttachments();
......@@ -1023,7 +1030,7 @@ export default {
this.initForm();
this.initMap();
this.onFeatureTypeLoaded();
if (this.feature) this.initExtraForms(this.feature);
this.initExtraForms(this.feature);
setTimeout(
function () {
......@@ -1038,6 +1045,7 @@ export default {
//* be sure that previous Formset have been cleared for creation
this.$store.commit("feature/CLEAR_ATTACHMENT_FORM");
this.$store.commit("feature/CLEAR_LINKED_FORM");
this.$store.commit("feature/CLEAR_EXTRA_FORM");
},
};
</script>
......
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