From ae120595d531734bdcad04fe8a8744100bb99753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr> Date: Fri, 22 Dec 2023 12:17:45 +0100 Subject: [PATCH] adapt csv import/export for non geographical features --- src/views/FeatureType/FeatureTypeDetail.vue | 29 ++++++++++++--------- src/views/FeatureType/FeatureTypeEdit.vue | 1 + 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/views/FeatureType/FeatureTypeDetail.vue b/src/views/FeatureType/FeatureTypeDetail.vue index d6acca8f..22c6b22c 100644 --- a/src/views/FeatureType/FeatureTypeDetail.vue +++ b/src/views/FeatureType/FeatureTypeDetail.vue @@ -222,7 +222,7 @@ GeoJSON </option> <option - v-if="structure.geom_type === 'point'" + v-if="structure.geom_type === 'point' || structure.geom_type === 'none'" value="CSV" > CSV @@ -679,12 +679,22 @@ export default { // Parse the CSV string into rows const rows = parseCSV(csvString, delimiter); - // Extract headers and check for required fields 'lat' and 'lon' + // Extract headers const headers = rows.shift(); - if (!headers.includes('lat') || !headers.includes('lon')) { - this.importError = 'Les champs obligatoires "lat" et "lon" sont absents.'; - return false; - } + if (this.structure.geom_type !== 'none') { + // Check for required fields 'lat' and 'lon' in headers + if (!headers.includes('lat') || !headers.includes('lon')) { + this.importError = 'Les champs obligatoires "lat" et "lon" sont absents des headers.'; + return false; + } + // Verify the presence and validity of coordinate values + const hasCoordValues = checkLonLatValues(headers, rows); + if (!hasCoordValues) { + this.importError = 'Les valeurs de "lon" et "lat" ne sont pas valides ou absentes.'; + return false; + } + + } // Ensure there are data rows after the headers if (rows.length === 0) { @@ -698,13 +708,6 @@ export default { return false; } - // Verify the presence and validity of coordinate values - const hasCoordValues = checkLonLatValues(headers, rows); - if (!hasCoordValues) { - this.importError = 'Les valeurs de "lon" et "lat" ne sont pas valides.'; - return false; - } - // Convert the CSV string to a JSON object for further processing const jsonFromCsv = await csv({ delimiter }).fromString(csvString); diff --git a/src/views/FeatureType/FeatureTypeEdit.vue b/src/views/FeatureType/FeatureTypeEdit.vue index 9871f0e1..aa003072 100644 --- a/src/views/FeatureType/FeatureTypeEdit.vue +++ b/src/views/FeatureType/FeatureTypeEdit.vue @@ -551,6 +551,7 @@ export default { this.loading = false; }); }, + postCSVFeatures(feature_type_slug) { this.$store .dispatch('feature-type/SEND_FEATURES_FROM_CSV', { -- GitLab