mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
cleaning store
This commit is contained in:
parent
bfcd420cdf
commit
e911dd30f5
@ -142,7 +142,7 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
...mapGetters(['nodes', 'edges',
|
...mapGetters(['nodes', 'edges',
|
||||||
// not used
|
// not used
|
||||||
'isInWhitelist', 'isHouseholdLoading', 'isCourseLoaded', 'isRelationshipLoaded', 'isPersonLoaded', 'isExcludedNode', 'countLinksByNode', 'getParticipationsByCourse', 'getMembersByHousehold', 'getFoldedPersons',
|
'isInWhitelist', 'isHouseholdLoading', 'isCourseLoaded', 'isRelationshipLoaded', 'isPersonLoaded', 'isExcludedNode', 'countLinksByNode', 'getParticipationsByCourse', 'getMembersByHousehold', 'getWithFoldedPersons',
|
||||||
]),
|
]),
|
||||||
...mapState(['households', 'courses', 'excludedNodesIds', 'persons',
|
...mapState(['households', 'courses', 'excludedNodesIds', 'persons',
|
||||||
// not used
|
// not used
|
||||||
@ -219,7 +219,7 @@ export default {
|
|||||||
eventHub.off('delete-relationship-modal', this.deleteRelationshipModal)
|
eventHub.off('delete-relationship-modal', this.deleteRelationshipModal)
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
//console.log('=== mounted: init graph')hill
|
//console.log('=== mounted: init graph')
|
||||||
this.initGraph()
|
this.initGraph()
|
||||||
this.listenOnGraph()
|
this.listenOnGraph()
|
||||||
this.getRelationsList()
|
this.getRelationsList()
|
||||||
|
@ -39,11 +39,7 @@ const store = createStore({
|
|||||||
return nodes
|
return nodes
|
||||||
},
|
},
|
||||||
edges(state) {
|
edges(state) {
|
||||||
let edges = []
|
return state.links
|
||||||
state.links.forEach(l => {
|
|
||||||
edges.push(l)
|
|
||||||
})
|
|
||||||
return edges
|
|
||||||
},
|
},
|
||||||
isInWhitelist: (state) => (person_id) => {
|
isInWhitelist: (state) => (person_id) => {
|
||||||
return state.whitelistIds.includes(person_id)
|
return state.whitelistIds.includes(person_id)
|
||||||
@ -80,7 +76,6 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getParticipationsByCourse: (state) => (course_id) => {
|
getParticipationsByCourse: (state) => (course_id) => {
|
||||||
//console.log('getParticipationsByCourse', course_id)
|
|
||||||
const course = state.courses.filter(c => c.id === course_id)[0]
|
const course = state.courses.filter(c => c.id === course_id)[0]
|
||||||
const currentParticipations = course.participations.filter(p => p.endDate === null)
|
const currentParticipations = course.participations.filter(p => p.endDate === null)
|
||||||
console.log('get persons in', course_id, currentParticipations.map(p => p.person.id),
|
console.log('get persons in', course_id, currentParticipations.map(p => p.person.id),
|
||||||
@ -89,7 +84,6 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getMembersByHousehold: (state) => (household_id) => {
|
getMembersByHousehold: (state) => (household_id) => {
|
||||||
//console.log('getMembersByHousehold', household_id)
|
|
||||||
const household = state.households.filter(h => h.id === household_id)[0]
|
const household = state.households.filter(h => h.id === household_id)[0]
|
||||||
const currentMembers = household.members.filter(m => household.current_members_id.includes(m.id))
|
const currentMembers = household.members.filter(m => household.current_members_id.includes(m.id))
|
||||||
console.log('get persons in', household_id, currentMembers.map(m => m.person.id),
|
console.log('get persons in', household_id, currentMembers.map(m => m.person.id),
|
||||||
@ -98,75 +92,64 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This getter is a little bit mysterious :
|
||||||
|
* The 2 previous getters return complete array, but folded (missing) persons are not taken into consideration and are not displayed (!?!)
|
||||||
* This getter compare input array (participations|members) to personLoadedIds array
|
* This getter compare input array (participations|members) to personLoadedIds array
|
||||||
* It return an array of folded persons
|
* and return complete array with folded persons taken into consideration
|
||||||
*/
|
*/
|
||||||
getFoldedPersons: (state) => (array) => {
|
getWithFoldedPersons: (state) => (array) => {
|
||||||
let folded = []
|
let withFolded = []
|
||||||
array.forEach(item => {
|
array.forEach(item => {
|
||||||
let id = splitId(item.person.id, 'id')
|
let id = splitId(item.person.id, 'id')
|
||||||
if (state.personLoadedIds.includes(id)) {
|
if (state.personLoadedIds.includes(id)) {
|
||||||
folded.push(state.persons.filter(person => person._id === id)[0])
|
withFolded.push(state.persons.filter(person => person._id === id)[0])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
//console.log('array', array.map(item => item.person.id))
|
//console.log('array', array.map(item => item.person.id))
|
||||||
console.log('get FoldedPersons', folded.map(f => f.id))
|
console.log('get FoldedPersons', withFolded.map(f => f.id))
|
||||||
return folded
|
return withFolded
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
addPerson(state, [person, options]) {
|
addPerson(state, [person, options]) {
|
||||||
//console.log('+ addPerson', person.id)
|
|
||||||
|
|
||||||
person.group = person.type
|
person.group = person.type
|
||||||
person._id = person.id
|
person._id = person.id
|
||||||
person.id = `person_${person.id}`
|
person.id = `person_${person.id}`
|
||||||
person.label = `*${person.text}*\n_${getGender(person.gender)} - ${getAge(person.birthdate)}_`
|
person.label = `*${person.text}*\n_${getGender(person.gender)} - ${getAge(person.birthdate)}_`
|
||||||
person.folded = false
|
person.folded = false
|
||||||
|
// folded is used for missing persons
|
||||||
if (options.folded) { // used by missing persons
|
if (options.folded) {
|
||||||
person.title = visMessages.fr.visgraph.click_to_expand
|
person.title = visMessages.fr.visgraph.click_to_expand
|
||||||
person._label = person.label // keep label
|
person._label = person.label // keep label
|
||||||
person.label = null
|
person.label = null
|
||||||
person.folded = true
|
person.folded = true
|
||||||
}
|
}
|
||||||
|
|
||||||
state.persons.push(person)
|
state.persons.push(person)
|
||||||
},
|
},
|
||||||
addHousehold(state, household) {
|
addHousehold(state, household) {
|
||||||
//console.log('+ addHousehold', household.id)
|
|
||||||
|
|
||||||
household.group = household.type
|
household.group = household.type
|
||||||
household._id = household.id
|
household._id = household.id
|
||||||
household.label = `${visMessages.fr.visgraph.Household} n° ${household.id}`
|
household.label = `${visMessages.fr.visgraph.Household} n° ${household.id}`
|
||||||
household.id = `household_${household.id}`
|
household.id = `household_${household.id}`
|
||||||
|
|
||||||
state.households.push(household)
|
state.households.push(household)
|
||||||
},
|
},
|
||||||
addCourse(state, course) {
|
addCourse(state, course) {
|
||||||
//console.log('+ addCourse', course.id)
|
|
||||||
|
|
||||||
course.group = course.type
|
course.group = course.type
|
||||||
course._id = course.id
|
course._id = course.id
|
||||||
course.label = `${visMessages.fr.visgraph.Course} n° ${course.id}`
|
course.label = `${visMessages.fr.visgraph.Course} n° ${course.id}`
|
||||||
course.id = `accompanying_period_${course.id}`
|
course.id = `accompanying_period_${course.id}`
|
||||||
|
|
||||||
state.courses.push(course)
|
state.courses.push(course)
|
||||||
},
|
},
|
||||||
addRelationship(state, relationship) {
|
addRelationship(state, relationship) {
|
||||||
//console.log('+ addRelationship', relationship.id)
|
|
||||||
|
|
||||||
relationship.group = relationship.type
|
relationship.group = relationship.type
|
||||||
relationship._id = relationship.id
|
relationship._id = relationship.id
|
||||||
relationship.id = `relationship_${relationship.id}`
|
relationship.id = `relationship_${relationship.id}`
|
||||||
|
state.relationships.push(relationship)
|
||||||
state.relationships.push(relationship)
|
|
||||||
},
|
},
|
||||||
addLink(state, link) {
|
addLink(state, link) {
|
||||||
//console.log('+ addLink from', link.from, 'to', link.to)
|
state.links.push(link)
|
||||||
state.links.push(link)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
//// id markers
|
//// id markers
|
||||||
@ -211,7 +194,7 @@ const store = createStore({
|
|||||||
|
|
||||||
//// unfold
|
//// unfold
|
||||||
unfoldPerson(state, person) {
|
unfoldPerson(state, person) {
|
||||||
console.log('unfoldPerson', person)
|
//console.log('unfoldPerson', person)
|
||||||
person.label = person._label
|
person.label = person._label
|
||||||
delete person._label
|
delete person._label
|
||||||
delete person.title
|
delete person.title
|
||||||
@ -220,7 +203,11 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
/**
|
/**
|
||||||
* 1) Add a person in state
|
* Expand loop (steps 1->10), always start from a person.
|
||||||
|
* Fetch household, courses, relationships, and others persons.
|
||||||
|
* These persons are "missing" and will be first display in fold mode.
|
||||||
|
*
|
||||||
|
* 1) Add a new person
|
||||||
* @param object
|
* @param object
|
||||||
* @param person
|
* @param person
|
||||||
*/
|
*/
|
||||||
@ -256,7 +243,8 @@ const store = createStore({
|
|||||||
getHouseholdByPerson(person)
|
getHouseholdByPerson(person)
|
||||||
.then(household => new Promise(resolve => {
|
.then(household => new Promise(resolve => {
|
||||||
commit('addHousehold', household)
|
commit('addHousehold', household)
|
||||||
//dispatch('addExcludedNode', household.id) // uncheck layer when added
|
// DISABLED: in init or expand loop, layer is uncheck when added
|
||||||
|
//dispatch('addExcludedNode', household.id)
|
||||||
dispatch('addLinkFromPersonsToHousehold', household)
|
dispatch('addLinkFromPersonsToHousehold', household)
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
@ -286,7 +274,6 @@ const store = createStore({
|
|||||||
width: getHouseholdWidth(m),
|
width: getHouseholdWidth(m),
|
||||||
})
|
})
|
||||||
if (!getters.isPersonLoaded(m.person.id)) {
|
if (!getters.isPersonLoaded(m.person.id)) {
|
||||||
console.log('addMissingPerson from household', household.id)
|
|
||||||
dispatch('addMissingPerson', [m.person, household])
|
dispatch('addMissingPerson', [m.person, household])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -298,10 +285,8 @@ const store = createStore({
|
|||||||
* @param person
|
* @param person
|
||||||
*/
|
*/
|
||||||
fetchCoursesByPerson({ commit, dispatch }, person) {
|
fetchCoursesByPerson({ commit, dispatch }, person) {
|
||||||
//console.log('fetchCoursesByPerson', person)
|
|
||||||
getCoursesByPerson(person)
|
getCoursesByPerson(person)
|
||||||
.then(courses => new Promise(resolve => {
|
.then(courses => new Promise(resolve => {
|
||||||
//console.log('fetch courses', courses.length)
|
|
||||||
dispatch('addCourses', courses)
|
dispatch('addCourses', courses)
|
||||||
resolve()
|
resolve()
|
||||||
}))
|
}))
|
||||||
@ -313,15 +298,13 @@ const store = createStore({
|
|||||||
* @param courses
|
* @param courses
|
||||||
*/
|
*/
|
||||||
addCourses({ commit, getters, dispatch }, courses) {
|
addCourses({ commit, getters, dispatch }, courses) {
|
||||||
//console.log('addCourse', courses)
|
|
||||||
let currentCourses = courses.filter(c => c.closingDate === null)
|
let currentCourses = courses.filter(c => c.closingDate === null)
|
||||||
currentCourses.forEach(course => {
|
currentCourses.forEach(course => {
|
||||||
//console.log(' isCourseLoaded ?', getters.isCourseLoaded(course.id))
|
//console.log(' isCourseLoaded ?', getters.isCourseLoaded(course.id))
|
||||||
if (! getters.isCourseLoaded(course.id)) {
|
if (! getters.isCourseLoaded(course.id)) {
|
||||||
//console.log('course', course.id)
|
|
||||||
commit('markCourseLoaded', course.id)
|
commit('markCourseLoaded', course.id)
|
||||||
commit('addCourse', course)
|
commit('addCourse', course)
|
||||||
commit('addExcludedNode', course.id) // init: layer uncheck when added
|
commit('addExcludedNode', course.id) // in init or expand loop, layer is uncheck when added
|
||||||
dispatch('addLinkFromPersonsToCourse', course)
|
dispatch('addLinkFromPersonsToCourse', course)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -360,7 +343,6 @@ const store = createStore({
|
|||||||
//console.log('fetchRelationshipByPerson', person)
|
//console.log('fetchRelationshipByPerson', person)
|
||||||
getRelationshipsByPerson(person)
|
getRelationshipsByPerson(person)
|
||||||
.then(relationships => new Promise(resolve => {
|
.then(relationships => new Promise(resolve => {
|
||||||
//console.log('fetch relationships', relationships.length)
|
|
||||||
dispatch('addRelationships', relationships)
|
dispatch('addRelationships', relationships)
|
||||||
resolve()
|
resolve()
|
||||||
}))
|
}))
|
||||||
@ -375,7 +357,6 @@ const store = createStore({
|
|||||||
relationships.forEach(relationship => {
|
relationships.forEach(relationship => {
|
||||||
//console.log(' isRelationshipLoaded ?', getters.isRelationshipLoaded(relationship.id))
|
//console.log(' isRelationshipLoaded ?', getters.isRelationshipLoaded(relationship.id))
|
||||||
if (! getters.isRelationshipLoaded(relationship.id)) {
|
if (! getters.isRelationshipLoaded(relationship.id)) {
|
||||||
//console.log('relationship', relationship.id)
|
|
||||||
commit('markRelationshipLoaded', relationship.id)
|
commit('markRelationshipLoaded', relationship.id)
|
||||||
commit('addRelationship', relationship)
|
commit('addRelationship', relationship)
|
||||||
dispatch('addLinkFromRelationship', relationship)
|
dispatch('addLinkFromRelationship', relationship)
|
||||||
@ -386,24 +367,25 @@ const store = createStore({
|
|||||||
/**
|
/**
|
||||||
* 10) Add an edge for each relationship (person -> person)
|
* 10) Add an edge for each relationship (person -> person)
|
||||||
* @param object
|
* @param object
|
||||||
* @param r (relationship)
|
* @param relationship
|
||||||
*/
|
*/
|
||||||
addLinkFromRelationship({ commit, getters, dispatch }, r) {
|
addLinkFromRelationship({ commit, getters, dispatch }, relationship) {
|
||||||
//console.log('-> addLink from person', r.fromPerson.id, 'to person', r.toPerson.id)
|
//console.log('-> addLink from person', relationship.fromPerson.id, 'to person', relationship.toPerson.id)
|
||||||
commit('addLink', {
|
commit('addLink', {
|
||||||
from: `person_${r.fromPerson.id}`,
|
from: `person_${relationship.fromPerson.id}`,
|
||||||
to: `person_${r.toPerson.id}`,
|
to: `person_${relationship.toPerson.id}`,
|
||||||
id: 'relationship_' + splitId(r.id,'id') + '-person_' + r.fromPerson.id + '-person_' + r.toPerson.id,
|
id: 'relationship_' + splitId(relationship.id,'id')
|
||||||
arrows: getRelationshipDirection(r),
|
+ '-person_' + relationship.fromPerson.id + '-person_' + relationship.toPerson.id,
|
||||||
|
arrows: getRelationshipDirection(relationship),
|
||||||
color: 'lightblue',
|
color: 'lightblue',
|
||||||
font: { color: '#33839d' },
|
font: { color: '#33839d' },
|
||||||
dashes: true, //physics: false,
|
dashes: true,
|
||||||
label: getRelationshipLabel(r),
|
label: getRelationshipLabel(relationship),
|
||||||
title: getRelationshipTitle(r),
|
title: getRelationshipTitle(relationship),
|
||||||
})
|
})
|
||||||
for (let person of [r.fromPerson, r.toPerson]) {
|
for (let person of [relationship.fromPerson, relationship.toPerson]) {
|
||||||
if (!getters.isPersonLoaded(person.id)) {
|
if (!getters.isPersonLoaded(person.id)) {
|
||||||
dispatch('addMissingPerson', [person, r])
|
dispatch('addMissingPerson', [person, relationship])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -419,13 +401,13 @@ const store = createStore({
|
|||||||
commit('markPersonLoaded', person.id)
|
commit('markPersonLoaded', person.id)
|
||||||
commit('addPerson', [person, { folded: true }])
|
commit('addPerson', [person, { folded: true }])
|
||||||
if (getters.isExcludedNode(parent.id)) {
|
if (getters.isExcludedNode(parent.id)) {
|
||||||
commit('addExcludedNode', person.id) // init: exclude missing persons if parent is excluded
|
// in init or expand loop, exclude too missing persons if parent have been excluded
|
||||||
|
commit('addExcludedNode', person.id)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =============================================================================
|
* ==================================================================
|
||||||
*
|
|
||||||
* 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
|
||||||
@ -433,15 +415,12 @@ const store = createStore({
|
|||||||
*/
|
*/
|
||||||
unfoldPersonsByCourse({ getters, commit, dispatch }, course) {
|
unfoldPersonsByCourse({ getters, commit, dispatch }, course) {
|
||||||
const participations = getters.getParticipationsByCourse(course.id)
|
const participations = getters.getParticipationsByCourse(course.id)
|
||||||
getters.getFoldedPersons(participations)
|
getters.getWithFoldedPersons(participations)
|
||||||
.forEach(person => {
|
.forEach(person => {
|
||||||
if (person.folded === true) {
|
if (person.folded === true) {
|
||||||
console.log('-=. unfold and expand person', person.id)
|
console.log('-=. unfold and expand person', person.id)
|
||||||
commit('unfoldPerson', person)
|
commit('unfoldPerson', person)
|
||||||
dispatch('fetchInfoForPerson', person)
|
dispatch('fetchInfoForPerson', person)
|
||||||
//} else {
|
|
||||||
//console.log('person is not folded', person)
|
|
||||||
//throw 'person is not folded'
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -454,28 +433,23 @@ const store = createStore({
|
|||||||
*/
|
*/
|
||||||
unfoldPersonsByHousehold({ getters, commit, dispatch }, household) {
|
unfoldPersonsByHousehold({ getters, commit, dispatch }, household) {
|
||||||
const members = getters.getMembersByHousehold(household.id)
|
const members = getters.getMembersByHousehold(household.id)
|
||||||
getters.getFoldedPersons(members)
|
getters.getWithFoldedPersons(members)
|
||||||
.forEach(person => {
|
.forEach(person => {
|
||||||
if (person.folded === true) {
|
if (person.folded === true) {
|
||||||
console.log('-=. unfold and expand person', person.id)
|
console.log('-=. unfold and expand person', person.id)
|
||||||
commit('unfoldPerson', person)
|
commit('unfoldPerson', person)
|
||||||
dispatch('fetchInfoForPerson', person)
|
dispatch('fetchInfoForPerson', person)
|
||||||
//} else {
|
|
||||||
//console.log('person is not folded', person)
|
|
||||||
//throw 'person is not folded'
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* =============================================================================
|
* ==================================================================
|
||||||
*
|
|
||||||
* For an excluded node, add|remove relative persons excluded too
|
* For an excluded node, add|remove relative persons excluded too
|
||||||
* @param object
|
* @param object
|
||||||
* @param array (add|remove action, id)
|
* @param array (add|remove action, id)
|
||||||
*/
|
*/
|
||||||
excludedNode({ getters, commit }, [action, id]) {
|
excludedNode({ getters, commit }, [action, id]) {
|
||||||
|
|
||||||
const personGroup = () => {
|
const personGroup = () => {
|
||||||
switch (splitId(id, 'type')) {
|
switch (splitId(id, 'type')) {
|
||||||
case 'accompanying_period':
|
case 'accompanying_period':
|
||||||
@ -488,7 +462,7 @@ const store = createStore({
|
|||||||
}
|
}
|
||||||
if (action === 'add') {
|
if (action === 'add') {
|
||||||
commit('addExcludedNode', id)
|
commit('addExcludedNode', id)
|
||||||
getters.getFoldedPersons(personGroup())
|
getters.getWithFoldedPersons(personGroup())
|
||||||
.forEach(person => {
|
.forEach(person => {
|
||||||
// countLinks < 2 but parent has just already been added !
|
// countLinks < 2 but parent has just already been added !
|
||||||
if (!getters.isInWhitelist(person.id) && getters.countLinksByNode(person.id) < 1) {
|
if (!getters.isInWhitelist(person.id) && getters.countLinksByNode(person.id) < 1) {
|
||||||
@ -498,7 +472,7 @@ const store = createStore({
|
|||||||
}
|
}
|
||||||
if (action === 'remove') {
|
if (action === 'remove') {
|
||||||
commit('removeExcludedNode', id)
|
commit('removeExcludedNode', id)
|
||||||
getters.getFoldedPersons(personGroup())
|
getters.getWithFoldedPersons(personGroup())
|
||||||
.forEach(person => {
|
.forEach(person => {
|
||||||
commit('removeExcludedNode', person.id)
|
commit('removeExcludedNode', person.id)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user