activity: add location from concerned person and 3rd parties in the location selector

This commit is contained in:
nobohan 2021-11-23 17:24:54 +01:00
parent 1519fcd4dd
commit c1a2112d48
2 changed files with 70 additions and 30 deletions

View File

@ -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
};

View File

@ -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
}
}
},
};
</script>