replace comment by commentEmbeddable

This commit is contained in:
Julien Fastré 2021-06-15 10:17:53 +02:00
parent f827e50431
commit efdfd10e49
6 changed files with 132 additions and 30 deletions

View File

@ -4,6 +4,7 @@ namespace Chill\PersonBundle\Controller;
use Chill\PersonBundle\Form\HouseholdType; use Chill\PersonBundle\Form\HouseholdType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
@ -77,10 +78,17 @@ class HouseholdController extends AbstractController
// some queries // some queries
$household->getMembers()->initialize(); $household->getMembers()->initialize();
if ($request->query->has('edit')) {
$form = $this->createMetadataForm($household);
} else {
$form = null;
}
return $this->render('@ChillPerson/Household/members.html.twig', return $this->render('@ChillPerson/Household/members.html.twig',
[ [
'household' => $household, 'household' => $household,
'positions' => $positions 'positions' => $positions,
'form' => NULL !== $form ? $form->createView(): $form
] ]
); );
} }
@ -132,10 +140,7 @@ class HouseholdController extends AbstractController
public function editHouseholdMetadata(Request $request, Household $household) public function editHouseholdMetadata(Request $request, Household $household)
{ {
// TODO ACL // TODO ACL
$form = $this->createForm( $form = $this->createMetadataForm($household);
HouseholdType::class,
$household
);
$form->handleRequest($request); $form->handleRequest($request);
@ -154,4 +159,22 @@ class HouseholdController extends AbstractController
'form' => $form->createView() 'form' => $form->createView()
]); ]);
} }
private function createMetadataForm(Household $household): FormInterface
{
$form = $this->createForm(
HouseholdType::class,
$household,
[
'action' => $this->generateUrl(
'chill_person_household_members_metadata_edit',
[
'household_id' => $household->getId()
]
)
]
);
return $form;
}
} }

View File

