improve layout of third parties in AddPerson

This commit is contained in:
Julien Fastré 2021-10-11 11:07:49 +02:00
parent c54edd8407
commit 08764aa0b4
7 changed files with 120 additions and 29 deletions

View File

@ -23,6 +23,7 @@
namespace Chill\MainBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Table(name="chill_main_civility")
@ -34,16 +35,19 @@ class Civility
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Groups({"read"})
*/
private $id;
/**
* @ORM\Column(type="json")
* @Serializer\Groups({"read"})
*/
private array $name = [];
/**
* @ORM\Column(type="json")
* @Serializer\Groups({"read"})
*/
private array $abbreviation = [];

View File

@ -1,42 +1,102 @@
<template>
<div class="container">
<div class="container tpartycontainer">
<div class="tparty-identification">
<span class="name">
{{ item.result.text }}
</span>
<span class="location">
<template v-if="hasAddress">
{{ getAddress.text }} -
{{ getAddress.postcode.name }}
</template>
</span>
</div>
<div class="tpartyparent" v-if="hasParent">
<span class="name">
{{ item.result.parent.text }}
</span>
</div>
</div>
<div class="right_actions">
<span class="name">
{{ item.result.text }}
</span>
<span class="location">
<template v-if="item.result.address != null">
{{ item.result.address.text }} -
{{ item.result.address.postcode.name }}
</template>
</span>
</div>
<div class="right_actions">
<span class="badge rounded-pill bg-info" v-if="item.result.isChild">
{{ $t('item.thirdparty_contact')}}
<span class="badge bg-chill-red" v-if="item.result.kind == 'child'">
{{ $t('thirdparty.contact')}}
</span>
<span class="badge rounded-pill bg-secondary" :title="item.key">
<span class="badge bg-info" v-else-if="item.result.kind == 'company'">
{{ $t('thirdparty.company')}}
</span>
<span class="badge bg-secondary" v-else="item.result.kind == 'contact'">
{{ $t('thirdparty.contact')}}
</span>
<span class="badge rounded-pill bg-secondary" :title="item.key">
{{ $t('item.type_thirdparty') }}
</span>
<on-the-fly
type="thirdparty"
v-bind:id="item.result.id"
action="show">
type="thirdparty"
v-bind:id="item.result.id"
action="show">
</on-the-fly>
</div>
</div>
</template>
<script>
import OnTheFly from 'ChillMainAssets/vuejs/OnTheFly/components/OnTheFly.vue';
const i18n = {
messages: {
fr: {
thirdparty: {
contact: "Contact",
company: "Institution",
child: "Personne de contact"
}
}
}
};
export default {
name: 'SuggestionThirdParty',
components: {
OnTheFly
},
props: ['item']
props: ['item'],
i18n,
computed: {
hasAddress() {
if (this.$props.item.result.address !== null) {
return true;
}
if (this.$props.item.result.parent !== null) {
this.$props.item.result.parent.address !== null;
}
},
hasParent() {
return this.$props.item.result.parent !== null;
},
getAddress() {
if (this.$props.item.result.address !== null) {
return this.$props.item.result.address;
}
if (this.$props.item.result.parent.address !== null) {
return this.$props.item.result.parent.address;
}
return null;
}
}
}
</script>
<style lang="scss" scoped>
.tpartycontainer {
.tpartyparent {
.name {
font-weight: bold;
font-variant: all-small-caps;
}
}
}
</style>

View File

@ -20,7 +20,7 @@
#}
{% macro raw(thirdparty, options) %}
<span class="name">{{ thirdparty.name }}</span>
<span class="name">{{ thirdparty|chill_entity_render_string }}</span>
{% endmacro raw %}
{% macro label(thirdparty, options) %}

View File

@ -3,6 +3,7 @@
namespace Chill\ThirdPartyBundle\Serializer\Normalizer;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
@ -12,19 +13,27 @@ class ThirdPartyNormalizer implements NormalizerInterface, NormalizerAwareInterf
{
use NormalizerAwareTrait;
private ThirdPartyRender $thirdPartyRender;
public function __construct(ThirdPartyRender $thirdPartyRender)
{
$this->thirdPartyRender = $thirdPartyRender;
}
public function normalize($thirdParty, string $format = null, array $context = [])
{
/** @var $thirdParty ThirdParty */
$data['type'] = 'thirdparty';
// TODO should be replaced by a "render entity"
$data['text'] = $thirdParty->getName();
$data['text'] = $this->thirdPartyRender->renderString($thirdParty, []);
$data['id'] = $thirdParty->getId();
$data['kind'] = $thirdParty->getKind();
$data['address'] = $this->normalizer->normalize($thirdParty->getAddress(), $format,
[ 'address_rendering' => 'short' ]);
$data['phonenumber'] = $thirdParty->getTelephone();
$data['email'] = $thirdParty->getEmail();
$data['isChild'] = $thirdParty->isChild();
$data['parent'] = $this->normalizer->normalize($thirdParty->getParent(), $format, $context);
$data['civility'] = $this->normalizer->normalize($thirdParty->getCivility(), $format, $context);
return $data;
}

View File

@ -21,6 +21,7 @@
namespace Chill\ThirdPartyBundle\Templating\Entity;
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Symfony\Component\Templating\EngineInterface;
@ -32,10 +33,15 @@ class ThirdPartyRender extends AbstractChillEntityRender
{
protected EngineInterface $engine;
protected TranslatableStringHelper $translatableStringHelper;
public function __construct(EngineInterface $engine)
public function __construct(
EngineInterface $engine,
TranslatableStringHelper $translatableStringHelper
)
{
$this->engine = $engine;
$this->translatableStringHelper = $translatableStringHelper;
}
/**
@ -76,7 +82,18 @@ class ThirdPartyRender extends AbstractChillEntityRender
*/
public function renderString($entity, array $options): string
{
return $entity->getName();
if ($entity->getCivility() !== NULL) {
$civility = $this->translatableStringHelper
->localize($entity->getCivility()->getAbbreviation()).' ';
} else {
$civility = '';
}
if (!empty($entity->getAcronym())) {
$acronym = ' ('.$entity->getAcronym().')';
} else {
$acronym = '';
}
return $civility.$entity->getName().$acronym;
}
public function supports($entity, array $options): bool

View File

@ -1,6 +1,6 @@
services:
Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender:
arguments:
$engine: '@Symfony\Component\Templating\EngineInterface'
autowire: true
autoconfigure: true
tags:
- 'chill.render_entity'

View File

@ -39,6 +39,7 @@ thirdparty.a_company_explanation: >-
thirdparty.a_contact_explanation: >-
Les personnes physiques ne disposent pas d'acronyme, de service, ou de contacts sous-jacents.
thirdparty.Which kind of third party ?: Quel type de tiers souhaitez-vous créer ?
thirdparty.Contact data are confidential: Données de contact confidentielles
New third party: Ajouter un nouveau tiers
Show third party %name%: Tiers "%name%"