mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-29 13:10:06 +02:00
Improved bool columns for Part Tables
This commit is contained in:
parent
0fc0136914
commit
4020aab049
2 changed files with 52 additions and 8 deletions
49
src/DataTables/Column/PrettyBoolColumn.php
Normal file
49
src/DataTables/Column/PrettyBoolColumn.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace App\DataTables\Column;
|
||||
|
||||
use Omines\DataTablesBundle\Column\AbstractColumn;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class PrettyBoolColumn extends AbstractColumn
|
||||
{
|
||||
|
||||
protected $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function normalize($value): ?bool
|
||||
{
|
||||
if (null === $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (bool) $value;
|
||||
}
|
||||
|
||||
public function render($value, $context)
|
||||
{
|
||||
if ($value === true) {
|
||||
return '<span class="badge bg-success"><i class="fa-solid fa-circle-check fa-fw"></i> '
|
||||
. $this->translator->trans('bool.true')
|
||||
. '</span>';
|
||||
}
|
||||
|
||||
if ($value === false) {
|
||||
return '<span class="badge bg-danger"><i class="fa-solid fa-circle-xmark fa-fw"></i> '
|
||||
. $this->translator->trans('bool.false')
|
||||
. '</span>';
|
||||
}
|
||||
|
||||
if ($value === null) {
|
||||
return '<span class="badge bg-secondary>"<i class="fa-solid fa-circle-question fa-fw"></i> '
|
||||
. $this->translator->trans('bool.unknown')
|
||||
. '</span>';
|
||||
}
|
||||
|
||||
throw new \RuntimeException('Unexpected value!');
|
||||
}
|
||||
}
|
|
@ -47,6 +47,7 @@ use App\DataTables\Column\IconLinkColumn;
|
|||
use App\DataTables\Column\LocaleDateTimeColumn;
|
||||
use App\DataTables\Column\MarkdownColumn;
|
||||
use App\DataTables\Column\PartAttachmentsColumn;
|
||||
use App\DataTables\Column\PrettyBoolColumn;
|
||||
use App\DataTables\Column\TagsColumn;
|
||||
use App\DataTables\Filters\PartFilter;
|
||||
use App\Entity\Parts\Category;
|
||||
|
@ -255,18 +256,12 @@ final class PartsDataTable implements DataTableTypeInterface
|
|||
'label' => $this->translator->trans('part.table.lastModified'),
|
||||
'visible' => false,
|
||||
])
|
||||
->add('needs_review', BoolColumn::class, [
|
||||
->add('needs_review', PrettyBoolColumn::class, [
|
||||
'label' => $this->translator->trans('part.table.needsReview'),
|
||||
'trueValue' => $this->translator->trans('true'),
|
||||
'falseValue' => $this->translator->trans('false'),
|
||||
'nullValue' => '',
|
||||
'visible' => false,
|
||||
])
|
||||
->add('favorite', BoolColumn::class, [
|
||||
->add('favorite', PrettyBoolColumn::class, [
|
||||
'label' => $this->translator->trans('part.table.favorite'),
|
||||
'trueValue' => $this->translator->trans('true'),
|
||||
'falseValue' => $this->translator->trans('false'),
|
||||
'nullValue' => '',
|
||||
'visible' => false,
|
||||
])
|
||||
->add('manufacturing_status', MapColumn::class, [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue