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

add json import (adapting geojson) for non geographical features

parent 590d0207
No related branches found
No related tags found
1 merge request!735REDMINE_ISSUE-19119 | Permettre la gestion de signalements non-géographiques (REDMINE_ISSUE-19667 | La recherche de doublon à l'import de signalement s'applique sur les signalements supprimés)
......@@ -9,14 +9,14 @@ const getColorsStyles = (customForms) => customForms
});
const pending2draftFeatures = (features) => {
const result = [];
for (const el of features) {
if (el.properties.status === 'pending') {
if (el.properties && el.properties.status === 'pending') {
el.properties.status = 'draft';
} else if (el.status === 'pending') {
el.status = 'draft';
}
result.push(el);
}
return result;
return features;
};
const feature_type = {
......@@ -199,16 +199,15 @@ const feature_type = {
if (!name && state.fileToImport) {
name = state.fileToImport.name;
}
if (rootState.projects.project.moderation) {
if (state.fileToImport && state.fileToImport.size > 0) { //* if data in a binary file, read it as text
const textFile = await state.fileToImport.text();
geojson = JSON.parse(textFile);
}
const unmoderatedFeatures = pending2draftFeatures(geojson.features);
geojson= {
const unmoderatedFeatures = pending2draftFeatures(geojson.features || geojson);
geojson = geojson.features ? {
type: 'FeatureCollection', features: unmoderatedFeatures
};
} : unmoderatedFeatures;
}
const fileToImport = new File([JSON.stringify(geojson)], name, { type });
......
import featureAPI from '@/services/feature-api';
import { isNil } from 'lodash';
export function formatStringDate(stringDate) {
const date = new Date(stringDate);
if (date instanceof Date && !isNaN(date.valueOf())) {
......
......@@ -123,8 +123,9 @@
@change="onGeojsonFileChange"
>
</div>
<div
v-if="structure.geom_type === 'point'"
v-if="structure.geom_type === 'point' || structure.geom_type === 'none'"
class="field"
>
<label
......@@ -568,7 +569,7 @@ export default {
return this.selectedPrerecordedListValues[listName].some((el) => el.label === fieldLabel);
},
async isValidTypes(data) {
async isValidTypes(features) {
this.importError = '';
const fields = this.structure.customfield_set.map((el) => {
return {
......@@ -578,7 +579,7 @@ export default {
};
});
for (const feature of data.features) {
for (const feature of features) {
for (const { name, field_type, options } of fields) {
const properties = feature.properties || feature;
......@@ -708,7 +709,7 @@ export default {
const jsonFromCsv = await csv({ delimiter }).fromString(csvString);
// Validate the types of values in the JSON object
const validity = await this.isValidTypes({ features: jsonFromCsv });
const validity = await this.isValidTypes(jsonFromCsv);
return validity;
},
......@@ -751,7 +752,7 @@ export default {
// If the file is smaller than 10 Mo, check its validity
try {
const json = JSON.parse(fileContent);
jsonValidity = await this.isValidTypes(json);
jsonValidity = await this.isValidTypes(json.features || json);
} catch (error) {
this.DISPLAY_MESSAGE({ comment: error, level: 'negative' });
jsonValidity = false;
......
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