From 08764aa0b49dde02dccc3b5d66da71859c650b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 11 Oct 2021 11:07:49 +0200 Subject: [PATCH] improve layout of third parties in AddPerson --- .../ChillMainBundle/Entity/Civility.php | 4 + .../_components/AddPersons/TypeThirdParty.vue | 104 ++++++++++++++---- .../views/Entity/thirdparty.html.twig | 2 +- .../Normalizer/ThirdPartyNormalizer.php | 13 ++- .../Templating/Entity/ThirdPartyRender.php | 21 +++- .../config/services/templating.yaml | 4 +- .../translations/messages.fr.yml | 1 + 7 files changed, 120 insertions(+), 29 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/Civility.php b/src/Bundle/ChillMainBundle/Entity/Civility.php index 7bed4f633..32f5396cd 100644 --- a/src/Bundle/ChillMainBundle/Entity/Civility.php +++ b/src/Bundle/ChillMainBundle/Entity/Civility.php @@ -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 = []; diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons/TypeThirdParty.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons/TypeThirdParty.vue index f91f3b16b..4bb2e2d1e 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons/TypeThirdParty.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons/TypeThirdParty.vue @@ -1,42 +1,102 @@ + + diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig index e49dd6a5c..f7dcf3bc5 100644 --- a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig +++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig @@ -20,7 +20,7 @@ #} {% macro raw(thirdparty, options) %} - {{ thirdparty.name }} + {{ thirdparty|chill_entity_render_string }} {% endmacro raw %} {% macro label(thirdparty, options) %} diff --git a/src/Bundle/ChillThirdPartyBundle/Serializer/Normalizer/ThirdPartyNormalizer.php b/src/Bundle/ChillThirdPartyBundle/Serializer/Normalizer/ThirdPartyNormalizer.php index cef2d562e..d821011e5 100644 --- a/src/Bundle/ChillThirdPartyBundle/Serializer/Normalizer/ThirdPartyNormalizer.php +++ b/src/Bundle/ChillThirdPartyBundle/Serializer/Normalizer/ThirdPartyNormalizer.php @@ -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; } diff --git a/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php b/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php index bbc3fd7dc..db53108d4 100644 --- a/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php +++ b/src/Bundle/ChillThirdPartyBundle/Templating/Entity/ThirdPartyRender.php @@ -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 diff --git a/src/Bundle/ChillThirdPartyBundle/config/services/templating.yaml b/src/Bundle/ChillThirdPartyBundle/config/services/templating.yaml index 6b12d3aa0..0e5a26df2 100644 --- a/src/Bundle/ChillThirdPartyBundle/config/services/templating.yaml +++ b/src/Bundle/ChillThirdPartyBundle/config/services/templating.yaml @@ -1,6 +1,6 @@ services: Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender: - arguments: - $engine: '@Symfony\Component\Templating\EngineInterface' + autowire: true + autoconfigure: true tags: - 'chill.render_entity' diff --git a/src/Bundle/ChillThirdPartyBundle/translations/messages.fr.yml b/src/Bundle/ChillThirdPartyBundle/translations/messages.fr.yml index 744c49682..604eafbad 100644 --- a/src/Bundle/ChillThirdPartyBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillThirdPartyBundle/translations/messages.fr.yml @@ -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%"