update case when the person was already on the graph

This commit is contained in:
Julien Fastré 2022-03-24 15:07:46 +01:00
parent f9d87876f2
commit 2e336ac874
3 changed files with 65 additions and 22 deletions

View File

@ -113,16 +113,18 @@
</template> </template>
</modal> </modal>
</teleport> </teleport>
<div style="float: right;"> <ul class="record_actions sticky-form-buttons">
<add-persons <li>
buttonTitle="visgraph.add_person" <add-persons
modalTitle="visgraph.add_person" buttonTitle="visgraph.add_person"
v-bind:key="addPersons.key" modalTitle="visgraph.add_person"
v-bind:options="addPersons.options" v-bind:key="addPersons.key"
@addNewPersons="addNewPersons" v-bind:options="addPersons.options"
ref="addPersons"> @addNewPersons="addNewPersons"
</add-persons> ref="addPersons">
</div> </add-persons>
</li>
</ul>
</template> </template>
<script> <script>
@ -263,7 +265,7 @@ export default {
addNewPersons({ selected, modal }) { addNewPersons({ selected, modal }) {
// console.log('@@@ CLICK button addNewPersons', selected); // console.log('@@@ CLICK button addNewPersons', selected);
selected.forEach(function(item) { selected.forEach(function(item) {
this.$store.dispatch('addPerson', item.result) this.$store.dispatch('addMorePerson', item.result)
.catch(({name, violations}) => { .catch(({name, violations}) => {
if (name === 'ValidationException' || name === 'AccessException') { if (name === 'ValidationException' || name === 'AccessException') {
violations.forEach((violation) => this.$toast.open({message: violation})); violations.forEach((violation) => this.$toast.open({message: violation}));

View File

@ -117,10 +117,27 @@ const store = createStore({
return group return group
}, },
getPersonById: (state) => (person_id) => {
return state.persons.find(p => p._id === person_id);
}
}, },
mutations: { mutations: {
addPerson(state, [person, options]) { addPerson(state, [person, options]) {
if (!'_id' in person) {
person._id = person.id
person.id = `person_${person.id}`
}
let existing = state.persons.find(p => p._id === person._id);
if (typeof existing !== 'undefined') {
if (!options.folded && person.folded) {
// unfold
}
return;
}
let age = getAge(person) let age = getAge(person)
age = (age === '')? '' : ' - ' + age age = (age === '')? '' : ' - ' + age
@ -232,6 +249,9 @@ const store = createStore({
//// unfold //// unfold
unfoldPerson(state, person) { unfoldPerson(state, person) {
if (!person.folded) {
return;
}
//console.log('unfoldPerson', person) //console.log('unfoldPerson', person)
person.label = person._label person.label = person._label
delete person._label delete person._label
@ -261,6 +281,31 @@ const store = createStore({
dispatch('fetchInfoForPerson', person) dispatch('fetchInfoForPerson', person)
}, },
/**
* Add a person manually
*
* @param commit
* @param dispatch
* @param person
*/
addMorePerson({ commit, dispatch, getters }, person) {
let nodeId = `person_${person.id}`;
if (getters.isPersonLoaded(person.id)) {
if (getters.isExcludedNode(nodeId)) {
commit('removeExcludedNode', nodeId);
let p = getters.getPersonById(person.id);
if (typeof p !== 'undefined') {
commit('unfoldPerson', p);
} else {
throw 'a person loaded was not found';
}
commit('updateHack');
}
} else {
return dispatch('addPerson', person);
}
},
/** /**
* 2) Fetch infos for this person (hub) * 2) Fetch infos for this person (hub)
* @param object * @param object
@ -287,7 +332,7 @@ const store = createStore({
//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) return getHouseholdByPerson(person)
.then(household => new Promise(resolve => { .then(household => new Promise(resolve => {
commit('addHousehold', household) commit('addHousehold', household)
// DISABLED: in init or expand loop, layer is uncheck when added // DISABLED: in init or expand loop, layer is uncheck when added
@ -295,7 +340,7 @@ const store = createStore({
//commit('updateHack') //commit('updateHack')
dispatch('addLinkFromPersonsToHousehold', household) dispatch('addLinkFromPersonsToHousehold', household)
commit('updateHack') commit('updateHack')
resolve() resolve();
}) })
).catch( () => { ).catch( () => {
commit('unmarkHouseholdLoading', person.current_household_id) commit('unmarkHouseholdLoading', person.current_household_id)
@ -335,7 +380,7 @@ const store = createStore({
* @param person * @param person
*/ */
fetchCoursesByPerson({ commit, dispatch }, person) { fetchCoursesByPerson({ commit, dispatch }, person) {
getCoursesByPerson(person) return getCoursesByPerson(person)
.then(courses => new Promise(resolve => { .then(courses => new Promise(resolve => {
dispatch('addCourses', courses) dispatch('addCourses', courses)
resolve() resolve()
@ -383,6 +428,8 @@ const store = createStore({
dispatch('addMissingPerson', [p.person, course]) dispatch('addMissingPerson', [p.person, course])
} }
}) })
return Promise.resolve();
}, },
/** /**

View File

@ -164,14 +164,8 @@ const getGender = (gender) => {
* @returns {string|null} * @returns {string|null}
*/ */
const getAge = (person) => { const getAge = (person) => {
if (person.birthdate) { if (person.age) {
let birthdate = new Date(person.birthdate.datetime) return person.age + ' ' + visMessages.fr.visgraph.years;
if (person.deathdate) {
let deathdate = new Date(person.deathdate.datetime)
return (deathdate.getFullYear() - birthdate.getFullYear()) + visMessages.fr.visgraph.years
}
let now = new Date()
return (now.getFullYear() - birthdate.getFullYear()) + visMessages.fr.visgraph.years
} }
return '' return ''
} }