finalize members lists

This commit is contained in:
Julien Fastré 2021-06-07 17:03:45 +02:00
parent 604e78f35e
commit 5cb076495a
9 changed files with 201 additions and 36 deletions

View File

@ -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()
]);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -0,0 +1,42 @@
<?php
namespace Chill\PersonBundle\Form;
use Chill\MainBundle\Form\Type\ChillTextareaType;
use Chill\MainBundle\Form\Type\ChillDateType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
class HouseholdMemberType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->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'
])
;
}
}

View File

@ -0,0 +1,28 @@
{% extends '@ChillPerson/Household/layout.html.twig' %}
{% block title 'household.Edit member household'|trans %}
{% block content %}
<h1>{{ block('title') }}</h1>
{{ form_start(form) }}
{{ form_widget(form) }}
<ul class="record_actions sticky-form-buttons">
<li class="cancel">
<a
href="{{ chill_return_path_or('chill_person_household_members', { 'household_id': household.id}) }}"
class="sc-button bt-cancel"
>
{{ 'Cancel'|trans }}
</a>
</li>
<li>
<button type="submit" class="sc-button bt-save">{{ 'Save'|trans }}</button>
</li>
</ul>
{{ form_end(form) }}
{% endblock %}

View File

@ -5,7 +5,7 @@
<div class="grid-6">{% set title = title %}
<h1>
<i class="fa fa-child"></i>
{{ 'Household'|trans }}
{{ 'household.Household'|trans }}
<span style="font-weight: lighter; font-size: 50%;">(n°{{ household.id }})</span>
</h1>
</div>

View File

@ -1,12 +1,10 @@
{% extends '@ChillPerson/Household/layout.html.twig' %}
{% block title 'Household members'|trans %}
{% block title 'household.Household members'|trans %}
{% block content %}
<h1>{{ block('title') }}</h1>
<p>Household with id {{ household.id }}</p>
{% for p in positions %}
<h3>{{ p.label|localize_translatable_string }}</h3>
@ -22,9 +20,9 @@
<div class="item-row person">
<div class="item-col box-person">
<div>
{{ m.person|chill_entity_render_box }}
{{ m.person|chill_entity_render_box({'addLink': true}) }}
{% if m.holder %}
<span class="badge badge-primary">{{ 'Holder'|trans }}</span>
<span class="badge badge-primary">{{ 'household.holder'|trans }}</span>
{% endif %}
</div>
<div>
@ -40,12 +38,25 @@
<li>{{ 'Until %date%'|trans({'%date%': m.endDate|format_date('long') }) }}</li>
{% endif %}
</ul>
<ul class="record_actions">
<li>
<a
href="{{ chill_path_add_return_path('chill_person_household_member_edit', { 'id': m.id }) }}"
class="sc-button bt-edit"
/>
{{ 'household.Update membership'|trans }}
</a>
</li>
<li>
<a href="#" class="sc-button" /><i class="fa fa-sign-out"></i>{{ 'household.Leave'|trans }}</a>
</li>
</ul>
</div>
</div>
{% if m.comment is not empty %}
<div class="item-row comment">
<blockquote class="chill-user-quote">
{{ m.comment }}
{{ m.comment|chill_markdown_to_html }}
</blockquote>
</div>
{% endif %}
@ -53,7 +64,7 @@
{% endfor %}
</div>
{% else %}
<p class="chill-no-data-statement">{{ 'Any persons into this position'|trans }}</p>
<p class="chill-no-data-statement">{{ 'household.Any persons into this position'|trans }}</p>
{% endif %}
{% set members = household.nonCurrentMembersByPosition(p) %}
@ -70,9 +81,9 @@
<div class="item-row person">
<div class="item-col box-person">
<div>
{{ m.person|chill_entity_render_box }}
{{ m.person|chill_entity_render_box({'addLink': true}) }}
{% if m.holder %}
<span class="badge badge-primary">{{ 'Holder'|trans }}</span>
<span class="badge badge-primary">{{ 'household.holder'|trans }}</span>
{% endif %}
</div>
<div>
@ -88,16 +99,27 @@
<li>{{ 'Until %date%'|trans({'%date%': m.endDate|format_date('long') }) }}</li>
{% endif %}
</ul>
<ul class="record_actions">
<li>
<a
href="{{ chill_path_add_return_path('chill_person_household_member_edit', { 'id': m.id }) }}"
class="sc-button bt-edit"
/>
{{ 'household.Update membership'|trans }}
</a>
</li>
</ul>
</div>
</div>
{% if m.comment is not empty %}
<div class="item-row comment">
<blockquote class="chill-user-quote">
{{ m.comment }}
{{ m.comment|chill_markdown_to_html }}
</blockquote>
</div>
{% endif %}
</div>
{% endfor %}
</div>
</div>

View File

@ -62,3 +62,8 @@ services:
autoconfigure: true
resource: '../Repository/'
tags: ['doctrine.repository_service']
Chill\PersonBundle\Controller\:
autowire: true
resource: '../Controller/'
tags: ['controller.service_arguments']

View File

@ -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