From 1bbec9efae7ac7adfebc62fa21a0e7af1da52528 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 5 May 2021 19:25:28 +0200 Subject: [PATCH] improve addpersons store cycle: init query, selections and suggestions --- .../vuejs/AccompanyingCourse/store/index.js | 24 +++++++++---------- .../public/vuejs/_components/AddPersons.vue | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) 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 515df1169..347874f7c 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js @@ -22,6 +22,9 @@ let getDataPromise = getAccompanyingCourse(id) errorMsg: [] }, getters: { + getSelectedByid: (state) => (id) => { + return state.add_persons.selected.find(item => item.id === id) + } }, mutations: { removeParticipation(state, item) { @@ -30,20 +33,17 @@ let getDataPromise = getAccompanyingCourse(id) participation => participation !== item ); }, - addParticipation(state, participation) { - console.log('### mutation: add participation', participation); + addParticipation(state, { participation, payload }) { + //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('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); + //console.log('après', state.add_persons.selected); - 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 = ""; + state.add_persons.suggested = []; }, setQuery(state, query) { //console.log('q=', query); @@ -66,7 +66,7 @@ let getDataPromise = getAccompanyingCourse(id) console.log('## action: fetch post participation: payload', payload.id); postParticipation(id, payload.id, 'POST') .then(participation => new Promise((resolve, reject) => { - commit('addParticipation', participation); + commit('addParticipation', { participation, payload }); resolve(); })) .catch((error) => { // si y a une erreur diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue index 41ad36004..4dc09cdf5 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue @@ -28,7 +28,7 @@