update case when the person was already on the graph

This commit is contained in:
2022-03-24 15:07:46 +01:00
parent f9d87876f2
commit 2e336ac874
3 changed files with 65 additions and 22 deletions

View File

@@ -117,10 +117,27 @@ const store = createStore({
return group
},
getPersonById: (state) => (person_id) => {
return state.persons.find(p => p._id === person_id);
}
},
mutations: {
addPerson(state, [person, options]) {
if (!'_id' in person) {
person._id = person.id
person.id = `person_${person.id}`
}
let existing = state.persons.find(p => p._id === person._id);
if (typeof existing !== 'undefined') {
if (!options.folded && person.folded) {
// unfold
}
return;
}
let age = getAge(person)
age = (age === '')? '' : ' - ' + age
@@ -232,6 +249,9 @@ const store = createStore({
//// unfold
unfoldPerson(state, person) {
if (!person.folded) {
return;
}
//console.log('unfoldPerson', person)
person.label = person._label
delete person._label
@@ -261,6 +281,31 @@ const store = createStore({
dispatch('fetchInfoForPerson', person)
},
/**
* Add a person manually
*
* @param commit
* @param dispatch
* @param person
*/
addMorePerson({ commit, dispatch, getters }, person) {
let nodeId = `person_${person.id}`;
if (getters.isPersonLoaded(person.id)) {
if (getters.isExcludedNode(nodeId)) {
commit('removeExcludedNode', nodeId);
let p = getters.getPersonById(person.id);
if (typeof p !== 'undefined') {
commit('unfoldPerson', p);
} else {
throw 'a person loaded was not found';
}
commit('updateHack');
}
} else {
return dispatch('addPerson', person);
}
},
/**
* 2) Fetch infos for this person (hub)
* @param object
@@ -287,7 +332,7 @@ const store = createStore({
//console.log(' isHouseholdLoading ?', getters.isHouseholdLoading(person.current_household_id))
if (! getters.isHouseholdLoading(person.current_household_id)) {
commit('markHouseholdLoading', person.current_household_id)
getHouseholdByPerson(person)
return getHouseholdByPerson(person)
.then(household => new Promise(resolve => {
commit('addHousehold', household)
// DISABLED: in init or expand loop, layer is uncheck when added
@@ -295,7 +340,7 @@ const store = createStore({
//commit('updateHack')
dispatch('addLinkFromPersonsToHousehold', household)
commit('updateHack')
resolve()
resolve();
})
).catch( () => {
commit('unmarkHouseholdLoading', person.current_household_id)
@@ -335,7 +380,7 @@ const store = createStore({
* @param person
*/
fetchCoursesByPerson({ commit, dispatch }, person) {
getCoursesByPerson(person)
return getCoursesByPerson(person)
.then(courses => new Promise(resolve => {
dispatch('addCourses', courses)
resolve()
@@ -383,6 +428,8 @@ const store = createStore({
dispatch('addMissingPerson', [p.person, course])
}
})
return Promise.resolve();
},
/**