From c1a2112d4828e7b93d215e721201d654ce900acd Mon Sep 17 00:00:00 2001 From: nobohan Date: Tue, 23 Nov 2021 17:24:54 +0100 Subject: [PATCH] activity: add location from concerned person and 3rd parties in the location selector --- .../Resources/public/vuejs/Activity/api.js | 6 +- .../vuejs/Activity/components/Location.vue | 94 +++++++++++++------ 2 files changed, 70 insertions(+), 30 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/api.js b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/api.js index 96a8d0107..70ba4c04e 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/api.js +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/api.js @@ -38,10 +38,10 @@ const getLocationTypes = () => { /* -* Load Location Types by defaultFor +* Load Location Type by defaultFor * @param {string} entity - can be "person" or "thirdparty" */ -const getLocationTypesByDefaultFor = (entity) => { +const getLocationTypeByDefaultFor = (entity) => { return getLocationTypes().then(response => response.results.filter(t => t.defaultFor === entity)[0] ); @@ -70,6 +70,6 @@ export { getSocialActionByIssue, getLocations, getLocationTypes, - getLocationTypesByDefaultFor, + getLocationTypeByDefaultFor, postLocation }; 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 b64d7ccb2..6cad3dd8d 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue @@ -30,7 +30,7 @@ import { mapState, mapGetters } from "vuex"; import VueMultiselect from "vue-multiselect"; import NewLocation from "./Location/NewLocation.vue"; -import { getLocations, getLocationTypesByDefaultFor } from "../api.js"; +import { getLocations, getLocationTypeByDefaultFor } from "../api.js"; export default { name: "Location", @@ -56,34 +56,36 @@ export default { }, }, mounted() { - this.getAccompanyingPeriodLocation(); getLocations().then( (response) => new Promise((resolve) => { - getLocationTypesByDefaultFor('person').then( - t => { - const accPeriodLocation = this.activity.accompanyingPeriod.location; - const personLocation = { - type: 'location', - name: 'XXXXXX Domicile de l\'usager du parcours', - address: { id: accPeriodLocation.address_id }, //TODO is the id sufficient? - locationType: t - } - this.locations = [ - personLocation, - ...response.results, - ]; - console.log(this.locations); - if (window.default_location_id) { - let location = this.locations.filter( - (l) => l.id === window.default_location_id - ); - this.$store.dispatch("updateLocation", location); - } - resolve(); + getLocationTypeByDefaultFor('person').then( + personLocationType => { + const personLocation = this.makePersonLocation(personLocationType); + const concernedPersonsLocation = + this.makeConcernedPersonsLocation(personLocationType); + getLocationTypeByDefaultFor('thirdparty').then( + thirdpartyLocationType => { + const concernedThirdPartiesLocation = + this.makeConcernedThirdPartiesLocation(thirdpartyLocationType); + this.locations = [ + personLocation, + ...concernedPersonsLocation, + ...concernedThirdPartiesLocation, + ...response.results, + ]; + console.log(this.locations); + if (window.default_location_id) { + let location = this.locations.filter( + (l) => l.id === window.default_location_id + ); + this.$store.dispatch("updateLocation", location); + } + resolve(); + } + ) } ) - }) ); }, @@ -93,10 +95,48 @@ export default { value.name ? value.name : "" }`; }, - createConcernedPersonsLocation() { - let entities = this.suggestedEntities; - return []; // TODO WIP + makeConcernedPersonsLocation(locationType) { + let locations = []; + this.suggestedEntities.forEach( + (e) => { + if (e.type === 'person' && e.current_household_address !== null){ + locations.push({ + type: 'location', + name: e.text, + address: { id: e.current_household_address.id }, + locationType: locationType + }); + } + } + ) + return locations; }, + makeConcernedThirdPartiesLocation(locationType) { + let locations = []; + this.suggestedEntities.forEach( + (e) => { + if (e.type === 'thirdparty' && e.address !== null){ + locations.push({ + type: 'location', + name: e.text, + address: { id: e.address.id }, + locationType: locationType + }); + } + } + ) + return locations; + }, + makePersonLocation(locationType) { + console.log(this.activity) + const accPeriodLocation = this.activity.accompanyingPeriod.location; + return { + type: 'location', + name: 'Adresse du parcours', //TODO trans + address: { id: accPeriodLocation.address_id }, //TODO is the id sufficient? + locationType: locationType + } + } }, };