mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
vue_visgraph: vuex get household and update nodes array
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { createStore } from 'vuex'
|
||||
import { getHousehold, getCourse, getRelationship } from './api'
|
||||
import { getHouseholdByPerson, getCourseByPerson, getRelationship } from './api'
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production'
|
||||
|
||||
@@ -10,36 +10,75 @@ const store = createStore({
|
||||
households: [],
|
||||
courses: [],
|
||||
relationships: [],
|
||||
householdLoadingIds: [],
|
||||
},
|
||||
getters: {
|
||||
getNodes() {
|
||||
nodes(state) {
|
||||
let nodes = [];
|
||||
state.persons.forEach(p => {
|
||||
nodes.push(p)
|
||||
})
|
||||
state.households.forEach(h => {
|
||||
nodes.push(h)
|
||||
});
|
||||
})
|
||||
// push all others kinds of nodes..
|
||||
return nodes
|
||||
},
|
||||
getEdges() {
|
||||
}
|
||||
edges(state) {
|
||||
return []
|
||||
},
|
||||
isHouseholdLoading: (state) => (household_id) => {
|
||||
return state.householdLoadingIds.includes(household_id);
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
addPerson(state, person) {
|
||||
person.label = person.text // vis need label
|
||||
state.persons.push(person)
|
||||
},
|
||||
addHousehold(state, household) {
|
||||
household.label = `Ménage n° ${household.id}` // vis need label
|
||||
state.households.push(household)
|
||||
},
|
||||
markHouseholdLoading(state, id) {
|
||||
console.log('mutation: markHouseholdLoading', id)
|
||||
state.householdLoadingIds.push(id)
|
||||
},
|
||||
unmarkHouseholdLoading(state, id) {
|
||||
state.householdLoadingIds = state.householdLoadingIds.filter(i => i !== id)
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
addPerson({ commit }, person) {
|
||||
//console.log('addPerson', person)
|
||||
addPerson({ commit, dispatch }, person) {
|
||||
console.log('addPerson', person.id)
|
||||
commit('addPerson', person)
|
||||
dispatch('fetchInfoForPerson', person)
|
||||
},
|
||||
fetchInfoForPerson({ dispatch }, person) {
|
||||
//console.log('fetchInfoForPerson', person.id)
|
||||
dispatch('fetchHouseholdForPerson', person)
|
||||
//getCourseByPerson(person)
|
||||
//getRelationship(person)
|
||||
},
|
||||
fetchInfoForPerson({ commit }, person) {
|
||||
console.log('fetchInfoForPerson', person)
|
||||
|
||||
getHousehold(person)
|
||||
getCourse(person)
|
||||
getRelationship(person)
|
||||
|
||||
/**
|
||||
* Fetch person current household if it is not already loading
|
||||
* check first isHouseholdLoading to fetch household once
|
||||
*/
|
||||
fetchHouseholdForPerson({ commit, getters }, person) {
|
||||
console.log('isHouseholdLoading', getters.isHouseholdLoading(person.current_household_id))
|
||||
if (! getters.isHouseholdLoading(person.current_household_id)) {
|
||||
commit('markHouseholdLoading', person.current_household_id)
|
||||
getHouseholdByPerson(person)
|
||||
.then(household => new Promise(resolve => {
|
||||
console.log('getHouseholdByPerson', household)
|
||||
commit('addHousehold', household)
|
||||
resolve()
|
||||
})
|
||||
).catch( () => {
|
||||
commit('unmarkHouseholdLoading', person.current_household_id)
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user