From 88d1fe24b44f611e025c33e7e81424a2768644ff Mon Sep 17 00:00:00 2001 From: LenaertsJ Date: Wed, 26 Jan 2022 12:52:15 +0000 Subject: [PATCH] Creation of PersonResource --- CHANGELOG.md | 7 +- .../Authorization/ActivityVoterTest.php | 4 - .../Entity/Workflow/EntityWorkflow.php | 1 - .../Entity/Workflow/EntityWorkflowComment.php | 1 - ...former.php => EntityToJsonTransformer.php} | 41 ++- .../Form/Type/PickUserDynamicType.php | 6 +- .../public/lib/show_hide/show_hide.js | 1 + .../public/module/pick-entity/index.js | 47 ++- .../public/vuejs/PickEntity/PickEntity.vue | 6 +- .../Resources/views/Form/fields.html.twig | 2 +- .../Tests/Export/ExportManagerTest.php | 2 - .../Authorization/AuthorizationHelperTest.php | 3 - .../Controller/PersonResourceController.php | 178 ++++++++++++ .../Entity/Household/HouseholdComposition.php | 1 - .../Entity/Person/PersonResource.php | 275 ++++++++++++++++++ .../Entity/Person/PersonResourceKind.php | 69 +++++ .../Form/PersonResourceType.php | 95 ++++++ .../Form/Type/PickPersonDynamicType.php | 62 ++++ .../Menu/PersonMenuBuilder.php | 10 + .../Repository/PersonResourceRepository.php | 61 ++++ .../mod/AccompanyingPeriod/setReferrer.js | 47 +++ .../page/person_resource/showhide-input.js | 55 ++++ .../AccompanyingPeriod/SetReferrer.vue | 44 +++ .../AccompanyingPeriod/_list_item.html.twig | 6 +- .../views/PersonResource/create.html.twig | 14 + .../views/PersonResource/delete.html.twig | 17 ++ .../views/PersonResource/edit.html.twig | 23 ++ .../views/PersonResource/form.html.twig | 78 +++++ .../views/PersonResource/list.html.twig | 101 +++++++ .../AccompanyingPeriodResourceNormalizer.php | 1 - .../AccompanyingPeriodWorkDenormalizer.php | 1 - .../Normalizer/PersonJsonNormalizer.php | 2 - .../Templating/Entity/ResourceKindRender.php | 52 ++++ .../Authorization/PersonVoterTest.php | 2 - .../ChillPersonBundle/chill.webpack.config.js | 3 + .../ChillPersonBundle/config/routes.yaml | 12 + .../migrations/Version20220119155944.php | 54 ++++ .../translations/messages.fr.yml | 17 ++ .../Authorization/ReportVoterTest.php | 2 - .../Form/Type/PickThirdpartyDynamicType.php | 62 ++++ 40 files changed, 1426 insertions(+), 39 deletions(-) rename src/Bundle/ChillMainBundle/Form/Type/DataTransformer/{UserToJsonTransformer.php => EntityToJsonTransformer.php} (71%) create mode 100644 src/Bundle/ChillPersonBundle/Controller/PersonResourceController.php create mode 100644 src/Bundle/ChillPersonBundle/Entity/Person/PersonResource.php create mode 100644 src/Bundle/ChillPersonBundle/Entity/Person/PersonResourceKind.php create mode 100644 src/Bundle/ChillPersonBundle/Form/PersonResourceType.php create mode 100644 src/Bundle/ChillPersonBundle/Form/Type/PickPersonDynamicType.php create mode 100644 src/Bundle/ChillPersonBundle/Repository/PersonResourceRepository.php create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/mod/AccompanyingPeriod/setReferrer.js create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/page/person_resource/showhide-input.js create mode 100644 src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AccompanyingPeriod/SetReferrer.vue create mode 100644 src/Bundle/ChillPersonBundle/Resources/views/PersonResource/create.html.twig create mode 100644 src/Bundle/ChillPersonBundle/Resources/views/PersonResource/delete.html.twig create mode 100644 src/Bundle/ChillPersonBundle/Resources/views/PersonResource/edit.html.twig create mode 100644 src/Bundle/ChillPersonBundle/Resources/views/PersonResource/form.html.twig create mode 100644 src/Bundle/ChillPersonBundle/Resources/views/PersonResource/list.html.twig create mode 100644 src/Bundle/ChillPersonBundle/Templating/Entity/ResourceKindRender.php create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20220119155944.php create mode 100644 src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdpartyDynamicType.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cf2fa64c..8a56b0945 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to ## Unreleased +* [person]: possibility to add person resources (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/382) ## Test releases @@ -32,7 +33,6 @@ and this project adheres to * add My workflow section with my opened subscriptions * apply workflow on documents, accompanyingCourseWork and Evaluations * [wopi-link] a new vue component allow to open wopi link in a fullscreen chill-themed modal - ### test release 2022-01-19 * vuejs: add dead information on all on-the-fly person render boxes, in vis graph and other templates (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/271) @@ -40,6 +40,7 @@ and this project adheres to * [main] location form type: fix unmapped address field (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/246) * [activity] fix wrong import of js assets for adding and viewing documents in activity (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/83 & https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/176) * [person]: space added between deathdate and age in twig renderbox (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/380) +* [forms] dynamic picker types for user/person/thirdparty types created (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/386) ### test release 2022-01-17 @@ -49,10 +50,14 @@ and this project adheres to * [main] Add mainLocation field to User entity and add it in user form type * [course list in person context] show full username/label for ref * [accompanying period work] remove the possibility to generate document from an accompanying period work +* vuejs: add validation on required fields for AddPerson, Address and Location components +* vuejs: treat 422 validation errors in locations and AddPerson components +* [person]: space added between deathdate and age in twig renderbox (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/380) ## Test releases * vuejs: add validation on required fields for AddPerson, Address and Location components * vuejs: treat 422 validation errors in locations and AddPerson components +* [person]: space added between deathdate and age in twig renderbox (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/380) ### test release 2022-01-12 diff --git a/src/Bundle/ChillActivityBundle/Tests/Security/Authorization/ActivityVoterTest.php b/src/Bundle/ChillActivityBundle/Tests/Security/Authorization/ActivityVoterTest.php index 3ca5aab45..b3d8472c6 100644 --- a/src/Bundle/ChillActivityBundle/Tests/Security/Authorization/ActivityVoterTest.php +++ b/src/Bundle/ChillActivityBundle/Tests/Security/Authorization/ActivityVoterTest.php @@ -29,13 +29,9 @@ use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; final class ActivityVoterTest extends KernelTestCase { use PrepareActivityTrait; - use PrepareCenterTrait; - use PreparePersonTrait; - use PrepareScopeTrait; - use PrepareUserTrait; /** diff --git a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php index 0d7142e9f..b56435f5d 100644 --- a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php +++ b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflow.php @@ -37,7 +37,6 @@ use function count; class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface { use TrackCreationTrait; - use TrackUpdateTrait; /** diff --git a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowComment.php b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowComment.php index 9f4e7f096..b041a5aa3 100644 --- a/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowComment.php +++ b/src/Bundle/ChillMainBundle/Entity/Workflow/EntityWorkflowComment.php @@ -24,7 +24,6 @@ use Doctrine\ORM\Mapping as ORM; class EntityWorkflowComment implements TrackCreationInterface, TrackUpdateInterface { use TrackCreationTrait; - use TrackUpdateTrait; /** diff --git a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/UserToJsonTransformer.php b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php similarity index 71% rename from src/Bundle/ChillMainBundle/Form/Type/DataTransformer/UserToJsonTransformer.php rename to src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php index ca87ea4f5..c6c205a47 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/UserToJsonTransformer.php +++ b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/EntityToJsonTransformer.php @@ -12,14 +12,18 @@ declare(strict_types=1); namespace Chill\MainBundle\Form\Type\DataTransformer; use Chill\MainBundle\Entity\User; +use Chill\PersonBundle\Entity\Person; +use Chill\ThirdPartyBundle\Entity\ThirdParty; use Symfony\Component\Form\DataTransformerInterface; use Symfony\Component\Form\Exception\TransformationFailedException; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\SerializerInterface; +use UnexpectedValueException; + use function array_key_exists; -class UserToJsonTransformer implements DataTransformerInterface +class EntityToJsonTransformer implements DataTransformerInterface { private DenormalizerInterface $denormalizer; @@ -27,17 +31,22 @@ class UserToJsonTransformer implements DataTransformerInterface private SerializerInterface $serializer; - public function __construct(DenormalizerInterface $denormalizer, SerializerInterface $serializer, bool $multiple) + private string $type; + + public function __construct(DenormalizerInterface $denormalizer, SerializerInterface $serializer, bool $multiple, string $type) { $this->denormalizer = $denormalizer; $this->serializer = $serializer; $this->multiple = $multiple; + $this->type = $type; } public function reverseTransform($value) { $denormalized = json_decode($value, true); + dump($value); + if ($this->multiple) { if (null === $denormalized) { return []; @@ -49,6 +58,10 @@ class UserToJsonTransformer implements DataTransformerInterface ); } + if ('' === $value) { + return null; + } + return $this->denormalizeOne($denormalized); } @@ -66,7 +79,7 @@ class UserToJsonTransformer implements DataTransformerInterface ]); } - private function denormalizeOne(array $item): User + private function denormalizeOne(array $item) { if (!array_key_exists('type', $item)) { throw new TransformationFailedException('the key "type" is missing on element'); @@ -76,10 +89,30 @@ class UserToJsonTransformer implements DataTransformerInterface throw new TransformationFailedException('the key "id" is missing on element'); } + switch ($this->type) { + case 'user': + $class = User::class; + + break; + + case 'person': + $class = Person::class; + + break; + + case 'thirdparty': + $class = ThirdParty::class; + + break; + + default: + throw new UnexpectedValueException('This type is not supported'); + } + return $this->denormalizer->denormalize( ['type' => $item['type'], 'id' => $item['id']], - User::class, + $class, 'json', [AbstractNormalizer::GROUPS => ['read']], ); diff --git a/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php b/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php index 52798608e..3bc4df436 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/PickUserDynamicType.php @@ -12,7 +12,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Form\Type; use Chill\MainBundle\Entity\User; -use Chill\MainBundle\Form\Type\DataTransformer\UserToJsonTransformer; +use Chill\MainBundle\Form\Type\DataTransformer\EntityToJsonTransformer; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormInterface; @@ -38,7 +38,7 @@ class PickUserDynamicType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->addViewTransformer(new UserToJsonTransformer($this->denormalizer, $this->serializer, $options['multiple'])); + $builder->addViewTransformer(new EntityToJsonTransformer($this->denormalizer, $this->serializer, $options['multiple'], 'user')); } public function buildView(FormView $view, FormInterface $form, array $options) @@ -58,6 +58,6 @@ class PickUserDynamicType extends AbstractType public function getBlockPrefix() { - return 'pick_user_dynamic'; + return 'pick_entity_dynamic'; } } diff --git a/src/Bundle/ChillMainBundle/Resources/public/lib/show_hide/show_hide.js b/src/Bundle/ChillMainBundle/Resources/public/lib/show_hide/show_hide.js index ec6b796ec..f2bcc9b45 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/lib/show_hide/show_hide.js +++ b/src/Bundle/ChillMainBundle/Resources/public/lib/show_hide/show_hide.js @@ -39,6 +39,7 @@ var ShowHide = function(options) { contents.push(el); } container_content.push(contents); + // console.log('container content', container_content); } // attach the listener on each input 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 329ac4e6c..c3786f137 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js @@ -5,18 +5,22 @@ import { appMessages } from 'ChillMainAssets/vuejs/PickEntity/i18n'; const i18n = _createI18n(appMessages); -window.addEventListener('DOMContentLoaded', function(e) { +let appsOnPage = new Map(); - let apps = document.querySelectorAll('[data-module="pick-dynamic"]'); + +function loadDynamicPicker(element) { + + let apps = element.querySelectorAll('[data-module="pick-dynamic"]'); apps.forEach(function(el) { const isMultiple = parseInt(el.dataset.multiple) === 1, - input = document.querySelector('[data-input-uniqid="'+ el.dataset.uniqid +'"]'), - picked = isMultiple ? JSON.parse(input.value) : [JSON.parse(input.value)]; + uniqId = el.dataset.uniqid, + input = element.querySelector('[data-input-uniqid="'+ el.dataset.uniqid +'"]'), + picked = (isMultiple) ? (JSON.parse(input.value)) : ((input.value === '[]') ? (null) : ([JSON.parse(input.value)])); - createApp({ + const app = createApp({ template: ' { +// 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) + loadDynamicPicker(document) +}) + + + + + diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue index 43f3ebf94..137224691 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue @@ -1,5 +1,5 @@