From f002d48efdd0074274c56a6a6704df734737adaa Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 25 Nov 2021 16:53:02 +0100 Subject: [PATCH] location: fix error when there is no defaultFor defined for locationType entities --- .../vuejs/Activity/components/Location.vue | 78 +++++++++++-------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue index 25c75ed8b..012c550aa 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue @@ -63,35 +63,45 @@ export default { new Promise((resolve) => { getLocationTypeByDefaultFor('person').then( personLocationType => { - const personLocation = this.makeAccompanyingPeriodLocation(personLocationType); - const concernedPersonsLocation = - this.makeConcernedPersonsLocation(personLocationType); - getLocationTypeByDefaultFor('thirdparty').then( - thirdpartyLocationType => { - const concernedThirdPartiesLocation = - this.makeConcernedThirdPartiesLocation(thirdpartyLocationType); - this.locations = [ - { - locationGroup: 'Localisation du parcours', - locations: [personLocation] - }, - { - locationGroup: 'Parties concernées', - locations: [...concernedPersonsLocation, ...concernedThirdPartiesLocation]}, - { - locationGroup: 'Autres localisations', - locations: response.results - } - ]; - if (window.default_location_id) { - let location = this.locations.filter( - (l) => l.id === window.default_location_id - ); - this.$store.dispatch("updateLocation", location); + if (personLocationType) { + const personLocation = this.makeAccompanyingPeriodLocation(personLocationType); + const concernedPersonsLocation = + this.makeConcernedPersonsLocation(personLocationType); + getLocationTypeByDefaultFor('thirdparty').then( + thirdpartyLocationType => { + const concernedThirdPartiesLocation = + this.makeConcernedThirdPartiesLocation(thirdpartyLocationType); + this.locations = [ + { + locationGroup: 'Localisation du parcours', + locations: [personLocation] + }, + { + locationGroup: 'Parties concernées', + locations: [...concernedPersonsLocation, ...concernedThirdPartiesLocation] + }, + { + locationGroup: 'Autres localisations', + locations: response.results + } + ]; } - resolve(); - } - ) + ) + } else { + this.locations = [ + { + locationGroup: 'Localisations', + locations: response.results + } + ]; + } + if (window.default_location_id) { + let location = this.locations.filter( + (l) => l.id === window.default_location_id + ); + this.$store.dispatch("updateLocation", location); + } + resolve(); } ) }) @@ -102,11 +112,13 @@ export default { return `${value.address.text} (${value.locationType.title.fr})` }, customLabel(value) { - return value.name ? - value.name === '__AccompanyingCourseLocation__' ? - this.labelAccompanyingCourseLocation(value) : - `${value.name} (${value.locationType.title.fr})` : - value.locationType.title.fr; + return value.locationType + ? value.name + ? value.name === '__AccompanyingCourseLocation__' + ? this.labelAccompanyingCourseLocation(value) + : `${value.name} (${value.locationType.title.fr})` + : value.locationType.title.fr + : ''; }, makeConcernedPersonsLocation(locationType) { let locations = [];