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

add loader to feature edition

parent 143e227e
No related branches found
No related tags found
No related merge requests found
...@@ -99,9 +99,12 @@ const feature = { ...@@ -99,9 +99,12 @@ const feature = {
}); });
}, },
SEND_FEATURE({ state, rootState, dispatch }, routeName) { SEND_FEATURE({ state, rootState, commit, dispatch }, routeName) {
commit("DISPLAY_LOADER", "Le signalement est en cours de création", { root: true })
const message = routeName === "editer-signalement" ? "Le signalement a été mis à jour" : "Le signalement a été crée"; const message = routeName === "editer-signalement" ? "Le signalement a été mis à jour" : "Le signalement a été crée";
function redirect(featureId) { function redirect(featureId) {
commit("DISCARD_LOADER", null, { root: true })
router.push({ router.push({
name: "details-signalement", name: "details-signalement",
params: { params: {
...@@ -111,12 +114,14 @@ const feature = { ...@@ -111,12 +114,14 @@ const feature = {
}, },
}); });
} }
async function handleOtherForms(featureId) { async function handleOtherForms(featureId) {
await dispatch("SEND_ATTACHMENTS", featureId) await dispatch("SEND_ATTACHMENTS", featureId)
await dispatch("PUT_LINKED_FEATURES", featureId) await dispatch("PUT_LINKED_FEATURES", featureId)
redirect(featureId); redirect(featureId);
} }
//* prepare feature data to send
let extraFormObject = {}; //* prepare an object to be flatten in properties of geojson let extraFormObject = {}; //* prepare an object to be flatten in properties of geojson
for (const field of state.extra_form) { for (const field of state.extra_form) {
extraFormObject[field.name] = field.value; extraFormObject[field.name] = field.value;
...@@ -134,12 +139,13 @@ const feature = { ...@@ -134,12 +139,13 @@ const feature = {
...extraFormObject ...extraFormObject
} }
} }
if (routeName === "editer-signalement") { if (routeName === "editer-signalement") {
axios return axios
.put(`${rootState.configuration.VUE_APP_DJANGO_API_BASE}features/${state.form.feature_id}/?` + .put(`${rootState.configuration.VUE_APP_DJANGO_API_BASE}features/${state.form.feature_id}/?` +
`feature_type__slug=${rootState.feature_type.current_feature_type_slug}` + `feature_type__slug=${rootState.feature_type.current_feature_type_slug}` +
`&project__slug=${rootState.project_slug}` `&project__slug=${rootState.project_slug}`
, geojson) , geojson)
.then((response) => { .then((response) => {
if (response.status === 200 && response.data) { if (response.status === 200 && response.data) {
if (state.attachmentFormset.length > 0 || state.linkedFormset.length > 0) { if (state.attachmentFormset.length > 0 || state.linkedFormset.length > 0) {
...@@ -150,10 +156,11 @@ const feature = { ...@@ -150,10 +156,11 @@ const feature = {
} }
}) })
.catch((error) => { .catch((error) => {
commit("DISCARD_LOADER", null, { root: true })
throw error; throw error;
}); });
} else { } else {
axios return axios
.post(`${rootState.configuration.VUE_APP_DJANGO_API_BASE}features/`, geojson) .post(`${rootState.configuration.VUE_APP_DJANGO_API_BASE}features/`, geojson)
.then((response) => { .then((response) => {
if (response.status === 201 && response.data) { if (response.status === 201 && response.data) {
...@@ -165,6 +172,7 @@ const feature = { ...@@ -165,6 +172,7 @@ const feature = {
} }
}) })
.catch((error) => { .catch((error) => {
commit("DISCARD_LOADER", null, { root: true })
throw error; throw error;
}); });
} }
...@@ -189,7 +197,7 @@ const feature = { ...@@ -189,7 +197,7 @@ const feature = {
console.error(error); console.error(error);
return error return error
}); });
} }
} }
...@@ -203,7 +211,7 @@ const feature = { ...@@ -203,7 +211,7 @@ const feature = {
if (attachment.title) if (attachment.title)
data['info'] = attachment.info data['info'] = attachment.info
formdataToUpdate.append("data", JSON.stringify(data)); formdataToUpdate.append("data", JSON.stringify(data));
let payload ={ let payload = {
'attachmentsId': attachment.id, 'attachmentsId': attachment.id,
'featureId': featureId, 'featureId': featureId,
'formdataToUpdate': formdataToUpdate 'formdataToUpdate': formdataToUpdate
...@@ -213,7 +221,7 @@ const feature = { ...@@ -213,7 +221,7 @@ const feature = {
} }
function deleteAttachement(attachmentsId, featureId) { function deleteAttachement(attachmentsId, featureId) {
let payload ={ let payload = {
'attachmentsId': attachmentsId, 'attachmentsId': attachmentsId,
'featureId': featureId 'featureId': featureId
} }
...@@ -224,7 +232,7 @@ const feature = { ...@@ -224,7 +232,7 @@ const feature = {
...state.attachmentFormset.map((attachment) => postAttachement(attachment)), ...state.attachmentFormset.map((attachment) => postAttachement(attachment)),
...state.attachmentsToPut.map((attachments) => putAttachement(attachments, featureId)), ...state.attachmentsToPut.map((attachments) => putAttachement(attachments, featureId)),
...state.attachmentsToDelete.map((attachmentsId) => deleteAttachement(attachmentsId, featureId)) ...state.attachmentsToDelete.map((attachmentsId) => deleteAttachement(attachmentsId, featureId))
] ]
); );
state.attachmentsToDelete = [] state.attachmentsToDelete = []
state.attachmentsToPut = [] state.attachmentsToPut = []
...@@ -280,8 +288,8 @@ const feature = { ...@@ -280,8 +288,8 @@ const feature = {
DELETE_FEATURE({ state, rootState }, feature_id) { DELETE_FEATURE({ state, rootState }, feature_id) {
console.log("Deleting feature:", feature_id, state) console.log("Deleting feature:", feature_id, state)
const url = `${rootState.configuration.VUE_APP_DJANGO_API_BASE}features/${feature_id}/?` + const url = `${rootState.configuration.VUE_APP_DJANGO_API_BASE}features/${feature_id}/?` +
`feature_type__slug=${rootState.feature_type.current_feature_type_slug}` + `feature_type__slug=${rootState.feature_type.current_feature_type_slug}` +
`&project__slug=${rootState.project_slug}`; `&project__slug=${rootState.project_slug}`;
return axios return axios
.delete(url) .delete(url)
.then((response) => response) .then((response) => response)
......
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