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

transform pending to draft if import in non moderate project

parent 7c20ca33
No related branches found
No related tags found
2 merge requests!2132.3.2-rc1,!206REDMINE_ISSUE-12339
import axios from '@/axios-client.js'; import axios from '@/axios-client.js';
// axios.defaults.headers.common['X-CSRFToken'] = (name => {
// var re = new RegExp(name + "=([^;]+)");
// var value = re.exec(document.cookie);
// return (value !== null) ? unescape(value[1]) : null;
// })('csrftoken');
const getColorsStyles = (customForms) => customForms.filter(customForm => customForm.options && customForm.options.length).map(el => { const getColorsStyles = (customForms) => customForms.filter(customForm => customForm.options && customForm.options.length).map(el => {
//* in dropdown, value is the name and name is the label to be displayed, could be changed... //* in dropdown, value is the name and name is the label to be displayed, could be changed...
return { value: el.name, name: el.label, options: el.options } return { value: el.name, name: el.label, options: el.options }
}); });
const pending2draftFeatures = (features) => {
let result = []
for (let el of features) {
if (el.properties.status === "pending") {
el.properties.status = "draft"
}
result.push(el)
}
return result;
}
const feature_type = { const feature_type = {
namespaced: true, namespaced: true,
...@@ -159,12 +163,25 @@ const feature_type = { ...@@ -159,12 +163,25 @@ const feature_type = {
}); });
}, },
SEND_FEATURES_FROM_GEOJSON({ state, dispatch }, payload) { async SEND_FEATURES_FROM_GEOJSON({ state, dispatch, rootGetters }, payload) {
const { feature_type_slug } = payload; const { feature_type_slug } = payload;
if (state.fileToImport.size > 0) { if (state.fileToImport.size > 0) {
let formData = new FormData(); let formData = new FormData();
formData.append('json_file', state.fileToImport);
if (!rootGetters.project.moderation) {
const textFile = await state.fileToImport.text();
const geojson = JSON.parse(textFile);
const unmoderatedFeatures = pending2draftFeatures(geojson.features);
const newGeojson= {
"type": "FeatureCollection", "features": unmoderatedFeatures
};
const newFile = new File([JSON.stringify(newGeojson)], state.fileToImport.name, {type: state.fileToImport.type});
formData.append('json_file', newFile);
} else {
formData.append('json_file', state.fileToImport);
}
formData.append('feature_type_slug', feature_type_slug); formData.append('feature_type_slug', feature_type_slug);
let url = let url =
this.state.configuration.VUE_APP_DJANGO_API_BASE + this.state.configuration.VUE_APP_DJANGO_API_BASE +
......
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