@ -10,6 +10,7 @@ use Symfony\Component\Serializer\Annotation as Serializer;
use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\Address;
use Chill\PersonBundle\Entity\Household\HouseholdMember; use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\PersonBundle\Validator\Constraints\Household\MaxHolder; use Chill\PersonBundle\Validator\Constraints\Household\MaxHolder;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
/** /**
* @ORM\Entity * @ORM\Entity
@ -52,9 +53,9 @@ class Household
private Collection $members; private Collection $members;
/** /**
* @ORM\Column(type="text", name="comment_members", options={"default": ""}) * @ORM\Embedded(class=CommentEmbeddable::class, columnPrefix="comment_members_")
*/ */
private string $commentMembers = ""; private CommentEmbeddable $commentMembers;
/** /**
* @ORM\Column(type="boolean", name="waiting_for_birth", options={"default": false}) * @ORM\Column(type="boolean", name="waiting_for_birth", options={"default": false})
@ -70,6 +71,7 @@ class Household
{ {
$this->addresses = new ArrayCollection(); $this->addresses = new ArrayCollection();
$this->members = new ArrayCollection(); $this->members = new ArrayCollection();
$this->commentMembers = new CommentEmbeddable();
} }
public function getId(): ?int public function getId(): ?int
@ -221,12 +223,12 @@ class Household
return $this; return $this;
} }
public function getCommentMembers(): ?string public function getCommentMembers(): CommentEmbeddable
{ {
return $this->commentMembers; return $this->commentMembers;
} }
public function setCommentMembers(string $commentMembers): self public function setCommentMembers(CommentEmbeddable $commentMembers): self
{ {
$this->commentMembers = $commentMembers; $this->commentMembers = $commentMembers;

View File

@ -3,7 +3,7 @@
namespace Chill\PersonBundle\Form; namespace Chill\PersonBundle\Form;
use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Form\Type\ChillTextareaType; use Chill\MainBundle\Form\Type\CommentType;
use Chill\PersonBundle\Entity\Household\Household; use Chill\PersonBundle\Entity\Household\Household;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
@ -15,7 +15,7 @@ class HouseholdType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
$builder $builder
->add('commentMembers', ChillTextareaType::class, [ ->add('commentMembers', CommentType::class, [
'label' => 'household.comment_membership', 'label' => 'household.comment_membership',
'required' => false 'required' => false
]) ])

View File

@ -5,18 +5,58 @@
{% block content %} {% block content %}
<h1>{{ block('title') }}</h1> <h1>{{ block('title') }}</h1>
{% if household.commentMembers is not empty %} {% if form is not null %}
<blockquote class="chill-user-quote"> {{ form_start(form) }}
{{ household.commentMembers|chill_markdown_to_html }}
</blockquote>
{% endif %}
{% if household.waitingForBirth %} {{ form_row(form.commentMembers) }}
{% if household.waitingForBirthDate is not null %}
{{ 'household.Expecting for birth on date'|trans({ 'date': household.waitingForBirthDate|format_date('long') }) }} <div id="waitingForBirthContainer">
{% else %} {{ form_row(form.waitingForBirth) }}
{{ 'household.Expecting for birth'|trans }} </div>
<div id="waitingForBirthDateContainer">
{{ form_row(form.waitingForBirthDate) }}
</div>
<ul class="record_actions">
<li>
<button type="submit" class="sc-button bt-save">
{{ 'Save'|trans }}
</button>
</li>
</ul>
{{ form_end(form) }}
{% else %}
{% if not household.commentMembers.isEmpty() %}
{{ household.commentMembers|chill_entity_render_box }}
{% endif %} {% endif %}
{% if household.waitingForBirth %}
{% if household.waitingForBirthDate is not null %}
{{ 'household.Expecting for birth on date'|trans({ 'date': household.waitingForBirthDate|format_date('long') }) }}
{% else %}
{{ 'household.Expecting for birth'|trans }}
{% endif %}
{% else %}
<p class="chill-no-data-statement">
{{ 'household.Any expecting birth'|trans }}
</p>
{% endif %}
<ul class="record_actions">
<li>
<a
href="{{ chill_path_add_return_path('chill_person_household_members', { 'household_id': household.id, 'edit': 1 }) }}"
class="sc-button bt-edit"
>
{{ 'household.Comment and expecting birth'|trans }}
</a>
</li>
</ul>
{% endif %} {% endif %}
{% for p in positions %} {% for p in positions %}
@ -153,14 +193,6 @@
{% endfor %} {% endfor %}
<ul class="record_actions sticky-form-buttons"> <ul class="record_actions sticky-form-buttons">
<li>
<a
href="{{ chill_path_add_return_path('chill_person_household_members_metadata_edit', { 'household_id': household.id }) }}"
class="sc-button bt-edit"
>
{{ 'household.Edit member metadata'|trans }}
</a>
</li>
<li> <li>
<a <a
href="{{ chill_path_add_return_path('chill_person_household_members_editor', {'household': household.id }) }}" href="{{ chill_path_add_return_path('chill_person_household_members_editor', {'household': household.id }) }}"
@ -171,3 +203,7 @@
</ul> </ul>
{% endblock %} {% endblock %}
{% block js %}
{{ encore_entry_script_tags('household_edit_metadata') }}
{% endblock %}

View File

@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Set comment in household as Embedded Comment
*/
final class Version20210615074857 extends AbstractMigration
{
public function getDescription(): string
{
return 'replace comment in household as embedded comment';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_person_household RENAME comment_members TO comment_members_comment');
$this->addSql('ALTER TABLE chill_person_household ALTER COLUMN comment_members_comment DROP NOT NULL');
$this->addSql('ALTER TABLE chill_person_household ALTER COLUMN comment_members_comment SET DEFAULT NULL');
$this->addSql('ALTER TABLE chill_person_household ADD comment_members_userId INT DEFAULT NULL');
$this->addSql('ALTER TABLE chill_person_household ADD comment_members_date TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
$this->addSql('ALTER TABLE chill_person_household ADD CONSTRAINT fk_household_comment_embeddable_user FOREIGN KEY (comment_members_userId) REFERENCES users (id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_person_household RENAME comment_members_comment TO comment_members');
$this->addSql('ALTER TABLE chill_person_household ALTER comment_members SET DEFAULT \'\'');
$this->addSql('ALTER TABLE chill_person_household ALTER comment_members SET NOT NULL');
$this->addSql('ALTER TABLE chill_person_household DROP comment_members_comment');
$this->addSql('ALTER TABLE chill_person_household DROP comment_members_userId');
$this->addSql('ALTER TABLE chill_person_household DROP comment_members_date');
}
}

View File

@ -42,10 +42,12 @@ household:
} }
Expecting for birth on date: Naissance attendue pour le {date} Expecting for birth on date: Naissance attendue pour le {date}
Expecting for birth: Naissance attendue (date inconnue) Expecting for birth: Naissance attendue (date inconnue)
Any expecting birth: Aucune naissance proche n'a été renseignée.
Comment and expecting birth: Commentaire et naissance attendue
Edit member metadata: Données supplémentaires Edit member metadata: Données supplémentaires
comment_membership: Commentaire général sur les membres comment_membership: Commentaire général sur les membres
expecting_birth: Naissance attendue ? expecting_birth: Naissance attendue ?
date_expecting_birth: Date de la naissance attendue date_expecting_birth: Date de la naissance attendue
data_saved: Données enregistrées data_saved: Données enregistrées