mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
onthefly create new person: adding result in suggested/selected list
This commit is contained in:
parent
5884fbaffc
commit
e369e43b00
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -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();
|
||||
}));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user