From 4142ed470ee7d4b1925d4ffddc5f0ce9c65ca61d Mon Sep 17 00:00:00 2001 From: florent <flavelle@neogeo.fr> Date: Fri, 1 Apr 2022 15:20:29 +0200 Subject: [PATCH] fix csv import errors --- src/components/ImportTask.vue | 5 +- .../Project/Detail/ProjectFeatureTypes.vue | 5 +- src/store/index.js | 1 - src/views/FeatureType/FeatureTypeDetail.vue | 224 ++++++------------ src/views/FeatureType/FeatureTypeEdit.vue | 1 - src/views/Project/ProjectDetail.vue | 1 - 6 files changed, 80 insertions(+), 157 deletions(-) diff --git a/src/components/ImportTask.vue b/src/components/ImportTask.vue index 42626786..8db144cf 100644 --- a/src/components/ImportTask.vue +++ b/src/components/ImportTask.vue @@ -145,13 +145,16 @@ export default { }; </script> -<style scoped> +<style scoped lang="less"> .sync { cursor: pointer; } #table-imports { padding-top: 1em; + table { + width: 100%; + } } i.icon { diff --git a/src/components/Project/Detail/ProjectFeatureTypes.vue b/src/components/Project/Detail/ProjectFeatureTypes.vue index e4371374..0ec336a9 100644 --- a/src/components/Project/Detail/ProjectFeatureTypes.vue +++ b/src/components/Project/Detail/ProjectFeatureTypes.vue @@ -375,7 +375,7 @@ <i class="close icon" aria-hidden="true" - @click="csvError = null" + @click="csvError = null; csvFileToImport = { name: '', size: 0 }" /> {{ csvError }} </div> @@ -521,6 +521,9 @@ export default { }, methods: { + ...mapMutations([ + 'SET_RELOAD_INTERVAL_ID' + ]), ...mapMutations('feature-type', [ 'SET_FILE_TO_IMPORT' ]), diff --git a/src/store/index.js b/src/store/index.js index 04a89cb4..3836a3d2 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -45,7 +45,6 @@ export default new Vuex.Store({ mutations: { SET_IS_ONLINE(state, payload) { state.isOnline = payload; - console.log(state.isOnline); }, SET_USER(state, payload) { state.user = payload; diff --git a/src/views/FeatureType/FeatureTypeDetail.vue b/src/views/FeatureType/FeatureTypeDetail.vue index 924e7f14..6d65a3bc 100644 --- a/src/views/FeatureType/FeatureTypeDetail.vue +++ b/src/views/FeatureType/FeatureTypeDetail.vue @@ -71,21 +71,18 @@ </div> <div class="ui bottom attached secondary segment"> - <div - :class="['title', { active: showImport && isOnline, nohover: !isOnline }]" - @click="toggleShowImport" - > - <i - class="dropdown icon" - aria-hidden="true" - /> - Importer des signalements - </div> - <div :class="['content', { active: showImport && isOnline }]"> + <div class="ui styled accordion"> <div - :class="['title', { active: showImport }]" + :class="['title', { active: showImport && isOnline, nohover: !isOnline }]" @click="toggleShowImport" > + <i + class="dropdown icon" + aria-hidden="true" + /> + Importer des signalements + </div> + <div :class="['content', { active: showImport && isOnline }]"> <div class="field"> <label class="ui icon button ellipsis" @@ -106,7 +103,6 @@ @change="onGeojsonFileChange" > </div> - <div class="field"> <label class="ui icon button ellipsis" @@ -127,7 +123,6 @@ @change="onCsvFileChange" > </div> - <router-link v-if=" IDGO && @@ -145,84 +140,40 @@ > Importer les signalements à partir de {{ CATALOG_NAME|| 'IDGO' }} </router-link> - <div - v-if="$route.params.geojson" - class="ui button import-catalog basic active teal nohover" + + <ul + v-if="importError" + class="errorlist" > - <div class="field"> - <label - class="ui icon button ellipsis" - for="json_file" - > - <i - class="file icon" - aria-hidden="true" - /> - <span class="label">{{ fileToImport.name }}</span> - </label> - <input - id="json_file" - type="file" - accept="application/json, .json, .geojson" - style="display: none" - name="json_file" - @change="onFileChange" - > - </div> + <li> + {{ importError }} + </li> + </ul> - <router-link - v-if=" - IDGO && - permissions && - permissions.can_create_feature - " - :to="{ - name: 'catalog-import', - params: { - slug, - feature_type_slug: $route.params.feature_type_slug - }, - }" - class="ui icon button import-catalog" - > - Importer les signalements à partir de {{ CATALOG_NAME|| 'IDGO' }} - </router-link> - <div - v-if="$route.params.geojson" - class="ui button import-catalog basic active teal no-hover" - > - Ressource {{ $route.params.geojson.name }} - </div> - <ul - v-if="importError" - class="errorlist" - > - <li> - {{ importError }} - </li> - </ul> - <button - :disabled="fileToImport.size === 0 && !$route.params.geojson" - class="ui fluid teal icon button" - @click="importGeoJson" - > - <i - class="upload icon" - aria-hidden="true" - /> - Lancer l'import - </button> - <ImportTask - v-if="importFeatureTypeData && importFeatureTypeData.length" - :data="importFeatureTypeData" - :reloading="reloadingImport" + <button + :disabled=" + (geojsonFileToImport.size === 0 && !$route.params.geojson) && + (csvFileToImport.size === 0 && !$route.params.csv) + " + class="ui fluid teal icon button" + @click="geojsonFileToImport.size !== 0 ? importGeoJson() : importCSV()" + > + <i + class="upload icon" + aria-hidden="true" /> - </div> + Lancer l'import + </button> + <ImportTask + v-if="importFeatureTypeData && importFeatureTypeData.length" + :data="importFeatureTypeData" + :reloading="reloadingImport" + /> </div> </div> <div class="ui styled accordion"> <div - :class="['title', { active: !showImport }]" + :class="['title', { active: !showImport && isOnline, nohover: !isOnline }]" @click="toggleShowImport" > <i @@ -231,18 +182,27 @@ /> Exporter les signalements </div> - <div :class="['content', { active: !showImport }]"> + <div :class="['content', { active: !showImport && isOnline }]"> <p> Vous pouvez télécharger tous les signalements qui vous sont accessibles. </p> + <select + v-model="exportFormat" + class="ui fluid dropdown" + style="margin-bottom: 1em;" + > + <option value="GeoJSON"> + GeoJSON + </option> + <option value="CSV"> + CSV + </option> + </select> <button - :disabled=" - (geojsonFileToImport.size === 0 && !$route.params.geojson) && - (csvFileToImport.size === 0 && !$route.params.csv) - " + type="button" class="ui fluid teal icon button" - @click="geojsonFileToImport.size !== 0 ? importGeoJson() : importCSV()" + @click="exportFeatures" > <i class="download icon" @@ -253,59 +213,6 @@ </div> </div> </div> - <div class="ui styled accordion"> - <div - :class="['title', { active: !showImport && isOnline, nohover: !isOnline }]" - @click="toggleShowImport" - > - <i - class="dropdown icon" - aria-hidden="true" - /> - Exporter les signalements - </div> - <div :class="['content', { active: !showImport && isOnline}]"> - <p> - Vous pouvez télécharger tous les signalements qui vous sont - accessibles. - </p> - - <!-- <div class="ui selection dropdown fluid"> - <input type="hidden" name="format"> - <i class="dropdown icon"></em> - <div class="default text">Format</div> - <div class="menu"> - <div class="item" data-value="1">GeoJSON</div> - <div class="item" data-value="2">CSV</div> - </div> - </div> --> - - <select - v-model="exportFormat" - class="ui fluid dropdown" - style="margin-bottom: 1em;" - > - <option value="GeoJSON"> - GeoJSON - </option> - <option value="CSV"> - CSV - </option> - </select> - - <button - type="button" - class="ui fluid teal icon button" - @click="exportFeatures" - > - <i - class="download icon" - aria-hidden="true" - /> - Exporter - </button> - </div> - </div> </div> <div class="nine wide column"> @@ -605,9 +512,11 @@ export default { methods: { ...mapMutations('feature-type', [ - 'SET_CURRENT_FEATURE_TYPE_SLUG' + 'SET_CURRENT_FEATURE_TYPE_SLUG', + 'SET_FILE_TO_IMPORT' ]), ...mapActions('feature-type', [ + 'SEND_FEATURES_FROM_CSV', 'GET_IMPORTS' ]), ...mapActions('feature', [ @@ -636,7 +545,7 @@ export default { date instanceof Date && !isNaN(date.valueOf()) ) { - return 'date'; + return 'char'; } else if (type === 'number' && !isNaN(parseFloat(prop))) { return 'decimal'; } @@ -754,8 +663,7 @@ export default { if (jsonValidity) { this.geojsonFileToImport = files[0]; // todo : remove this value from state as it stored (first attempt didn't work) - this.$store.commit( - 'feature_type/SET_FILE_TO_IMPORT', + this.SET_FILE_TO_IMPORT( this.geojsonFileToImport ); } @@ -784,8 +692,7 @@ export default { if (csvValidity) { this.csvFileToImport = files[0]; // todo : remove this value from state as it stored (first attempt didn't work) - this.$store.commit( - 'feature_type/SET_FILE_TO_IMPORT', + this.SET_FILE_TO_IMPORT( this.csvFileToImport ); } @@ -828,7 +735,7 @@ export default { this.importError = "La ressource n'a pas pu être récupéré."; return; } - this.$store.dispatch('feature_type/SEND_FEATURES_FROM_CSV', payload) + this.SEND_FEATURES_FROM_CSV(payload) .then(() => { this.waitMessage = false; }); @@ -863,7 +770,7 @@ export default { }; </script> -<style scoped> +<style scoped lang="less"> .margin-25 { margin: 0 0.25em 0.25em 0 !important; } @@ -879,4 +786,17 @@ export default { .ui.styled.accordion .nohover.title:hover { color: rgba(0, 0, 0, .4); } + +.ui.styled.accordion { + .content { + .field { + label { + width: 100%; + } + } + .import-catalog { + width: 100%; + } + } +} </style> \ No newline at end of file diff --git a/src/views/FeatureType/FeatureTypeEdit.vue b/src/views/FeatureType/FeatureTypeEdit.vue index b3ea954e..36efe41b 100644 --- a/src/views/FeatureType/FeatureTypeEdit.vue +++ b/src/views/FeatureType/FeatureTypeEdit.vue @@ -823,7 +823,6 @@ export default { // y:false // }; // }); - for (const [key, val] of Object.entries(this.csv[0])) { //* check that the property is not a keyword from the backend or map style // todo: add map style keywords diff --git a/src/views/Project/ProjectDetail.vue b/src/views/Project/ProjectDetail.vue index 33c0a4d0..e90652ea 100644 --- a/src/views/Project/ProjectDetail.vue +++ b/src/views/Project/ProjectDetail.vue @@ -241,7 +241,6 @@ export default { methods: { ...mapMutations([ - 'SET_RELOAD_INTERVAL_ID', 'CLEAR_RELOAD_INTERVAL_ID', 'DISPLAY_MESSAGE', 'DISPLAY_LOADER', -- GitLab