mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-24 10:49:00 +02:00
Added filters for creationDate and lastModified state
This commit is contained in:
parent
798eb4c1bc
commit
d3a42cd989
6 changed files with 137 additions and 9 deletions
10
src/DataTables/Filters/Constraints/DateTimeConstraint.php
Normal file
10
src/DataTables/Filters/Constraints/DateTimeConstraint.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\DataTables\Filters\Constraints;
|
||||
|
||||
/**
|
||||
* An alias of NumberConstraint to use to filter on a DateTime
|
||||
*/
|
||||
class DateTimeConstraint extends NumberConstraint
|
||||
{
|
||||
}
|
|
@ -12,13 +12,13 @@ class NumberConstraint extends AbstractConstraint
|
|||
|
||||
/**
|
||||
* The value1 used for comparison (this is the main one used for all mono-value comparisons)
|
||||
* @var float|null
|
||||
* @var float|null|int|\DateTimeInterface
|
||||
*/
|
||||
protected $value1;
|
||||
|
||||
/**
|
||||
* The second value used when operator is RANGE; this is the upper bound of the range
|
||||
* @var float|null
|
||||
* @var float|null|int|\DateTimeInterface
|
||||
*/
|
||||
protected $value2;
|
||||
|
||||
|
@ -28,7 +28,7 @@ class NumberConstraint extends AbstractConstraint
|
|||
protected $operator;
|
||||
|
||||
/**
|
||||
* @return float|mixed|null
|
||||
* @return float|int|null|\DateTimeInterface
|
||||
*/
|
||||
public function getValue1()
|
||||
{
|
||||
|
@ -36,7 +36,7 @@ class NumberConstraint extends AbstractConstraint
|
|||
}
|
||||
|
||||
/**
|
||||
* @param float|mixed|null $value1
|
||||
* @param float|int|\DateTimeInterface|null $value1
|
||||
*/
|
||||
public function setValue1($value1): void
|
||||
{
|
||||
|
@ -44,7 +44,7 @@ class NumberConstraint extends AbstractConstraint
|
|||
}
|
||||
|
||||
/**
|
||||
* @return float|mixed|null
|
||||
* @return float|int|null
|
||||
*/
|
||||
public function getValue2()
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ class NumberConstraint extends AbstractConstraint
|
|||
}
|
||||
|
||||
/**
|
||||
* @param float|mixed|null $value2
|
||||
* @param float|int|null $value2
|
||||
*/
|
||||
public function setValue2($value2): void
|
||||
{
|
||||
|
@ -60,7 +60,7 @@ class NumberConstraint extends AbstractConstraint
|
|||
}
|
||||
|
||||
/**
|
||||
* @return mixed|string
|
||||
* @return string
|
||||
*/
|
||||
public function getOperator(): string
|
||||
{
|
||||
|
@ -68,7 +68,7 @@ class NumberConstraint extends AbstractConstraint
|
|||
}
|
||||
|
||||
/**
|
||||
* @param mixed|string $operator
|
||||
* @param string $operator
|
||||
*/
|
||||
public function setOperator(?string $operator): void
|
||||
{
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\DataTables\Filters;
|
||||
|
||||
use App\DataTables\Filters\Constraints\BooleanConstraint;
|
||||
use App\DataTables\Filters\Constraints\DateTimeConstraint;
|
||||
use App\DataTables\Filters\Constraints\NumberConstraint;
|
||||
use App\DataTables\Filters\Constraints\TextConstraint;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
@ -27,6 +28,12 @@ class PartFilter implements FilterInterface
|
|||
/** @var NumberConstraint */
|
||||
protected $mass;
|
||||
|
||||
/** @var DateTimeConstraint */
|
||||
protected $lastModified;
|
||||
|
||||
/** @var DateTimeConstraint */
|
||||
protected $addedDate;
|
||||
|
||||
/**
|
||||
* @return BooleanConstraint|false
|
||||
*/
|
||||
|
@ -58,13 +65,33 @@ class PartFilter implements FilterInterface
|
|||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateTimeConstraint
|
||||
*/
|
||||
public function getLastModified(): DateTimeConstraint
|
||||
{
|
||||
return $this->lastModified;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateTimeConstraint
|
||||
*/
|
||||
public function getAddedDate(): DateTimeConstraint
|
||||
{
|
||||
return $this->addedDate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->favorite = new BooleanConstraint('part.favorite');
|
||||
$this->favorite =
|
||||
$this->needsReview = new BooleanConstraint('part.needs_review');
|
||||
$this->mass = new NumberConstraint('part.mass');
|
||||
$this->name = new TextConstraint('part.name');
|
||||
$this->description = new TextConstraint('part.description');
|
||||
$this->addedDate = new DateTimeConstraint('part.addedDate');
|
||||
$this->lastModified = new DateTimeConstraint('part.lastModified');
|
||||
}
|
||||
|
||||
public function apply(QueryBuilder $queryBuilder): void
|
||||
|
|
76
src/Form/Filters/Constraints/DateTimeConstraintType.php
Normal file
76
src/Form/Filters/Constraints/DateTimeConstraintType.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
namespace App\Form\Filters\Constraints;
|
||||
|
||||
use App\DataTables\Filters\Constraints\DateTimeConstraint;
|
||||
use App\DataTables\Filters\Constraints\NumberConstraint;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\NumberType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class DateTimeConstraintType extends AbstractType
|
||||
{
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'compound' => true,
|
||||
'data_class' => DateTimeConstraint::class,
|
||||
'text_suffix' => '', // An suffix which is attached as text-append to the input group. This can for example be used for units
|
||||
|
||||
'value1_options' => [], // Options for the first value input
|
||||
'value2_options' => [], // Options for the second value input
|
||||
]);
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$choices = [
|
||||
'' => '',
|
||||
'=' => '=',
|
||||
'!=' => '!=',
|
||||
'<' => '<',
|
||||
'>' => '>',
|
||||
'<=' => '<=',
|
||||
'>=' => '>=',
|
||||
'BETWEEN' => 'BETWEEN',
|
||||
];
|
||||
|
||||
$builder->add('value1', DateTimeType::class, array_merge_recursive([
|
||||
'label' => 'filter.datetime_constraint.value1',
|
||||
'attr' => [
|
||||
'placeholder' => 'filter.datetime_constraint.value1',
|
||||
],
|
||||
'required' => false,
|
||||
'html5' => true,
|
||||
'widget' => 'single_text',
|
||||
], $options['value1_options']));
|
||||
|
||||
$builder->add('value2', DateTimeType::class, array_merge_recursive([
|
||||
'label' => 'filter.datetime_constraint.value2',
|
||||
'attr' => [
|
||||
'placeholder' => 'filter.datetime_constraint.value2',
|
||||
],
|
||||
'required' => false,
|
||||
'html5' => true,
|
||||
'widget' => 'single_text',
|
||||
], $options['value2_options']));
|
||||
|
||||
$builder->add('operator', ChoiceType::class, [
|
||||
'label' => 'filter.datetime_constraint.operator',
|
||||
'choices' => $choices,
|
||||
'required' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
parent::buildView($view, $form, $options);
|
||||
|
||||
$view->vars['text_suffix'] = $options['text_suffix'];
|
||||
}
|
||||
}
|
|
@ -4,9 +4,11 @@ namespace App\Form\Filters;
|
|||
|
||||
use App\DataTables\Filters\PartFilter;
|
||||
use App\Form\Filters\Constraints\BooleanConstraintType;
|
||||
use App\Form\Filters\Constraints\DateTimeConstraintType;
|
||||
use App\Form\Filters\Constraints\NumberConstraintType;
|
||||
use App\Form\Filters\Constraints\TextConstraintType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\SubmitButton;
|
||||
|
@ -47,6 +49,15 @@ class PartFilterType extends AbstractType
|
|||
'label' => 'part.edit.description',
|
||||
]);
|
||||
|
||||
$builder->add('lastModified', DateTimeConstraintType::class, [
|
||||
'label' => 'lastModified'
|
||||
]);
|
||||
|
||||
$builder->add('addedDate', DateTimeConstraintType::class, [
|
||||
'label' => 'createdAt'
|
||||
]);
|
||||
|
||||
|
||||
$builder->add('submit', SubmitType::class, [
|
||||
'label' => 'Update',
|
||||
]);
|
||||
|
|
|
@ -19,3 +19,7 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block date_time_constraint_widget %}
|
||||
{{ block('number_constraint_widget') }}
|
||||
{% endblock %}
|
Loading…
Add table
Add a link
Reference in a new issue