Rebase auf Part-DB v2.1.2

This commit is contained in:
Marcel Diegelmann 2025-09-10 13:56:36 +02:00
parent 2648bd2c6d
commit dc3279c449
30 changed files with 947 additions and 58 deletions

View file

@ -216,6 +216,7 @@ class AssemblyController extends AbstractController
'assembly.bom_import.type.json' => 'json',
'assembly.bom_import.type.csv' => 'csv',
'assembly.bom_import.type.kicad_pcbnew' => 'kicad_pcbnew',
'assembly.bom_import.type.kicad_schematic' => 'kicad_schematic',
]
]);
$builder->add('clear_existing_bom', CheckboxType::class, [

View file

@ -421,7 +421,7 @@ class ProjectController extends AbstractController
}
// Import with field mapping and priorities (validation already passed)
$entries = $BOMImporter->stringToBOMEntries($file_content, [
$entries = $BOMImporter->stringToBOMEntries($project, $file_content, [
'type' => 'kicad_schematic',
'field_mapping' => $field_mapping,
'field_priorities' => $field_priorities,

View file

@ -34,8 +34,8 @@ use App\Entity\Attachments\Attachment;
use App\Entity\Parts\Part;
use App\Entity\AssemblySystem\AssemblyBOMEntry;
use App\Entity\ProjectSystem\Project;
use App\Services\EntityURLGenerator;
use App\Services\Formatters\AmountFormatter;
use App\Settings\BehaviorSettings\TableSettings;
use Doctrine\ORM\QueryBuilder;
use Omines\DataTablesBundle\Adapter\Doctrine\ORM\SearchCriteriaProvider;
use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;
@ -47,15 +47,14 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class AssemblyBomEntriesDataTable implements DataTableTypeInterface
{
public function __construct(
protected TranslatorInterface $translator,
protected PartDataTableHelper $partDataTableHelper,
protected ProjectDataTableHelper $projectDataTableHelper,
protected AssemblyDataTableHelper $assemblyDataTableHelper,
protected EntityURLGenerator $entityURLGenerator,
protected AmountFormatter $amountFormatter,
private string $visible_columns,
private ColumnSortHelper $csh
){
private readonly TranslatorInterface $translator,
private readonly PartDataTableHelper $partDataTableHelper,
private readonly ProjectDataTableHelper $projectDataTableHelper,
private readonly AssemblyDataTableHelper $assemblyDataTableHelper,
private readonly AmountFormatter $amountFormatter,
private readonly ColumnSortHelper $csh,
private readonly TableSettings $tableSettings,
) {
}
public function configure(DataTable $dataTable, array $options): void
@ -200,11 +199,11 @@ class AssemblyBomEntriesDataTable implements DataTableTypeInterface
])
->add('lastModified', LocaleDateTimeColumn::class, [
'label' => $this->translator->trans('part.table.lastModified'),
])
;
]);
//Apply the user configured order and visibility and add the columns to the table
$this->csh->applyVisibilityAndConfigureColumns($dataTable, $this->visible_columns,"TABLE_ASSEMBLIES_BOM_DEFAULT_COLUMNS");
$this->csh->applyVisibilityAndConfigureColumns($dataTable, $this->tableSettings->assembliesBomDefaultColumns,
"TABLE_ASSEMBLIES_BOM_DEFAULT_COLUMNS");
$dataTable->addOrderBy('name', DataTable::SORT_ASCENDING);

View file

@ -34,6 +34,7 @@ use App\DataTables\Helpers\ColumnSortHelper;
use App\Doctrine\Helpers\FieldHelper;
use App\Entity\AssemblySystem\Assembly;
use App\Services\EntityURLGenerator;
use App\Settings\BehaviorSettings\TableSettings;
use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\QueryBuilder;
use Omines\DataTablesBundle\Adapter\Doctrine\ORM\SearchCriteriaProvider;
@ -53,8 +54,8 @@ final class AssemblyDataTable implements DataTableTypeInterface
private readonly TranslatorInterface $translator,
private readonly AssemblyDataTableHelper $assemblyDataTableHelper,
private readonly Security $security,
private readonly string $visible_columns,
private readonly ColumnSortHelper $csh,
private readonly TableSettings $tableSettings,
) {
}
@ -139,7 +140,8 @@ final class AssemblyDataTable implements DataTableTypeInterface
]);
//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");
$this->csh->applyVisibilityAndConfigureColumns($dataTable, $this->tableSettings->assembliesDefaultColumns,
"TABLE_ASSEMBLIES_DEFAULT_COLUMNS");
$dataTable->addOrderBy('name')
->createAdapter(TwoStepORMAdapter::class, [

View file

@ -150,18 +150,6 @@ class AssemblyBOMEntry extends AbstractDBElement implements UniqueValidatableInt
#[Groups(['bom_entry:read', 'bom_entry:write'])]
protected ?Assembly $referencedAssembly = null;
/**
* @var Project|null The associated project
*/
#[Assert\Expression(
'(this.getPart() === null or this.getProject() === null) and (this.getName() === null or (this.getName() != null and this.getName() != ""))',
message: 'validator.project.bom_entry.only_part_or_assembly_allowed'
)]
#[ORM\ManyToOne(targetEntity: Project::class)]
#[ORM\JoinColumn(name: 'id_project', nullable: true)]
#[Groups(['bom_entry:read', 'bom_entry:write'])]
protected ?Project $project = null;
/**
* @var BigDecimal|null The price of this non-part BOM entry
*/

