Default-Sortierung für Assemblies per YAML-Konfiguration einführen

This commit is contained in:
Marcel Diegelmann 2025-03-20 09:55:48 +01:00
parent 6fa960df42
commit 667b3fd69d
4 changed files with 33 additions and 11 deletions

9
.env
View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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,