update list of referrers when loading and updating some parts of the course

This commit is contained in:
Julien Fastré 2021-10-20 15:03:42 +02:00
parent c8762d2bc2
commit 0a058bad82
4 changed files with 55 additions and 25 deletions

View File

@ -211,8 +211,13 @@ $workflow = $this->registry->get($accompanyingPeriod);
$total = $this->referralAvailable->countReferralAvailable($period); $total = $this->referralAvailable->countReferralAvailable($period);
$paginator = $this->getPaginatorFactory()->create($total); $paginator = $this->getPaginatorFactory()->create($total);
$users = $this->referralAvailable->findReferralAvailable($period, $paginator->getItemsPerPage(),
$paginator->getCurrentPageFirstItemNumber()); if (0 < $total) {
$users = $this->referralAvailable->findReferralAvailable($period, $paginator->getItemsPerPage(),
$paginator->getCurrentPageFirstItemNumber());
} else {
$users = [];
}
return $this->json(new Collection($users, $paginator), Response::HTTP_OK, return $this->json(new Collection($users, $paginator), Response::HTTP_OK,
[], [ AbstractNormalizer::GROUPS => [ 'read' ]]); [], [ AbstractNormalizer::GROUPS => [ 'read' ]]);

View File

@ -1,3 +1,5 @@
import { fetchResults } from 'ChillMainAssets/lib/api/download.js';
/* /*
* Endpoint v.2 chill_api_single_accompanying_course__entity * Endpoint v.2 chill_api_single_accompanying_course__entity
* method GET/HEAD, get AccompanyingCourse Instance * method GET/HEAD, get AccompanyingCourse Instance
@ -216,8 +218,6 @@ const addScope = (id, scope) => {
const removeScope = (id, scope) => { const removeScope = (id, scope) => {
const url = `/api/1.0/person/accompanying-course/${id}/scope.json`; const url = `/api/1.0/person/accompanying-course/${id}/scope.json`;
console.log(url);
console.log(scope);
return fetch(url, { return fetch(url, {
method: 'DELETE', method: 'DELETE',
@ -235,6 +235,12 @@ const removeScope = (id, scope) => {
}); });
}; };
const getAvailableReferrals = (course) => {
const url = `/api/1.0/person/accompanying-course/${course.id}/referral-availables.json`;
return fetchResults(url);
}
export { export {
getAccompanyingCourse, getAccompanyingCourse,
patchAccompanyingCourse, patchAccompanyingCourse,
@ -249,4 +255,5 @@ export {
postSocialIssue, postSocialIssue,
addScope, addScope,
removeScope, removeScope,
getAvailableReferrals
}; };

View File

@ -15,7 +15,7 @@
v-bind:searchable="true" v-bind:searchable="true"
v-bind:placeholder="$t('referrer.placeholder')" v-bind:placeholder="$t('referrer.placeholder')"
v-model="value" v-model="value"
v-bind:options="options" v-bind:options="referrersAvailable"
@select="updateReferrer"> @select="updateReferrer">
</VueMultiselect> </VueMultiselect>
</div> </div>
@ -45,26 +45,13 @@ import { mapState } from 'vuex';
export default { export default {
name: "Referrer", name: "Referrer",
components: { VueMultiselect }, components: { VueMultiselect },
data() {
return {
options: []
}
},
computed: { computed: {
...mapState({ ...mapState({
value: state => state.accompanyingCourse.user, value: state => state.accompanyingCourse.user,
referrersAvailable: state => state.referrersAvailable,
}), }),
}, },
mounted() {
this.getOptions();
},
methods: { methods: {
getOptions() {
getUsers().then(response => new Promise((resolve, reject) => {
this.options = response.results;
resolve();
}));
},
updateReferrer(value) { updateReferrer(value) {
//console.log('value', value); //console.log('value', value);
this.$store.dispatch('updateReferrer', value); this.$store.dispatch('updateReferrer', value);

View File

@ -10,6 +10,7 @@ import { getAccompanyingCourse,
postSocialIssue, postSocialIssue,
addScope, addScope,
removeScope, removeScope,
getAvailableReferrals,
} from '../api'; } from '../api';
import { patchPerson } from "ChillPersonAssets/vuejs/_api/OnTheFly"; import { patchPerson } from "ChillPersonAssets/vuejs/_api/OnTheFly";
import { patchThirdparty } from "ChillThirdPartyAssets/vuejs/_api/OnTheFly"; import { patchThirdparty } from "ChillThirdPartyAssets/vuejs/_api/OnTheFly";
@ -38,6 +39,8 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
scopesAtStart: accompanyingCourse.scopes.map(scope => scope), scopesAtStart: accompanyingCourse.scopes.map(scope => scope),
// the scope states at server side // the scope states at server side
scopesAtBackend: accompanyingCourse.scopes.map(scope => scope), scopesAtBackend: accompanyingCourse.scopes.map(scope => scope),
// the users which are available for referrer
referrersAvailable: [],
}, },
getters: { getters: {
isParticipationValid(state) { isParticipationValid(state) {
@ -170,6 +173,9 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
//console.log('value', value); //console.log('value', value);
state.accompanyingCourse.user = value; state.accompanyingCourse.user = value;
}, },
setReferrersAvailables(state, users) {
state.referrersAvailable = users;
},
confirmAccompanyingCourse(state, response) { confirmAccompanyingCourse(state, response) {
//console.log('### mutation: confirmAccompanyingCourse: response', response); //console.log('### mutation: confirmAccompanyingCourse: response', response);
state.accompanyingCourse.step = response.step; state.accompanyingCourse.step = response.step;
@ -272,6 +278,7 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
})).catch((error) => { commit('catchError', error) }); })).catch((error) => { commit('catchError', error) });
}, },
patchOnTheFly({ commit }, payload) { patchOnTheFly({ commit }, payload) {
// TODO should be into the dedicated component, no ? JF
console.log('## action: patch OnTheFly', payload); console.log('## action: patch OnTheFly', payload);
let body = { type: payload.type }; let body = { type: payload.type };
if (payload.type === 'person') { if (payload.type === 'person') {
@ -313,10 +320,12 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
}, },
toggleEmergency({ commit }, payload) { toggleEmergency({ commit }, payload) {
patchAccompanyingCourse(id, { type: "accompanying_period", emergency: payload }) patchAccompanyingCourse(id, { type: "accompanying_period", emergency: payload })
.then(course => new Promise((resolve, reject) => { .then(course => new Promise((resolve, reject) => {
commit('toggleEmergency', course.emergency); commit('toggleEmergency', course.emergency);
resolve(); return dispatch('setRefererresAvailable');
})).catch((error) => { commit('catchError', error) }); }))
.then(() => Promise.resolve())
.catch((error) => { commit('catchError', error) });
}, },
toggleConfidential({ commit }, payload) { toggleConfidential({ commit }, payload) {
patchAccompanyingCourse(id, { type: "accompanying_period", confidential: payload }) patchAccompanyingCourse(id, { type: "accompanying_period", confidential: payload })
@ -387,11 +396,15 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
// check/uncheck in the UI. I do not know of to avoid it. // check/uncheck in the UI. I do not know of to avoid it.
commit('setScopes', scopes); commit('setScopes', scopes);
return Promise.resolve(); return Promise.resolve();
}).then(() => {
return dispatch('fetchReferrersAvailable');
}); });
} else { } else {
return dispatch('setScopes', state.scopesAtStart).then(() => { return dispatch('setScopes', state.scopesAtStart).then(() => {
commit('setScopes', scopes); commit('setScopes', scopes);
return Promise.resolve(); return Promise.resolve();
}).then(() => {
return dispatch('fetchReferrersAvailable');
}); });
} }
}, },
@ -434,7 +447,7 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
resolve(); resolve();
})).catch((error) => { commit('catchError', error) }); })).catch((error) => { commit('catchError', error) });
}, },
updateSocialIssues({ state, commit }, { payload, body, method }) { updateSocialIssues({ state, commit, dispatch }, { payload, body, method }) {
//console.log('## action: payload', { payload, body, method }); //console.log('## action: payload', { payload, body, method });
postSocialIssue(id, body, method) postSocialIssue(id, body, method)
.then(response => new Promise((resolve, reject) => { .then(response => new Promise((resolve, reject) => {
@ -445,6 +458,7 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
return getAccompanyingCourse(state.accompanyingCourse.id); return getAccompanyingCourse(state.accompanyingCourse.id);
}).then(accompanying_course => { }).then(accompanying_course => {
commit('refreshSocialIssues', accompanying_course.socialIssues); commit('refreshSocialIssues', accompanying_course.socialIssues);
dispatch('fetchReferrersAvailable');
}) })
.catch((error) => { commit('catchError', error) }); .catch((error) => { commit('catchError', error) });
}, },
@ -462,7 +476,21 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
resolve(); resolve();
})).catch((error) => { commit('catchError', error) }); })).catch((error) => { commit('catchError', error) });
}, },
updateLocation({ commit }, payload) { async fetchReferrersAvailable({ state, commit}) {
let users = await getAvailableReferrals(state.accompanyingCourse);
commit('setReferrersAvailables', users);
let userIds = users.map(u => u.id);
if (
null !== state.accompanyingCourse.user
&& !state.accompanyingCourse.confidential
&& !state.accompanyingCourse.step === 'DRAFT'
) {
if (!userIds.include(state.accompanyingCourse.user.id)) {
commit('updateReferrer', null);
}
}
},
updateLocation({ commit, dispatch }, payload) {
//console.log('## action: updateLocation', payload.locationStatusTo); //console.log('## action: updateLocation', payload.locationStatusTo);
let body = { 'type': payload.target, 'id': payload.targetId }; let body = { 'type': payload.target, 'id': payload.targetId };
let location = {}; let location = {};
@ -484,6 +512,7 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
personLocation: accompanyingCourse.personLocation personLocation: accompanyingCourse.personLocation
}); });
resolve(); resolve();
dispatch('fetchReferrersAvailable');
})).catch((error) => { commit('catchError', error) }); })).catch((error) => { commit('catchError', error) });
}, },
confirmAccompanyingCourse({ commit }) { confirmAccompanyingCourse({ commit }) {
@ -498,6 +527,8 @@ let initPromise = Promise.all([scopesPromise, accompanyingCoursePromise])
} }
} }
}); });
store.dispatch('fetchReferrersAvailable');
resolve(store); resolve(store);
})); }));