View file

@ -26,6 +26,7 @@ use App\Entity\Base\AbstractNamedDBElement;
use App\Form\AssemblySystem\AssemblyBOMEntryCollectionType;
use App\Form\Type\RichTextEditorType;
use App\Services\LogSystem\EventCommentNeededHelper;
use App\Settings\MiscSettings\AssemblySettings;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
@ -36,9 +37,9 @@ class AssemblyAdminForm extends BaseEntityAdminForm
public function __construct(
protected Security $security,
protected EventCommentNeededHelper $eventCommentNeededHelper,
protected bool $useAssemblyIpnPlaceholder = false
protected AssemblySettings $assemblySettings,
) {
parent::__construct($security, $eventCommentNeededHelper, $useAssemblyIpnPlaceholder);
parent::__construct($security, $eventCommentNeededHelper, $assemblySettings);
}
protected function additionalFormElements(FormBuilderInterface $builder, array $options, AbstractNamedDBElement $entity): void

View file

@ -27,6 +27,7 @@ use App\Entity\PriceInformations\Currency;
use App\Entity\ProjectSystem\Project;
use App\Entity\UserSystem\Group;
use App\Services\LogSystem\EventCommentType;
use App\Settings\MiscSettings\AssemblySettings;
use Symfony\Bundle\SecurityBundle\Security;
use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
@ -51,7 +52,7 @@ class BaseEntityAdminForm extends AbstractType
public function __construct(
protected Security $security,
protected EventCommentNeededHelper $eventCommentNeededHelper,
protected bool $useAssemblyIpnPlaceholder = false
protected AssemblySettings $assemblySettings,
) {
}
@ -73,7 +74,7 @@ class BaseEntityAdminForm extends AbstractType
->add('name', TextType::class, [
'empty_data' => '',
'label' => 'name.label',
'data' => $is_new && $entity instanceof Assembly && $this->useAssemblyIpnPlaceholder ? '%%ipn%%' : $entity->getName(),
'data' => $is_new && $entity instanceof Assembly && $this->assemblySettings->useIpnPlaceholderInName ? '%%ipn%%' : $entity->getName(),
'attr' => [
'placeholder' => 'part.name.placeholder',
],

View file

@ -72,9 +72,9 @@ class BOMImporter
private CategoryRepository $categoryRepository;
private DBElementRepository $projectBOMEntryRepository;
private DBElementRepository $projectBomEntryRepository;
private DBElementRepository $assemblyBOMEntryRepository;
private DBElementRepository $assemblyBomEntryRepository;
public function __construct(
private readonly EntityManagerInterface $entityManager,
@ -85,8 +85,8 @@ class BOMImporter
$this->partRepository = $entityManager->getRepository(Part::class);
$this->manufacturerRepository = $entityManager->getRepository(Manufacturer::class);
$this->categoryRepository = $entityManager->getRepository(Category::class);
$this->projectBOMEntryRepository = $entityManager->getRepository(ProjectBOMEntry::class);
$this->assemblyBOMEntryRepository = $entityManager->getRepository(AssemblyBOMEntry::class);
$this->projectBomEntryRepository = $entityManager->getRepository(ProjectBOMEntry::class);
$this->assemblyBomEntryRepository = $entityManager->getRepository(AssemblyBOMEntry::class);
}
protected function configureOptions(OptionsResolver $resolver): OptionsResolver
@ -828,11 +828,11 @@ class BOMImporter
}
if ($importObject instanceof Assembly) {
$bomEntry = $this->assemblyBOMEntryRepository->findOneBy(['assembly' => $importObject, 'part' => $part]);
$bomEntry = $this->assemblyBomEntryRepository->findOneBy(['assembly' => $importObject, 'part' => $part]);
if ($bomEntry === null) {
if (isset($entry['name']) && $entry['name'] !== '') {
$bomEntry = $this->assemblyBOMEntryRepository->findOneBy(['assembly' => $importObject, 'name' => $entry['name']]);
$bomEntry = $this->assemblyBomEntryRepository->findOneBy(['assembly' => $importObject, 'name' => $entry['name']]);
}
if ($bomEntry === null) {
@ -840,11 +840,11 @@ class BOMImporter
}
}
} else {
$bomEntry = $this->projectBOMEntryRepository->findOneBy(['project' => $importObject, 'part' => $part]);
$bomEntry = $this->projectBomEntryRepository->findOneBy(['project' => $importObject, 'part' => $part]);
if ($bomEntry === null) {
if (isset($entry['name']) && $entry['name'] !== '') {
$bomEntry = $this->projectBOMEntryRepository->findOneBy(['project' => $importObject, 'name' => $entry['name']]);
$bomEntry = $this->projectBomEntryRepository->findOneBy(['project' => $importObject, 'name' => $entry['name']]);
}
if ($bomEntry === null) {
@ -914,9 +914,9 @@ class BOMImporter
//Check whether there is a name
if (!empty($name)) {
if ($importObject instanceof Project) {
$bomEntry = $this->projectBOMEntryRepository->findOneBy(['name' => $name]);
$bomEntry = $this->projectBomEntryRepository->findOneBy(['name' => $name]);
} else {
$bomEntry = $this->assemblyBOMEntryRepository->findOneBy(['name' => $name]);
$bomEntry = $this->assemblyBomEntryRepository->findOneBy(['name' => $name]);
}
}

View file

@ -0,0 +1,46 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Settings\BehaviorSettings;
use Symfony\Contracts\Translation\TranslatableInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
enum AssemblyBomTableColumns : string implements TranslatableInterface
{
case NAME = "name";
case ID = "id";
case QUANTITY = "quantity";
case IPN = "ipn";
case DESCRIPTION = "description";
public function trans(TranslatorInterface $translator, ?string $locale = null): string
{
$key = match($this) {
default => 'assembly.bom.table.' . $this->value,
};
return $translator->trans($key, locale: $locale);
}
}

View file

@ -0,0 +1,49 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Settings\BehaviorSettings;
use Symfony\Contracts\Translation\TranslatableInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
enum AssemblyTableColumns : string implements TranslatableInterface
{
case NAME = "name";
case ID = "id";
case IPN = "ipn";
case DESCRIPTION = "description";
case REFERENCED_ASSEMBLIES = "referencedAssemblies";
case ADDED_DATE = "addedDate";
case LAST_MODIFIED = "lastModified";
case EDIT = "edit";
public function trans(TranslatorInterface $translator, ?string $locale = null): string
{
$key = match($this) {
default => 'assembly.table.' . $this->value,
};
return $translator->trans($key, locale: $locale);
}
}

View file

@ -53,7 +53,6 @@ class TableSettings
)]
public int $fullDefaultPageSize = 50;
/** @var PartTableColumns[] */
#[SettingsParameter(ArrayType::class,
label: new TM("settings.behavior.table.parts_default_columns"),
@ -70,6 +69,37 @@ class TableSettings
PartTableColumns::CATEGORY, PartTableColumns::FOOTPRINT, PartTableColumns::MANUFACTURER,
PartTableColumns::LOCATION, PartTableColumns::AMOUNT];
/** @var AssemblyTableColumns[] */
#[SettingsParameter(ArrayType::class,
label: new TM("settings.behavior.table.assemblies_default_columns"),
description: new TM("settings.behavior.table.assemblies_default_columns.help"),
options: ['type' => EnumType::class, 'options' => ['class' => AssemblyTableColumns::class]],
formType: \Symfony\Component\Form\Extension\Core\Type\EnumType::class,
formOptions: ['class' => AssemblyTableColumns::class, 'multiple' => true, 'ordered' => true],
envVar: "TABLE_ASSEMBLIES_DEFAULT_COLUMNS", envVarMode: EnvVarMode::OVERWRITE, envVarMapper: [self::class, 'mapAssembliesDefaultColumnsEnv']
)]
#[Assert\NotBlank()]
#[Assert\Unique()]
#[Assert\All([new Assert\Type(AssemblyTableColumns::class)])]
public array $assembliesDefaultColumns = [AssemblyTableColumns::ID, AssemblyTableColumns::IPN, AssemblyTableColumns::NAME,
AssemblyTableColumns::DESCRIPTION, AssemblyTableColumns::REFERENCED_ASSEMBLIES, AssemblyTableColumns::EDIT];
/** @var AssemblyBomTableColumns[] */
#[SettingsParameter(ArrayType::class,
label: new TM("settings.behavior.table.assemblies_bom_default_columns"),
description: new TM("settings.behavior.table.assemblies_bom_default_columns.help"),
options: ['type' => EnumType::class, 'options' => ['class' => AssemblyBomTableColumns::class]],
formType: \Symfony\Component\Form\Extension\Core\Type\EnumType::class,
formOptions: ['class' => AssemblyBomTableColumns::class, 'multiple' => true, 'ordered' => true],
envVar: "TABLE_ASSEMBLIES_BOM_DEFAULT_COLUMNS", envVarMode: EnvVarMode::OVERWRITE, envVarMapper: [self::class, 'mapAssemblyBomsDefaultColumnsEnv']
)]
#[Assert\NotBlank()]
#[Assert\Unique()]
#[Assert\All([new Assert\Type(AssemblyBomTableColumns::class)])]
public array $assembliesBomDefaultColumns = [AssemblyBomTableColumns::QUANTITY, AssemblyTableColumns::ID, AssemblyTableColumns::IPN,
AssemblyTableColumns::NAME, AssemblyTableColumns::DESCRIPTION];
#[SettingsParameter(label: new TM("settings.behavior.table.preview_image_min_width"),
formOptions: ['attr' => ['min' => 1, 'max' => 100]],
envVar: "int:TABLE_IMAGE_PREVIEW_MIN_SIZE", envVarMode: EnvVarMode::OVERWRITE
@ -101,4 +131,36 @@ class TableSettings
return $ret;
}
public static function mapAssembliesDefaultColumnsEnv(string $columns): array
{
$exploded = explode(',', $columns);
$ret = [];
foreach ($exploded as $column) {
$enum = AssemblyTableColumns::tryFrom($column);
if (!$enum) {
throw new \InvalidArgumentException("Invalid column '$column' in TABLE_ASSEMBLIES_DEFAULT_COLUMNS");
}
$ret[] = $enum;
}
return $ret;
}
public static function mapAssemblyBomsDefaultColumnsEnv(string $columns): array
{
$exploded = explode(',', $columns);
$ret = [];
foreach ($exploded as $column) {
$enum = AssemblyBomTableColumns::tryFrom($column);
if (!$enum) {
throw new \InvalidArgumentException("Invalid column '$column' in TABLE_ASSEMBLIES_BOM_DEFAULT_COLUMNS");
}
$ret[] = $enum;
}
return $ret;
}
}

View file

@ -0,0 +1,45 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\Settings\MiscSettings;
use App\Settings\SettingsIcon;
use Jbtronics\SettingsBundle\Metadata\EnvVarMode;
use Jbtronics\SettingsBundle\Settings\Settings;
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
use Symfony\Component\Translation\TranslatableMessage as TM;
#[Settings(label: new TM("settings.misc.assembly"))]
#[SettingsIcon("fa-list")]
class AssemblySettings
{
use SettingsTrait;
#[SettingsParameter(
label: new TM("settings.misc.assembly.useIpnPlaceholderInName"),
envVar: "bool:CREATE_ASSEMBLY_USE_IPN_PLACEHOLDER_IN_NAME", envVarMode: EnvVarMode::OVERWRITE,
)]
public bool $useIpnPlaceholderInName = true;
}

View file

@ -34,4 +34,7 @@ class MiscSettings
#[EmbeddedSettings]
public ?ExchangeRateSettings $exchangeRate = null;
}
#[EmbeddedSettings]
public ?AssemblySettings $assembly = null;
}