visgraph: improve update graph mechanism

adding an updateHack in store, and a watcher in component.
* updateHack increment a value in the lpop,
* the watcher detect when value changes
* and $forceUpdate

improve layer checkbox legend refresh and rebuild
This commit is contained in:
2021-11-10 19:57:19 +01:00
parent 7230fd9c07
commit 95610ffd34
2 changed files with 44 additions and 30 deletions

View File

@@ -18,7 +18,8 @@ const store = createStore({
householdLoadingIds: [],
courseLoadedIds: [],
relationshipLoadedIds: [],
excludedNodesIds: []
excludedNodesIds: [],
updateHack: 0
},
getters: {
nodes(state) {
@@ -71,7 +72,7 @@ const store = createStore({
//console.log(link.id, state.excludedNodesIds.indexOf(splitId(link.id, 'link')))
}
})
console.log('count links', array.length, array.map(i => i.id))
//console.log('count links', array.length, array.map(i => i.id))
return array.length
},
@@ -231,6 +232,11 @@ const store = createStore({
delete person._label
delete person.title
person.folded = false
},
//// force update hack
updateHack(state) {
state.updateHack = state.updateHack + 1
}
},
actions: {
@@ -246,6 +252,7 @@ const store = createStore({
addPerson({ commit, dispatch }, person) {
commit('markPersonLoaded', person.id)
commit('addPerson', [person, { folded: false }])
commit('updateHack')
dispatch('fetchInfoForPerson', person)
},
@@ -255,9 +262,9 @@ const store = createStore({
* @param person
*/
fetchInfoForPerson({ dispatch }, person) {
// TODO enfants hors ménages
// example: household 61
// console.log(person.text, 'household', person.current_household_id)
// TODO enfants hors ménages
// example: household 61
// console.log(person.text, 'household', person.current_household_id)
if (null !== person.current_household_id) {
dispatch('fetchHouseholdForPerson', person)
}
@@ -278,9 +285,11 @@ const store = createStore({
getHouseholdByPerson(person)
.then(household => new Promise(resolve => {
commit('addHousehold', household)
// DISABLED: in init or expand loop, layer is uncheck when added
//dispatch('addExcludedNode', household.id)
// DISABLED: in init or expand loop, layer is uncheck when added
//commit('addExcludedNode', household.id)
//commit('updateHack')
dispatch('addLinkFromPersonsToHousehold', household)
commit('updateHack')
resolve()
})
).catch( () => {
@@ -341,6 +350,7 @@ const store = createStore({
commit('addCourse', course)
commit('addExcludedNode', course.id) // in init or expand loop, layer is uncheck when added
dispatch('addLinkFromPersonsToCourse', course)
commit('updateHack')
}
})
},
@@ -395,6 +405,7 @@ const store = createStore({
commit('markRelationshipLoaded', relationship.id)
commit('addRelationship', relationship)
dispatch('addLinkFromRelationship', relationship)
commit('updateHack')
}
})
},
@@ -441,6 +452,7 @@ const store = createStore({
// in init or expand loop, exclude too missing persons if parent have been excluded
commit('addExcludedNode', person.id)
}
commit('updateHack')
},
/**
@@ -513,6 +525,7 @@ const store = createStore({
commit('removeExcludedNode', person.id)
})
}
commit('updateHack')
},
}