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: {
//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();
}

View File

@ -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);

View File

@ -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);
}
}
},
}

View File

@ -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();
}));
}