diff --git a/src/store/modules/feature-type.store.js b/src/store/modules/feature-type.store.js index 7838123006da49c9fc0922f04dcb6df8701ad0a6..b822ac4c8fc2f61e54b82445d224d750b6f0309a 100644 --- a/src/store/modules/feature-type.store.js +++ b/src/store/modules/feature-type.store.js @@ -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 }); diff --git a/src/utils/index.js b/src/utils/index.js index 12a54ae61668fc197b898c81a34c822cb12c3c9a..66fa35387fe58fdd0dca73ff49f0b23a0b964c35 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,5 +1,6 @@ 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())) { diff --git a/src/views/FeatureType/FeatureTypeDetail.vue b/src/views/FeatureType/FeatureTypeDetail.vue index 8d780b126a938e1078c348210bb7b5fa0b17046c..d6acca8f9b47e9e11f9c0db4596b6dab7dfcdc09 100644 --- a/src/views/FeatureType/FeatureTypeDetail.vue +++ b/src/views/FeatureType/FeatureTypeDetail.vue @@ -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;