add age in some place and re-organize some usage of the component

This commit is contained in:
Julien Fastré 2022-01-31 12:45:50 +01:00
parent 186b8847d9
commit e04c02055c
13 changed files with 39 additions and 35 deletions

View File

@ -73,7 +73,7 @@ ul.list-suggest {
&.remove-items { &.remove-items {
li { li {
position: relative; position: relative;
span { & > span {
display: block; display: block;
padding-right: 1.75rem; padding-right: 1.75rem;
@include remove_link; @include remove_link;

View File

@ -42,6 +42,3 @@
{% endif %} {% endif %}
></span> ></span>
{{ encore_entry_script_tags('vue_onthefly') }}
{{ encore_entry_link_tags('vue_onthefly') }}

View File

@ -13,6 +13,7 @@
{{ encore_entry_link_tags('mod_ckeditor5') }} {{ encore_entry_link_tags('mod_ckeditor5') }}
{{ encore_entry_link_tags('chill') }} {{ encore_entry_link_tags('chill') }}
{{ encore_entry_link_tags('mod_blur') }} {{ encore_entry_link_tags('mod_blur') }}
{{ encore_entry_link_tags('vue_onthefly') }}
{% block css %}<!-- nothing added to css -->{% endblock %} {% block css %}<!-- nothing added to css -->{% endblock %}
</head> </head>
@ -94,6 +95,7 @@
{{ encore_entry_script_tags('mod_ckeditor5') }} {{ encore_entry_script_tags('mod_ckeditor5') }}
{{ encore_entry_script_tags('mod_blur') }} {{ encore_entry_script_tags('mod_blur') }}
{{ encore_entry_script_tags('chill') }} {{ encore_entry_script_tags('chill') }}
{{ encore_entry_script_tags('vue_onthefly') }}
<script type="text/javascript"> <script type="text/javascript">
window.addEventListener('DOMContentLoaded', function(e) { window.addEventListener('DOMContentLoaded', function(e) {

View File

@ -4,7 +4,7 @@
<i class="fa fa-home fa-fw text-light" :title="$t('persons_associated.show_household_number', { id: h.id })"></i> <i class="fa fa-home fa-fw text-light" :title="$t('persons_associated.show_household_number', { id: h.id })"></i>
</a> </a>
<span v-for="person in h.persons" class="me-1" :key="person.id"> <span v-for="person in h.persons" class="me-1" :key="person.id">
<on-the-fly :type="person.type" :id="person.id" :buttonText="person.text" :displayBadge="'true' === 'true'" action="show"></on-the-fly> <on-the-fly :type="person.type" :id="person.id" :buttonText="person.textAge" :displayBadge="'true' === 'true'" action="show"></on-the-fly>
</span> </span>
</span> </span>
</template> </template>

View File

@ -45,7 +45,8 @@
addInfo: true, addInfo: true,
hLevel: 3, hLevel: 3,
isMultiline: true, isMultiline: true,
isConfidential: false isConfidential: false,
addAge: true,
}" }"
> >
<template v-slot:record-actions> <template v-slot:record-actions>

View File

@ -11,7 +11,7 @@
<ul class="list-suggest remove-items inline"> <ul class="list-suggest remove-items inline">
<li v-for="c in concerned" :key="c.person.id" @click="removeConcerned(c)"> <li v-for="c in concerned" :key="c.person.id" @click="removeConcerned(c)">
<span>{{ c.person.text }}</span> <span><person-text :person="c.person"></person-text></span>
</li> </li>
</ul> </ul>
@ -57,12 +57,14 @@
import { mapState, mapGetters } from 'vuex'; import { mapState, mapGetters } from 'vuex';
import AddPersons from 'ChillPersonAssets/vuejs/_components/AddPersons.vue'; import AddPersons from 'ChillPersonAssets/vuejs/_components/AddPersons.vue';
import PersonRenderBox from 'ChillPersonAssets/vuejs/_components/Entity/PersonRenderBox.vue'; import PersonRenderBox from 'ChillPersonAssets/vuejs/_components/Entity/PersonRenderBox.vue';
import PersonText from 'ChillPersonAssets/vuejs/_components/Entity/PersonText.vue';
export default { export default {
name: 'Concerned', name: 'Concerned',
components: { components: {
AddPersons, AddPersons,
PersonRenderBox, PersonRenderBox,
PersonText,
}, },
computed: { computed: {
...mapState([ ...mapState([

View File

@ -87,7 +87,7 @@ export default {
& > input { & > input {
margin-right: 0.8em; margin-right: 0.8em;
} }
span:not(.name) { > span:not(.name) {
margin-left: 0.5em; margin-left: 0.5em;
opacity: 0.5; opacity: 0.5;
font-size: 90%; font-size: 90%;

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="container"> <div class="container">
<span class="name"> <span class="name">
{{ item.result.text }} <person-text :person="item.result"></person-text>
</span> </span>
<span class="birthday" v-if="hasBirthdate"> <span class="birthday" v-if="hasBirthdate">
{{ $d(item.result.birthdate.datetime, 'short') }} {{ $d(item.result.birthdate.datetime, 'short') }}
@ -28,12 +28,14 @@
<script> <script>
import OnTheFly from 'ChillMainAssets/vuejs/OnTheFly/components/OnTheFly.vue'; import OnTheFly from 'ChillMainAssets/vuejs/OnTheFly/components/OnTheFly.vue';
import BadgeEntity from 'ChillMainAssets/vuejs/_components/BadgeEntity.vue'; import BadgeEntity from 'ChillMainAssets/vuejs/_components/BadgeEntity.vue';
import PersonText from 'ChillPersonAssets/vuejs/_components/Entity/PersonText.vue';
export default { export default {
name: 'SuggestionPerson', name: 'SuggestionPerson',
components: { components: {
OnTheFly, OnTheFly,
BadgeEntity BadgeEntity,
PersonText,
}, },
props: ['item'], props: ['item'],
computed: { computed: {

View File

@ -2,7 +2,7 @@
<div class="container tpartycontainer"> <div class="container tpartycontainer">
<div class="tparty-identification"> <div class="tparty-identification">
<span class="name"> <span class="name">
{{ item.result.text }} {{ item.result.text }}&nbsp;
</span> </span>
<span class="location"> <span class="location">
<template v-if="hasAddress"> <template v-if="hasAddress">

View File

@ -9,6 +9,7 @@
<div :class="'denomination h' + options.hLevel"> <div :class="'denomination h' + options.hLevel">
<a v-if="options.addLink === true" :href="getUrl"> <a v-if="options.addLink === true" :href="getUrl">
<!-- use person-text here to avoid code duplication ? TODO -->
<span class="firstname">{{ person.firstName }}</span> <span class="firstname">{{ person.firstName }}</span>
<span class="lastname">{{ person.lastName }}</span> <span class="lastname">{{ person.lastName }}</span>
<span v-if="person.altNames && options.addAltNames == true" class="altnames"> <span v-if="person.altNames && options.addAltNames == true" class="altnames">
@ -16,6 +17,7 @@
</span> </span>
</a> </a>
<!-- use person-text here to avoid code duplication ? TODO -->
<span class="firstname">{{ person.firstName }}</span> <span class="firstname">{{ person.firstName }}</span>
<span class="lastname">{{ person.lastName }}</span> <span class="lastname">{{ person.lastName }}</span>
<span v-if="person.deathdate" class="deathdate"> ()</span> <span v-if="person.deathdate" class="deathdate"> ()</span>
@ -127,7 +129,6 @@
</span> </span>
<person-text :person="person"></person-text> <person-text :person="person"></person-text>
<span v-if="person.deathdate" class="deathdate"> ()</span>
</a> </a>
<span v-else> <span v-else>
<span v-if="options.isHolder" class="fa-stack fa-holder" :title="$t('renderbox.holder')"> <span v-if="options.isHolder" class="fa-stack fa-holder" :title="$t('renderbox.holder')">
@ -202,24 +203,6 @@ export default {
getUrl: function() { getUrl: function() {
return `/fr/person/${this.person.id}/general`; return `/fr/person/${this.person.id}/general`;
}, },
// getAge: function() {
// // TODO only one abstract function
// if(this.person.birthdate && !this.person.deathdate){
// const birthday = new Date(this.person.birthdate.datetime)
// const now = new Date()
// return (now.getFullYear() - birthday.getFullYear())
// } else if(this.person.birthdate && this.person.deathdate){
// const birthday = new Date(this.person.birthdate.datetime)
// const deathdate = new Date(this.person.deathdate.datetime)
// return (deathdate.getFullYear() - birthday.getFullYear())
// } else if(!this.person.birthdate && this.person.deathdate.datetime) {
// // todo: change this
// return "Age unknown"
// } else {
// // todo: change this
// return "Age unknown"
// }
// },
getCurrentHouseholdUrl: function() { getCurrentHouseholdUrl: function() {
let returnPath = this.returnPath ? `?returnPath=${this.returnPath}` : ``; let returnPath = this.returnPath ? `?returnPath=${this.returnPath}` : ``;
return `/fr/person/household/${this.person.current_household_id}/summary${returnPath}` return `/fr/person/household/${this.person.current_household_id}/summary${returnPath}`

View File

@ -6,8 +6,8 @@
<span v-if="person.altNames && person.altNames.length > 0" class="altnames"> <span v-if="person.altNames && person.altNames.length > 0" class="altnames">
<span :class="'altname altname-' + altNameKey"> ({{ altNameLabel }})</span> <span :class="'altname altname-' + altNameKey"> ({{ altNameLabel }})</span>
</span> </span>
<span class="age" v-if="person.birthdate !== null && person.deathdate === null">{{ $tc('renderbox.years_old', person.age) }}</span> <span class="age" v-if="this.addAge && person.birthdate !== null && person.deathdate === null">{{ $tc('renderbox.years_old', person.age) }}</span>
<span v-else-if="person.deathdate !== null"> ()</span> <span v-else-if="this.addAge && person.deathdate !== null">&nbsp;()</span>
</span> </span>
</template> </template>
@ -15,7 +15,21 @@
export default { export default {
name: "PersonText", name: "PersonText",
props: ['person', 'isCut'], props: {
person: {
required: true,
},
isCut: {
type: Boolean,
required: false,
default: false
},
addAge: {
type: Boolean,
required: false,
default: true,
}
},
computed: { computed: {
altNameLabel: function() { altNameLabel: function() {
for(let i = 0; i < this.person.altNames.length; i++){ for(let i = 0; i < this.person.altNames.length; i++){

View File

@ -179,7 +179,8 @@ class PersonJsonNormalizer implements
return [ return [
'type' => 'person', 'type' => 'person',
'id' => $person->getId(), 'id' => $person->getId(),
'text' => $this->render->renderString($person), 'text' => $this->render->renderString($person, ['addAge' => false]),
'textAge' => $this->render->renderString($person, ['addAge' => true]),
'firstName' => $person->getFirstName(), 'firstName' => $person->getFirstName(),
'lastName' => $person->getLastName(), 'lastName' => $person->getLastName(),
'birthdate' => $this->normalizer->normalize($person->getBirthdate(), $format, $context), 'birthdate' => $this->normalizer->normalize($person->getBirthdate(), $format, $context),

View File

@ -76,7 +76,9 @@ class PersonRender extends AbstractChillEntityRender
*/ */
public function renderString($person, array $options): string public function renderString($person, array $options): string
{ {
if (null !== $person->getAge() && $person->getDeathDate() === null) { $options = array_merge(['addAge' => true], $options);
if (null !== $person->getAge() && $person->getDeathDate() === null && $options['addAge']) {
return $person->getFirstName() . ' ' . $person->getLastName() return $person->getFirstName() . ' ' . $person->getLastName()
. $this->addAltNames($person, false) . ' (' . $this->translator->trans('years_old', ['age' => $person->getAge()]) . ')'; . $this->addAltNames($person, false) . ' (' . $this->translator->trans('years_old', ['age' => $person->getAge()]) . ')';
} }