mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-12-16 07:59:30 +00:00
Refactored constraints, to reuse existing mechanisms
This commit is contained in:
parent
702e5c8732
commit
0d49632b92
26 changed files with 264 additions and 542 deletions
|
|
@ -1,63 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace App\Form\Filters\Constraints;
|
||||
|
||||
use App\DataTables\Filters\Constraints\Part\BulkImportJobExistsConstraint;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class BulkImportJobExistsConstraintType extends AbstractType
|
||||
{
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'compound' => true,
|
||||
'data_class' => BulkImportJobExistsConstraint::class,
|
||||
]);
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$choices = [
|
||||
'' => '',
|
||||
'part.filter.in_bulk_import_job.yes' => true,
|
||||
'part.filter.in_bulk_import_job.no' => false,
|
||||
];
|
||||
|
||||
$builder->add('value', ChoiceType::class, [
|
||||
'label' => 'part.filter.in_bulk_import_job',
|
||||
'choices' => $choices,
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options): void
|
||||
{
|
||||
parent::buildView($view, $form, $options);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace App\Form\Filters\Constraints;
|
||||
|
||||
use App\DataTables\Filters\Constraints\Part\BulkImportJobStatusConstraint;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class BulkImportJobStatusConstraintType extends AbstractType
|
||||
{
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'compound' => true,
|
||||
'data_class' => BulkImportJobStatusConstraint::class,
|
||||
]);
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$statusChoices = [
|
||||
'bulk_import.status.pending' => 'pending',
|
||||
'bulk_import.status.in_progress' => 'in_progress',
|
||||
'bulk_import.status.completed' => 'completed',
|
||||
'bulk_import.status.stopped' => 'stopped',
|
||||
'bulk_import.status.failed' => 'failed',
|
||||
];
|
||||
|
||||
$operatorChoices = [
|
||||
'filter.choice_constraint.operator.ANY' => 'ANY',
|
||||
'filter.choice_constraint.operator.NONE' => 'NONE',
|
||||
];
|
||||
|
||||
$builder->add('operator', ChoiceType::class, [
|
||||
'label' => 'filter.operator',
|
||||
'choices' => $operatorChoices,
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$builder->add('values', ChoiceType::class, [
|
||||
'label' => 'part.filter.bulk_import_job_status',
|
||||
'choices' => $statusChoices,
|
||||
'required' => false,
|
||||
'multiple' => true,
|
||||
'attr' => [
|
||||
'data-controller' => 'elements--select-multiple',
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options): void
|
||||
{
|
||||
parent::buildView($view, $form, $options);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2023 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/>.
|
||||
*/
|
||||
|
||||
namespace App\Form\Filters\Constraints;
|
||||
|
||||
use App\DataTables\Filters\Constraints\Part\BulkImportPartStatusConstraint;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class BulkImportPartStatusConstraintType extends AbstractType
|
||||
{
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'compound' => true,
|
||||
'data_class' => BulkImportPartStatusConstraint::class,
|
||||
]);
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$statusChoices = [
|
||||
'bulk_import.part_status.pending' => 'pending',
|
||||
'bulk_import.part_status.completed' => 'completed',
|
||||
'bulk_import.part_status.skipped' => 'skipped',
|
||||
'bulk_import.part_status.failed' => 'failed',
|
||||
];
|
||||
|
||||
$operatorChoices = [
|
||||
'filter.choice_constraint.operator.ANY' => 'ANY',
|
||||
'filter.choice_constraint.operator.NONE' => 'NONE',
|
||||
];
|
||||
|
||||
$builder->add('operator', ChoiceType::class, [
|
||||
'label' => 'filter.operator',
|
||||
'choices' => $operatorChoices,
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$builder->add('values', ChoiceType::class, [
|
||||
'label' => 'part.filter.bulk_import_part_status',
|
||||
'choices' => $statusChoices,
|
||||
'required' => false,
|
||||
'multiple' => true,
|
||||
'attr' => [
|
||||
'data-controller' => 'elements--select-multiple',
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options): void
|
||||
{
|
||||
parent::buildView($view, $form, $options);
|
||||
}
|
||||
}
|
||||
|
|
@ -22,9 +22,12 @@ declare(strict_types=1);
|
|||
*/
|
||||
namespace App\Form\Filters;
|
||||
|
||||
use App\DataTables\Filters\Constraints\Part\BulkImportPartStatusConstraint;
|
||||
use App\DataTables\Filters\Constraints\Part\ParameterConstraint;
|
||||
use App\DataTables\Filters\PartFilter;
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Entity\InfoProviderSystem\BulkImportJobStatus;
|
||||
use App\Entity\InfoProviderSystem\BulkImportPartStatus;
|
||||
use App\Entity\Parts\Category;
|
||||
use App\Entity\Parts\Footprint;
|
||||
use App\Entity\Parts\Manufacturer;
|
||||
|
|
@ -32,13 +35,13 @@ use App\Entity\Parts\MeasurementUnit;
|
|||
use App\Entity\Parts\StorageLocation;
|
||||
use App\Entity\Parts\Supplier;
|
||||
use App\Entity\ProjectSystem\Project;
|
||||
use App\Entity\BulkInfoProviderImportJob;
|
||||
use App\Form\Filters\Constraints\BooleanConstraintType;
|
||||
use App\Form\Filters\Constraints\BulkImportJobExistsConstraintType;
|
||||
use App\Form\Filters\Constraints\BulkImportJobStatusConstraintType;
|
||||
use App\Form\Filters\Constraints\BulkImportPartStatusConstraintType;
|
||||
use App\Form\Filters\Constraints\ChoiceConstraintType;
|
||||
use App\Form\Filters\Constraints\DateTimeConstraintType;
|
||||
use App\Form\Filters\Constraints\EnumConstraintType;
|
||||
use App\Form\Filters\Constraints\NumberConstraintType;
|
||||
use App\Form\Filters\Constraints\ParameterConstraintType;
|
||||
use App\Form\Filters\Constraints\StructuralEntityConstraintType;
|
||||
|
|
@ -54,6 +57,8 @@ use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
use function Symfony\Component\Translation\t;
|
||||
|
||||
class PartFilterType extends AbstractType
|
||||
{
|
||||
public function __construct(private readonly Security $security)
|
||||
|
|
@ -307,14 +312,22 @@ class PartFilterType extends AbstractType
|
|||
**************************************************************************/
|
||||
if ($this->security->isGranted('@info_providers.create_parts')) {
|
||||
$builder
|
||||
->add('inBulkImportJob', BulkImportJobExistsConstraintType::class, [
|
||||
->add('inBulkImportJob', BooleanConstraintType::class, [
|
||||
'label' => 'part.filter.in_bulk_import_job',
|
||||
])
|
||||
->add('bulkImportJobStatus', BulkImportJobStatusConstraintType::class, [
|
||||
->add('bulkImportJobStatus', EnumConstraintType::class, [
|
||||
'enum_class' => BulkImportJobStatus::class,
|
||||
'label' => 'part.filter.bulk_import_job_status',
|
||||
'choice_label' => function (BulkImportJobStatus $value) {
|
||||
return t('bulk_import.status.' . $value->value);
|
||||
},
|
||||
])
|
||||
->add('bulkImportPartStatus', BulkImportPartStatusConstraintType::class, [
|
||||
->add('bulkImportPartStatus', EnumConstraintType::class, [
|
||||
'enum_class' => BulkImportPartStatus::class,
|
||||
'label' => 'part.filter.bulk_import_part_status',
|
||||
'choice_label' => function (BulkImportPartStatus $value) {
|
||||
return t('bulk_import.part_status.' . $value->value);
|
||||
},
|
||||
])
|
||||
;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue