mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-13 11:54:32 +02:00
Use a enum for level in LogEntries
This commit is contained in:
parent
4a644d8712
commit
2da7463edf
18 changed files with 322 additions and 149 deletions
73
src/Form/Filters/Constraints/EnumConstraintType.php
Normal file
73
src/Form/Filters/Constraints/EnumConstraintType.php
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2022 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\ChoiceConstraint;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EnumType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class EnumConstraintType extends AbstractType
|
||||
{
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setRequired('enum_class');
|
||||
$resolver->setAllowedTypes('enum_class', 'string');
|
||||
|
||||
$resolver->setRequired('choice_label');
|
||||
$resolver->setAllowedTypes('choice_label', ['string', 'callable']);
|
||||
|
||||
$resolver->setDefaults([
|
||||
'compound' => true,
|
||||
'data_class' => ChoiceConstraint::class,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$choices = [
|
||||
'' => '',
|
||||
'filter.choice_constraint.operator.ANY' => 'ANY',
|
||||
'filter.choice_constraint.operator.NONE' => 'NONE',
|
||||
];
|
||||
|
||||
$builder->add('operator', ChoiceType::class, [
|
||||
'choices' => $choices,
|
||||
'required' => false,
|
||||
]);
|
||||
|
||||
$builder->add('value', EnumType::class, [
|
||||
'class' => $options['enum_class'],
|
||||
'choice_label' => $options['choice_label'],
|
||||
'required' => false,
|
||||
'multiple' => true,
|
||||
'attr' => [
|
||||
'data-controller' => 'elements--select-multiple',
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
|
@ -25,6 +25,7 @@ namespace App\Form\Filters;
|
|||
use App\DataTables\Filters\LogFilter;
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Entity\LogSystem\LogLevel;
|
||||
use App\Entity\LogSystem\PartStockChangedLogEntry;
|
||||
use App\Entity\ProjectSystem\Project;
|
||||
use App\Entity\ProjectSystem\ProjectBOMEntry;
|
||||
|
@ -56,6 +57,7 @@ use App\Entity\UserSystem\Group;
|
|||
use App\Entity\UserSystem\User;
|
||||
use App\Form\Filters\Constraints\ChoiceConstraintType;
|
||||
use App\Form\Filters\Constraints\DateTimeConstraintType;
|
||||
use App\Form\Filters\Constraints\EnumConstraintType;
|
||||
use App\Form\Filters\Constraints\InstanceOfConstraintType;
|
||||
use App\Form\Filters\Constraints\NumberConstraintType;
|
||||
use App\Form\Filters\Constraints\UserEntityConstraintType;
|
||||
|
@ -67,17 +69,6 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||
|
||||
class LogFilterType extends AbstractType
|
||||
{
|
||||
protected const LEVEL_CHOICES = [
|
||||
'log.level.debug' => AbstractLogEntry::LEVEL_DEBUG,
|
||||
'log.level.info' => AbstractLogEntry::LEVEL_INFO,
|
||||
'log.level.notice' => AbstractLogEntry::LEVEL_NOTICE,
|
||||
'log.level.warning' => AbstractLogEntry::LEVEL_WARNING,
|
||||
'log.level.error' => AbstractLogEntry::LEVEL_ERROR,
|
||||
'log.level.critical' => AbstractLogEntry::LEVEL_CRITICAL,
|
||||
'log.level.alert' => AbstractLogEntry::LEVEL_ALERT,
|
||||
'log.level.emergency' => AbstractLogEntry::LEVEL_EMERGENCY,
|
||||
];
|
||||
|
||||
protected const TARGET_TYPE_CHOICES = [
|
||||
'log.type.collection_element_deleted' => CollectionElementDeleted::class,
|
||||
'log.type.database_updated' => DatabaseUpdatedLogEntry::class,
|
||||
|
@ -117,9 +108,10 @@ class LogFilterType extends AbstractType
|
|||
|
||||
|
||||
|
||||
$builder->add('level', ChoiceConstraintType::class, [
|
||||
$builder->add('level', EnumConstraintType::class, [
|
||||
'label' => 'log.level',
|
||||
'choices' => self::LEVEL_CHOICES,
|
||||
'enum_class' => LogLevel::class,
|
||||
'choice_label' => fn(LogLevel $level): string => 'log.level.' . $level->toPSR3LevelString(),
|
||||
]);
|
||||
|
||||
$builder->add('eventType', InstanceOfConstraintType::class, [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue