From fbf351103f7a0b67e2d2c1f21c8fad44462765b3 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Wed, 31 Jul 2024 16:14:47 +0200 Subject: [PATCH 1/3] Allow to select a color for a label --- src/Entity/Label.php | 11 +++--- src/Form/Type/LabelType.php | 7 ++-- src/Misc/AdditionalTranslations.php | 8 ++++ templates/labels/_form.html.twig | 26 +++++++++++++ tests/Controller/LabelsControllerTest.php | 45 ++++++++++++++++++----- tests/Factory/LabelFactory.php | 1 - translations/errors+intl-icu.en_GB.yaml | 3 +- translations/errors+intl-icu.fr_FR.yaml | 3 +- translations/messages+intl-icu.en_GB.yaml | 7 ++++ translations/messages+intl-icu.fr_FR.yaml | 7 ++++ 10 files changed, 95 insertions(+), 23 deletions(-) diff --git a/src/Entity/Label.php b/src/Entity/Label.php index 22a4c672..60fa8d4d 100644 --- a/src/Entity/Label.php +++ b/src/Entity/Label.php @@ -29,6 +29,8 @@ class Label implements MonitorableEntityInterface, UidEntityInterface use MonitorableEntityTrait; use UidEntityTrait; + public const COLORS = ['grey', 'primary', 'blue', 'green', 'orange', 'red']; + #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] @@ -67,11 +69,8 @@ class Label implements MonitorableEntityInterface, UidEntityInterface private ?string $description = null; #[ORM\Column(length: 7)] - #[Assert\NotBlank( - message: new TranslatableMessage('label.color.required', [], 'errors'), - )] - #[Assert\CssColor( - formats: Assert\CssColor::HEX_LONG, + #[Assert\Choice( + choices: self::COLORS, message: new TranslatableMessage('label.color.invalid', [], 'errors'), )] private ?string $color = null; @@ -84,7 +83,7 @@ public function __construct() { $this->name = ''; $this->description = ''; - $this->color = '#e0e1e6'; + $this->color = 'grey'; $this->tickets = new ArrayCollection(); } diff --git a/src/Form/Type/LabelType.php b/src/Form/Type/LabelType.php index f9d7c1b2..85c65854 100644 --- a/src/Form/Type/LabelType.php +++ b/src/Form/Type/LabelType.php @@ -26,9 +26,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'trim' => true, ]); - $builder->add('color', Type\HiddenType::class, [ - 'data' => '#e0e1e6', - 'trim' => true, + $builder->add('color', Type\ChoiceType::class, [ + 'choices' => Entity\Label::COLORS, + 'expanded' => true, + 'multiple' => false, ]); } diff --git a/src/Misc/AdditionalTranslations.php b/src/Misc/AdditionalTranslations.php index f89fb4de..f9dd2d23 100644 --- a/src/Misc/AdditionalTranslations.php +++ b/src/Misc/AdditionalTranslations.php @@ -40,3 +40,11 @@ new TranslatableMessage('roles.permissions.orga.update.tickets.status'); new TranslatableMessage('roles.permissions.orga.update.tickets.title'); new TranslatableMessage('roles.permissions.orga.update.tickets.type'); + +// See templates/labels/_form.html.twig +new TranslatableMessage('common.colors.grey'); +new TranslatableMessage('common.colors.primary'); +new TranslatableMessage('common.colors.blue'); +new TranslatableMessage('common.colors.green'); +new TranslatableMessage('common.colors.orange'); +new TranslatableMessage('common.colors.red'); diff --git a/templates/labels/_form.html.twig b/templates/labels/_form.html.twig index 70b7c8d6..a674abc1 100644 --- a/templates/labels/_form.html.twig +++ b/templates/labels/_form.html.twig @@ -58,6 +58,32 @@ /> +
+ {{ 'labels.color' | trans }} + +
+ {{ form_errors(form.color) }} + +
+ {% for color in form.color %} + + + + + + {% endfor %} +
+
+ +
{% endfor %} diff --git a/templates/tickets/_list.html.twig b/templates/tickets/_list.html.twig index ea93dd98..8dc0334c 100644 --- a/templates/tickets/_list.html.twig +++ b/templates/tickets/_list.html.twig @@ -50,7 +50,7 @@ {% if ticket.labels %}