visgraph: refactor store excludedNode action

This commit is contained in:
Mathieu Jaumotte 2021-11-05 12:17:39 +01:00
parent 9a00e13532
commit 0f8ca77105
2 changed files with 33 additions and 54 deletions

View File

@ -289,12 +289,12 @@ export default {
addLayer(id) {
//console.log('+ addLayer', id)
this.checkedLayers.push(id)
this.$store.dispatch('removeExcludedNode', id)
this.$store.dispatch('excludedNode', ['remove', id])
},
removeLayer(id) {
//console.log('- removeLayer', id)
this.checkedLayers = this.checkedLayers.filter(i => i !== id)
this.$store.dispatch('addExcludedNode', id)
this.$store.dispatch('excludedNode', ['add', id])
},
addRelationshipModal(edgeData) {

View File

@ -415,9 +415,7 @@ const store = createStore({
/**
* =============================================================================
*/
/**
*
* Triggered by a vis-network event when clicking on a Course Node.
* Each folded node is unfold, then expanded with fetch infos
* @param object
@ -450,58 +448,39 @@ const store = createStore({
},
/**
* For an excluded node, detect folded person and exclude too
* =============================================================================
*
* For an excluded node, add|remove relative persons excluded too
* @param object
* @param id
* @param array (add|remove action, id)
*/
addExcludedNode({ getters, commit }, id) {
console.log('==> ExcludedNode')
commit('addExcludedNode', id)
switch (splitId(id, 'type')) {
case 'accompanying_period':
const participations = getters.getParticipationsByCourse(id)
getters.getFoldedPersons(participations)
.forEach(person => {
commit('addExcludedNode', person.id)
})
break
case 'household':
let members = getters.getMembersByHousehold(id)
getters.getFoldedPersons(members)
.forEach(person => {
commit('addExcludedNode', person.id)
})
break
default:
throw 'case undefined'
}
},
excludedNode({ getters, commit }, [action, id]) {
/**
* For an excluded node, remove relative persons excluded too
* @param object
* @param id
*/
removeExcludedNode({ getters, commit }, id) {
console.log('<== ExcludedNode')
commit('removeExcludedNode', id)
switch (splitId(id, 'type')) {
case 'accompanying_period':
const participations = getters.getParticipationsByCourse(id)
getters.getFoldedPersons(participations)
.forEach(person => {
commit('removeExcludedNode', person.id)
})
break
case 'household':
let members = getters.getMembersByHousehold(id)
getters.getFoldedPersons(members)
.forEach(person => {
commit('removeExcludedNode', person.id)
})
break
default:
throw 'case undefined'
const personGroup = () => {
switch (splitId(id, 'type')) {
case 'accompanying_period':
return getters.getParticipationsByCourse(id)
case 'household':
return getters.getMembersByHousehold(id)
default:
throw 'undefined case with this id'
}
}
if (action === 'add') {
commit('addExcludedNode', id)
getters.getFoldedPersons(personGroup())
.forEach(person => {
if (!getters.isInWhitelist(person.id)) {
commit('addExcludedNode', person.id)
}
})
}
if (action === 'remove') {
commit('removeExcludedNode', id)
getters.getFoldedPersons(personGroup())
.forEach(person => {
commit('removeExcludedNode', person.id)
})
}
},