From cd7f78ecce779ceb71c831336cc07b7f5f9df3c4 Mon Sep 17 00:00:00 2001 From: Florent <florent@MacBook-Air-de-neogeo.local> Date: Tue, 30 Nov 2021 16:10:55 +0100 Subject: [PATCH] fix json validity check --- src/store/modules/feature_type.js | 7 ++-- .../feature_type/Feature_type_detail.vue | 33 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/store/modules/feature_type.js b/src/store/modules/feature_type.js index cfc3c0dd..612c4140 100644 --- a/src/store/modules/feature_type.js +++ b/src/store/modules/feature_type.js @@ -160,12 +160,13 @@ const feature_type = { }, SEND_FEATURES_FROM_GEOJSON({ state, dispatch }, payload) { - const { feature_type_slug } = payload + console.log(payload); + const { feature_type_slug } = payload; if (state.fileToImport.size > 0) { let formData = new FormData(); - formData.append("json_file", state.fileToImport); - formData.append("feature_type_slug", feature_type_slug); + formData.append('json_file', state.fileToImport); + formData.append('feature_type_slug', feature_type_slug); let url = this.state.configuration.VUE_APP_DJANGO_API_BASE + 'import-tasks/' diff --git a/src/views/feature_type/Feature_type_detail.vue b/src/views/feature_type/Feature_type_detail.vue index 80e1e6eb..b8723589 100644 --- a/src/views/feature_type/Feature_type_detail.vue +++ b/src/views/feature_type/Feature_type_detail.vue @@ -267,6 +267,7 @@ export default { return "integer"; } else if ( type === "string" && + ['/', ':', '-'].some(el => prop.includes(el)) && // check for chars found in datestring date instanceof Date && !isNaN(date.valueOf()) ) { @@ -288,24 +289,22 @@ export default { }); for (const feature of json.features) { for (const { name, field_type, options } of fields) { - //* check if custom field is present - if (!(name in feature.properties)) { - return false; - } - const fieldInFeature = feature.properties[name]; - const customType = this.transformProperties(fieldInFeature); - //* if custom field value is not null, then check validity of field - if (fieldInFeature !== null) { - //* if field type is list, it's not possible to guess from value type - if (field_type === "list") { - //*then check if the value is an available option - if (!options.includes(fieldInFeature)) { + if (name in feature.properties) { + const fieldInFeature = feature.properties[name]; + const customType = this.transformProperties(fieldInFeature); + //* if custom field value is not null, then check validity of field + if (fieldInFeature !== null) { + //* if field type is list, it's not possible to guess from value type + if (field_type === "list") { + //*then check if the value is an available option + if (!options.includes(fieldInFeature)) { + return false; + } + } else if (customType !== field_type) { + //* check if custom field value match + this.importError = `Le fichier est invalide: Un champ de type ${field_type} ne peut pas avoir la valeur [ ${fieldInFeature} ]`; return false; } - } else if (customType !== field_type) { - //* check if custom field value match - this.importError = `Le fichier est invalide: Un champ de type ${field_type} ne peut pas avoir la valeur [ ${fieldInFeature} ]`; - return false; } } } @@ -331,7 +330,7 @@ export default { }, importGeoJson() { - this.$store.dispatch("feature_type/SEND_FEATURES_FROM_GEOJSON", { + this.$store.dispatch('feature_type/SEND_FEATURES_FROM_GEOJSON', { slug: this.$route.params.slug, feature_type_slug: this.$route.params.feature_type_slug, fileToImport: this.fileToImport, -- GitLab