mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
loop on household members to add edges to graph
This commit is contained in:
parent
f4b9942f3c
commit
b7f3700928
@ -14,8 +14,9 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(['persons', 'households', 'courses', 'relationships', 'householdLoadingIds']),
|
//not used ...mapState(['persons', 'households', 'courses', 'relationships', 'householdLoadingIds']),
|
||||||
...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 +25,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: {
|
||||||
|
@ -14,7 +14,7 @@ const store = createStore({
|
|||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
nodes(state) {
|
nodes(state) {
|
||||||
let nodes = [];
|
let nodes = []
|
||||||
state.persons.forEach(p => {
|
state.persons.forEach(p => {
|
||||||
nodes.push(p)
|
nodes.push(p)
|
||||||
})
|
})
|
||||||
@ -24,40 +24,55 @@ const store = createStore({
|
|||||||
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)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
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
|
person.label = person.text // vis need label
|
||||||
person.id = `person_${person.id}` // vis need unique id
|
person.id = `person_${person.id}` // vis need unique id
|
||||||
state.persons.push(person)
|
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
|
household.label = `Ménage n° ${household.id}` // vis need label
|
||||||
household.id = `household_${household.id}` // vis need unique id
|
household.id = `household_${household.id}` // vis need unique id
|
||||||
state.households.push(household)
|
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(course)
|
||||||
},
|
},
|
||||||
addRelationship(state, relationship) {
|
addRelationship(state, relationship) {
|
||||||
console.log('addRelationship', relationship.id)
|
console.log('+ addRelationship', relationship.id)
|
||||||
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)
|
||||||
}
|
},
|
||||||
|
addLinkFromPersonsToHousehold(state, 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)
|
||||||
|
state.relationships.push({
|
||||||
|
from: `${m.person.type}_${m.person.id}`,
|
||||||
|
to: `household_${m.person.current_household_id}`
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
addPerson({ commit, dispatch }, person) {
|
addPerson({ commit, dispatch }, person) {
|
||||||
@ -75,18 +90,19 @@ const store = createStore({
|
|||||||
* check first isHouseholdLoading to fetch household once
|
* check first isHouseholdLoading to fetch household once
|
||||||
*/
|
*/
|
||||||
fetchHouseholdForPerson({ commit, getters }, person) {
|
fetchHouseholdForPerson({ commit, getters }, 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)
|
||||||
|
commit('addLinkFromPersonsToHousehold', household)
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
).catch( () => {
|
).catch( () => {
|
||||||
commit('unmarkHouseholdLoading', person.current_household_id)
|
commit('unmarkHouseholdLoading', person.current_household_id)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -101,7 +117,7 @@ const store = createStore({
|
|||||||
commit('addCourse', course)
|
commit('addCourse', course)
|
||||||
resolve()
|
resolve()
|
||||||
}))
|
}))
|
||||||
;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -115,10 +131,10 @@ const store = createStore({
|
|||||||
commit('addRelationship', relationship)
|
commit('addRelationship', relationship)
|
||||||
resolve()
|
resolve()
|
||||||
}))
|
}))
|
||||||
;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
export { store }
|
export { store }
|
||||||
|
@ -29,6 +29,9 @@ window.options = {
|
|||||||
},
|
},
|
||||||
nodes: {
|
nodes: {
|
||||||
physics: true
|
physics: true
|
||||||
|
},
|
||||||
|
edges: {
|
||||||
|
physics: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user