From 8113fddcb2383bb5f9cbcb51c7973ff5b2c850f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 2 May 2022 15:37:23 +0200 Subject: [PATCH] use pick dynamic user type for reassigning + layout stuffs --- .../public/module/pick-entity/index.js | 7 -- .../public/vuejs/PickEntity/PickEntity.vue | 18 ++-- .../Resources/public/vuejs/PickEntity/i18n.js | 4 + .../Resources/views/Form/fields.html.twig | 1 + .../ReassignAccompanyingPeriodController.php | 44 +++++---- .../reassign_list.html.twig | 89 ++++++++++--------- .../translations/messages.fr.yml | 8 ++ 7 files changed, 92 insertions(+), 79 deletions(-) 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 f184bf100..511d2126e 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/module/pick-entity/index.js @@ -51,9 +51,7 @@ function loadDynamicPicker(element) { }, methods: { addNewEntity(entity) { - console.log('addNewEntity', entity); if (this.multiple) { - console.log('adding multiple'); if (!this.picked.some(el => { return el.type === entity.type && el.id === entity.id; })) { @@ -71,7 +69,6 @@ function loadDynamicPicker(element) { } }, removeEntity(entity) { - console.log('removeEntity', entity); this.picked = this.picked.filter(e => !(e.type === entity.type && e.id === entity.id)); input.value = JSON.stringify(this.picked); }, @@ -86,7 +83,6 @@ function loadDynamicPicker(element) { document.addEventListener('show-hide-show', function(e) { - console.log('creation event caught') loadDynamicPicker(e.detail.container) }) @@ -94,17 +90,14 @@ 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) 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 c75001005..e69b26619 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/PickEntity.vue @@ -66,9 +66,18 @@ export default { translatedListOfTypes() { let trans = []; this.types.forEach(t => { - trans.push(appMessages.fr.pick_entity[t].toLowerCase()); + if (this.$props.multiple) { + trans.push(appMessages.fr.pick_entity[t].toLowerCase()); + } else { + trans.push(appMessages.fr.pick_entity[t + '_one'].toLowerCase()); + } }) - return appMessages.fr.pick_entity.modal_title + trans.join(', '); + + if (this.$props.multiple) { + return appMessages.fr.pick_entity.modal_title + trans.join(', '); + } else { + return appMessages.fr.pick_entity.modal_title_one + trans.join(', '); + } } }, methods: { @@ -79,15 +88,10 @@ export default { ); this.$refs.addPersons.resetSearch(); // to cast child method modal.showModal = false; - console.log(this.picked) }, removeEntity(entity) { - console.log('remove entity', entity); this.$emit('removeEntity', entity); } }, - mounted() { - console.log(this.picked); - } } diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/i18n.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/i18n.js index f3ae3a928..cc3f324e8 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/i18n.js +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/PickEntity/i18n.js @@ -11,6 +11,10 @@ const appMessages = { user: 'Utilisateurs', person: 'Usagers', thirdparty: 'Tiers', + modal_title_one: 'Indiquer un ', + user_one: 'Utilisateur', + thirdparty_one: 'Tiers', + person_one: 'Usager', } } } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig index 8bb09623f..1da384920 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig @@ -217,6 +217,7 @@ {% endblock %} {% block pick_entity_dynamic_widget %} + {{ form_help(form)}}
{% endblock %} diff --git a/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php b/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php index 5e07bc96d..0729fd90d 100644 --- a/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php +++ b/src/Bundle/ChillPersonBundle/Controller/ReassignAccompanyingPeriodController.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\PersonBundle\Controller; use Chill\MainBundle\Entity\User; +use Chill\MainBundle\Form\Type\PickUserDynamicType; use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Repository\UserRepository; use Chill\MainBundle\Templating\Entity\UserRender; @@ -31,7 +32,10 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Security\Core\Security; +use Symfony\Component\Serializer\SerializerInterface; use Symfony\Component\Templating\EngineInterface; +use Symfony\Component\Validator\Constraints\NotEqualTo; +use Symfony\Component\Validator\Constraints\NotIdenticalTo; use function is_int; class ReassignAccompanyingPeriodController extends AbstractController @@ -129,18 +133,17 @@ class ReassignAccompanyingPeriodController extends AbstractController $this->em->flush(); // redirect to the first page - return $this->redirectToRoute('chill_course_list_reassign', [ - 'form' => ['user' => $userFrom->getId()], - ]); + return $this->redirectToRoute('chill_course_list_reassign', $request->query->all()); } } return new Response( $this->engine->render('@ChillPerson/AccompanyingPeriod/reassign_list.html.twig', [ + 'assignForm' => $assignForm->createView(), + 'form' => $form->createView(), 'paginator' => $paginator, 'periods' => $periods, - 'form' => $form->createView(), - 'assignForm' => $assignForm->createView(), + 'userFrom' => $userFrom, ]) ); } @@ -154,15 +157,11 @@ class ReassignAccompanyingPeriodController extends AbstractController 'method' => 'get', 'csrf_protection' => false, ]); $builder - ->add('user', EntityType::class, [ - 'class' => User::class, // pickUserType or PickDyamicUserType - 'choices' => $this->userRepository->findByActive(['username' => 'ASC']), - 'choice_label' => function (User $u) { - return $this->userRender->renderString($u, []); - }, + ->add('user', PickUserDynamicType::class, [ 'multiple' => false, - 'label' => 'User', + 'label' => 'reassign.Current user', 'required' => false, + 'help' => 'reassign.Choose a user and click on "Filter" to apply', ]); return $builder->getForm(); @@ -173,26 +172,23 @@ class ReassignAccompanyingPeriodController extends AbstractController $defaultData = [ 'userFrom' => $userFrom, 'periods' => json_encode($periodIds), - 'assignTo' => null, ]; - $builder = $this->formFactory->createBuilder(FormType::class, $defaultData); + $builder = $this->formFactory->createNamedBuilder('reassign', FormType::class, $defaultData); + + if (null !== $userFrom) { + $constraints = [new NotIdenticalTo(['value' => $userFrom])]; + } $builder ->add('periods', HiddenType::class) ->add('userFrom', HiddenType::class) - ->add('userTo', EntityType::class, [ - 'class' => User::class, // PickUserType - 'choices' => $this->userRepository->findByActive(['username' => 'ASC']), - 'choice_label' => function (User $u) { - return $this->userRender->renderString($u, []); - }, - 'placeholder' => 'Choose a user to reassign to', + ->add('userTo', PickUserDynamicType::class, [ 'multiple' => false, - 'label' => 'User', + 'label' => 'reassign.Next user', 'required' => true, - // add a constraint: userFrom is not equal to userTo - //'constraints' => NotEqualToh + 'help' => 'reassign.All periods on this list will be reassigned to this user, excepted the one you manually reassigned before', + 'constraints' => $constraints ?? [], ]); $builder->get('userFrom')->addModelTransformer(new CallbackTransformer( diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/reassign_list.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/reassign_list.html.twig index a77693775..63e25efeb 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/reassign_list.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingPeriod/reassign_list.html.twig @@ -4,10 +4,12 @@ {% block js %} {{ encore_entry_script_tags('mod_set_referrer') }} + {{ encore_entry_script_tags('mod_pickentity_type') }} {% endblock %} {% block css %} {{ encore_entry_link_tags('mod_set_referrer') }} + {{ encore_entry_link_tags('mod_pickentity_type') }} {% endblock %} {% macro period_meta(period) %} @@ -38,61 +40,66 @@ {% import _self as m %} {% block content %} -
+

{{ block('title') }}

- {{ form_start(form) }}
+ {{ form_start(form) }} {{ form_label(form.user ) }} {{ form_widget(form.user, {'attr': {'class': 'select2'}}) }} -
-
- -
    -
  • - -
  • -
- - {{ form_end(form) }} - - {% if form.user.vars.value is empty %} -

{{ 'period_by_user_list.Pick a user'|trans }}

- {% elseif periods|length == 0 and form.user.vars.value is not empty %} -

{{ 'period_by_user_list.Any course or no authorization to see them'|trans }}

- {% else %} -

{{ 'Attribute parcours in this list to the following user,'|trans }}

-

{{ paginator.totalItems }} parcours à réassigner (calculé ce jour à {{ null|format_time('medium') }})

- - {{ form_start(assignForm) }} -
-
- {{ form_label(assignForm.userTo ) }} - {{ form_widget(assignForm.userTo, {'attr': {'class': 'select2'}}) }} -
-
  • -
- {{ form_end(assignForm) }} -
- {% for period in periods %} - {% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': period, - 'recordAction': m.period_actions(period), 'itemMeta': m.period_meta(period) } %} - {% endfor %} + {{ form_end(form) }}
+ +
+ {% if userFrom is not null %} +
+ {{ form_start(assignForm) }} + {{ form_label(assignForm.userTo ) }} + {{ form_widget(assignForm.userTo, {'attr': {'class': 'select2'}}) }} +
+
    +
  • + +
  • +
+ {{ form_end(assignForm) }} + {% else %} +
{{ 'reassign.List periods to be able to reassign them'|trans }}
+ {% endif %} + +
+
+ + {% if userFrom is not null %} +

{{ paginator.totalItems }} parcours à réassigner (calculé ce jour à {{ null|format_time('medium') }})

{% endif %} - {% if paginator is defined %} - {{ chill_pagination(paginator) }} - {% endif %} +
+ {% for period in periods %} + {% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': period, + 'recordAction': m.period_actions(period), 'itemMeta': m.period_meta(period) } %} + {% else %} + {% if userFrom is same as(null) %} +

{{ 'period_by_user_list.Pick a user'|trans }}

+ {% else %} +

{{ 'period_by_user_list.Any course or no authorization to see them'|trans }}

+ {% endif %} + {% endfor %} +
+ {% if paginator is defined %} + {{ chill_pagination(paginator) }} + {% endif %}
+ {% endblock %} diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 70441965c..5ad18796c 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -596,3 +596,11 @@ period_by_user_list: Period by user: Parcours d'accompagnement par utilisateur Pick a user: Choisissez un utilisateur pour obtenir la liste de ses parcours Any course or no authorization to see them: Aucun parcours pour ce référent, ou aucun droit pour visualiser les parcours de ce référent. + +reassign: + Current user: Parcours par référent + Next user: Nouveau référent + Choose a user and click on "Filter" to apply: Choisissez un utilisateur et cliquez sur "Filtrer" pour visualiser ses parcours + All periods on this list will be reassigned to this user, excepted the one you manually reassigned before: Tous les parcours visibles sur cette page seront assignés à cet utilisateur, sauf ceux que vous aurez assigné à un utilisateur manuellement. + Reassign: Assigner le référent + List periods to be able to reassign them: Choisissez un utilisateur et cliquez sur "Filtrer" pour visualiser ses parcours. Vous pourrez ensuite les réassigner.