Implement a filter for Log Table (part 1)

This commit is contained in:
Jan Böhmer 2022-09-11 18:45:31 +02:00
parent 017b0f717e
commit c7f5c23374
12 changed files with 444 additions and 23 deletions

View file

@ -23,7 +23,7 @@ use App\Form\Filters\Constraints\BooleanConstraintType;
use App\Form\Filters\Constraints\DateTimeConstraintType;
use App\Form\Filters\Constraints\InstanceOfConstraintType;
use App\Form\Filters\Constraints\NumberConstraintType;
use App\Form\Filters\Constraints\StructuralEntityConstraintType;
use App\Form\Filters\Constraints\UserEntityConstraintType;
use App\Form\Filters\Constraints\TextConstraintType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ResetType;
@ -73,7 +73,7 @@ class AttachmentFilterType extends AbstractType
]
]);
$builder->add('attachmentType', StructuralEntityConstraintType::class, [
$builder->add('attachmentType', UserEntityConstraintType::class, [
'label' => 'attachment.attachment_type',
'entity_class' => AttachmentType::class
]);

View file

@ -0,0 +1,153 @@
<?php
namespace App\Form\Filters;
use App\DataTables\Filters\LogFilter;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Devices\Device;
use App\Entity\Devices\DevicePart;
use App\Entity\LabelSystem\LabelProfile;
use App\Entity\LogSystem\AbstractLogEntry;
use App\Entity\LogSystem\CollectionElementDeleted;
use App\Entity\LogSystem\DatabaseUpdatedLogEntry;
use App\Entity\LogSystem\ElementCreatedLogEntry;
use App\Entity\LogSystem\ElementDeletedLogEntry;
use App\Entity\LogSystem\ElementEditedLogEntry;
use App\Entity\LogSystem\InstockChangedLogEntry;
use App\Entity\LogSystem\SecurityEventLogEntry;
use App\Entity\LogSystem\UserLoginLogEntry;
use App\Entity\LogSystem\UserLogoutLogEntry;
use App\Entity\LogSystem\UserNotAllowedLogEntry;
use App\Entity\Parameters\AbstractParameter;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Part;
use App\Entity\Parts\PartLot;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use App\Entity\PriceInformations\Orderdetail;
use App\Entity\PriceInformations\Pricedetail;
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\InstanceOfConstraintType;
use App\Form\Filters\Constraints\NumberConstraintType;
use App\Form\Filters\Constraints\StructuralEntityConstraintType;
use App\Form\Filters\Constraints\UserEntityConstraintType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ResetType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
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,
'log.type.element_created' => ElementCreatedLogEntry::class,
'log.type.element_deleted' => ElementDeletedLogEntry::class,
'log.type.element_edited' => ElementEditedLogEntry::class,
'log.type.security' => SecurityEventLogEntry::class,
'log.type.user_login' => UserLoginLogEntry::class,
'log.type.user_logout' => UserLogoutLogEntry::class,
'log.type.user_not_allowed' => UserNotAllowedLogEntry::class,
//Legacy entries
'log.type.instock_changed' => InstockChangedLogEntry::class,
];
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'compound' => true,
'data_class' => LogFilter::class,
'csrf_protection' => false,
]);
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('dbId', NumberConstraintType::class, [
'label' => 'part.filter.dbId',
'min' => 1,
'step' => 1,
]);
$builder->add('timestamp', DateTimeConstraintType::class, [
'label' => 'log.timestamp',
]);
$builder->add('level', ChoiceConstraintType::class, [
'label' => 'log.level',
'choices' => self::LEVEL_CHOICES,
]);
$builder->add('eventType', InstanceOfConstraintType::class, [
'label' => 'log.type',
'choices' => self::TARGET_TYPE_CHOICES
]);
$builder->add('user', StructuralEntityConstraintType::class, [
'label' => 'log.user',
'entity_class' => User::class,
]);
$builder->add('targetType', ChoiceConstraintType::class, [
'label' => 'log.target_type',
'choices' => [
'user.label' => AbstractLogEntry::targetTypeClassToID(User::class),
'attachment.label' => AbstractLogEntry::targetTypeClassToID(Attachment::class),
'attachment_type.label' => AbstractLogEntry::targetTypeClassToID(AttachmentType::class),
'category.label' => AbstractLogEntry::targetTypeClassToID(Category::class),
'device.label' => AbstractLogEntry::targetTypeClassToID(Device::class),
'device_part.label' => AbstractLogEntry::targetTypeClassToID(DevicePart::class),
'footprint.label' => AbstractLogEntry::targetTypeClassToID(Footprint::class),
'group.label' => AbstractLogEntry::targetTypeClassToID(Group::class),
'manufacturer.label' => AbstractLogEntry::targetTypeClassToID(Manufacturer::class),
'part.label' => AbstractLogEntry::targetTypeClassToID(Part::class),
'storelocation.label' => AbstractLogEntry::targetTypeClassToID(Storelocation::class),
'supplier.label' => AbstractLogEntry::targetTypeClassToID(Supplier::class),
'part_lot.label' => AbstractLogEntry::targetTypeClassToID(PartLot::class),
'currency.label' => AbstractLogEntry::targetTypeClassToID(Currency::class),
'orderdetail.label' => AbstractLogEntry::targetTypeClassToID(Orderdetail::class),
'pricedetail.label' => AbstractLogEntry::targetTypeClassToID(Pricedetail::class),
'measurement_unit.label' => AbstractLogEntry::targetTypeClassToID(MeasurementUnit::class),
'parameter.label' => AbstractLogEntry::targetTypeClassToID(AbstractParameter::class),
'label_profile.label' => AbstractLogEntry::targetTypeClassToID(LabelProfile::class),
]
]);
$builder->add('targetId', NumberConstraintType::class, [
'label' => 'log.target_id',
'min' => 1,
'step' => 1,
]);
$builder->add('submit', SubmitType::class, [
'label' => 'filter.submit',
]);
$builder->add('discard', ResetType::class, [
'label' => 'filter.discard',
]);
}
}

