mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
for each selected, loop for post participation, then get response and commit state
This commit is contained in:
@@ -4,7 +4,13 @@ const
|
||||
, accompanying_period_id = window.accompanyingCourseId //tmp
|
||||
;
|
||||
|
||||
// 1. chill_person_accompanying_course_api_show (GET)
|
||||
/*
|
||||
* Endpoint chill_person_accompanying_course_api_show
|
||||
* method GET, get AccompanyingCourse Object
|
||||
*
|
||||
* @accompanying_period_id___ integer
|
||||
* @TODO var is not used but necessary in method signature
|
||||
*/
|
||||
let getAccompanyingCourse = (accompanying_period_id___) => { //tmp
|
||||
const url = `/${locale}/person/api/1.0/accompanying-course/${accompanying_period_id}/show.${format}`;
|
||||
return fetch(url)
|
||||
@@ -14,11 +20,17 @@ let getAccompanyingCourse = (accompanying_period_id___) => { //tmp
|
||||
});
|
||||
};
|
||||
|
||||
// 2. chill_person_accompanying_course_api_add_participation (POST)
|
||||
let postParticipation = (accompanying_period_id, person_id) => {
|
||||
/*
|
||||
* Endpoint chill_person_accompanying_course_api_add_participation,
|
||||
* method POST, add a participation to the accompanyingCourse
|
||||
*
|
||||
* @accompanying_period_id integer - id of accompanyingCourse
|
||||
* @person_id integer - id of person
|
||||
*/
|
||||
let postParticipation = (accompanying_period_id, person_id, method) => {
|
||||
const url = `/${locale}/person/api/1.0/accompanying-course/${accompanying_period_id}/participation.${format}`
|
||||
return fetch(url, {
|
||||
method: 'POST',
|
||||
method: method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json;charset=utf-8'
|
||||
},
|
||||
|
@@ -30,22 +30,31 @@ let getDataPromise = getAccompanyingCourse(id)
|
||||
participation => participation !== item
|
||||
);
|
||||
},
|
||||
addParticipation(state, item) {
|
||||
//console.log('add new item');
|
||||
state.accompanying_course.participations.push(item);
|
||||
addParticipation(state, participation) {
|
||||
console.log('### mutation: add participation', participation);
|
||||
state.accompanying_course.participations.push(participation);
|
||||
console.log('count participations from state', state.accompanying_course.participations.length);
|
||||
|
||||
let item = { id: participation.person.id, text: participation.person.firstName + ' ' + participation.person.lastName };
|
||||
console.log('item', item);
|
||||
console.log('avant', state.add_persons.selected.length);
|
||||
state.add_persons.selected = state.add_persons.selected.filter(value => value !== item);
|
||||
console.log('après', state.add_persons.selected.length);
|
||||
},
|
||||
resetQuery() {
|
||||
console.log('### mutation: reset query');
|
||||
state.add_persons.query = "";
|
||||
},
|
||||
setQuery(state, query) {
|
||||
//console.log('q=', query);
|
||||
state.add_persons = Object.assign({}, state.add_persons, query);
|
||||
},
|
||||
loadSuggestions(state, suggested) {
|
||||
console.log('suggested', suggested);
|
||||
// doublons si on ré-affiche des suggestions avec certains selected
|
||||
//suggested.results.filter(selected => selected !== suggested.results);
|
||||
loadSuggestions(state, suggested) {
|
||||
// doublons qd on ré-affiche des suggestions avec certains selected
|
||||
state.add_persons.suggested = suggested;
|
||||
},
|
||||
updateSelected(state, value) {
|
||||
console.log('update value', value);
|
||||
console.log('update selected values', value);
|
||||
state.add_persons.selected = value;
|
||||
}
|
||||
},
|
||||
@@ -54,18 +63,23 @@ let getDataPromise = getAccompanyingCourse(id)
|
||||
commit('removeParticipation', payload);
|
||||
},
|
||||
addParticipation({ commit }, payload) {
|
||||
commit('addParticipation', payload);
|
||||
postParticipation(id, payload.id).catch((error) => {
|
||||
commit('removeParticipation', payload);
|
||||
state.errorMsg.push(error.message); // result action ??
|
||||
});
|
||||
console.log('## action: fetch post participation: payload', payload.id);
|
||||
postParticipation(id, payload.id, 'POST')
|
||||
.then(participation => new Promise((resolve, reject) => {
|
||||
commit('addParticipation', participation);
|
||||
resolve();
|
||||
}))
|
||||
.catch((error) => { // si y a une erreur
|
||||
//commit('removeParticipation', payload);
|
||||
state.errorMsg.push(error.message);
|
||||
});
|
||||
},
|
||||
setQuery({ commit }, payload) {
|
||||
commit('setQuery', payload);
|
||||
if (payload.query.length >= 3) {
|
||||
searchPersons(payload.query)
|
||||
.then(suggested => new Promise((resolve, reject) => {
|
||||
commit('loadSuggestions', suggested.results); // <====
|
||||
commit('loadSuggestions', suggested.results);
|
||||
resolve();
|
||||
}));
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user