mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
vue_visgraph: store missing persons from courses, household and relationship
This commit is contained in:
parent
69e3a0a6cd
commit
317ba0a095
@ -36,13 +36,9 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters(['nodes', 'edges']),
|
...mapGetters(['nodes', 'edges']),
|
||||||
...mapState(['households', 'courses', 'excludedNodesIds'
|
...mapState(['households', 'courses', 'excludedNodesIds',
|
||||||
//'persons',
|
// not used
|
||||||
//'links,
|
'persons', 'links', 'relationships', 'personLoadedIds', 'householdLoadingIds', 'courseLoadedIds', 'relationshipLoadedIds',
|
||||||
//'relationships',
|
|
||||||
//'householdLoadingIds',
|
|
||||||
//'courseLoadedIds',
|
|
||||||
//'relationshipLoadedIds',
|
|
||||||
]),
|
]),
|
||||||
|
|
||||||
visgraph_data() {
|
visgraph_data() {
|
||||||
|
@ -13,6 +13,7 @@ const store = createStore({
|
|||||||
courses: [],
|
courses: [],
|
||||||
relationships: [],
|
relationships: [],
|
||||||
links: [],
|
links: [],
|
||||||
|
personLoadedIds: [],
|
||||||
householdLoadingIds: [],
|
householdLoadingIds: [],
|
||||||
courseLoadedIds: [],
|
courseLoadedIds: [],
|
||||||
relationshipLoadedIds: [],
|
relationshipLoadedIds: [],
|
||||||
@ -41,9 +42,6 @@ const store = createStore({
|
|||||||
state.links.forEach(l => {
|
state.links.forEach(l => {
|
||||||
edges.push(l)
|
edges.push(l)
|
||||||
})
|
})
|
||||||
//state.relationships.forEach(r => {
|
|
||||||
// edges.push(r)
|
|
||||||
//})
|
|
||||||
return edges
|
return edges
|
||||||
},
|
},
|
||||||
isHouseholdLoading: (state) => (household_id) => {
|
isHouseholdLoading: (state) => (household_id) => {
|
||||||
@ -54,6 +52,9 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
isRelationshipLoaded: (state) => (relationship_id) => {
|
isRelationshipLoaded: (state) => (relationship_id) => {
|
||||||
return state.relationshipLoadedIds.includes(relationship_id)
|
return state.relationshipLoadedIds.includes(relationship_id)
|
||||||
|
},
|
||||||
|
isPersonLoaded: (state) => (person_id) => {
|
||||||
|
return state.personLoadedIds.includes(person_id)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
@ -77,6 +78,12 @@ const store = createStore({
|
|||||||
console.log('+ addLink from', link.from, 'to', link.to)
|
console.log('+ addLink from', link.from, 'to', link.to)
|
||||||
state.links.push(link)
|
state.links.push(link)
|
||||||
},
|
},
|
||||||
|
markPersonLoaded(state, id) {
|
||||||
|
state.personLoadedIds.push(id)
|
||||||
|
},
|
||||||
|
unmarkPersonLoaded(state, id) {
|
||||||
|
state.personLoadedIds = state.personLoadedIds.filter(i => i !== id)
|
||||||
|
},
|
||||||
markHouseholdLoading(state, id) {
|
markHouseholdLoading(state, id) {
|
||||||
console.log('..loading household', id)
|
console.log('..loading household', id)
|
||||||
state.householdLoadingIds.push(id)
|
state.householdLoadingIds.push(id)
|
||||||
@ -108,7 +115,9 @@ const store = createStore({
|
|||||||
* 1) Add a person in state
|
* 1) Add a person in state
|
||||||
* @param Person person
|
* @param Person person
|
||||||
*/
|
*/
|
||||||
|
|
||||||
addPerson({ commit, dispatch }, person) {
|
addPerson({ commit, dispatch }, person) {
|
||||||
|
commit('markPersonLoaded', person.id)
|
||||||
commit('addPerson', person)
|
commit('addPerson', person)
|
||||||
dispatch('fetchInfoForPerson', person)
|
dispatch('fetchInfoForPerson', person)
|
||||||
},
|
},
|
||||||
@ -149,7 +158,7 @@ const store = createStore({
|
|||||||
* 4) Add an edge for each household member (household -> person)
|
* 4) Add an edge for each household member (household -> person)
|
||||||
* @param Household household
|
* @param Household household
|
||||||
*/
|
*/
|
||||||
addLinkFromPersonsToHousehold({ commit }, household) {
|
addLinkFromPersonsToHousehold({ commit, getters, dispatch }, household) {
|
||||||
const currentMembers = household.members.filter(v => household.current_members_id.includes(v.id))
|
const currentMembers = household.members.filter(v => household.current_members_id.includes(v.id))
|
||||||
currentMembers.forEach(m => {
|
currentMembers.forEach(m => {
|
||||||
//console.log('-> addLink from person', m.person.id, 'to household', m.person.current_household_id)
|
//console.log('-> addLink from person', m.person.id, 'to household', m.person.current_household_id)
|
||||||
@ -163,30 +172,32 @@ const store = createStore({
|
|||||||
label: getHouseholdLabel(m),
|
label: getHouseholdLabel(m),
|
||||||
width: getHouseholdWidth(m),
|
width: getHouseholdWidth(m),
|
||||||
})
|
})
|
||||||
|
if (!getters.isPersonLoaded(m.person.id)) {
|
||||||
|
console.log(' person is not loaded', m.person.id)
|
||||||
|
dispatch('addMissingPerson', m.person)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 5) Fetch AccompanyingCourses for the person
|
* 5) Fetch AccompanyingCourses for the person
|
||||||
* @param Person person
|
* @param Person person
|
||||||
*/
|
*/
|
||||||
fetchCoursesByPerson({ dispatch }, person) {
|
fetchCoursesByPerson({ commit, dispatch }, person) {
|
||||||
//console.log('fetchCoursesByPerson', 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)
|
console.log('fetch courses', courses.length)
|
||||||
dispatch('addCourse', courses)
|
dispatch('addCourses', courses)
|
||||||
resolve()
|
resolve()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 6) Add each distinct course
|
* 6) Add each distinct course
|
||||||
* @param array courses
|
* @param array courses
|
||||||
*/
|
*/
|
||||||
addCourse({ commit, getters, dispatch }, courses) {
|
addCourses({ commit, getters, dispatch }, courses) {
|
||||||
//console.log('addCourse', 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 => {
|
||||||
@ -204,7 +215,7 @@ const store = createStore({
|
|||||||
* 7) Add an edge for each course participation (course <- person)
|
* 7) Add an edge for each course participation (course <- person)
|
||||||
* @param AccompanyingCourse course
|
* @param AccompanyingCourse course
|
||||||
*/
|
*/
|
||||||
addLinkFromPersonsToCourse({ commit }, course) {
|
addLinkFromPersonsToCourse({ commit, getters, dispatch }, course) {
|
||||||
let currentParticipations = course.participations.filter(p => p.endDate === null)
|
let currentParticipations = course.participations.filter(p => p.endDate === null)
|
||||||
console.log(' participations', currentParticipations.length)
|
console.log(' participations', currentParticipations.length)
|
||||||
currentParticipations.forEach(p => {
|
currentParticipations.forEach(p => {
|
||||||
@ -217,6 +228,10 @@ const store = createStore({
|
|||||||
font: { color: 'darkorange' },
|
font: { color: 'darkorange' },
|
||||||
label: visMessages.fr.visgraph.concerned,
|
label: visMessages.fr.visgraph.concerned,
|
||||||
})
|
})
|
||||||
|
if (!getters.isPersonLoaded(p.person.id)) {
|
||||||
|
console.log(' person is not loaded', p.person.id)
|
||||||
|
dispatch('addMissingPerson', p.person)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -229,7 +244,7 @@ const store = createStore({
|
|||||||
getRelationshipsByPerson(person)
|
getRelationshipsByPerson(person)
|
||||||
.then(relationships => new Promise(resolve => {
|
.then(relationships => new Promise(resolve => {
|
||||||
console.log('fetch relationships', relationships.length)
|
console.log('fetch relationships', relationships.length)
|
||||||
dispatch('addRelationship', relationships)
|
dispatch('addRelationships', relationships)
|
||||||
resolve()
|
resolve()
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
@ -239,7 +254,7 @@ const store = createStore({
|
|||||||
* 9) Add each distinct relationship
|
* 9) Add each distinct relationship
|
||||||
* @param array relationships
|
* @param array relationships
|
||||||
*/
|
*/
|
||||||
addRelationship({ commit, getters, dispatch }, relationships) {
|
addRelationships({ commit, getters, dispatch }, relationships) {
|
||||||
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)) {
|
||||||
@ -253,40 +268,36 @@ const store = createStore({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 10) Add an edge for each relationship (person -> person)
|
* 10) Add an edge for each relationship (person -> person)
|
||||||
* @param Relationship relationship
|
* @param Relationship r
|
||||||
*/
|
*/
|
||||||
addLinkFromRelationship({ commit }, r) {
|
addLinkFromRelationship({ commit, getters, dispatch }, r) {
|
||||||
|
//console.log('-> addLink from person', r.fromPerson.id, 'to person', r.toPerson.id)
|
||||||
console.log(
|
|
||||||
'-> addLink from person', r.fromPerson.id, 'to person', r.toPerson.id,
|
|
||||||
//'reverse', r.reverse,
|
|
||||||
//'relation', r.relation.title.fr, r.relation.reverseTitle.fr
|
|
||||||
)
|
|
||||||
|
|
||||||
commit('addLink', {
|
commit('addLink', {
|
||||||
from: `person_${r.fromPerson.id}`,
|
from: `person_${r.fromPerson.id}`,
|
||||||
to: `person_${r.toPerson.id}`,
|
to: `person_${r.toPerson.id}`,
|
||||||
id: 'r' + r.id + '_p' + r.fromPerson.id + '_p' + r.toPerson.id,
|
id: 'r' + r.id + '_p' + r.fromPerson.id + '_p' + r.toPerson.id,
|
||||||
arrows: 'from',
|
arrows: 'to',
|
||||||
color: 'lightblue', dashes: true,
|
color: 'lightblue', dashes: true,
|
||||||
font: { color: 'lightblue' },
|
font: { color: '#33839d' },
|
||||||
label: getRelationshipLabel(r, false),
|
label: getRelationshipLabel(r, false),
|
||||||
})
|
})
|
||||||
|
for (let person of [r.fromPerson, r.toPerson]) {
|
||||||
/*
|
if (!getters.isPersonLoaded(person.id)) {
|
||||||
// add reverse relation
|
console.log(' person is not loaded', person.id)
|
||||||
commit('addLink', {
|
dispatch('addMissingPerson', person)
|
||||||
from: `person_${r.toPerson.id}`,
|
}
|
||||||
to: `person_${r.fromPerson.id}`,
|
}
|
||||||
id: 'rr' + r.id + '_p' + r.fromPerson.id + '_p' + r.toPerson.id,
|
|
||||||
arrows: 'from',
|
|
||||||
color: 'lightblue', dashes: true,
|
|
||||||
font: { color: 'lightblue' },
|
|
||||||
label: getRelationshipLabel(r, true),
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch missing person
|
||||||
|
* @param Person person
|
||||||
|
*/
|
||||||
|
addMissingPerson({ commit, getters, dispatch }, person) {
|
||||||
|
//console.log('addMissingPerson', person)
|
||||||
|
commit('markPersonLoaded', person.id)
|
||||||
|
commit('addPerson', person)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -167,7 +167,11 @@ const getHouseholdLabel = (member) => {
|
|||||||
/**
|
/**
|
||||||
* Return edge width for member (depends of position in household)
|
* Return edge width for member (depends of position in household)
|
||||||
* @param member
|
* @param member
|
||||||
* @returns string
|
* @returns integer (width)
|
||||||
|
*
|
||||||
|
* TODO
|
||||||
|
* to use: holder, shareHousehold
|
||||||
|
* not use: ordering, position (-> null)
|
||||||
*/
|
*/
|
||||||
const getHouseholdWidth = (member) => {
|
const getHouseholdWidth = (member) => {
|
||||||
switch (member.position.ordering) {
|
switch (member.position.ordering) {
|
||||||
@ -179,6 +183,8 @@ const getHouseholdWidth = (member) => {
|
|||||||
case 2: //children
|
case 2: //children
|
||||||
case 3: //children out of household
|
case 3: //children out of household
|
||||||
return 1
|
return 1
|
||||||
|
default:
|
||||||
|
throw 'Ordering not supported'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user