mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
Merge branch 'household_filiation' of gitlab.com:Chill-Projet/chill-bundles into household_filiation
This commit is contained in:
commit
b6dd5e92fc
@ -1,5 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<div id="visgraph"></div>
|
<div id="visgraph"></div>
|
||||||
|
<!--
|
||||||
|
<button class="btn btn-outline-primary" @click="refreshNetwork">refresh</button>
|
||||||
|
-->
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -14,8 +17,9 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(['persons', 'households', 'courses', 'relationships', 'householdLoadingIds']),
|
//not used ...mapState(['persons', 'households', 'courses', 'relationships', 'householdLoadingIds', 'courseLoadedIds']),
|
||||||
...mapGetters(['nodes', 'edges']),
|
...mapGetters(['nodes', 'edges']),
|
||||||
|
|
||||||
visgraph_data() {
|
visgraph_data() {
|
||||||
console.log('::: visgraph_data :::', this.nodes.length, 'nodes,', this.edges.length, 'edges')
|
console.log('::: visgraph_data :::', this.nodes.length, 'nodes,', this.edges.length, 'edges')
|
||||||
return {
|
return {
|
||||||
@ -24,12 +28,12 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
refreshNetwork() { // B
|
refreshNetwork() { // B
|
||||||
console.log('refresh network')
|
console.log('--- refresh network')
|
||||||
window.network.setData(this.visgraph_data)
|
window.network.setData(this.visgraph_data) // <-- Error: [vuex] do not mutate vuex store state outside mutation handlers.
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
console.log('mounted: init graph')
|
console.log('=== mounted: init graph')
|
||||||
this.initGraph()
|
this.initGraph()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -78,14 +78,14 @@ const getHouseholdByPerson = (person) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function getCourseByPerson
|
* @function getCoursesByPerson
|
||||||
* @param person
|
* @param person
|
||||||
* @returns {Promise<Response>}
|
* @returns {Promise<Response>}
|
||||||
*/
|
*/
|
||||||
const getCourseByPerson = (person) => {
|
const getCoursesByPerson = (person) => {
|
||||||
//console.log('getCourseByPerson', person.id)
|
//console.log('getCoursesByPerson', person._id)
|
||||||
return getFetch(
|
return getFetch(
|
||||||
`/api/1.0/person/accompanying-course/by-person/${person.id}.json`)
|
`/api/1.0/person/accompanying-course/by-person/${person._id}.json`)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -119,7 +119,7 @@ const postRelationship = (person) => {
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
getHouseholdByPerson,
|
getHouseholdByPerson,
|
||||||
getCourseByPerson,
|
getCoursesByPerson,
|
||||||
getRelationship,
|
getRelationship,
|
||||||
postRelationship
|
postRelationship
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
const visMessages = {
|
const visMessages = {
|
||||||
fr: {
|
fr: {
|
||||||
visgraph: {
|
visgraph: {
|
||||||
|
'Course': 'Parcours',
|
||||||
|
'Household': 'Ménage',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { createStore } from 'vuex'
|
import { createStore } from 'vuex'
|
||||||
import { getHouseholdByPerson, getCourseByPerson, getRelationship } from './api'
|
import { getHouseholdByPerson, getCoursesByPerson, getRelationship } from './api'
|
||||||
|
import { adapt2vis } from './vis-network'
|
||||||
|
|
||||||
const debug = process.env.NODE_ENV !== 'production'
|
const debug = process.env.NODE_ENV !== 'production'
|
||||||
|
|
||||||
@ -11,53 +12,66 @@ const store = createStore({
|
|||||||
courses: [],
|
courses: [],
|
||||||
relationships: [],
|
relationships: [],
|
||||||
householdLoadingIds: [],
|
householdLoadingIds: [],
|
||||||
|
courseLoadedIds: []
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
nodes(state) {
|
nodes(state) {
|
||||||
let nodes = [];
|
let nodes = []
|
||||||
state.persons.forEach(p => {
|
state.persons.forEach(p => {
|
||||||
nodes.push(p)
|
nodes.push(p)
|
||||||
})
|
})
|
||||||
state.households.forEach(h => {
|
state.households.forEach(h => {
|
||||||
nodes.push(h)
|
nodes.push(h)
|
||||||
})
|
})
|
||||||
|
state.courses.forEach(c => {
|
||||||
|
nodes.push(c)
|
||||||
|
})
|
||||||
return nodes
|
return nodes
|
||||||
},
|
},
|
||||||
edges(state) {
|
edges(state) {
|
||||||
return []
|
let edges = []
|
||||||
|
state.relationships.forEach(r => {
|
||||||
|
edges.push(r)
|
||||||
|
})
|
||||||
|
return edges
|
||||||
},
|
},
|
||||||
isHouseholdLoading: (state) => (household_id) => {
|
isHouseholdLoading: (state) => (household_id) => {
|
||||||
return state.householdLoadingIds.includes(household_id);
|
return state.householdLoadingIds.includes(household_id)
|
||||||
|
},
|
||||||
|
isCourseLoaded: (state) => (course_id) => {
|
||||||
|
return state.courseLoadedIds.includes(course_id)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
addPerson(state, person) {
|
addPerson(state, person) {
|
||||||
console.log('addPerson', person.id)
|
console.log('+ addPerson', person.id)
|
||||||
person.label = person.text // vis need label
|
state.persons.push(adapt2vis(person))
|
||||||
person.id = `person_${person.id}` // vis need unique id
|
|
||||||
state.persons.push(person)
|
|
||||||
},
|
},
|
||||||
addHousehold(state, household) {
|
addHousehold(state, household) {
|
||||||
console.log('addHousehold', household.id)
|
console.log('+ addHousehold', household.id)
|
||||||
household.label = `Ménage n° ${household.id}` // vis need label
|
state.households.push(adapt2vis(household))
|
||||||
household.id = `household_${household.id}` // vis need unique id
|
|
||||||
state.households.push(household)
|
|
||||||
},
|
},
|
||||||
addCourse(state, course) {
|
addCourse(state, course) {
|
||||||
console.log('addCourse', course.id)
|
console.log('+ addCourse', course.id)
|
||||||
state.courses.push(course)
|
state.courses.push(adapt2vis(course))
|
||||||
},
|
},
|
||||||
addRelationship(state, relationship) {
|
addRelationship(state, relationship) {
|
||||||
console.log('addRelationship', relationship.id)
|
console.log('+ addRelationship', relationship)
|
||||||
state.relationships.push(relationship)
|
state.relationships.push(relationship)
|
||||||
},
|
},
|
||||||
markHouseholdLoading(state, id) {
|
markHouseholdLoading(state, id) {
|
||||||
console.log('..loading', id)
|
console.log('..loading household', id)
|
||||||
state.householdLoadingIds.push(id)
|
state.householdLoadingIds.push(id)
|
||||||
},
|
},
|
||||||
unmarkHouseholdLoading(state, id) {
|
unmarkHouseholdLoading(state, id) {
|
||||||
state.householdLoadingIds = state.householdLoadingIds.filter(i => i !== id)
|
state.householdLoadingIds = state.householdLoadingIds.filter(i => i !== id)
|
||||||
}
|
},
|
||||||
|
markCourseLoaded(state, id) {
|
||||||
|
state.courseLoadedIds.push(id)
|
||||||
|
},
|
||||||
|
unmarkCourseLoaded(state, id) {
|
||||||
|
state.courseLoadedIds = state.courseLoadedIds.filter(i => i !== id)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
addPerson({ commit, dispatch }, person) {
|
addPerson({ commit, dispatch }, person) {
|
||||||
@ -66,7 +80,7 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
fetchInfoForPerson({ dispatch }, person) {
|
fetchInfoForPerson({ dispatch }, person) {
|
||||||
dispatch('fetchHouseholdForPerson', person)
|
dispatch('fetchHouseholdForPerson', person)
|
||||||
//dispatch('fetchCourseByPerson', person)
|
dispatch('fetchCoursesByPerson', person)
|
||||||
//dispatch('fetchRelationship', person)
|
//dispatch('fetchRelationship', person)
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -74,35 +88,73 @@ const store = createStore({
|
|||||||
* Fetch person current household if it is not already loading
|
* Fetch person current household if it is not already loading
|
||||||
* check first isHouseholdLoading to fetch household once
|
* check first isHouseholdLoading to fetch household once
|
||||||
*/
|
*/
|
||||||
fetchHouseholdForPerson({ commit, getters }, person) {
|
fetchHouseholdForPerson({ commit, getters, dispatch }, person) {
|
||||||
console.log('isHouseholdLoading', getters.isHouseholdLoading(person.current_household_id))
|
console.log(' isHouseholdLoading ?', getters.isHouseholdLoading(person.current_household_id))
|
||||||
if (! getters.isHouseholdLoading(person.current_household_id)) {
|
if (! getters.isHouseholdLoading(person.current_household_id)) {
|
||||||
commit('markHouseholdLoading', person.current_household_id)
|
commit('markHouseholdLoading', person.current_household_id)
|
||||||
getHouseholdByPerson(person)
|
getHouseholdByPerson(person)
|
||||||
.then(household => new Promise(resolve => {
|
.then(household => new Promise(resolve => {
|
||||||
//console.log('getHouseholdByPerson', household)
|
//console.log('getHouseholdByPerson', household)
|
||||||
commit('addHousehold', household)
|
commit('addHousehold', household)
|
||||||
|
dispatch('addLinkFromPersonsToHousehold', household)
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
).catch( () => {
|
).catch( () => {
|
||||||
commit('unmarkHouseholdLoading', person.current_household_id)
|
commit('unmarkHouseholdLoading', person.current_household_id)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
addLinkFromPersonsToHousehold({ commit }, household) {
|
||||||
|
const members = household.members.filter(v => household.current_members_id.includes(v.id))
|
||||||
|
members.forEach(m => {
|
||||||
|
//console.log('-> addLink from person', m.person.id, 'to household', m.person.current_household_id)
|
||||||
|
commit('addRelationship', {
|
||||||
|
from: `${m.person.type}_${m.person.id}`,
|
||||||
|
to: `household_${m.person.current_household_id}`,
|
||||||
|
id: `p${m.person.id}-h${m.person.current_household_id}`
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch person current AccompanyingCourses
|
* Fetch person current AccompanyingCourses
|
||||||
*/
|
*/
|
||||||
fetchCourseByPerson({ commit, getters }, person) {
|
fetchCoursesByPerson({ dispatch }, person) {
|
||||||
console.log('fetchCourseByPerson', person)
|
//console.log('fetchCoursesByPerson', person)
|
||||||
getCourseByPerson(person)
|
getCoursesByPerson(person)
|
||||||
.then(course => new Promise(resolve => {
|
.then(courses => new Promise(resolve => {
|
||||||
console.log('getCourseByPerson', course)
|
console.log('fetch courses', courses.length)
|
||||||
commit('addCourse', course)
|
dispatch('addCourse', courses)
|
||||||
resolve()
|
resolve()
|
||||||
}))
|
}))
|
||||||
;
|
|
||||||
},
|
},
|
||||||
|
addCourse({ commit, getters, dispatch }, courses) {
|
||||||
|
//console.log('addCourse', courses)
|
||||||
|
let currentCourses = courses.filter(c => c.closingDate === null)
|
||||||
|
currentCourses.forEach(course => {
|
||||||
|
console.log(' isCourseLoaded ?', getters.isCourseLoaded(course.id))
|
||||||
|
if (! getters.isCourseLoaded(course.id)) {
|
||||||
|
//console.log('course', course.id)
|
||||||
|
commit('markCourseLoaded', course.id)
|
||||||
|
commit('addCourse', course)
|
||||||
|
dispatch('addLinkFromPersonsToCourse', course)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
addLinkFromPersonsToCourse({ commit }, course) {
|
||||||
|
let currentParticipations = course.participations.filter(p => p.endDate === null)
|
||||||
|
console.log(' participations', currentParticipations.length)
|
||||||
|
currentParticipations.forEach(p => {
|
||||||
|
commit('addRelationship', {
|
||||||
|
from: `${p.person.type}_${p.person.id}`,
|
||||||
|
to: `${course.id}`,
|
||||||
|
id: `p${p.person.id}-c`+ course.id.split('_')[2]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch Relationship
|
* Fetch Relationship
|
||||||
@ -115,10 +167,10 @@ const store = createStore({
|
|||||||
commit('addRelationship', relationship)
|
commit('addRelationship', relationship)
|
||||||
resolve()
|
resolve()
|
||||||
}))
|
}))
|
||||||
;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
export { store }
|
export { store }
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { visMessages } from './i18n'
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Vis-network initial data/configuration script
|
* Vis-network initial data/configuration script
|
||||||
* Notes:
|
* Notes:
|
||||||
@ -29,8 +31,40 @@ window.options = {
|
|||||||
},
|
},
|
||||||
nodes: {
|
nodes: {
|
||||||
physics: true
|
physics: true
|
||||||
|
},
|
||||||
|
edges: {
|
||||||
|
physics: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.network = {};
|
window.network = {};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Adapt entity to graph (id, label)
|
||||||
|
* we rename id in _id
|
||||||
|
* and add properties needed by vis
|
||||||
|
*/
|
||||||
|
const adapt2vis = (entity) => {
|
||||||
|
switch (entity.type) {
|
||||||
|
case 'person':
|
||||||
|
entity._id = entity.id
|
||||||
|
entity.label = entity.text
|
||||||
|
entity.id = `person_${entity.id}`
|
||||||
|
break
|
||||||
|
case 'household':
|
||||||
|
entity._id = entity.id
|
||||||
|
entity.label = `${visMessages.fr.visgraph.Household} n° ${entity.id}`
|
||||||
|
entity.id = `household_${entity.id}`
|
||||||
|
break
|
||||||
|
case 'accompanying_period':
|
||||||
|
entity._id = entity.id
|
||||||
|
entity.label = `${visMessages.fr.visgraph.Course} n° ${entity.id}`
|
||||||
|
entity.id = `accompanying_period_${entity.id}`
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return entity
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
adapt2vis
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user