location: fix error when there is no defaultFor defined for locationType entities

This commit is contained in:
nobohan 2021-11-25 16:53:02 +01:00
parent aad4b6e5d0
commit f002d48efd

View File

@ -63,35 +63,45 @@ export default {
new Promise((resolve) => { new Promise((resolve) => {
getLocationTypeByDefaultFor('person').then( getLocationTypeByDefaultFor('person').then(
personLocationType => { personLocationType => {
const personLocation = this.makeAccompanyingPeriodLocation(personLocationType); if (personLocationType) {
const concernedPersonsLocation = const personLocation = this.makeAccompanyingPeriodLocation(personLocationType);
this.makeConcernedPersonsLocation(personLocationType); const concernedPersonsLocation =
getLocationTypeByDefaultFor('thirdparty').then( this.makeConcernedPersonsLocation(personLocationType);
thirdpartyLocationType => { getLocationTypeByDefaultFor('thirdparty').then(
const concernedThirdPartiesLocation = thirdpartyLocationType => {
this.makeConcernedThirdPartiesLocation(thirdpartyLocationType); const concernedThirdPartiesLocation =
this.locations = [ this.makeConcernedThirdPartiesLocation(thirdpartyLocationType);
{ this.locations = [
locationGroup: 'Localisation du parcours', {
locations: [personLocation] locationGroup: 'Localisation du parcours',
}, locations: [personLocation]
{ },
locationGroup: 'Parties concernées', {
locations: [...concernedPersonsLocation, ...concernedThirdPartiesLocation]}, locationGroup: 'Parties concernées',
{ locations: [...concernedPersonsLocation, ...concernedThirdPartiesLocation]
locationGroup: 'Autres localisations', },
locations: response.results {
} 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);
} }
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})` return `${value.address.text} (${value.locationType.title.fr})`
}, },
customLabel(value) { customLabel(value) {
return value.name ? return value.locationType
value.name === '__AccompanyingCourseLocation__' ? ? value.name
this.labelAccompanyingCourseLocation(value) : ? value.name === '__AccompanyingCourseLocation__'
`${value.name} (${value.locationType.title.fr})` : ? this.labelAccompanyingCourseLocation(value)
value.locationType.title.fr; : `${value.name} (${value.locationType.title.fr})`
: value.locationType.title.fr
: '';
}, },
makeConcernedPersonsLocation(locationType) { makeConcernedPersonsLocation(locationType) {
let locations = []; let locations = [];