From 5cb076495a269dc27eb14bb40bed6c05de5e63f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 7 Jun 2021 17:03:45 +0200 Subject: [PATCH] finalize members lists --- .../Controller/HouseholdMemberController.php | 50 +++++++++++ .../Entity/Household/HouseholdMember.php | 2 +- .../Entity/Household/Position.php | 5 ++ .../Form/HouseholdMemberType.php | 42 +++++++++ .../views/Household/Member/edit.html.twig | 28 ++++++ .../views/Household/banner.html.twig | 2 +- .../views/Household/members.html.twig | 90 ++++++++++++------- .../ChillPersonBundle/config/services.yaml | 5 ++ .../translations/messages+intl-icu.fr.yaml | 13 +++ 9 files changed, 201 insertions(+), 36 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Form/HouseholdMemberType.php create mode 100644 src/Bundle/ChillPersonBundle/Resources/views/Household/Member/edit.html.twig diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php index eafdd2ae9..d8e45471a 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php @@ -2,17 +2,32 @@ namespace Chill\PersonBundle\Controller; +use Chill\PersonBundle\Form\HouseholdMemberType; +use Chill\PersonBundle\Entity\Household\HouseholdMember; use Symfony\Component\HttpFoundation\Exception\BadRequestException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Serializer\Exception; use Symfony\Component\Routing\Annotation\Route; use Chill\MainBundle\CRUD\Controller\ApiController; +use Symfony\Component\Translation\TranslatorInterface; use Chill\PersonBundle\Household\MembersEditor; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; class HouseholdMemberController extends ApiController { + private UrlGeneratorInterface $generator; + + private TranslatorInterface $translator; + + + public function __construct(UrlGeneratorInterface $generator, TranslatorInterface $translator) + { + $this->generator = $generator; + $this->translator = $translator; + } + /** * @Route( * "/api/1.0/person/household/members/move.{_format}", @@ -44,4 +59,39 @@ class HouseholdMemberController extends ApiController "groups" => ["read"], ]); } + + /** + * @Route( + * "/api/1.0/person/household/member/{id}/edit", + * name="chill_person_household_member_edit" + * ) + */ + public function editMembership(Request $request, HouseholdMember $member): Response + { + // TODO ACL + + $form = $this->createForm(HouseholdMemberType::class, $member); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->getDoctrine()->getManager()->flush(); + + $this->addFlash('success', $this->translator + ->trans('household.successfully saved member')) + ; + + return $this->redirect( + $request->get('returnPath', null) ?? + $this->generator->generate('chill_person_household_members', [ 'household_id' => + $member->getHousehold()->getId() ]) + ); + } + + return $this->render('@ChillPerson/Household/Member/edit.html.twig', [ + 'household' => $member->getHousehold(), + 'member' => $member, + 'form' => $form->createView() + ]); + + } } diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMember.php b/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMember.php index cd58af565..58a731697 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMember.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/HouseholdMember.php @@ -120,7 +120,7 @@ class HouseholdMember return $this->endDate; } - public function setEndDate(\DateTimeImmutable $endDate): self + public function setEndDate(?\DateTimeImmutable $endDate = null): self { $this->endDate = $endDate; diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/Position.php b/src/Bundle/ChillPersonBundle/Entity/Household/Position.php index 156631b63..3ce95189d 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/Position.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/Position.php @@ -77,6 +77,11 @@ class Position return $this->allowHolder; } + public function isAllowHolder(): ?bool + { + return $this->getAllowHolder(); + } + public function setAllowHolder(bool $allowHolder): self { $this->allowHolder = $allowHolder; diff --git a/src/Bundle/ChillPersonBundle/Form/HouseholdMemberType.php b/src/Bundle/ChillPersonBundle/Form/HouseholdMemberType.php new file mode 100644 index 000000000..44b364c56 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Form/HouseholdMemberType.php @@ -0,0 +1,42 @@ +add('startDate', ChillDateType::class, [ + 'label' => 'household.Start date', + 'input' => 'datetime_immutable', + ]) + ->add('endDate', ChillDateType::class, [ + 'label' => 'household.End date', + 'input' => 'datetime_immutable', + 'required' => false + ]) + ; + if ($options['data']->getPosition()->isAllowHolder()) { + $builder + ->add('holder', ChoiceType::class, [ + 'label' => 'household.holder', + 'choices' => [ + 'household.is holder' => true, + 'household.is not holder' => false + ] + ]); + } + $builder + ->add('comment', ChillTextareaType::class, [ + 'label' => 'household.Comment' + ]) + ; + } +} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Household/Member/edit.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Household/Member/edit.html.twig new file mode 100644 index 000000000..09813c2bb --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Resources/views/Household/Member/edit.html.twig @@ -0,0 +1,28 @@ +{% extends '@ChillPerson/Household/layout.html.twig' %} + +{% block title 'household.Edit member household'|trans %} + +{% block content %} + +

{{ block('title') }}

+ +{{ form_start(form) }} +{{ form_widget(form) }} + + + +{{ form_end(form) }} + +{% endblock %} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Household/banner.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Household/banner.html.twig index 9ea33c8d4..57b89851d 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Household/banner.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Household/banner.html.twig @@ -5,7 +5,7 @@
{% set title = title %}

- {{ 'Household'|trans }} + {{ 'household.Household'|trans }} (n°{{ household.id }})

diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Household/members.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Household/members.html.twig index 768a3321c..538ec7dd0 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Household/members.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Household/members.html.twig @@ -1,12 +1,10 @@ {% extends '@ChillPerson/Household/layout.html.twig' %} -{% block title 'Household members'|trans %} +{% block title 'household.Household members'|trans %} {% block content %}

{{ block('title') }}

-

Household with id {{ household.id }}

- {% for p in positions %}

{{ p.label|localize_translatable_string }}

@@ -22,9 +20,9 @@
- {{ m.person|chill_entity_render_box }} + {{ m.person|chill_entity_render_box({'addLink': true}) }} {% if m.holder %} - {{ 'Holder'|trans }} + {{ 'household.holder'|trans }} {% endif %}
@@ -40,12 +38,25 @@
  • {{ 'Until %date%'|trans({'%date%': m.endDate|format_date('long') }) }}
  • {% endif %} +
    {% if m.comment is not empty %}
    - {{ m.comment }} + {{ m.comment|chill_markdown_to_html }}
    {% endif %} @@ -53,7 +64,7 @@ {% endfor %}
    {% else %} -

    {{ 'Any persons into this position'|trans }}

    +

    {{ 'household.Any persons into this position'|trans }}

    {% endif %} {% set members = household.nonCurrentMembersByPosition(p) %} @@ -66,38 +77,49 @@
    {% for m in members %} -
    -
    -
    -
    - {{ m.person|chill_entity_render_box }} - {% if m.holder %} - {{ 'Holder'|trans }} - {% endif %} -
    -
    - {{ 'Born the date'|trans({ 'gender': m.person.gender, 'birthdate': m.person.birthdate|format_date('long') }) }} -
    +
    +
    +
    +
    + {{ m.person|chill_entity_render_box({'addLink': true}) }} + {% if m.holder %} + {{ 'household.holder'|trans }} + {% endif %}
    -
    -
      - {% if m.startDate is not empty %} -
    • {{ 'Since %date%'|trans({'%date%': m.startDate|format_date('long') }) }}
    • - {% endif %} - {% if m.endDate is not empty %} -
    • {{ 'Until %date%'|trans({'%date%': m.endDate|format_date('long') }) }}
    • - {% endif %} -
    +
    + {{ 'Born the date'|trans({ 'gender': m.person.gender, 'birthdate': m.person.birthdate|format_date('long') }) }}
    - {% if m.comment is not empty %} -
    -
    - {{ m.comment }} -
    +
    +
      + {% if m.startDate is not empty %} +
    • {{ 'Since %date%'|trans({'%date%': m.startDate|format_date('long') }) }}
    • + {% endif %} + {% if m.endDate is not empty %} +
    • {{ 'Until %date%'|trans({'%date%': m.endDate|format_date('long') }) }}
    • + {% endif %} +
    +
    - {% endif %}
    + {% if m.comment is not empty %} +
    +
    + {{ m.comment|chill_markdown_to_html }} +
    +
    + {% endif %} +
    + {% endfor %}
    diff --git a/src/Bundle/ChillPersonBundle/config/services.yaml b/src/Bundle/ChillPersonBundle/config/services.yaml index d164fd089..582d24d19 100644 --- a/src/Bundle/ChillPersonBundle/config/services.yaml +++ b/src/Bundle/ChillPersonBundle/config/services.yaml @@ -62,3 +62,8 @@ services: autoconfigure: true resource: '../Repository/' tags: ['doctrine.repository_service'] + + Chill\PersonBundle\Controller\: + autowire: true + resource: '../Controller/' + tags: ['controller.service_arguments'] diff --git a/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml b/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml index f9db5063b..dcb541d50 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml +++ b/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml @@ -6,6 +6,8 @@ Born the date: >- } household: + Household: Ménage + Household members: Membres du ménage Show future or past memberships: >- {length, plural, one {Montrer une ancienne appartenance} @@ -13,4 +15,15 @@ household: other {Montrer # anciennes ou futures appartenances} } Those members does not share address: Ces usagers ne partagent pas l'adresse du ménage. + Any persons into this position: Aucune personne n'appartient au ménage à cette position. + Leave: Quitter le ménage + Update membership: Modifier + successfully saved member: Membre enregistré avec succès + Start date: Date de début de l'appartenance au ménage + End date: Date de fin de l'appartenance au ménage + Comment: Commentaire + is holder: Est titulaire + is not holder: N'est pas titulaire + holder: Titulaire + Edit member household: Modifier l'appartenance au ménage