From 0bc9e74853c68305c1fe676ea15b46ff9ebbd7f7 Mon Sep 17 00:00:00 2001 From: jojoemade Date: Tue, 14 Apr 2020 14:18:11 +0200 Subject: [PATCH] added colors to tags (#1631) --- src/Entity/Tag.php | 2 ++ src/Form/TagEditForm.php | 3 +- src/Migrations/Version20200413133226.php | 38 +++++++++++++++++++++++ src/Repository/TagRepository.php | 3 +- templates/macros/widgets.html.twig | 5 ++- templates/tags/index.html.twig | 5 ++- tests/API/TagControllerTest.php | 2 +- tests/Entity/TagTest.php | 4 +++ var/data/kimai_test.sqlite | Bin 770048 -> 770048 bytes 9 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 src/Migrations/Version20200413133226.php 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 6bdb59583cd2eed4b946d4ca0e12cf64620551c3..f1c8fb918d8a7b24c898091a92ef9ec4f2ff9e2d 100644 GIT binary patch delta 475 zcmY+Lxe{KF1E9<c%2ck9deDo)6TW{Fw!9;0+j&~O9F#stq zyDQeYFl@Cz0<2ijyISyje}hkc5+`vru2*aIQhdC5EN;q1FW!HGb}Zg|J60Tg%l|^= zw(->9V^IBZI0th~S%pmtpRLSD|{SE9cQd_nXPihsypV&o=fJeCC?yTEQJz6U2U zYhspAcXRlFFjIX=`FUJYk&XBDP9B2-jl{BYVmw2{viS|fp(vtL@_$@hugRK}NiwrL zHJNGF8~R}j?=l*Bi^`cbYj4r4EzjRer*QW;($~-8#(O@FLm&+tDqbQL-6)YYRM|X! Z?rxQdK@DbDhHW?oH(Vp5x60zelYgP4cA@|P delta 367 zcmW;GJxBs!9LMqJ|J>ukl+Z}1t1O8JYWo)!~@AlPS%^x6{glyKIJ<*Sz zc9cYpk`#7WM%nP`HGNQfM@engUbIiBIhE2iWlTPiy9&ddr6kPrRT;K1FKh6N*^&vn z*XQs6s&hoKLLt~$V0##{JS;&A^KS|lxE|1#fg0kV30cJKZO|=k5vTYx1w8A59A?b` ze&JsxSY9cl<(bk4qhcP?cs>prL<$)xrX>Dbhrv_hP<|vHTt!Ux;|L)xg!q6T9|F6j tVCcQ-8F^EzXcYDrS<44*rf%9Uv(+FLB!LJvK^7E&3aVh|)u1+g{0Ej$W6b~n