Add tag icons

This commit is contained in:
Dennis Eichhorn 2020-12-19 20:26:28 +01:00
parent 076e2c0026
commit b10b031c49
12 changed files with 37 additions and 40 deletions

View File

@ -14,6 +14,12 @@
"type": "VARCHAR(9)",
"null": false
},
"tag_icon": {
"name": "tag_icon",
"type": "VARCHAR(255)",
"null": true,
"default": null
},
"tag_type": {
"name": "tag_type",
"type": "TINYINT(1)",

View File

@ -95,7 +95,7 @@ final class ApiController extends Controller
/** @var Tag $tag */
$tag = TagMapper::get((int) $request->getData('id'));
$tag->setTitle((string) ($request->getData('title') ?? $tag->getTitle()));
$tag->setColor(\str_pad($request->getData('color') ?? $tag->getColor(), 9, 'ff', \STR_PAD_RIGHT));
$tag->color = \str_pad($request->getData('color') ?? $tag->color, 9, 'ff', \STR_PAD_RIGHT);
return $tag;
}
@ -198,8 +198,9 @@ final class ApiController extends Controller
*/
private function createTagFromRequest(RequestAbstract $request) : Tag
{
$tag = new Tag();
$tag->setColor(\str_pad($request->getData('color') ?? '#000000ff', 9, 'f'));
$tag = new Tag();
$tag->color = \str_pad($request->getData('color') ?? '#000000ff', 9, 'f');
$tag->icon = $request->getData('icon');
return $tag;
}

View File

