render_box address: new options and render modes

This commit is contained in:
Mathieu Jaumotte 2021-07-30 14:17:16 +02:00
parent 08cd6c81f2
commit 31c5c8b52a
5 changed files with 153 additions and 48 deletions

View File

@ -47,27 +47,33 @@ section.chill-entity {
div.entity-bloc {} div.entity-bloc {}
} }
// address render_box // used for addresses
&.entity-address { &.entity-address {
div.noaddress {}
div.address { .address {
margin: 0.7em 0;
font-size: 98%; font-size: 98%;
font-variant: small-caps; font-variant: small-caps;
&.multiline { &.multiline {
margin: 0.7em 0;
p { p {
display: block; display: block;
} }
} }
&.delimiter {
p:not(:first-child):before {
content: '';
}
}
p { p {
display: inline-block; display: inline-block;
margin: 0 0 0 1.5em; margin: 0 0 0 1.5em;
text-indent: -1.5em; text-indent: -1.5em;
&.street { &.street {
&.street1 {} span.streetnumber {
&.street2, &.streetnumber {} &::before { content: ", "; }
}
} }
&.postalcode { &.postalcode {
span.code {} span.code {}
@ -76,6 +82,10 @@ section.chill-entity {
&.country {} &.country {}
} }
} }
span.address-since {}
.noaddress {}
span.address-since,
span.address-until {}
} }
} }

View File

@ -1,36 +0,0 @@
{#
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 %}
<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 %}
{% 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>

View File

@ -0,0 +1,121 @@
{#
Template to render an address
OPTIONS
* render string ['list'|'bloc'|'inline']
* with_valid_from bool start date
* with_valid_to bool end date
* with_picto bool add a forkawesome pictogram
* with_delimiter bool add a delimiter between fragments
* has_no_address bool
* multiline bool multiline display
* extended_infos bool add extra informations (step, floor, etc.)
#}
{% macro raw(address, options) %}
{% if address.street is not empty %}
<p class="street">{{ address.street }}
{% if address.streetNumber is not empty %}
<span class="streetnumber">{{ address.streetNumber }}</span>
{% endif %}
</p>
{% endif %}
{% if options['extended_infos'] %}
{{ _self.extended(address, options) }}
{% 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 %}
{% endmacro %}
{% macro extended(address, options) %}
{% if address.floor is not empty %}
<span class="floor">{{ address.floor }}</span>
{% endif %}
{% if address.corridor is not empty %}
<span class="corridor">{{ address.corridor }}</span>
{% endif %}
{% if address.steps is not empty %}
<span class="steps">{{ address.steps }}</span>
{% endif %}
{% if address.buildingName is not empty %}
<span class="buildingName">{{ address.buildingName }}</span>
{% endif %}
{% if address.flat is not empty %}
<span class="flat">{{ address.flat }}</span>
{% endif %}
{% if address.distribution is not empty %}
<span class="distribution">{{ address.distribution }}</span>
{% endif %}
{% if address.extra is not empty %}
<span class="extra">{{ address.extra }}</span>
{% endif %}
{% endmacro %}
{% macro inline(address, options) %}
{% if options['has_no_address'] == true and address.isNoAddress == true %}
<span class="noaddress">
{{ 'address.consider homeless'|trans }}
</span>
{% else %}
<span class="address{% if options['multiline'] %} multiline{% endif %}{% if options['with_delimiter'] %} delimiter{% endif %}">
{{ _self.raw(address, options) }}
</span>
{% endif %}
{{ _self.validity(address, options) }}
{% endmacro %}
{% macro validity(address, options) %}
{%- if options['with_valid_from'] == true -%}
<span class="address-since">
{{ 'Since %date%'|trans( { '%date%' : address.validFrom|format_date('long') } ) }}
</span>
{%- endif -%}
{%- if options['with_valid_to'] == true -%}
<span class="address-until">
{{ 'Until %date%'|trans( { '%date%' : address.validTo|format_date('long') } ) }}
</span>
{%- endif -%}
{% endmacro %}
{%- if render == 'list' -%}
<li class="chill-entity entity-address">
{% if options['with_picto'] %}
<i class="fa fa-li fa-map-marker"></i>
{% endif %}
{{ _self.inline(address, options) }}
</li>
{%- endif -%}
{%- if render == 'inline' -%}
<span class="chill-entity entity-address">
{% if options['with_picto'] %}
<i class="fa fa-fw fa-map-marker"></i>
{% endif %}
{{ _self.inline(address, options) }}
</span>
{%- endif -%}
{%- if render == 'bloc' -%}
<div class="chill-entity entity-address">
{% if options['has_no_address'] == true and address.isNoAddress == true %}
<div class="noaddress">
{{ 'address.consider homeless'|trans }}
</div>
{% else %}
<div class="address{% if options['multiline'] %} multiline{% endif %}{% if options['with_delimiter'] %} delimiter{% endif %}">
{% if options['with_picto'] %}
<i class="fa fa-fw fa-map-marker"></i>
{% endif %}
{{ _self.raw(address, options) }}
</div>
{% endif %}
{{ _self.validity(address, options) }}
</div>
{%- endif -%}

View File

@ -10,16 +10,20 @@ class AddressRender implements ChillEntityRenderInterface
private EngineInterface $templating; private EngineInterface $templating;
public const DEFAULT_OPTIONS = [ public const DEFAULT_OPTIONS = [
'with_valid_from' => true, 'with_valid_from' => false,
'with_valid_to' => false,
'with_picto' => false,
'with_delimiter' => false,
'has_no_address' => false, 'has_no_address' => false,
'multiline' => true, 'multiline' => true,
'extended_infos' => false
]; ];
public function __construct(EngineInterface $templating) public function __construct(EngineInterface $templating)
{ {
$this->templating = $templating; $this->templating = $templating;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -56,11 +60,12 @@ class AddressRender implements ChillEntityRenderInterface
*/ */
public function renderBox($addr, array $options): string public function renderBox($addr, array $options): string
{ {
$options = \array_merge(self::DEFAULT_OPTIONS, $options); $options = \array_merge(self::DEFAULT_OPTIONS, $options);
return $this->templating return $this->templating
->render('@ChillMain/Address/entity_render.html.twig', [ ->render('@ChillMain/Entity/address.html.twig', [
'address' => $addr, 'address' => $addr,
'render' => $options['render'] ?? 'bloc',
'options' => $options 'options' => $options
]); ]);
} }

View File

@ -169,7 +169,12 @@ 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 -%}
{{ person.lastAddress|chill_entity_render_box({'has_no_address': true}) }} {{ person.lastAddress|chill_entity_render_box({
'render': 'bloc',
'multiline': true,
'extended_infos': true,
'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">