mirror of
				https://gitlab.com/Chill-Projet/chill-bundles.git
				synced 2025-11-04 03:08:25 +00:00 
			
		
		
		
	update case when the person was already on the graph
This commit is contained in:
		@@ -113,16 +113,18 @@
 | 
			
		||||
         </template>
 | 
			
		||||
      </modal>
 | 
			
		||||
   </teleport>
 | 
			
		||||
   <div style="float: right;">
 | 
			
		||||
      <add-persons
 | 
			
		||||
         buttonTitle="visgraph.add_person"
 | 
			
		||||
         modalTitle="visgraph.add_person"
 | 
			
		||||
         v-bind:key="addPersons.key"
 | 
			
		||||
         v-bind:options="addPersons.options"
 | 
			
		||||
         @addNewPersons="addNewPersons"
 | 
			
		||||
         ref="addPersons">
 | 
			
		||||
      </add-persons>
 | 
			
		||||
   </div>
 | 
			
		||||
   <ul class="record_actions sticky-form-buttons">
 | 
			
		||||
     <li>
 | 
			
		||||
       <add-persons
 | 
			
		||||
           buttonTitle="visgraph.add_person"
 | 
			
		||||
           modalTitle="visgraph.add_person"
 | 
			
		||||
           v-bind:key="addPersons.key"
 | 
			
		||||
           v-bind:options="addPersons.options"
 | 
			
		||||
           @addNewPersons="addNewPersons"
 | 
			
		||||
           ref="addPersons">
 | 
			
		||||
       </add-persons>
 | 
			
		||||
     </li>
 | 
			
		||||
   </ul>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
@@ -263,7 +265,7 @@ export default {
 | 
			
		||||
      addNewPersons({ selected, modal }) {
 | 
			
		||||
         // console.log('@@@ CLICK button addNewPersons', selected);
 | 
			
		||||
         selected.forEach(function(item) {
 | 
			
		||||
               this.$store.dispatch('addPerson', item.result)
 | 
			
		||||
               this.$store.dispatch('addMorePerson', item.result)
 | 
			
		||||
                  .catch(({name, violations}) => {
 | 
			
		||||
                     if (name === 'ValidationException' || name === 'AccessException') {
 | 
			
		||||
                        violations.forEach((violation) => this.$toast.open({message: violation}));
 | 
			
		||||
 
 | 
			
		||||
@@ -117,10 +117,27 @@ const store = createStore({
 | 
			
		||||
            return group
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        getPersonById: (state) => (person_id) => {
 | 
			
		||||
            return state.persons.find(p => p._id === person_id);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    },
 | 
			
		||||
    mutations: {
 | 
			
		||||
        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)
 | 
			
		||||
            age = (age === '')? '' : ' - ' + age
 | 
			
		||||
 | 
			
		||||
@@ -232,6 +249,9 @@ const store = createStore({
 | 
			
		||||
 | 
			
		||||
        //// unfold
 | 
			
		||||
        unfoldPerson(state, person) {
 | 
			
		||||
            if (!person.folded) {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            //console.log('unfoldPerson', person)
 | 
			
		||||
            person.label = person._label
 | 
			
		||||
            delete person._label
 | 
			
		||||
@@ -261,6 +281,31 @@ const store = createStore({
 | 
			
		||||
            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)
 | 
			
		||||
         *  @param object
 | 
			
		||||
@@ -287,7 +332,7 @@ const store = createStore({
 | 
			
		||||
            //console.log('  isHouseholdLoading ?', getters.isHouseholdLoading(person.current_household_id))
 | 
			
		||||
            if (! getters.isHouseholdLoading(person.current_household_id)) {
 | 
			
		||||
                commit('markHouseholdLoading', person.current_household_id)
 | 
			
		||||
                getHouseholdByPerson(person)
 | 
			
		||||
                return getHouseholdByPerson(person)
 | 
			
		||||
                    .then(household => new Promise(resolve => {
 | 
			
		||||
                        commit('addHousehold', household)
 | 
			
		||||
                            // DISABLED: in init or expand loop, layer is uncheck when added
 | 
			
		||||
@@ -295,7 +340,7 @@ const store = createStore({
 | 
			
		||||
                            //commit('updateHack')
 | 
			
		||||
                        dispatch('addLinkFromPersonsToHousehold', household)
 | 
			
		||||
                        commit('updateHack')
 | 
			
		||||
                        resolve()
 | 
			
		||||
                        resolve();
 | 
			
		||||
                        })
 | 
			
		||||
                    ).catch( () => {
 | 
			
		||||
                        commit('unmarkHouseholdLoading', person.current_household_id)
 | 
			
		||||
@@ -335,7 +380,7 @@ const store = createStore({
 | 
			
		||||
         *  @param person
 | 
			
		||||
         */
 | 
			
		||||
        fetchCoursesByPerson({ commit, dispatch }, person) {
 | 
			
		||||
            getCoursesByPerson(person)
 | 
			
		||||
            return getCoursesByPerson(person)
 | 
			
		||||
                .then(courses => new Promise(resolve => {
 | 
			
		||||
                    dispatch('addCourses', courses)
 | 
			
		||||
                    resolve()
 | 
			
		||||
@@ -383,6 +428,8 @@ const store = createStore({
 | 
			
		||||
                    dispatch('addMissingPerson', [p.person, course])
 | 
			
		||||
                }
 | 
			
		||||
            })
 | 
			
		||||
 | 
			
		||||
            return Promise.resolve();
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
 
 | 
			
		||||
@@ -164,14 +164,8 @@ const getGender = (gender) => {
 | 
			
		||||
 * @returns {string|null}
 | 
			
		||||
 */
 | 
			
		||||
const getAge = (person) => {
 | 
			
		||||
    if (person.birthdate) {
 | 
			
		||||
        let birthdate = new Date(person.birthdate.datetime)
 | 
			
		||||
        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
 | 
			
		||||
    if (person.age) {
 | 
			
		||||
        return person.age + ' ' + visMessages.fr.visgraph.years;
 | 
			
		||||
    }
 | 
			
		||||
    return ''
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user