diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/App.vue index 6c12676b3..173967eb3 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/App.vue @@ -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) { diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/store.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/store.js index 6304146b3..64b755d06 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/store.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/store.js @@ -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) + }) } },