activity: add location of the accompanying course

This commit is contained in:
nobohan 2021-11-23 16:10:34 +01:00
parent b808e970ab
commit 1519fcd4dd
3 changed files with 38 additions and 20 deletions

View File

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

View File

@ -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,15 +56,24 @@ export default {
},
},
mounted() {
this.getAccompanyingPeriodLocation();
getLocations().then(
(response) =>
new Promise((resolve) => {
console.log("getLocations", response);
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 = [
...this.getAccompanyingPeriodLocation(),
personLocation,
...response.results,
...this.createConcernedPersonsLocation(),
];
console.log(this.locations);
if (window.default_location_id) {
let location = this.locations.filter(
(l) => l.id === window.default_location_id
@ -72,6 +81,9 @@ export default {
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
},
},

View File

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