diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/api.js b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/api.js index 9dab14ef1..96a8d0107 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/api.js +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/api.js @@ -36,6 +36,17 @@ const getLocationTypes = () => { }); }; + +/* +* Load Location Types by defaultFor +* @param {string} entity - can be "person" or "thirdparty" + */ +const getLocationTypesByDefaultFor = (entity) => { + return getLocationTypes().then(response => + response.results.filter(t => t.defaultFor === entity)[0] + ); +}; + /* * Post a Location */ @@ -59,5 +70,6 @@ export { getSocialActionByIssue, getLocations, getLocationTypes, + getLocationTypesByDefaultFor, 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 147184098..b64d7ccb2 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 } from "../api.js"; +import { getLocations, getLocationTypesByDefaultFor } from "../api.js"; export default { name: "Location", @@ -56,22 +56,34 @@ export default { }, }, mounted() { + this.getAccompanyingPeriodLocation(); getLocations().then( (response) => new Promise((resolve) => { - console.log("getLocations", response); - this.locations = [ - ...this.getAccompanyingPeriodLocation(), - ...response.results, - ...this.createConcernedPersonsLocation(), - ]; - if (window.default_location_id) { - let location = this.locations.filter( - (l) => l.id === window.default_location_id - ); - this.$store.dispatch("updateLocation", location); - } - 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(); + } + ) + }) ); }, @@ -81,13 +93,8 @@ export default { value.name ? value.name : "" }`; }, - getAccompanyingPeriodLocation() { - let location = this.activity.accompanyingPeriod.location; - return location; - }, createConcernedPersonsLocation() { let entities = this.suggestedEntities; - console.log(entities); return []; // TODO WIP }, }, diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location/NewLocation.vue b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location/NewLocation.vue index 2920e15b2..18190564d 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location/NewLocation.vue +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location/NewLocation.vue @@ -215,7 +215,6 @@ export default { }, getLocationTypesList() { getLocationTypes().then(response => new Promise(resolve => { - console.log('getLocationTypes', response); this.locationTypes = response.results.filter(t => t.availableForUsers === true); resolve(); }))