onthefly create new person: adding result in suggested/selected list

This commit is contained in:
Mathieu Jaumotte 2021-08-25 18:09:48 +02:00
parent 5884fbaffc
commit e369e43b00
4 changed files with 34 additions and 6 deletions

View File

@ -84,9 +84,6 @@ export default {
} }
}, },
computed: { computed: {
//action() {
// return this.$data.action;
//},
classAction() { classAction() {
switch (this.action) { switch (this.action) {
case 'show': case 'show':
@ -142,7 +139,6 @@ export default {
}) })
}, },
changeActionTo(action) { 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; this.$data.action = action;
}, },
saveAction() { saveAction() {
@ -152,6 +148,7 @@ export default {
} else if (this.type === 'thirdparty') { } else if (this.type === 'thirdparty') {
this.$refs.castThirdparty.postData(); this.$refs.castThirdparty.postData();
} else { } else {
// => save new person created
// saveAction() ==cast=to==> child.castByType() ==cast=to==> grand-child.postData() // saveAction() ==cast=to==> child.castByType() ==cast=to==> grand-child.postData()
this.$refs.castNew.castByType(); this.$refs.castNew.castByType();
} }

View File

@ -22,6 +22,7 @@ let initPromise = getAccompanyingCourse(id)
state: { state: {
accompanyingCourse: accompanying_course, accompanyingCourse: accompanying_course,
addressContext: {}, addressContext: {},
priorSuggestion: {},
errorMsg: [] errorMsg: []
}, },
getters: { getters: {
@ -47,9 +48,25 @@ let initPromise = getAccompanyingCourse(id)
return true; return true;
} }
return false; return false;
},
hasPriorSuggestion(state, getters) {
return state.priorSuggestion.key ? true : false;
} }
}, },
mutations: { 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) { catchError(state, error) {
console.log('### mutation: a new error have been catched and pushed in store !', error); console.log('### mutation: a new error have been catched and pushed in store !', error);
state.errorMsg.push(error); state.errorMsg.push(error);

View File

@ -90,6 +90,7 @@ import Modal from 'ChillMainAssets/vuejs/_components/Modal';
import OnTheFly from 'ChillMainAssets/vuejs/_components/OnTheFly.vue'; import OnTheFly from 'ChillMainAssets/vuejs/_components/OnTheFly.vue';
import PersonSuggestion from './AddPersons/PersonSuggestion'; import PersonSuggestion from './AddPersons/PersonSuggestion';
import { searchPersons, searchPersons_2 } from 'ChillPersonAssets/vuejs/_api/AddPersons'; import { searchPersons, searchPersons_2 } from 'ChillPersonAssets/vuejs/_api/AddPersons';
import {mapGetters, mapState} from "vuex";
export default { export default {
name: 'AddPersons', name: 'AddPersons',
@ -118,6 +119,8 @@ export default {
} }
}, },
computed: { computed: {
...mapState(['priorSuggestion']),
...mapGetters(['hasPriorSuggestion']),
query: { query: {
set(query) { set(query) {
return this.setQuery(query); return this.setQuery(query);
@ -142,6 +145,7 @@ export default {
return this.search.selected.length; return this.search.selected.length;
}, },
selectedAndSuggested() { selectedAndSuggested() {
this.checkPriorSuggestion();
const uniqBy = (a, key) => [ const uniqBy = (a, key) => [
...new Map( ...new Map(
a.map(x => [key(x), x]) a.map(x => [key(x), x])
@ -190,7 +194,6 @@ export default {
} }
}, },
loadSuggestions(suggested) { loadSuggestions(suggested) {
//console.log('suggested', suggested);
this.search.suggested = suggested; this.search.suggested = suggested;
this.search.suggested.forEach(function(item) { this.search.suggested.forEach(function(item) {
item.key = this.itemKey(item); item.key = this.itemKey(item);
@ -218,6 +221,16 @@ export default {
}, },
itemKey(item) { itemKey(item) {
return item.result.type + item.result.id; 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);
}
} }
}, },
} }

View File

@ -162,10 +162,11 @@ export default {
})); }));
}, },
postData() { postData() {
console.log('postdata before fetch', this.person);
postPerson(this.person) postPerson(this.person)
.then(person => new Promise((resolve, reject) => { .then(person => new Promise((resolve, reject) => {
this.person = person; this.person = person;
//console.log('post person', person); this.$store.commit('newPriorSuggestion', person);
resolve(); resolve();
})); }));
} }