Merge branch 'household_filiation' of gitlab.com:Chill-Projet/chill-bundles into household_filiation

This commit is contained in:
Julie Lenaerts 2021-10-29 15:57:06 +02:00
commit b60b1cb668
6 changed files with 81 additions and 45 deletions

View File

@ -901,13 +901,19 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
* return gender as a Numeric form. * return gender as a Numeric form.
* This is used for translations * This is used for translations
* @return int * @return int
* @deprecated Keep for legacy. Used in Chill 1.5 for feminize before icu translations
*/ */
public function getGenderNumeric() public function getGenderNumeric()
{ {
if ($this->getGender() == self::FEMALE_GENDER) { switch ($this->getGender()) {
return 1; case self::FEMALE_GENDER:
} else { return 1;
return 0; case self::MALE_GENDER:
return 0;
case self::BOTH_GENDER:
return 2;
default:
return -1;
} }
} }

View File

@ -20,7 +20,9 @@ const makeFetch = (method, url, body) => {
} }
if (response.status === 422) { if (response.status === 422) {
return response.json(); return response.json().then(violations => {
throw ValidationException(violations)
});
} }
throw { throw {
@ -33,13 +35,22 @@ const makeFetch = (method, url, body) => {
}); });
} }
/**
* @param violations
* @constructor
*/
const ValidationException = (violations) => {
this.violations = violations
this.name = 'ValidationException'
}
/** /**
* @function getFetch * @function getFetch
* @param url * @param url
* @returns {Promise<Response>} * @returns {Promise<Response>}
*/ */
const getFetch = (url) => { const getFetch = (url) => {
return makeFetch('GET', url, null); return makeFetch('GET', url, null)
} }
/** /**
@ -49,7 +60,7 @@ const getFetch = (url) => {
* @returns {Promise<Response>} * @returns {Promise<Response>}
*/ */
const postFetch = (url, body) => { const postFetch = (url, body) => {
return makeFetch('POST', url, body); return makeFetch('POST', url, body)
} }
/** /**
@ -59,7 +70,7 @@ const postFetch = (url, body) => {
* @returns {Promise<Response>} * @returns {Promise<Response>}
*/ */
const patchFetch = (url, body) => { const patchFetch = (url, body) => {
return makeFetch('PATCH', url, body); return makeFetch('PATCH', url, body)
} }

View File

@ -6,6 +6,11 @@ const visMessages = {
Holder: 'Titulaire', Holder: 'Titulaire',
Legend: 'Calques', Legend: 'Calques',
concerned: 'concerné', concerned: 'concerné',
both: 'neutre, non binaire',
woman: 'féminin',
man: 'masculin',
years: 'ans'
}, },
edit: 'Éditer', edit: 'Éditer',
del: 'Supprimer', del: 'Supprimer',

View File

