Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add color to tags #1631

Merged
merged 5 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Entity/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class Tag
*/
private $name;

use ColorTrait;

/**
* @var Timesheet[]|ArrayCollection
*
Expand Down
3 changes: 2 additions & 1 deletion src/Form/TagEditForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +30,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'autofocus' => 'autofocus'
],
])
;
->add('color', ColorPickerType::class);
}

/**
Expand Down
38 changes: 38 additions & 0 deletions src/Migrations/Version20200413133226.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace DoctrineMigrations;

use App\Doctrine\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
* @version 1.9
*/
final class Version20200413133226 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add color for tags';
}

public function up(Schema $schema): void
{
$tags = $schema->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');
}
}
3 changes: 2 additions & 1 deletion src/Repository/TagRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ public function getTagCount(TagQuery $query)
$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();
Expand Down
5 changes: 2 additions & 3 deletions templates/macros/widgets.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@
{% endmacro %}

{% macro badge(title, color) %}
{# black, green, blue, yellow #}
<span class="badge bg-{{ color|default('red') }}">{{ title|trans }}</span>
<span class="badge" style="background-color:{{ color|default('#dd4b39') }}">{{ title|trans }}</span>
{% endmacro %}

{% macro alert(type, description, title, icon) %}
Expand Down Expand Up @@ -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 %}

Expand Down
5 changes: 4 additions & 1 deletion templates/tags/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@

<tr{% if manageAllowed %} class="modal-ajax-form open-edit" data-href="{{ path('tags_edit', {'id': tag.id}) }}"{% endif %}>
<td class="text-nowrap">{{ tables.datatable_multiupdate_row(tag.id) }}</td>
<td>{{ tag.name }}</td>
<td>
{{ widgets.color_dot(tag.color|default('#00a65a')) }}
{{ tag.name }}
</td>
<td>{{ widgets.label(tag.amount, type) }}</td>
<td class="actions">
{{ actions.tag(tag, 'index') }}
Expand Down
2 changes: 1 addition & 1 deletion tests/API/TagControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function testDeleteActionWithUnknownTimesheet()
protected function assertStructure(array $result, $full = true)
{
$expectedKeys = [
'id', 'name', 'timesheets'
'id', 'name', 'color', 'timesheets'
];

if ($full) {
Expand Down
4 changes: 4 additions & 0 deletions tests/Entity/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function testDefaultValues()
$sut = new Tag();
$this->assertNull($sut->getId());
$this->assertNull($sut->getName());
$this->assertNull($sut->getColor());
}

public function testSetterAndGetter()
Expand All @@ -32,6 +33,9 @@ public function testSetterAndGetter()
$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());
Comment on lines +36 to +38
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the addition!

Wouldn't it make more sense to test the trait just once instead of testing every place where it's used?

See https://phpunit.readthedocs.io/en/9.1/test-doubles.html#mocking-traits-and-abstract-classes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really testing that the method works as expected, but I rather want to make sure that the methods exists on the object.

}

public function testWithTimesheet()
Expand Down
Binary file modified var/data/kimai_test.sqlite
Binary file not shown.