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 @@ {{ tables.datatable_multiupdate_row(tag.id) }} - {{ tag.name }} + + {{ widgets.color_dot(tag.color|default('#00a65a')) }} + {{ tag.name }} + {{ widgets.label(tag.amount, type) }} {{ actions.tag(tag, 'index') }} diff --git a/tests/API/TagControllerTest.php b/tests/API/TagControllerTest.php index 5f528b66..cfa3fdc6 100644 --- a/tests/API/TagControllerTest.php +++ b/tests/API/TagControllerTest.php @@ -132,7 +132,7 @@ class TagControllerTest extends APIControllerBaseTest protected function assertStructure(array $result, $full = true) { $expectedKeys = [ - 'id', 'name', 'timesheets' + 'id', 'name', 'color', 'timesheets' ]; if ($full) { diff --git a/tests/Entity/TagTest.php b/tests/Entity/TagTest.php index 6633ca31..2cd13582 100644 --- a/tests/Entity/TagTest.php +++ b/tests/Entity/TagTest.php @@ -23,6 +23,7 @@ class TagTest extends TestCase $sut = new Tag(); $this->assertNull($sut->getId()); $this->assertNull($sut->getName()); + $this->assertNull($sut->getColor()); } public function testSetterAndGetter() @@ -32,6 +33,9 @@ class TagTest extends TestCase $this->assertInstanceOf(Tag::class, $sut->setName('foo')); $this->assertEquals('foo', $sut->getName()); $this->assertEquals('foo', (string) $sut); + + $this->assertInstanceOf(Tag::class, $sut->setColor('#fffccc')); + $this->assertEquals('#fffccc', $sut->getColor()); } public function testWithTimesheet() diff --git a/var/data/kimai_test.sqlite b/var/data/kimai_test.sqlite index 6bdb5958..f1c8fb91 100644 Binary files a/var/data/kimai_test.sqlite and b/var/data/kimai_test.sqlite differ