From 667b3fd69d26c1ac3ba906b6e619bec02e581cf3 Mon Sep 17 00:00:00 2001 From: Marcel Diegelmann Date: Thu, 20 Mar 2025 09:55:48 +0100 Subject: [PATCH] =?UTF-8?q?Default-Sortierung=20f=C3=BCr=20Assemblies=20pe?= =?UTF-8?q?r=20YAML-Konfiguration=20einf=C3=BChren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 9 ++++++ config/parameters.yaml | 4 +++ config/services.yaml | 3 ++ .../AssemblyBomEntriesDataTable.php | 28 +++++++++++-------- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/.env b/.env index 982d4bbd..cfa3bb05 100644 --- a/.env +++ b/.env @@ -60,6 +60,15 @@ ERROR_PAGE_ADMIN_EMAIL='' # If this is set to true, solutions to common problems are shown on error pages. Disable this, if you do not want your users to see them... ERROR_PAGE_SHOW_HELP=1 +################################################################################## +# Part table settings +################################################################################## + +# Configure which columns will be visible by default in the specific table (and in which order). +# This is a comma separated list of column names. See documentation for available values. +TABLE_PARTS_DEFAULT_COLUMNS=name,description,category,footprint,manufacturer,storage_location,amount +TABLE_ASSEMBLIES_DEFAULT_COLUMNS=quantity,manufacturer,name,description,category + ################################################################################### # SAML Single sign on-settings diff --git a/config/parameters.yaml b/config/parameters.yaml index 5b40899d..3584df3c 100644 --- a/config/parameters.yaml +++ b/config/parameters.yaml @@ -43,6 +43,10 @@ parameters: ###################################################################################################################### partdb.saml.enabled: '%env(bool:SAML_ENABLED)%' # If this is set to true, SAML authentication is enabled + ###################################################################################################################### + # Table settings + ###################################################################################################################### + partdb.table.assemblies.default_columns: '%env(trim:string:TABLE_ASSEMBLIES_DEFAULT_COLUMNS)%' # The default columns in assembly tables and their order ###################################################################################################################### # Miscellaneous diff --git a/config/services.yaml b/config/services.yaml index 17611cea..be293d38 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -167,6 +167,9 @@ services: #################################################################################################################### # Table settings #################################################################################################################### + App\DataTables\AssemblyBomEntriesDataTable: + arguments: + $visible_columns: '%partdb.table.assemblies.default_columns%' App\DataTables\Helpers\ColumnSortHelper: shared: false # Service has a state so not share it between different tables diff --git a/src/DataTables/AssemblyBomEntriesDataTable.php b/src/DataTables/AssemblyBomEntriesDataTable.php index 7149ed5f..a953179a 100644 --- a/src/DataTables/AssemblyBomEntriesDataTable.php +++ b/src/DataTables/AssemblyBomEntriesDataTable.php @@ -25,6 +25,7 @@ namespace App\DataTables; use App\DataTables\Column\EntityColumn; use App\DataTables\Column\LocaleDateTimeColumn; use App\DataTables\Column\MarkdownColumn; +use App\DataTables\Helpers\ColumnSortHelper; use App\DataTables\Helpers\PartDataTableHelper; use App\Entity\Attachments\Attachment; use App\Entity\Parts\Part; @@ -41,14 +42,19 @@ use Symfony\Contracts\Translation\TranslatorInterface; class AssemblyBomEntriesDataTable implements DataTableTypeInterface { - public function __construct(protected TranslatorInterface $translator, protected PartDataTableHelper $partDataTableHelper, protected EntityURLGenerator $entityURLGenerator, protected AmountFormatter $amountFormatter) - { + public function __construct( + protected TranslatorInterface $translator, + protected PartDataTableHelper $partDataTableHelper, + protected EntityURLGenerator $entityURLGenerator, + protected AmountFormatter $amountFormatter, + private string $visible_columns, + private ColumnSortHelper $csh + ){ } - public function configure(DataTable $dataTable, array $options): void { - $dataTable + $this->csh //->add('select', SelectColumn::class) ->add('picture', TextColumn::class, [ 'label' => '', @@ -62,7 +68,6 @@ class AssemblyBomEntriesDataTable implements DataTableTypeInterface ]) ->add('id', TextColumn::class, [ 'label' => $this->translator->trans('part.table.id'), - 'visible' => false, ]) ->add('quantity', TextColumn::class, [ 'label' => $this->translator->trans('assembly.bom.quantity'), @@ -97,11 +102,12 @@ class AssemblyBomEntriesDataTable implements DataTableTypeInterface ->add('ipn', TextColumn::class, [ 'label' => $this->translator->trans('part.table.ipn'), 'orderField' => 'NATSORT(part.ipn)', - 'visible' => false, 'render' => function ($value, AssemblyBOMEntry $context) { if($context->getPart() instanceof Part) { return $context->getPart()->getIpn(); } + + return ''; } ]) ->add('description', MarkdownColumn::class, [ @@ -142,7 +148,6 @@ class AssemblyBomEntriesDataTable implements DataTableTypeInterface ]) ->add('instockAmount', TextColumn::class, [ 'label' => 'assembly.bom.instockAmount', - 'visible' => false, 'render' => function ($value, AssemblyBOMEntry $context) { if ($context->getPart() !== null) { return $this->partDataTableHelper->renderAmount($context->getPart()); @@ -153,7 +158,6 @@ class AssemblyBomEntriesDataTable implements DataTableTypeInterface ]) ->add('storageLocations', TextColumn::class, [ 'label' => 'part.table.storeLocations', - 'visible' => false, 'render' => function ($value, AssemblyBOMEntry $context) { if ($context->getPart() !== null) { return $this->partDataTableHelper->renderStorageLocations($context->getPart()); @@ -164,15 +168,17 @@ class AssemblyBomEntriesDataTable implements DataTableTypeInterface ]) ->add('addedDate', LocaleDateTimeColumn::class, [ 'label' => $this->translator->trans('part.table.addedDate'), - 'visible' => false, ]) ->add('lastModified', LocaleDateTimeColumn::class, [ 'label' => $this->translator->trans('part.table.lastModified'), - 'visible' => false, ]) ; - $dataTable->addOrderBy('name', DataTable::SORT_ASCENDING); + //Apply the user configured order and visibility and add the columns to the table + $this->csh->applyVisibilityAndConfigureColumns($dataTable, $this->visible_columns, + "TABLE_ASSEMBLIES_DEFAULT_COLUMNS"); + + $dataTable->addOrderBy('name'); $dataTable->createAdapter(ORMAdapter::class, [ 'entity' => Attachment::class,