From 014c460eefbb325dc24288ca69868ebffd05e723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 27 May 2022 15:39:32 +0200 Subject: [PATCH] improvements on private comments --- .../ChillActivityBundle/Form/ActivityType.php | 2 +- .../Resources/views/Activity/show.html.twig | 34 +++++++-------- .../migrations/Version20220425133027.php | 5 --- .../migrations/Version20220527124438.php | 26 ++++++++++++ .../migrations/Version20220527124558.php | 26 ++++++++++++ .../translations/messages.fr.yml | 1 - .../Embeddable/PrivateCommentEmbeddable.php | 13 ++++-- .../Form/Type/PrivateCommentType.php | 10 ++--- .../Resources/views/Form/fields.html.twig | 17 ++++++++ .../migrations/Version20220426133048.php | 42 ------------------- .../translations/messages.fr.yml | 2 +- .../migrations/Version20220527124737.php | 26 ++++++++++++ 12 files changed, 125 insertions(+), 79 deletions(-) create mode 100644 src/Bundle/ChillActivityBundle/migrations/Version20220527124438.php create mode 100644 src/Bundle/ChillCalendarBundle/migrations/Version20220527124558.php delete mode 100644 src/Bundle/ChillMainBundle/migrations/Version20220426133048.php create mode 100644 src/Bundle/ChillPersonBundle/migrations/Version20220527124737.php diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityType.php b/src/Bundle/ChillActivityBundle/Form/ActivityType.php index 4361158e5..4c767cd54 100644 --- a/src/Bundle/ChillActivityBundle/Form/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Form/ActivityType.php @@ -254,7 +254,7 @@ class ActivityType extends AbstractType if ($activityType->isVisible('privateComment')) { $builder->add('privateComment', PrivateCommentType::class, [ - 'label' => empty($activityType->getLabel('privateComment')) ? 'activity.private comment' : $activityType->getPrivateCommentLabel(), + 'label' => '' === $activityType->getLabel('privateComment') ? 'private comment' : $activityType->getPrivateCommentLabel(), 'required' => false, ]); } diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/show.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/show.html.twig index 65134a754..8b47f4de2 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/show.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/show.html.twig @@ -147,6 +147,21 @@ {% endif %} + {% if t.privateCommentVisible and is_granted('CHILL_ACTIVITY_SEE_DETAILS', entity) and entity.privateComment.hasCommentForUser(app.user) %} + {% if t.privateCommentLabel is not empty %} +
{{ t.privateCommentLabel }}
+ {% else %} +
{{ 'Private comment'|trans }}
+ {% endif %} +
+
+
+ {{ entity.privateComment.comments[userId] }} +
+
+
+ {% endif %} + {% if t.documentsVisible and is_granted('CHILL_ACTIVITY_SEE_DETAILS', entity) %}
{{ 'Documents'|trans }}
@@ -178,25 +193,6 @@ -{% if t.privateCommentVisible and is_granted('CHILL_ACTIVITY_SEE_DETAILS', entity) and userId in entity.privateComment.comments|keys %} -
-
- {% if t.privateCommentLabel is not empty %} -
{{ t.privateCommentLabel }}
- {% else %} -
{{ 'Private comment'|trans }}
- {% endif %} -
-
-
- {{ entity.privateComment.comments[userId] }} -
-
-
- - -{% endif %} -
{% set notifications = chill_list_notifications('Chill\\ActivityBundle\\Entity\\Activity', entity.id) %} {% if notifications is not empty %} diff --git a/src/Bundle/ChillActivityBundle/migrations/Version20220425133027.php b/src/Bundle/ChillActivityBundle/migrations/Version20220425133027.php index d5243b259..4a829f18c 100644 --- a/src/Bundle/ChillActivityBundle/migrations/Version20220425133027.php +++ b/src/Bundle/ChillActivityBundle/migrations/Version20220425133027.php @@ -14,14 +14,10 @@ namespace Chill\Migrations\Activity; use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; -/** - * Auto-generated Migration: Please modify to your needs! - */ final class Version20220425133027 extends AbstractMigration { public function down(Schema $schema): void { - // this down() migration is auto-generated, please modify it to your needs $this->addSql('ALTER TABLE activitytype DROP privateCommentLabel'); $this->addSql('ALTER TABLE activitytype DROP privateCommentVisible'); } @@ -33,7 +29,6 @@ final class Version20220425133027 extends AbstractMigration public function up(Schema $schema): void { - // this up() migration is auto-generated, please modify it to your needs $this->addSql('ALTER TABLE activitytype ADD privateCommentLabel VARCHAR(255) DEFAULT \'\' NOT NULL'); $this->addSql('ALTER TABLE activitytype ADD privateCommentVisible SMALLINT DEFAULT 1 NOT NULL'); } diff --git a/src/Bundle/ChillActivityBundle/migrations/Version20220527124438.php b/src/Bundle/ChillActivityBundle/migrations/Version20220527124438.php new file mode 100644 index 000000000..1ccf3f0b3 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/migrations/Version20220527124438.php @@ -0,0 +1,26 @@ +addSql('ALTER TABLE activity ADD privateComment_comments JSON DEFAULT \'{}\''); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_person_accompanying_period_work DROP privateComment_comments'); + } +} diff --git a/src/Bundle/ChillCalendarBundle/migrations/Version20220527124558.php b/src/Bundle/ChillCalendarBundle/migrations/Version20220527124558.php new file mode 100644 index 000000000..17c53a004 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/migrations/Version20220527124558.php @@ -0,0 +1,26 @@ +addSql('ALTER TABLE chill_calendar.calendar ADD privateComment_comments JSON DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_calendar.calendar DROP privateComment_comments'); + } +} diff --git a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml index eeb12298f..b7aa2e128 100644 --- a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml @@ -26,4 +26,3 @@ The calendar item has been successfully removed.: Le rendez-vous a été supprim From the day: Du to the day: au Transform to activity: Transformer en échange -private comment: Notes privé \ No newline at end of file diff --git a/src/Bundle/ChillMainBundle/Entity/Embeddable/PrivateCommentEmbeddable.php b/src/Bundle/ChillMainBundle/Entity/Embeddable/PrivateCommentEmbeddable.php index cfca2a86c..e27e906c0 100644 --- a/src/Bundle/ChillMainBundle/Entity/Embeddable/PrivateCommentEmbeddable.php +++ b/src/Bundle/ChillMainBundle/Entity/Embeddable/PrivateCommentEmbeddable.php @@ -20,15 +20,22 @@ use Doctrine\ORM\Mapping as ORM; class PrivateCommentEmbeddable { /** - * @ORM\Column(type="json", nullable=true) + * @ORM\Column(type="json", nullable=false, options={"default": "{}"}) + * @var array */ - private ?array $comments = []; + private array $comments = []; public function getCommentForUser(User $user): string { return $this->comments[$user->getId()] ?? ''; } + public function hasCommentForUser(User $user): bool + { + return array_key_exists($user->getId(), $this->comments) + && "" !== $this->comments[$user->getId()]; + } + public function getComments(): ?array { return $this->comments; @@ -47,7 +54,7 @@ class PrivateCommentEmbeddable public function setCommentForUser(User $user, string $content): self { - $this->comments[$user->getId()] = $content; + $this->comments[$user->getId()] = trim($content); return $this; } diff --git a/src/Bundle/ChillMainBundle/Form/Type/PrivateCommentType.php b/src/Bundle/ChillMainBundle/Form/Type/PrivateCommentType.php index 8ce33face..d4c0d1611 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/PrivateCommentType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/PrivateCommentType.php @@ -38,19 +38,15 @@ class PrivateCommentType extends AbstractType { $builder ->add('comments', ChillTextareaType::class, [ - 'label' => 'private comment', + 'disable_editor' => $options['disable_editor'], + 'label' => false, ]) ->setDataMapper($this->dataMapper); } public function buildView(FormView $view, FormInterface $form, array $options) { - $view->vars = array_replace( - $view->vars, - [ - 'hideLabel' => true, - ] - ); + $view->vars['hideLabel'] = true; } public function configureOptions(OptionsResolver $resolver) diff --git a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig index 1da384920..f45f91692 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Form/fields.html.twig @@ -198,6 +198,23 @@ {% endfor %} {% endblock %} + +{% block private_comment_row %} + {{ form_label(form) }} + {{ form_row(form) }} +{% endblock %} + +{% block private_comment_widget %} + {% for entry in form %} + {{ form_widget(entry) }} + {% endfor %} +{% endblock %} + +{% block comment_row %} + {{ form_label(form) }} + {{ form_row(form) }} +{% endblock %} + {% block comment_widget %} {% for entry in form %} {{ form_widget(entry) }} diff --git a/src/Bundle/ChillMainBundle/migrations/Version20220426133048.php b/src/Bundle/ChillMainBundle/migrations/Version20220426133048.php deleted file mode 100644 index 94f866e9b..000000000 --- a/src/Bundle/ChillMainBundle/migrations/Version20220426133048.php +++ /dev/null @@ -1,42 +0,0 @@ -addSql('ALTER TABLE chill_person_accompanying_period_work DROP privateComment_comments'); - $this->addSql('ALTER TABLE activity DROP privateComment_comments'); - $this->addSql('ALTER TABLE chill_calendar.calendar DROP privateComment_comments'); - } - - public function getDescription(): string - { - return 'add private embeddable comment to activity, calendar and accompanyingperiod work'; - } - - public function up(Schema $schema): void - { - // this up() migration is auto-generated, please modify it to your needs - $this->addSql('ALTER TABLE activity ADD privateComment_comments JSON DEFAULT NULL'); - $this->addSql('ALTER TABLE chill_calendar.calendar ADD privateComment_comments JSON DEFAULT NULL'); - $this->addSql('ALTER TABLE chill_person_accompanying_period_work ADD privateComment_comments JSON DEFAULT NULL'); - } -} diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index e9a5fce4d..db441af6e 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -65,7 +65,7 @@ Read more: Lire la suite # comment embeddable No comment associated: Aucun commentaire -private comment: Notes privé +private comment: Notes privées #pagination Previous: Précédent diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20220527124737.php b/src/Bundle/ChillPersonBundle/migrations/Version20220527124737.php new file mode 100644 index 000000000..b8f5b1dde --- /dev/null +++ b/src/Bundle/ChillPersonBundle/migrations/Version20220527124737.php @@ -0,0 +1,26 @@ +addSql('ALTER TABLE chill_person_accompanying_period_work ADD privateComment_comments JSON DEFAULT \'{}\''); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE activity DROP privateComment_comments'); + } +}