Skip to content
Snippets Groups Projects
Commit ab360113 authored by Camille Blanchon's avatar Camille Blanchon
Browse files

Merge branch 'redmine-issues/18740' into 'develop'

REDMINE_ISSUE-18740 |  Export signalements - Liste de valeurs pré-enregistrées n'ont pas la bonne forme

See merge request !706
parents 88bb82db afb54d76
No related branches found
No related tags found
1 merge request!706REDMINE_ISSUE-18740 | Export signalements - Liste de valeurs pré-enregistrées n'ont pas la bonne forme
......@@ -505,7 +505,7 @@ export default {
selectPrerecordedValue(e) {
this.selectedPrerecordedValue = e;
this.prerecordedListSearchQuery = null;
this.updateStore_extra_form({ target: { value: this.selectedPrerecordedValue } });
this.updateStore_extra_form({ target: { value: this.selectedPrerecordedValue.label } });
},
clearPrerecordedValue() {
......
......@@ -132,7 +132,7 @@ export default {
}, 1500);
} else {
// if no pending import, get last features
this.$emit('getLastFeatures');
this.$emit('reloadFeatureType');
}
});
},
......
......@@ -192,7 +192,7 @@
v-if="importsForFeatureType.length > 0"
ref="importTask"
:imports="importsForFeatureType"
@getLastFeatures="getLastFeatures"
@reloadFeatureType="reloadFeatureType"
/>
</div>
</div>
......@@ -384,6 +384,7 @@
<script>
import { csv } from 'csvtojson';
import { escape } from 'lodash';
import { mapActions, mapMutations, mapGetters, mapState } from 'vuex';
import { formatStringDate, transformProperties } from '@/utils';
......@@ -515,7 +516,7 @@ export default {
this.showImport = true;
}
// empty prerecorded lists in case the list has been previously loaded with a limit in other component like FeatureExtraForm
this.SET_PRERECORDED_LISTS({});
this.SET_PRERECORDED_LISTS([]);
},
......@@ -526,8 +527,9 @@ export default {
'SET_PRERECORDED_LISTS'
]),
...mapActions('feature-type', [
'SEND_FEATURES_FROM_CSV',
'GET_PROJECT_FEATURE_TYPES',
'GET_SELECTED_PRERECORDED_LIST_VALUES',
'SEND_FEATURES_FROM_CSV',
]),
...mapActions('feature', [
'GET_PROJECT_FEATURES'
......@@ -544,15 +546,21 @@ export default {
this.featuresLoading = false;
});
},
reloadFeatureType() {
this.GET_PROJECT_FEATURE_TYPES(this.slug);
this.getLastFeatures();
},
toggleShowImport() {
this.showImport = !this.showImport;
},
async checkPreRecordedValue(fieldLabel, listName) {
// query existing prerecordedvalues with label
await this.GET_SELECTED_PRERECORDED_LIST_VALUES({ name: listName, pattern: fieldLabel });
// check if the value exist in available pre_recorded_values
async checkPreRecordedValue(fieldValue, listName) {
const fieldLabel = fieldValue.label || fieldValue;
// query existing prerecorded list values (with label to limit results in response, there could be many) and escape special characters, since single quote causes error in backend
await this.GET_SELECTED_PRERECORDED_LIST_VALUES({ name: listName, pattern: escape(fieldLabel) });
// check if the value exist in available prerecorded list values
return this.selectedPrerecordedListValues[listName].some((el) => el.label === fieldLabel);
},
......@@ -570,6 +578,9 @@ export default {
const properties = feature.properties || feature;
if (name in properties) {
let fieldInFeature = properties[name];
if (field_type === 'boolean') { // in csv booleans are capitalized string that need to be translated in javascript syntax
fieldInFeature = fieldInFeature === 'True' ? true : (fieldInFeature === 'False' ? false : fieldInFeature);
}
const customType = transformProperties(fieldInFeature);
//* if custom field value is not defined or not null or in case of prerecorded list with defined value => then check validity of field type
if (fieldInFeature !== null && fieldInFeature !== '' && fieldInFeature !== undefined) {
......@@ -582,10 +593,10 @@ export default {
return false;
}
} else if (field_type === 'pre_recorded_list') {
if (typeof fieldInFeature === 'string') { // data from CSV come as string
if (typeof fieldInFeature === 'string' && fieldInFeature.includes('label')) { // data from CSV might come as stringified object
fieldInFeature = JSON.parse(fieldInFeature.replaceAll('\'', '"'));
}
const isPreRecordedValue = await this.checkPreRecordedValue(fieldInFeature.label, options[0]);
const isPreRecordedValue = await this.checkPreRecordedValue(fieldInFeature, options[0]);
if (!isPreRecordedValue) {
this.importError = `Le fichier est invalide: la valeur [ ${fieldInFeature.label} ] ne fait pas partie des valeurs pré-enregistrées
pour le champ personnalisé "${name}".`;
......
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