View file

@ -15,7 +15,7 @@ use App\Form\Filters\Constraints\ChoiceConstraintType;
use App\Form\Filters\Constraints\DateTimeConstraintType;
use App\Form\Filters\Constraints\NumberConstraintType;
use App\Form\Filters\Constraints\ParameterConstraintType;
use App\Form\Filters\Constraints\StructuralEntityConstraintType;
use App\Form\Filters\Constraints\UserEntityConstraintType;
use App\Form\Filters\Constraints\TagsConstraintType;
use App\Form\Filters\Constraints\TextConstraintType;
use Svg\Tag\Text;
@ -54,12 +54,12 @@ class PartFilterType extends AbstractType
'label' => 'part.edit.description',
]);
$builder->add('category', StructuralEntityConstraintType::class, [
$builder->add('category', UserEntityConstraintType::class, [
'label' => 'part.edit.category',
'entity_class' => Category::class
]);
$builder->add('footprint', StructuralEntityConstraintType::class, [
$builder->add('footprint', UserEntityConstraintType::class, [
'label' => 'part.edit.footprint',
'entity_class' => Footprint::class
]);
@ -96,7 +96,7 @@ class PartFilterType extends AbstractType
'min' => 0,
]);
$builder->add('measurementUnit', StructuralEntityConstraintType::class, [
$builder->add('measurementUnit', UserEntityConstraintType::class, [
'label' => 'part.edit.partUnit',
'entity_class' => MeasurementUnit::class
]);
@ -114,7 +114,7 @@ class PartFilterType extends AbstractType
* Manufacturer tab
*/
$builder->add('manufacturer', StructuralEntityConstraintType::class, [
$builder->add('manufacturer', UserEntityConstraintType::class, [
'label' => 'part.edit.manufacturer.label',
'entity_class' => Manufacturer::class
]);
@ -145,7 +145,7 @@ class PartFilterType extends AbstractType
* Purchasee informations
*/
$builder->add('supplier', StructuralEntityConstraintType::class, [
$builder->add('supplier', UserEntityConstraintType::class, [
'label' => 'supplier.label',
'entity_class' => Manufacturer::class
]);
@ -163,7 +163,7 @@ class PartFilterType extends AbstractType
/*
* Stocks tabs
*/
$builder->add('storelocation', StructuralEntityConstraintType::class, [
$builder->add('storelocation', UserEntityConstraintType::class, [
'label' => 'storelocation.label',
'entity_class' => Storelocation::class
]);
@ -210,7 +210,7 @@ class PartFilterType extends AbstractType
'min' => 0,
]);
$builder->add('attachmentType', StructuralEntityConstraintType::class, [
$builder->add('attachmentType', UserEntityConstraintType::class, [
'label' => 'attachment.attachment_type',
'entity_class' => AttachmentType::class
]);