@ -1,6 +1,6 @@
import { createStore } from 'vuex' import { createStore } from 'vuex'
import { getHouseholdByPerson, getCoursesByPerson, getRelationshipsByPerson } from './api' import { getHouseholdByPerson, getCoursesByPerson, getRelationshipsByPerson } from './api'
import { adapt2vis, getHouseholdLabel, getHouseholdWidth, getRelationshipLabel } from './vis-network' import { adapt2vis, getHouseholdLabel, getHouseholdWidth, getRelationshipLabel, getRelationshipTitle } from './vis-network'
import { visMessages } from './i18n' import { visMessages } from './i18n'
const debug = process.env.NODE_ENV !== 'production' const debug = process.env.NODE_ENV !== 'production'
@ -115,7 +115,6 @@ const store = createStore({
* 1) Add a person in state * 1) Add a person in state
* @param Person person * @param Person person
*/ */
addPerson({ commit, dispatch }, person) { addPerson({ commit, dispatch }, person) {
commit('markPersonLoaded', person.id) commit('markPersonLoaded', person.id)
commit('addPerson', person) commit('addPerson', person)
@ -127,7 +126,9 @@ const store = createStore({
* @param Person person * @param Person person
*/ */
fetchInfoForPerson({ dispatch }, person) { fetchInfoForPerson({ dispatch }, person) {
dispatch('fetchHouseholdForPerson', person) if (null !== person.current_household_id) {
dispatch('fetchHouseholdForPerson', person)
}
dispatch('fetchCoursesByPerson', person) dispatch('fetchCoursesByPerson', person)
dispatch('fetchRelationshipByPerson', person) dispatch('fetchRelationshipByPerson', person)
}, },
@ -226,7 +227,7 @@ const store = createStore({
arrows: 'from', arrows: 'from',
color: 'orange', color: 'orange',
font: { color: 'darkorange' }, font: { color: 'darkorange' },
label: visMessages.fr.visgraph.concerned, //label: visMessages.fr.visgraph.concerned,
}) })
if (!getters.isPersonLoaded(p.person.id)) { if (!getters.isPersonLoaded(p.person.id)) {
console.log(' person is not loaded', p.person.id) console.log(' person is not loaded', p.person.id)
@ -277,9 +278,11 @@ const store = createStore({
to: `person_${r.toPerson.id}`, to: `person_${r.toPerson.id}`,
id: 'r' + r.id + '_p' + r.fromPerson.id + '_p' + r.toPerson.id, id: 'r' + r.id + '_p' + r.fromPerson.id + '_p' + r.toPerson.id,
arrows: 'to', arrows: 'to',
color: 'lightblue', dashes: true, color: 'lightblue',
font: { color: '#33839d' }, font: { color: '#33839d' },
dashes: true,
label: getRelationshipLabel(r, false), label: getRelationshipLabel(r, false),
title: getRelationshipTitle(r),
}) })
for (let person of [r.fromPerson, r.toPerson]) { for (let person of [r.fromPerson, r.toPerson]) {
if (!getters.isPersonLoaded(person.id)) { if (!getters.isPersonLoaded(person.id)) {

View File

@ -128,7 +128,7 @@ window.options = {
background: 'none', background: 'none',
strokeWidth: 2, // px strokeWidth: 2, // px
strokeColor: '#ffffff', strokeColor: '#ffffff',
align: 'horizontal', align: 'middle',
multi: false, multi: false,
vadjust: 0, vadjust: 0,
}, },
@ -154,15 +154,9 @@ window.options = {
} }
}, },
household: { household: {
/*
shape: 'dot',
*/
color: 'pink' color: 'pink'
}, },
accompanying_period: { accompanying_period: {
/*
shape: 'triangle',
*/
color: 'orange', color: 'orange',
}, },
} }
@ -179,7 +173,8 @@ const adapt2vis = (entity) => {
switch (entity.type) { switch (entity.type) {
case 'person': case 'person':
entity._id = entity.id entity._id = entity.id
entity.label = `${entity.text}\n` + getGender(entity.gender_numeric) +' - '+ getAge(entity.birthdate) entity.label = `${entity.text}\n` + getGender(entity.gender) +' - '+ getAge(entity.birthdate)
//entity.title = `${entity.text}`
entity.id = `person_${entity.id}` entity.id = `person_${entity.id}`
break break
case 'household': case 'household':
@ -195,29 +190,42 @@ const adapt2vis = (entity) => {
case 'relationship': case 'relationship':
entity._id = entity.id entity._id = entity.id
entity.id = `relationship_${entity.id}` entity.id = `relationship_${entity.id}`
break
default:
throw 'entity undefined'
} }
return entity return entity
} }
/**
* @param gender
* @returns {string}
*/
const getGender = (gender) => { const getGender = (gender) => {
switch (gender) { switch (gender) {
case 0: case 'both':
return 'N' return visMessages.fr.visgraph.both
case 1: case 'woman':
return 'M' return visMessages.fr.visgraph.woman
case 2: case 'man':
return 'F' return visMessages.fr.visgraph.man
default: default:
throw 'gender undefined' throw 'gender undefined'
} }
} }
/**
* TODO Repeat getAge() in PersonRenderBox.vue
* @param birthdate
* @returns {string|null}
*/
const getAge = (birthdate) => { const getAge = (birthdate) => {
if (null === birthdate) { if (null === birthdate) {
return null return null
} }
const birthday = new Date(birthdate.datetime) const birthday = new Date(birthdate.datetime)
const now = new Date() const now = new Date()
return (now.getFullYear() - birthday.getFullYear()) + ' ans' return (now.getFullYear() - birthday.getFullYear()) + ' '+ visMessages.fr.visgraph.years
} }
/** /**
@ -235,24 +243,15 @@ const getHouseholdLabel = (member) => {
* Return edge width for member (depends of position in household) * Return edge width for member (depends of position in household)
* @param member * @param member
* @returns integer (width) * @returns integer (width)
*
* TODO
* to use: holder, shareHousehold
* not use: ordering, position (-> null)
*/ */
const getHouseholdWidth = (member) => { const getHouseholdWidth = (member) => {
switch (member.position.ordering) { if (member.holder) {
case 1: //adult return 5
if (member.holder) {
return 6
}
return 3
case 2: //children
case 3: //children out of household
return 1
default:
throw 'Ordering not supported'
} }
if (member.shareHousehold) {
return 2
}
return 1
} }
/** /**
@ -264,9 +263,22 @@ const getRelationshipLabel = (relationship, reverse) => {
return (!reverse) ? relationship.relation.title.fr : relationship.relation.reverseTitle.fr return (!reverse) ? relationship.relation.title.fr : relationship.relation.reverseTitle.fr
} }
/**
* Return title edge
* @param relationship
* @returns string
*/
const getRelationshipTitle = (relationship) => {
return relationship.relation.title.fr + ': '
+ relationship.fromPerson.text + '\n'
+ relationship.relation.reverseTitle.fr + ': '
+ relationship.toPerson.text
}
export { export {
adapt2vis, adapt2vis,
getHouseholdLabel, getHouseholdLabel,
getHouseholdWidth, getHouseholdWidth,
getRelationshipLabel getRelationshipLabel,
getRelationshipTitle
} }

View File

@ -79,7 +79,6 @@ class PersonNormalizer implements
'mobilenumber' => $person->getMobilenumber(), 'mobilenumber' => $person->getMobilenumber(),
'altNames' => $this->normalizeAltNames($person->getAltNames()), 'altNames' => $this->normalizeAltNames($person->getAltNames()),
'gender' => $person->getGender(), 'gender' => $person->getGender(),
'gender_numeric' => $person->getGenderNumeric(),
'current_household_address' => $this->normalizer->normalize($person->getCurrentHouseholdAddress()), 'current_household_address' => $this->normalizer->normalize($person->getCurrentHouseholdAddress()),
'current_household_id' => $household ? $this->normalizer->normalize($household->getId()) : null, 'current_household_id' => $household ? $this->normalizer->normalize($household->getId()) : null,
]; ];