@ -51,7 +51,15 @@ class Tag implements \JsonSerializable, ArrayableInterface
* @var string
* @since 1.0.0
*/
private string $color = '00000000';
public string $color = '00000000';
/**
* Icon.
*
* @var null|string
* @since 1.0.0
*/
public ?string $icon = null;
/**
* Creator.
@ -121,32 +129,6 @@ class Tag implements \JsonSerializable, ArrayableInterface
$this->type = $type;
}
/**
* Get color
*
* @return string
*
* @since 1.0.0
*/
public function getColor() : string
{
return $this->color;
}
/**
* Set color
*
* @param string $color Tag article color
*
* @return void
*
* @since 1.0.0
*/
public function setColor(string $color) : void
{
$this->color = $color;
}
/**
* Get id
*

View File

@ -40,6 +40,7 @@ final class TagMapper extends DataMapperAbstract
protected static array $columns = [
'tag_id' => ['name' => 'tag_id', 'type' => 'int', 'internal' => 'id'],
'tag_color' => ['name' => 'tag_color', 'type' => 'string', 'internal' => 'color'],
'tag_icon' => ['name' => 'tag_icon', 'type' => 'string', 'internal' => 'icon'],
'tag_type' => ['name' => 'tag_type', 'type' => 'int', 'internal' => 'type'],
'tag_owner' => ['name' => 'tag_owner', 'type' => 'int', 'internal' => 'owner'],
];

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
return ['Tag' => [
'Color' => 'Farbe',
'Create' => 'Erstellen',
'Icon' => 'Icon',
'Language' => 'Sprache',
'List' => 'Liste',
'Tag' => 'Tag',

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
return ['Tag' => [
'Color' => 'Color',
'Create' => 'Create',
'Icon' => 'Icon',
'Language' => 'Language',
'List' => 'List',
'Tag' => 'Tag',

View File

@ -27,6 +27,8 @@ echo $this->getData('nav')->render(); ?>
<tr><td><input type="text" name="title" id="iTitle" placeholder="&#xf040; oms" required>
<tr><td><label for="iColor"><?= $this->getHtml('Color'); ?></label>
<tr><td><input type="color" name="color" id="iColor"required>
<tr><td><label for="iIcon"><?= $this->getHtml('Icon'); ?></label>
<tr><td><input type="text" name="icon" id="iIcon" placeholder="&#xf040; oms" value="<?= $this->printHtml($tag->icon ?? ''); ?>">
</table>
</div>
<div class="portlet-foot">

View File

@ -31,14 +31,15 @@ echo $this->getData('nav')->render(); ?>
<table class="default">
<thead>
<tr>
<td><?= $this->getHtml('Color'); ?>
<td class="wf-100"><?= $this->getHtml('Title'); ?>
<td class="wf-100"><?= $this->getHtml('Color'); ?>
<tbody>
<?php $count = 0; foreach ($tags as $key => $value) : ++$count;
$url = UriFactory::build('{/prefix}tag/single?{?}&id=' . $value->getId()); ?>
<tr tabindex="0" data-href="<?= $url; ?>">
<td data-label="<?= $this->getHtml('Title'); ?>"><a href="<?= $url; ?>"><span class="tag" style="background: <?= $this->printHtml(\substr($value->color, 0, 7)); ?>">&nbsp;&nbsp;&nbsp;<?= $value->icon !== null ? '<i class="' . $this->printHtml($value->icon ?? '') . '"></i>' : '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; ?>&nbsp;</span></a>
<td data-label="<?= $this->getHtml('Title'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getTitle()); ?></a>
<td data-label="<?= $this->getHtml('Title'); ?>"><a href="<?= $url; ?>"><span class="tag" style="background: <?= $this->printHtml(\substr($value->getColor(), 0, 7)); ?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></a>
<?php endforeach; ?>
<?php if ($count === 0) : ?>
<tr><td colspan="3" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>

View File

@ -31,7 +31,9 @@ echo $this->getData('nav')->render(); ?>
<tr><td><label for="iTitle"><?= $this->getHtml('Title'); ?></label>
<tr><td><input type="text" name="title" id="iTitle" placeholder="&#xf040; oms" value="<?= $this->printHtml($tag->getTitle()); ?>" required>
<tr><td><label for="iColor"><?= $this->getHtml('Color'); ?></label>
<tr><td><input type="color" name="color" id="iColor" value="<?= $this->printHtml(\substr($tag->getColor(), 0, 7)); ?>" required>
<tr><td><input type="color" name="color" id="iColor" value="<?= $this->printHtml(\substr($tag->color, 0, 7)); ?>" required>
<tr><td><label for="iIcon"><?= $this->getHtml('Icon'); ?></label>
<tr><td><input type="text" name="icon" id="iIcon" placeholder="&#xf040; oms" value="<?= $this->printHtml($tag->icon ?? ''); ?>">
</table>
</div>
<div class="portlet-foot">

View File

@ -33,7 +33,7 @@ class TagL11nMapperTest extends \PHPUnit\Framework\TestCase
public function testCR() : void
{
$tag = new Tag();
$tag->setColor('#ffffffff');
$tag->color = '#ffffffff';
$tag->setType(TagType::SINGLE);
$id = TagMapper::create($tag);

View File

@ -31,7 +31,7 @@ class TagMapperTest extends \PHPUnit\Framework\TestCase
{
$tag = new Tag();
$tag->setTitle('TestTag');
$tag->setColor('#ff0000ff');
$tag->color = '#ff0000ff';
$tag->setType(TagType::SINGLE);
$id = TagMapper::create($tag);
@ -40,7 +40,7 @@ class TagMapperTest extends \PHPUnit\Framework\TestCase
$tagR = TagMapper::get($tag->getId());
self::assertEquals($tag->getTitle(), $tagR->getTitle());
self::assertEquals($tag->getColor(), $tagR->getColor());
self::assertEquals($tag->color, $tagR->color);
self::assertEquals($tag->getType(), $tagR->getType());
}
}

View File

@ -40,7 +40,7 @@ class TagTest extends \PHPUnit\Framework\TestCase
self::assertEquals(0, $this->tag->getId());
self::assertInstanceOf(NullAccount::class, $this->tag->getOwner());
self::assertEquals(TagType::SINGLE, $this->tag->getType());
self::assertEquals('00000000', $this->tag->getColor());
self::assertEquals('00000000', $this->tag->color);
self::assertEquals('', $this->tag->getTitle());
}
@ -76,8 +76,8 @@ class TagTest extends \PHPUnit\Framework\TestCase
*/
public function testColorInputOutput() : void
{
$this->tag->setColor('ffffffff');
self::assertEquals('ffffffff', $this->tag->getColor());
$this->tag->color = 'ffffffff';
self::assertEquals('ffffffff', $this->tag->color);
}
/**
@ -98,7 +98,7 @@ class TagTest extends \PHPUnit\Framework\TestCase
{
$this->tag->setTitle($t = new TagL11n('Test'));
$this->tag->setOwner($a = new NullAccount(2));
$this->tag->setColor('ffffffff');
$this->tag->color = 'ffffffff';
$this->tag->setType(TagType::SHARED);
self::assertEquals(