render box address, remove macro address, refactoring (wip)

This commit is contained in:
Mathieu Jaumotte 2021-07-29 16:51:46 +02:00
parent 55ac730c18
commit 6dac130844
9 changed files with 155 additions and 144 deletions

View File

@ -11,3 +11,38 @@ section.chill-entity {
flex-grow: 1; flex-shrink: 1; flex-basis: auto; flex-grow: 1; flex-shrink: 1; flex-basis: auto;
} }
} }
// specific rules
// address render_box
div.chill-entity {
&.entity-address {
div.noaddress {}
div.address {
margin: 0.7em 0;
font-size: 98%;
font-variant: small-caps;
&.multiline {
p {
display: block;
}
}
p {
display: inline-block;
margin: 0 0 0 1.5em;
text-indent: -1.5em;
&.street {
&.street1 {}
&.street2, &.streetnumber {}
}
&.postalcode {
span.code {}
span.name {}
}
&.country {}
}
}
span.address-since {}
}
}

View File

@ -1,16 +1,36 @@
<div class="chill_address"> {#
Template to render an address
OPTIONS
* has_no_address bool
* multiline bool
* with_valid_from bool
#}
<div class="chill-entity entity-address">
{% if options['has_no_address'] == true and address.isNoAddress == true %} {% if options['has_no_address'] == true and address.isNoAddress == true %}
<div class="chill_address_is_noaddress">{{ 'address.consider homeless'|trans }}</div> <div class="noaddress">
{{ 'address.consider homeless'|trans }}
</div>
{% endif %}
<div class="address{% if options['multiline'] %} multiline{% endif %}">
{% if address.street is not empty %}
<p class="street street1">{{ address.street }}</p>
{% endif %}
{% if address.streetNumber is not empty %}
<p class="street street2 streetnumber">{{ address.streetNumber }}</p>
{% endif %} {% endif %}
<div class="chill_address_address {% if options['multiline'] %}chill_address_address--multiline{% endif %}">
{% if address.street is not empty %}<p class="street street1">{{ address.street }}</p>{% endif %}
{% if address.streetNumber is not empty %}<p class="street street2">{{ address.streetNumber }}</p>{% endif %}
{% if address.postCode is not empty %} {% if address.postCode is not empty %}
<p class="postalCode"><span class="code">{{ address.postCode.code }}</span> <span class="name">{{ address.postCode.name }}</span></p> <p class="postalcode">
<span class="code">{{ address.postCode.code }}</span>
<span class="name">{{ address.postCode.name }}</span>
</p>
<p class="country">{{ address.postCode.country.name|localize_translatable_string }}</p> <p class="country">{{ address.postCode.country.name|localize_translatable_string }}</p>
{% endif %} {% endif %}
</div> </div>
{%- if options['with_valid_from'] == true -%}
<span class="address_since">{{ 'Since %date%'|trans( { '%date%' : address.validFrom|format_date('long') } ) }}</span> {%- if options['with_valid_from'] == true -%}
{%- endif -%} <span class="address-since">
{{ 'Since %date%'|trans( { '%date%' : address.validFrom|format_date('long') } ) }}
</span>
{%- endif -%}
</div> </div>

View File

@ -1,21 +0,0 @@
{%- macro _render(address, options) -%}
{%- set options = { 'with_valid_from' : true }|merge(options|default({})) -%}
{%- set options = { 'has_no_address' : false }|merge(options|default({})) -%}
{%- set options = { 'with_icon' : false }|merge(options|default({})) -%}
<div class="chill_address">
{% if options['has_no_address'] == true and address.isNoAddress == true %}
<div class="chill_address_is_noaddress">{{ 'address.consider homeless'|trans }}</div>
{% endif %}
<div class="chill_address_address">{% if options['with_icon'] == true %}<i class="fa fa-fw fa-map-marker"></i>{% endif %}
{% if address.street is not empty %}<p class="street street1">{{ address.street }}</p>{% endif %}
{% if address.streetNumber is not empty %}<p class="street street2">{{ address.streetNumber }}</p>{% endif %}
{% if address.postCode is not empty %}
<p class="postalCode"><span class="code">{{ address.postCode.code }}</span> <span class="name">{{ address.postCode.name }}</span></p>
<p class="country">{{ address.postCode.country.name|localize_translatable_string }}</p>
{% endif %}
</div>
{%- if options['with_valid_from'] == true -%}
<span class="address_since">{{ 'Since %date%'|trans( { '%date%' : address.validFrom|format_date('long') } ) }}</span>
{%- endif -%}
</div>
{%- endmacro -%}

View File

@ -1,7 +1,5 @@
{% extends '@ChillPerson/AccompanyingCourse/layout.html.twig' %} {% extends '@ChillPerson/AccompanyingCourse/layout.html.twig' %}
{% import '@ChillMain/Address/macro.html.twig' as address %}
{% block title %} {% block title %}
{{ 'Resume Accompanying Course'|trans }} {{ 'Resume Accompanying Course'|trans }}
{% endblock %} {% endblock %}

View File

@ -16,8 +16,6 @@
#} #}
{% extends "@ChillPerson/Person/layout.html.twig" %} {% extends "@ChillPerson/Person/layout.html.twig" %}
{% import '@ChillMain/Address/macro.html.twig' as address_macros %}
{% set activeRouteKey = '' %} {% set activeRouteKey = '' %}
{% block title %}{{ 'Addresses history for %name%'|trans({ '%name%': person.firstName ~ ' ' ~ person.lastName } ) }}{% endblock %} {% block title %}{{ 'Addresses history for %name%'|trans({ '%name%': person.firstName ~ ' ' ~ person.lastName } ) }}{% endblock %}
@ -43,23 +41,9 @@
{% if address.isNoAddress == true %} {% if address.isNoAddress == true %}
<div class="chill_address_is_noaddress">{{ 'address.consider homeless'|trans }}</div> <div class="chill_address_is_noaddress">{{ 'address.consider homeless'|trans }}</div>
{% else %} {% else %}
{{ address|chill_entity_render_box({
{% if address.street is not empty %} 'multiline': false, 'with_valid_from': false
<div class="street"> }) }}
<span class="streetNumber">{{ address.street }}</span>
{% if address.streetNumber is not empty %}
<span class="streetNumber">, {{ address.streetNumber }}</span>
{% endif %}
</div>
{% endif %}
{% if address.postCode is not empty %}
<div class="postCode">
<span>{{ address.postCode.code }}</span> <span>{{ address.postCode.name }}</span>
<span class="country">({{ address.postCode.country.name|localize_translatable_string }})</span>
</div>
{% endif %}
{% endif %} {% endif %}
<ul class="record_actions"> <ul class="record_actions">

View File

@ -16,8 +16,6 @@
#} #}
{% extends "@ChillPerson/Person/layout.html.twig" %} {% extends "@ChillPerson/Person/layout.html.twig" %}
{% import '@ChillMain/Address/macro.html.twig' as address %}
{% set activeRouteKey = 'chill_person_view' %} {% set activeRouteKey = 'chill_person_view' %}
{# {#
@ -171,7 +169,7 @@ This view should receive those arguments:
<dt>{{ 'Address'|trans }}</dt> <dt>{{ 'Address'|trans }}</dt>
<dd> <dd>
{%- if person.lastAddress is not empty -%} {%- if person.lastAddress is not empty -%}
{{ address._render(person.lastAddress, {'has_no_address': true}) }} {{ person.lastAddress|chill_entity_render_box({'has_no_address': true}) }}
<ul class="list-inline text-right mt-2"> <ul class="list-inline text-right mt-2">
<li class="list-inline-item"> <li class="list-inline-item">

View File

@ -1,7 +1,5 @@
{%- macro details(person, options) -%} {%- macro details(person, options) -%}
{% import '@ChillMain/Address/macro.html.twig' as address %}
<ul> <ul>
<li><b>{{ 'gender'|trans }}</b>: <li><b>{{ 'gender'|trans }}</b>:
{{ person.gender|trans }}</li> {{ person.gender|trans }}</li>
@ -24,7 +22,9 @@
<li><b>{{ 'memo'|trans }}</b>: <li><b>{{ 'memo'|trans }}</b>:
{{ person.memo }}</li> {{ person.memo }}</li>
<li><b>{{ 'address'|trans }}</b>: <li><b>{{ 'address'|trans }}</b>:
{%- if person.lastAddress is not empty -%}{{ address._render(person.lastAddress, {'with_valid_from': false}) }}{% endif %}</li> {%- if person.lastAddress is not empty -%}
{{ person.lastAddress|chill_entity_render_box({'with_valid_from': false}) }}
{% endif %}</li>
<li><b>{{ 'spokenLanguages'|trans }}</b>: <li><b>{{ 'spokenLanguages'|trans }}</b>:
{% for lang in person.spokenLanguages %}{{ lang.name|localize_translatable_string }}{% if not loop.last %},{% endif %}{% endfor %}</li> {% for lang in person.spokenLanguages %}{{ lang.name|localize_translatable_string }}{% if not loop.last %},{% endif %}{% endfor %}</li>
<li><b>{{ 'contactInfo'|trans }}</b>: <li><b>{{ 'contactInfo'|trans }}</b>:

View File

@ -25,7 +25,6 @@ use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper; use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
use Symfony\Component\Templating\EngineInterface; use Symfony\Component\Templating\EngineInterface;
/** /**
* Render a Person * Render a Person
* *
@ -83,7 +82,7 @@ class PersonRender extends AbstractChillEntityRender
.$this->addAltNames($person, false); .$this->addAltNames($person, false);
} }
protected function addAltNames(Person $person, bool $addSpan) protected function addAltNames(Person $person, bool $addSpan): string
{ {
$str = ''; $str = '';
@ -101,7 +100,7 @@ class PersonRender extends AbstractChillEntityRender
$str.= " "; $str.= " ";
} }
if ($addSpan) { if ($addSpan) {
$str .= '<span class="chill-entity__person__alt-name chill-entity__person__altname--'.$altName->getKey().'">'; $str .= '<span class="altname altname-'.$altName->getKey().'">';
} }
$str .= $altName->getLabel(); $str .= $altName->getLabel();

View File

@ -1,7 +1,5 @@
{% extends "@ChillMain/layout.html.twig" %} {% extends "@ChillMain/layout.html.twig" %}
{% import '@ChillMain/Address/macro.html.twig' as address %}
{% set title_ = 'Show third party %name%'|trans({'%name%' : thirdParty.name }) %} {% set title_ = 'Show third party %name%'|trans({'%name%' : thirdParty.name }) %}
{% block title title_ %} {% block title title_ %}
@ -38,7 +36,7 @@
{% if thirdParty.address == null %} {% if thirdParty.address == null %}
<span class="chill-no-data-statement">{{ 'No address given'|trans }}</span> <span class="chill-no-data-statement">{{ 'No address given'|trans }}</span>
{% else %} {% else %}
{{ address._render(thirdParty.address, {'with_valid_from': false }) }} {{ thirdParty.address|chill_entity_render_box({'with_valid_from': false }) }}
{% endif %} {% endif %}
</dd> </dd>