From dc0fae7549849c2d5317fbdec6d7b95d5cda509c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 26 Jan 2022 17:53:09 +0100 Subject: [PATCH] fixes person resources --- .../EntityToJsonTransformer.php | 2 - .../public/module/pick-entity/index.js | 33 +++--- .../Controller/PersonResourceController.php | 4 +- .../Entity/Person/PersonResource.php | 9 +- .../views/PersonResource/create.html.twig | 2 +- .../views/PersonResource/form.html.twig | 11 +- .../views/PersonResource/list.html.twig | 102 ++++++++---------- .../Normalizer/PersonDocGenNormalizer.php | 4 +- .../translations/validators.fr.yml | 3 + 9 files changed, 81 insertions(+), 89 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php index c6c205a47..95c447119 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php +++ b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php @@ -45,8 +45,6 @@ class EntityToJsonTransformer implements DataTransformerInterface { $denormalized = json_decode($value, true); - dump($value); - if ($this->multiple) { if (null === $denormalized) { return []; diff --git a/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js b/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js index c3786f137..1fd6b34f7 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js @@ -7,7 +7,6 @@ const i18n = _createI18n(appMessages); let appsOnPage = new Map(); - function loadDynamicPicker(element) { let apps = element.querySelectorAll('[data-module="pick-dynamic"]'); @@ -75,23 +74,23 @@ function loadDynamicPicker(element) { } -// document.addEventListener('show-hide-show', function(e) { -// console.log('creation event caught') -// loadDynamicPicker(e.detail.container) -// }) +document.addEventListener('show-hide-show', function(e) { + console.log('creation event caught') + loadDynamicPicker(e.detail.container) +}) -// document.addEventListener('show-hide-hide', function(e) { -// console.log('hiding event caught') -// e.detail.container.querySelectorAll('[data-module="pick-dynamic"]').forEach((el) => { -// let uniqId = el.dataset.uniqid; -// console.log(uniqId); -// if (appsOnPage.has(uniqId)) { -// appsOnPage.get(uniqId).unmount(); -// console.log('App has been unmounted') -// appsOnPage.delete(uniqId); -// } -// }) -// }) +document.addEventListener('show-hide-hide', function(e) { + console.log('hiding event caught') + e.detail.container.querySelectorAll('[data-module="pick-dynamic"]').forEach((el) => { + let uniqId = el.dataset.uniqid; + console.log(uniqId); + if (appsOnPage.has(uniqId)) { + appsOnPage.get(uniqId).unmount(); + console.log('App has been unmounted') + appsOnPage.delete(uniqId); + } + }) +}) document.addEventListener('DOMContentLoaded', function(e) { console.log('loaded event', e) diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php b/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php index 6b9b5dc6a..210b507e5 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php @@ -114,8 +114,6 @@ final class PersonResourceController extends AbstractController ]); } - dump($resource); - return $this->render( 'ChillPersonBundle:PersonResource:edit.html.twig', [ @@ -139,7 +137,7 @@ final class PersonResourceController extends AbstractController $form->handleRequest($request); - if ($request->getMethod() === Request::METHOD_POST && $form->isValid()) { + if ($form->isSubmitted() && $form->isValid()) { $this->denyAccessUnlessGranted(PersonVoter::CREATE, $personOwner); $personResource = new PersonResource(); diff --git a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php index 4e1718a64..2e8441511 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php @@ -55,7 +55,7 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface * @ORM\Column(type="text", nullable=true) * @Groups({"read"}) */ - private $freeText; + private ?string $freeText = null; /** * @ORM\Id @@ -204,6 +204,10 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface $this->setThirdParty(null); } + if ('' === $freeText) { + $this->freeText = null; + } + return $this; } @@ -266,9 +270,8 @@ class PersonResource implements TrackCreationInterface, TrackUpdateInterface */ public function validate(ExecutionContextInterface $context, $payload) { - if (null === $this->person && null === $this->thirdParty && null === $this->freeText) { + if (null === $this->person && null === $this->thirdParty && (null === $this->freeText || '' === $this->freeText)) { $context->buildViolation('You must associate at least one entity') - ->atPath('person') ->addViolation(); } } diff --git a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig index 46ba4ebef..8dde19750 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig @@ -1,5 +1,5 @@
-
+

{{ 'Add a person resource'|trans }}

{% include "@ChillPerson/PersonResource/form.html.twig" %}
diff --git a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/form.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/form.html.twig index 1ce3ea2ba..6fa294336 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/form.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/form.html.twig @@ -1,7 +1,6 @@ {{ form_start(form, {'attr' : {'id' : 'create-form'}}) }} - +{{ form_errors(form) }} {{ form_row(form.kind) }} -
@@ -10,7 +9,7 @@
{% if resource is defined and resource.person is not null %} - + {% else %} @@ -19,7 +18,7 @@
{% if resource is defined and resource.thirdparty is not null %} - + {% else %} @@ -28,7 +27,7 @@
{% if resource is defined and resource.freeText is not null %} - + {% else %} @@ -75,4 +74,4 @@ {% endif %} -{{ form_end(form) }} \ No newline at end of file +{{ form_end(form) }} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/list.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/list.html.twig index d8a67912f..a273277f9 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/list.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/PersonResource/list.html.twig @@ -19,74 +19,66 @@

{{ 'List of resources'|trans }}

{% if personResources|length > 0 %} - {% for resource in personResources %} -
+
+ {% for resource in personResources %}
-
-
-
- {% if resource.person is not null %} -
-
- {{ resource.person }} - {{ 'person'|trans|capitalize }} -
-
- {% elseif resource.thirdparty is not null %} -
-
- {{ resource.thirdparty }} - - {{ 'thirdparty'|trans|capitalize }} - - -
-
- {% else %} -
-
- {{ resource.freetext }} -
-
- {% endif %} -
- {% if resource.kind %} - {{ resource.kind.title.fr|capitalize }} - {% endif %} -
-
+
+ {% if resource.person is not null %} +
+ {{ resource.person }} + {{ 'person'|trans|capitalize }}
+ {% elseif resource.thirdparty is not null %} +
+ {{ resource.thirdparty }} + + {{ 'thirdparty'|trans|capitalize }} + + +
+ {% else %} +
+ {{ resource.freetext }} +
+ {% endif %} +
+
+ {% if resource.kind %} + {{ resource.kind.title.fr|capitalize }} + {% endif %}
- {% if resource.comment.comment is not null %} + {% if resource.comment.comment is not empty %}
{{ resource.comment|chill_entity_render_box }}
{% endif %} -
-
-
    -
  • - -
  • -
  • - -
  • -
+ {% if is_granted('CHILL_PERSON_UPDATE', resource.person) %} +
+
+
    +
  • + +
  • +
  • + +
  • +
+
-
+ {% endif %}
-
- {% endfor %} + {% endfor %} +
{% else %}

{{ 'There are no available resources'|trans }}

diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php index 2a99dfa8b..71b6ed92e 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php @@ -76,8 +76,8 @@ class PersonDocGenNormalizer implements 'type' => 'person', 'isNull' => false, 'civility' => $this->normalizer->normalize($person->getCivility(), $format, array_merge($context, ['docgen:expects' => Civility::class])), - 'firstname' => $person->getFirstName(), - 'lastname' => $person->getLastName(), + 'firstName' => $person->getFirstName(), + 'lastName' => $person->getLastName(), 'altNames' => implode( ', ', array_map( diff --git a/src/Bundle/ChillPersonBundle/translations/validators.fr.yml b/src/Bundle/ChillPersonBundle/translations/validators.fr.yml index 96cfd565f..a73880195 100644 --- a/src/Bundle/ChillPersonBundle/translations/validators.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/validators.fr.yml @@ -50,3 +50,6 @@ household_membership: A course must contains at least one social issue: 'Un parcours doit être associé à au moins une problématique sociale' A course must be associated to at least one scope: 'Un parcours doit être associé à au moins un service' The social %name% issue cannot be deleted because it is associated with an activity or an action: 'La problématique sociale "%name%" ne peut pas être supprimée car elle est associée à une activité ou une action' + +# resource +You must associate at least one entity: Associez un usager, un tiers ou indiquez une description libre