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) { addLayer(id) {
//console.log('+ addLayer', id) //console.log('+ addLayer', id)
this.checkedLayers.push(id) this.checkedLayers.push(id)
this.$store.dispatch('removeExcludedNode', id) this.$store.dispatch('excludedNode', ['remove', id])
}, },
removeLayer(id) { removeLayer(id) {
//console.log('- removeLayer', id) //console.log('- removeLayer', id)
this.checkedLayers = this.checkedLayers.filter(i => i !== id) this.checkedLayers = this.checkedLayers.filter(i => i !== id)
this.$store.dispatch('addExcludedNode', id) this.$store.dispatch('excludedNode', ['add', id])
}, },
addRelationshipModal(edgeData) { addRelationshipModal(edgeData) {

View File

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