From d6da6a5d9df21aa7ed6bbac5c15f210b5eb13cd3 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 8 Nov 2021 16:59:27 +0100 Subject: [PATCH] visgraph: trying to pass value to edit relationship form fields (wip) --- .../public/vuejs/AccompanyingCourse/App.vue | 5 +- .../Resources/public/vuejs/VisGraph/App.vue | 214 +++++++++++------- .../Resources/public/vuejs/VisGraph/api.js | 41 +++- .../public/vuejs/VisGraph/components/test.vue | 49 ++++ .../Resources/public/vuejs/VisGraph/i18n.js | 3 +- .../Resources/public/vuejs/VisGraph/store.js | 42 ++-- 6 files changed, 246 insertions(+), 108 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/components/test.vue diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/App.vue index bd7705ca4..c8dcaaa97 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/App.vue @@ -1,4 +1,6 @@ - diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/i18n.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/i18n.js index 1a0f9c106..c2ee09960 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/i18n.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/i18n.js @@ -20,9 +20,10 @@ const visMessages = { between: "entre", and: "et", add_link: "Créer un lien de filiation", - create_link_help: "Pour créer un lien de filiation: cliquez d'abord sur un usager, puis sur un second, précisez ensuite la nature du lien dans le formulaire d'édition.", + create_link_help: "Pour créer un lien de filiation, cliquez d'abord sur un usager, puis sur un second ; précisez ensuite la nature du lien dans le formulaire d'édition.", refresh: "Rafraîchir", screenshot: "Prendre une photo", + choose_relation: "Choisissez le lien de parenté", }, edit: 'Éditer', del: 'Supprimer', diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/store.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/store.js index 12305aa9d..98f188fdf 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/store.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/VisGraph/store.js @@ -78,16 +78,16 @@ const store = createStore({ getParticipationsByCourse: (state) => (course_id) => { const course = state.courses.filter(c => c.id === course_id)[0] const currentParticipations = course.participations.filter(p => p.endDate === null) - console.log('get persons in', course_id, currentParticipations.map(p => p.person.id), - 'with folded', currentParticipations.filter(p => p.person.folded === true).map(p => p.person.id)) + //console.log('get persons in', course_id, currentParticipations.map(p => p.person.id), + // 'with folded', currentParticipations.filter(p => p.person.folded === true).map(p => p.person.id)) return currentParticipations }, getMembersByHousehold: (state) => (household_id) => { const household = state.households.filter(h => h.id === household_id)[0] const currentMembers = household.members.filter(m => household.current_members_id.includes(m.id)) - console.log('get persons in', household_id, currentMembers.map(m => m.person.id), - 'with folded', currentMembers.filter(m => m.person.folded === true).map(m => m.person.id)) + //console.log('get persons in', household_id, currentMembers.map(m => m.person.id), + // 'with folded', currentMembers.filter(m => m.person.folded === true).map(m => m.person.id)) return currentMembers }, @@ -96,28 +96,37 @@ const store = createStore({ * The 2 previous getters return complete array, but folded (missing) persons are not taken into consideration and are not displayed (!?!) * This getter compare input array (participations|members) to personLoadedIds array * and return complete array with folded persons taken into consideration + * + * @param state + * @param array - An array of persons from course or household. + * This array is dirty, melting persons adapted (or not) to vis, with _id and _label. + * @return array - An array of persons mapped and taken in state.persons */ - getWithFoldedPersons: (state) => (array) => { - let withFolded = [] + getPersonsGroup: (state) => (array) => { + let group = [] array.forEach(item => { let id = splitId(item.person.id, 'id') if (state.personLoadedIds.includes(id)) { - withFolded.push(state.persons.filter(person => person._id === id)[0]) + group.push(state.persons.filter(person => person._id === id)[0]) } }) //console.log('array', array.map(item => item.person.id)) - console.log('get withFoldedPersons', withFolded.map(f => f.id)) - return withFolded + console.log('get persons group', group.map(f => f.id)) + return group }, }, mutations: { addPerson(state, [person, options]) { + let debug = '' + /// Debug mode ~ display person_id on visgraph + // uncomment + debug = `\nid ${person.id}` person.group = person.type person._id = person.id person.id = `person_${person.id}` - person.label = `*${person.text}*\n_${getGender(person.gender)} - ${getAge(person.birthdate)}_` + person.label = `*${person.text}*\n_${getGender(person.gender)} - ${getAge(person.birthdate)}_${debug}` // person.folded = false // folded is used for missing persons if (options.folded) { @@ -385,6 +394,8 @@ const store = createStore({ dashes: true, label: getRelationshipLabel(relationship), title: getRelationshipTitle(relationship), + relation: relationship.relation, + reverse: relationship.reverse }) for (let person of [relationship.fromPerson, relationship.toPerson]) { if (!getters.isPersonLoaded(person.id)) { @@ -418,7 +429,7 @@ const store = createStore({ */ unfoldPersonsByCourse({ getters, commit, dispatch }, course) { const participations = getters.getParticipationsByCourse(course.id) - getters.getWithFoldedPersons(participations) + getters.getPersonsGroup(participations) .forEach(person => { if (person.folded === true) { console.log('-=. unfold and expand person', person.id) @@ -436,7 +447,7 @@ const store = createStore({ */ unfoldPersonsByHousehold({ getters, commit, dispatch }, household) { const members = getters.getMembersByHousehold(household.id) - getters.getWithFoldedPersons(members) + getters.getPersonsGroup(members) .forEach(person => { if (person.folded === true) { console.log('-=. unfold and expand person', person.id) @@ -463,10 +474,10 @@ const store = createStore({ throw 'undefined case with this id' } } + let group = getters.getPersonsGroup(personGroup()) if (action === 'add') { commit('addExcludedNode', id) - getters.getWithFoldedPersons(personGroup()) - .forEach(person => { + group.forEach(person => { // countLinks < 2 but parent has just already been added ! if (!getters.isInWhitelist(person.id) && getters.countLinksByNode(person.id) < 1) { commit('addExcludedNode', person.id) @@ -475,8 +486,7 @@ const store = createStore({ } if (action === 'remove') { commit('removeExcludedNode', id) - getters.getWithFoldedPersons(personGroup()) - .forEach(person => { + group.forEach(person => { commit('removeExcludedNode', person.id) }) }