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

allow delete on attachment and linkedfeature if only one

parent 6ec8fd72
No related branches found
No related tags found
2 merge requests!2132.3.2-rc1,!208REDMINE_ISSUE-11814
...@@ -180,7 +180,6 @@ const feature = { ...@@ -180,7 +180,6 @@ const feature = {
SEND_FEATURE({ state, rootState, commit, dispatch }, routeName) { SEND_FEATURE({ state, rootState, commit, dispatch }, routeName) {
commit("DISPLAY_LOADER", "Le signalement est en cours de création", { root: true }) 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) {
dispatch( dispatch(
'GET_PROJECT_FEATURE', 'GET_PROJECT_FEATURE',
...@@ -228,110 +227,65 @@ const feature = { ...@@ -228,110 +227,65 @@ const feature = {
} }
} }
let url = `${rootState.configuration.VUE_APP_DJANGO_API_BASE}features/`
if (routeName === "editer-signalement") { if (routeName === "editer-signalement") {
return axios url += `${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)
.then((response) => {
if (response.status === 200 && response.data) {
if (state.attachmentFormset.length > 0 || state.linkedFormset.length > 0) {
handleOtherForms(response.data.id)
} else {
redirect(response.data.id)
}
}
})
.catch((error) => {
commit("DISCARD_LOADER", null, { root: true })
if (error.message === "Network Error" || window.navigator.onLine === false) {
let arraysOffline = [];
let localStorageArray = localStorage.getItem("geocontrib_offline");
if (localStorageArray) {
arraysOffline = JSON.parse(localStorageArray);
}
let updateMsg = {
project: rootState.project_slug,
type: 'put',
featureId: state.form.feature_id,
geojson: geojson
};
arraysOffline.push(updateMsg);
localStorage.setItem("geocontrib_offline", JSON.stringify(arraysOffline));
router.push({
name: "offline-signalement",
params: {
slug_type_signal: rootState.feature_type.current_feature_type_slug
},
});
return axios({
url,
method: routeName === "editer-signalement" ? "PUT" : "POST",
data: geojson
}).then((response) => {
if ((response.status === 200 || response.status === 201) && response.data) {
if (state.attachmentFormset.length > 0 || state.linkedFormset.length > 0 || state.attachmentFormset.length > 0 || state.attachmentsToDelete.length > 0) {
handleOtherForms(response.data.id)
} else {
redirect(response.data.id)
} }
else { }
console.log(error) })
throw error; .catch((error) => {
commit("DISCARD_LOADER", null, { root: true })
if (error.message === "Network Error" || window.navigator.onLine === false) {
let arraysOffline = [];
let localStorageArray = localStorage.getItem("geocontrib_offline");
if (localStorageArray) {
arraysOffline = JSON.parse(localStorageArray);
} }
let updateMsg = {
project: rootState.project_slug,
type: 'put',
featureId: state.form.feature_id,
geojson: geojson
};
arraysOffline.push(updateMsg);
localStorage.setItem("geocontrib_offline", JSON.stringify(arraysOffline));
router.push({
name: "offline-signalement",
params: {
slug_type_signal: rootState.feature_type.current_feature_type_slug
},
});
}
else {
console.error(error)
throw error; throw error;
}); }
} else { throw error;
return axios });
.post(`${rootState.configuration.VUE_APP_DJANGO_API_BASE}features/`, geojson)
.then((response) => {
if (response.status === 201 && response.data) {
if (state.attachmentFormset.length > 0 || state.linkedFormset.length > 0) {
handleOtherForms(response.data.id)
} else {
redirect(response.data.id)
}
}
})
.catch((error) => {
commit("DISCARD_LOADER", null, { root: true })
if (error.message === "Network Error" || window.navigator.onLine === false) {
let arraysOffline = [];
let localStorageArray = localStorage.getItem("geocontrib_offline");
if (localStorageArray) {
arraysOffline = JSON.parse(localStorageArray);
}
let updateMsg = {
project: rootState.project_slug,
type: 'post',
geojson: geojson
};
arraysOffline.push(updateMsg);
localStorage.setItem("geocontrib_offline", JSON.stringify(arraysOffline));
router.push({
name: "offline-signalement",
params: {
slug_type_signal: rootState.feature_type.current_feature_type_slug
},
});
}
else {
console.log(error)
throw error;
}
});
}
// this.$store.dispatch("GET_ALL_PROJECTS"), //* & refresh project list
}, },
async SEND_ATTACHMENTS({ state, rootState, dispatch }, featureId) { async SEND_ATTACHMENTS({ state, rootState, dispatch }, featureId) {
const DJANGO_API_BASE = rootState.configuration.VUE_APP_DJANGO_API_BASE; const DJANGO_API_BASE = rootState.configuration.VUE_APP_DJANGO_API_BASE;
function addFile(attachment, attchmtId) { function addFile(attachment, attchmtId) {
let formdata = new FormData(); let formdata = new FormData();
formdata.append("file", attachment.fileToImport, attachment.fileToImport.name); formdata.append("file", attachment.fileToImport, attachment.fileToImport.name);
return axios return axios
.put(`${DJANGO_API_BASE}features/${featureId}/attachments/${attchmtId}/upload-file/`, formdata) .put(`${DJANGO_API_BASE}features/${featureId}/attachments/${attchmtId}/upload-file/`, formdata)
.then((response) => { .then((response) => {
console.log(response)
if (response && response.status === 200) {
console.log(response.status)
}
return response; return response;
}) })
.catch((error) => { .catch((error) => {
...@@ -349,9 +303,7 @@ const feature = { ...@@ -349,9 +303,7 @@ const feature = {
return axios return axios
.post(`${DJANGO_API_BASE}features/${featureId}/attachments/`, formdata) .post(`${DJANGO_API_BASE}features/${featureId}/attachments/`, formdata)
.then((response) => { .then((response) => {
console.log(response)
if (response && response.status === 201 && attachment.fileToImport) { if (response && response.status === 201 && attachment.fileToImport) {
console.log(response.status)
return addFile(attachment, response.data.id); return addFile(attachment, response.data.id);
} }
return response return response
...@@ -364,9 +316,7 @@ const feature = { ...@@ -364,9 +316,7 @@ const feature = {
return axios return axios
.put(`${DJANGO_API_BASE}features/${featureId}/attachments/${attachment.id}/`, formdata) .put(`${DJANGO_API_BASE}features/${featureId}/attachments/${attachment.id}/`, formdata)
.then((response) => { .then((response) => {
console.log(response)
if (response && response.status === 200 && attachment.fileToImport) { if (response && response.status === 200 && attachment.fileToImport) {
console.log(response.status)
return addFile(attachment, response.data.id); return addFile(attachment, response.data.id);
} }
}) })
...@@ -386,6 +336,7 @@ const feature = { ...@@ -386,6 +336,7 @@ const feature = {
return dispatch("DELETE_ATTACHMENTS", payload) return dispatch("DELETE_ATTACHMENTS", payload)
.then((response) => response); .then((response) => response);
} }
const promisesResult = await Promise.all([ const promisesResult = await Promise.all([
...state.attachmentFormset.map((attachment) => putOrPostAttachement(attachment)), ...state.attachmentFormset.map((attachment) => putOrPostAttachement(attachment)),
...state.attachmentsToDelete.map((attachmentsId) => deleteAttachement(attachmentsId, featureId)) ...state.attachmentsToDelete.map((attachmentsId) => deleteAttachement(attachmentsId, featureId))
......
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