diff --git a/src/Entity/Tag.php b/src/Entity/Tag.php index d83b4516..2b94ba30 100644 --- a/src/Entity/Tag.php +++ b/src/Entity/Tag.php @@ -44,6 +44,8 @@ class Tag */ private $name; + use ColorTrait; + /** * @var Timesheet[]|ArrayCollection * diff --git a/src/Form/TagEditForm.php b/src/Form/TagEditForm.php index ee0a1170..d026b118 100644 --- a/src/Form/TagEditForm.php +++ b/src/Form/TagEditForm.php @@ -10,6 +10,7 @@ namespace App\Form; use App\Entity\Tag; +use App\Form\Type\ColorPickerType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; @@ -29,7 +30,7 @@ class TagEditForm extends AbstractType 'autofocus' => 'autofocus' ], ]) - ; + ->add('color', ColorPickerType::class); } /** diff --git a/src/Migrations/Version20200413133226.php b/src/Migrations/Version20200413133226.php new file mode 100644 index 00000000..8c01d277 --- /dev/null +++ b/src/Migrations/Version20200413133226.php @@ -0,0 +1,38 @@ +getTable('kimai2_tags'); + $tags->addColumn('color', 'string', ['length' => 7, 'notnull' => false, 'default' => null]); + } + + public function down(Schema $schema): void + { + $tags = $schema->getTable('kimai2_tags'); + $tags->dropColumn('color'); + } +} diff --git a/src/Repository/TagRepository.php b/src/Repository/TagRepository.php index a40e855d..d5ef3319 100644 --- a/src/Repository/TagRepository.php +++ b/src/Repository/TagRepository.php @@ -108,10 +108,11 @@ class TagRepository extends EntityRepository $qb = $this->createQueryBuilder('tag'); $qb - ->select('tag.id, tag.name, count(timesheets.id) as amount') + ->select('tag.id, tag.name, tag.color, count(timesheets.id) as amount') ->leftJoin('tag.timesheets', 'timesheets') ->addGroupBy('tag.id') ->addGroupBy('tag.name') + ->addGroupBy('tag.color') ; $orderBy = $query->getOrderBy(); diff --git a/templates/macros/widgets.html.twig b/templates/macros/widgets.html.twig index 1727847b..5e0a90cb 100644 --- a/templates/macros/widgets.html.twig +++ b/templates/macros/widgets.html.twig @@ -159,8 +159,7 @@ {% endmacro %} {% macro badge(title, color) %} - {# black, green, blue, yellow #} - {{ title|trans }} + {{ title|trans }} {% endmacro %} {% macro alert(type, description, title, icon) %} @@ -369,7 +368,7 @@ {% macro tag_list(taglist) %} {% import _self as macro %} {% for tag in taglist %} - {{ macro.badge(tag.name , 'green') }} + {{ macro.badge(tag.name, tag.color|default('#00a65a')) }} {% endfor %} {% endmacro %} diff --git a/templates/tags/index.html.twig b/templates/tags/index.html.twig index f133f8ba..1ab98075 100644 --- a/templates/tags/index.html.twig +++ b/templates/tags/index.html.twig @@ -38,7 +38,10 @@