From e369e43b003af71aab4b4e9e7ae5801090fba464 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 25 Aug 2021 18:09:48 +0200 Subject: [PATCH] onthefly create new person: adding result in suggested/selected list --- .../public/vuejs/_components/OnTheFly.vue | 5 +---- .../vuejs/AccompanyingCourse/store/index.js | 17 +++++++++++++++++ .../public/vuejs/_components/AddPersons.vue | 15 ++++++++++++++- .../vuejs/_components/OnTheFly/Person.vue | 3 ++- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/OnTheFly.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/OnTheFly.vue index c7ae88964..125c6e31b 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/OnTheFly.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/OnTheFly.vue @@ -84,9 +84,6 @@ export default { } }, computed: { - //action() { - // return this.$data.action; - //}, classAction() { switch (this.action) { case 'show': @@ -142,7 +139,6 @@ export default { }) }, changeActionTo(action) { - // [BUG] clic first on show item button; in modal clic edit button; close modal; clic again on show item button this.$data.action = action; }, saveAction() { @@ -152,6 +148,7 @@ export default { } else if (this.type === 'thirdparty') { this.$refs.castThirdparty.postData(); } else { + // => save new person created // saveAction() ==cast=to==> child.castByType() ==cast=to==> grand-child.postData() this.$refs.castNew.castByType(); } 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 34a6786fc..fa168ba9b 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,7 @@ let initPromise = getAccompanyingCourse(id) state: { accompanyingCourse: accompanying_course, addressContext: {}, + priorSuggestion: {}, errorMsg: [] }, getters: { @@ -47,9 +48,25 @@ let initPromise = getAccompanyingCourse(id) return true; } return false; + }, + hasPriorSuggestion(state, getters) { + return state.priorSuggestion.key ? true : false; } }, mutations: { + newPriorSuggestion(state, entity) { + console.log('### mutation newPriorSuggestion', entity); + if (entity !== null) { + let suggestion = { + key: entity.type + entity.id, + relevance: 0.5, + result: entity + } + state.priorSuggestion = suggestion; + } else { + state.priorSuggestion = {}; + } + }, catchError(state, error) { console.log('### mutation: a new error have been catched and pushed in store !', error); state.errorMsg.push(error); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue index 42ffb888e..782c68654 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue @@ -90,6 +90,7 @@ import Modal from 'ChillMainAssets/vuejs/_components/Modal'; import OnTheFly from 'ChillMainAssets/vuejs/_components/OnTheFly.vue'; import PersonSuggestion from './AddPersons/PersonSuggestion'; import { searchPersons, searchPersons_2 } from 'ChillPersonAssets/vuejs/_api/AddPersons'; +import {mapGetters, mapState} from "vuex"; export default { name: 'AddPersons', @@ -118,6 +119,8 @@ export default { } }, computed: { + ...mapState(['priorSuggestion']), + ...mapGetters(['hasPriorSuggestion']), query: { set(query) { return this.setQuery(query); @@ -142,6 +145,7 @@ export default { return this.search.selected.length; }, selectedAndSuggested() { + this.checkPriorSuggestion(); const uniqBy = (a, key) => [ ...new Map( a.map(x => [key(x), x]) @@ -190,7 +194,6 @@ export default { } }, loadSuggestions(suggested) { - //console.log('suggested', suggested); this.search.suggested = suggested; this.search.suggested.forEach(function(item) { item.key = this.itemKey(item); @@ -218,6 +221,16 @@ export default { }, itemKey(item) { return item.result.type + item.result.id; + }, + checkPriorSuggestion() { + if (this.hasPriorSuggestion) { + console.log('checkPriorSuggestion',); + this.suggested.unshift(this.priorSuggestion); + this.selected.unshift(this.priorSuggestion); + + console.log('reset onthefly'); + this.$store.commit('newPriorSuggestion', null); + } } }, } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/OnTheFly/Person.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/OnTheFly/Person.vue index 84c5e1a57..a05e1aed2 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/OnTheFly/Person.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/OnTheFly/Person.vue @@ -162,10 +162,11 @@ export default { })); }, postData() { + console.log('postdata before fetch', this.person); postPerson(this.person) .then(person => new Promise((resolve, reject) => { this.person = person; - //console.log('post person', person); + this.$store.commit('newPriorSuggestion', person); resolve(); })); }