From e78d53064b651dba49226df01bc9ef21745d2592 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 5 May 2021 21:48:00 +0200 Subject: [PATCH] closeParticipation fetch DELETE request --- .../Entity/AccompanyingPeriod.php | 2 +- .../components/PersonItem.vue | 13 +++------- .../components/PersonsAssociated.vue | 7 ++++- .../vuejs/AccompanyingCourse/store/index.js | 26 ++++++++++++++----- .../public/vuejs/_components/AddPersons.vue | 2 +- 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index fcf0c6cda..1f56ad7b7 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -351,7 +351,7 @@ class AccompanyingPeriod { foreach ($this->participations as $participation) { /** @var AccompanyingPeriodParticipation $participation */ - if ($person === $participation->getPerson() && $participation->getClosingDate() === NULL) { + if ($person === $participation->getPerson() && $participation->getEndDate() === NULL) { return $participation; }} diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonItem.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonItem.vue index 2df932e0f..0d81d61c4 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonItem.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonItem.vue @@ -22,16 +22,16 @@ :title="$t('action.edit')"> -
  • +
  • @@ -51,11 +51,6 @@ export default { } } }, - emits: ['remove'], - methods: { - closeParticiapation() { - - } - } + emits: ['remove', 'close'] } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue index 6827ea585..586ad3993 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue @@ -17,7 +17,8 @@ v-for="participation in participations" v-bind:participation="participation" v-bind:key="participation.id" - @remove="removeParticipation"> + @remove="removeParticipation" + @close="closeParticipation"> @@ -51,6 +52,10 @@ export default { removeParticipation(item) { this.$store.dispatch('removeParticipation', item) }, + closeParticipation(item) { + console.log('@@ CLICK close participation: item', item); + this.$store.dispatch('closeParticipation', item) + }, /* savePersons() { console.log('[wip] saving persons'); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js index 7a1f1a407..48cec2f86 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js @@ -31,18 +31,18 @@ let getDataPromise = getAccompanyingCourse(id) //console.log('mutation: remove item', item.id); state.accompanying_course.participations = state.accompanying_course.participations.filter(participation => participation !== item); }, - closeParticipation(state, item) { + closeParticipation(state, { participation, item }) { console.log('mutation: close item', item.id); - let participation = state.accompanying_course.participations.filter(participation => participation === item); - console.log('participation', participation); + state.accompanying_course.participations.filter(participation => participation !== item); + //console.log('participation', participation); }, - addParticipation(state, { participation, payload }) { + addParticipation(state, { participation, item }) { //console.log('### mutation: add participation', participation); state.accompanying_course.participations.push(participation); //console.log('count participations from state', state.accompanying_course.participations.length); //console.log('avant', state.add_persons.selected); - state.add_persons.selected = state.add_persons.selected.filter(value => value !== payload); + state.add_persons.selected = state.add_persons.selected.filter(value => value !== item); //console.log('après', state.add_persons.selected); state.add_persons.query = ""; @@ -65,9 +65,21 @@ let getDataPromise = getAccompanyingCourse(id) removeParticipation({ commit }, payload) { commit('removeParticipation', payload); }, + closeParticipation({ commit }, payload) { + console.log('## action: fetch delete participation: payload', payload.person.id); + postParticipation(id, payload.person.id, 'DELETE') + .then(participation => new Promise((resolve, reject) => { + commit('closeParticipation', { participation, payload }); + resolve(); + })) + .catch((error) => { // si y a une erreur + //commit('removeParticipation', payload); + state.errorMsg.push(error.message); + }); + }, addParticipation({ commit }, payload) { - console.log('## action: fetch post participation: payload', payload.id); - postParticipation(id, payload.id, 'POST') + console.log('## action: fetch post participation: payload', payload.person.id); + postParticipation(id, payload.person.id, 'POST') .then(participation => new Promise((resolve, reject) => { commit('addParticipation', { participation, payload }); resolve(); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue index f65b4a18f..e86b7bd43 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue @@ -118,7 +118,7 @@ export default { addPersons() { console.log('@@@ CLICK button addPersons') this.selected.forEach(function(item) { - console.log('# dispatch action for each item', item); + //console.log('# dispatch action for each item', item); this.$store.dispatch('addParticipation', item); }, this );