mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
add more filtering possibilities with order helper
This commit is contained in:
parent
aea5e9b1d7
commit
97dbc4bc16
@ -32,6 +32,7 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$checkboxesBuilder = $builder->create('checkboxes', null, [ 'compound' => true ]);
|
||||||
foreach ($helper->getCheckboxes() as $name => $c) {
|
foreach ($helper->getCheckboxes() as $name => $c) {
|
||||||
|
|
||||||
$choices = \array_combine(
|
$choices = \array_combine(
|
||||||
@ -42,17 +43,21 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
|||||||
$c['choices']
|
$c['choices']
|
||||||
);
|
);
|
||||||
|
|
||||||
$builder->add('c_'.$name, ChoiceType::class, [
|
$checkboxesBuilder->add($name, ChoiceType::class, [
|
||||||
'choices' => $choices,
|
'choices' => $choices,
|
||||||
'expanded' => true,
|
'expanded' => true,
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (0 < count($helper->getCheckboxes())) {
|
||||||
|
$builder->add($checkboxesBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($this->requestStack->getCurrentRequest()->query->getIterator() as $key => $value) {
|
foreach ($this->requestStack->getCurrentRequest()->query->getIterator() as $key => $value) {
|
||||||
switch($key) {
|
switch($key) {
|
||||||
case 'q':
|
case 'q':
|
||||||
case 'c_'.$key:
|
case 'checkboxes'.$key:
|
||||||
break;
|
break;
|
||||||
case 'page':
|
case 'page':
|
||||||
$builder->add($key, HiddenType::class, [
|
$builder->add($key, HiddenType::class, [
|
||||||
@ -75,7 +80,7 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
|||||||
$view->vars['has_search_box'] = $helper->hasSearchBox();
|
$view->vars['has_search_box'] = $helper->hasSearchBox();
|
||||||
$view->vars['checkboxes'] = [];
|
$view->vars['checkboxes'] = [];
|
||||||
foreach ($helper->getCheckboxes() as $name => $c) {
|
foreach ($helper->getCheckboxes() as $name => $c) {
|
||||||
$view->vars['checkboxes']['c_'.$name] = [];
|
$view->vars['checkboxes'][$name] = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,17 +10,30 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% for checkbox_name, options in form.vars.checkboxes %}
|
{% if form.checkboxes|length > 0 %}
|
||||||
<div class="col-md-12">
|
{% for checkbox_name, options in form.checkboxes %}
|
||||||
<div class="col-md-11">
|
<div class="row gx-0">
|
||||||
{{ form_widget(form[checkbox_name]) }}
|
<div class="col-md-12">
|
||||||
|
{% for c in form['checkboxes'][checkbox_name].children %}
|
||||||
|
<div class="form-check form-check-inline">
|
||||||
|
{{ form_widget(c) }}
|
||||||
|
{{ form_label(c) }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if loop.last %}
|
{% if loop.last %}
|
||||||
<div class="col-md-1">
|
<div class="row gx-0">
|
||||||
<button type="submit" class="btn btn-misc"><i class="fa fa-filter"></i></button>
|
<div class="col-md-12">
|
||||||
</div>
|
<ul class="record_actions">
|
||||||
|
<li>
|
||||||
|
<button type="submit" class="btn btn-misc"><i class="fa fa-filter"></i></button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{{ form_end(form) }}
|
{{ form_end(form) }}
|
||||||
|
@ -13,6 +13,11 @@ class FilterOrderHelper
|
|||||||
private RequestStack $requestStack;
|
private RequestStack $requestStack;
|
||||||
private ?array $searchBoxFields = null;
|
private ?array $searchBoxFields = null;
|
||||||
private array $checkboxes = [];
|
private array $checkboxes = [];
|
||||||
|
private ?array $submitted = null;
|
||||||
|
private ?string $formName = 'filter';
|
||||||
|
private string $formType = FilterOrderType::class;
|
||||||
|
private array $formOptions = [];
|
||||||
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
FormFactoryInterface $formFactory,
|
FormFactoryInterface $formFactory,
|
||||||
@ -45,10 +50,9 @@ class FilterOrderHelper
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCheckbox(string $name): array
|
public function getCheckboxData(string $name): array
|
||||||
{
|
{
|
||||||
return $this->requestStack->getCurrentRequest()
|
return $this->getFormData()['checkboxes'][$name];
|
||||||
->query->get('c_'.$name, $this->checkboxes[$name]['default']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCheckboxes(): array
|
public function getCheckboxes(): array
|
||||||
@ -63,12 +67,23 @@ class FilterOrderHelper
|
|||||||
|
|
||||||
private function getFormData(): array
|
private function getFormData(): array
|
||||||
{
|
{
|
||||||
$r = [
|
if (NULL === $this->submitted) {
|
||||||
'q' => $this->getQueryString(),
|
$this->submitted = $this->buildForm()
|
||||||
];
|
->getData();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->submitted;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getDefaultData(): array
|
||||||
|
{
|
||||||
|
$r = [];
|
||||||
|
|
||||||
|
if ($this->hasSearchBox()) {
|
||||||
|
$r['q'] = '';
|
||||||
|
}
|
||||||
foreach ($this->checkboxes as $name => $c) {
|
foreach ($this->checkboxes as $name => $c) {
|
||||||
$r[$name] = $this->getCheckbox($name);
|
$r['checkboxes'][$name] = $c['default'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $r;
|
return $r;
|
||||||
@ -76,21 +91,17 @@ class FilterOrderHelper
|
|||||||
|
|
||||||
public function getQueryString(): ?string
|
public function getQueryString(): ?string
|
||||||
{
|
{
|
||||||
$q = $this->requestStack->getCurrentRequest()
|
return $this->getFormData()['q'];
|
||||||
->query->get('q', null);
|
|
||||||
|
|
||||||
return empty($q) ? NULL : $q;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildForm($name = null, string $type = FilterOrderType::class, array $options = []): FormInterface
|
public function buildForm(): FormInterface
|
||||||
{
|
{
|
||||||
$form = $this->formFactory
|
return $this->formFactory
|
||||||
->createNamed($name, $type, $this->getFormData(), \array_merge([
|
->createNamed($this->formName, $this->formType, $this->getDefaultData(), \array_merge([
|
||||||
'helper' => $this,
|
'helper' => $this,
|
||||||
'method' => 'GET',
|
'method' => 'GET',
|
||||||
'csrf_protection' => false,
|
'csrf_protection' => false,
|
||||||
], $options));
|
], $this->formOptions))
|
||||||
|
->handleRequest($this->requestStack->getCurrentRequest());
|
||||||
return $form;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -532,14 +532,18 @@ final class SingleTaskController extends AbstractController
|
|||||||
$this->denyAccessUnlessGranted('ROLE_USER');
|
$this->denyAccessUnlessGranted('ROLE_USER');
|
||||||
|
|
||||||
$filterOrder = $this->buildFilterOrder();
|
$filterOrder = $this->buildFilterOrder();
|
||||||
|
$flags = \array_merge(
|
||||||
|
$filterOrder->getCheckboxData('status'),
|
||||||
|
\array_map(fn ($i) => 'state_'.$i, $filterOrder->getCheckboxData('states'))
|
||||||
|
);
|
||||||
$nb = $this->singleTaskAclAwareRepository->countByCurrentUsersTasks(
|
$nb = $this->singleTaskAclAwareRepository->countByCurrentUsersTasks(
|
||||||
$filterOrder->getQueryString(),
|
$filterOrder->getQueryString(),
|
||||||
$filterOrder->getCheckbox('status')
|
$flags
|
||||||
);
|
);
|
||||||
$paginator = $this->paginatorFactory->create($nb);
|
$paginator = $this->paginatorFactory->create($nb);
|
||||||
$tasks = $this->singleTaskAclAwareRepository->findByCurrentUsersTasks(
|
$tasks = $this->singleTaskAclAwareRepository->findByCurrentUsersTasks(
|
||||||
$filterOrder->getQueryString(),
|
$filterOrder->getQueryString(),
|
||||||
$filterOrder->getCheckbox('status'),
|
$flags,
|
||||||
$paginator->getCurrentPageFirstItemNumber(),
|
$paginator->getCurrentPageFirstItemNumber(),
|
||||||
$paginator->getItemsPerPage()
|
$paginator->getItemsPerPage()
|
||||||
);
|
);
|
||||||
@ -555,14 +559,19 @@ final class SingleTaskController extends AbstractController
|
|||||||
{
|
{
|
||||||
$statuses = ['no-alert', 'warning', 'alert'];
|
$statuses = ['no-alert', 'warning', 'alert'];
|
||||||
$statusTrans = [
|
$statusTrans = [
|
||||||
|
'Tasks without alert',
|
||||||
'Tasks near deadline',
|
'Tasks near deadline',
|
||||||
'Tasks over deadline',
|
'Tasks over deadline',
|
||||||
'Tasks without alert',
|
];
|
||||||
|
$states = [
|
||||||
|
// todo: get a list of possible states dynamically
|
||||||
|
'new', 'in_progress', 'closed', 'canceled'
|
||||||
];
|
];
|
||||||
return $this->filterOrderHelperFactory
|
return $this->filterOrderHelperFactory
|
||||||
->create(self::class)
|
->create(self::class)
|
||||||
->addSearchBox()
|
->addSearchBox()
|
||||||
->addCheckbox('status', $statuses, $statuses, $statusTrans)
|
->addCheckbox('status', $statuses, $statuses, $statusTrans)
|
||||||
|
->addCheckbox('states', $states, ['new', 'in_progress'])
|
||||||
->build()
|
->build()
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -63,64 +63,74 @@ final class SingleTaskAclAwareRepository implements SingleTaskAclAwareRepository
|
|||||||
|
|
||||||
if (!empty($pattern)) {
|
if (!empty($pattern)) {
|
||||||
$qb->andWhere($qb->expr()->like('LOWER(UNACCENT(t.title))', 'LOWER(UNACCENT(:pattern))'))
|
$qb->andWhere($qb->expr()->like('LOWER(UNACCENT(t.title))', 'LOWER(UNACCENT(:pattern))'))
|
||||||
->setParameter('pattern', $pattern)
|
->setParameter('pattern', '%'.$pattern.'%')
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($flags) > 0) {
|
if (count($flags) > 0) {
|
||||||
$orX = $qb->expr()->orX();
|
$orXDate = $qb->expr()->orX();
|
||||||
|
$orXState = $qb->expr()->orX();
|
||||||
$now = new \DateTime();
|
$now = new \DateTime();
|
||||||
|
|
||||||
if (\in_array('no-alert', $flags)) {
|
foreach ($flags as $key => $flag) {
|
||||||
$orX
|
switch ($flag) {
|
||||||
->add(
|
case 'no-alert':
|
||||||
$qb->expr()->orX(
|
$orXDate
|
||||||
$qb->expr()->isNull('t.endDate'),
|
->add(
|
||||||
$qb->expr()->gte('t.endDate - COALESCE(t.warningInterval, :intervalBlank)', ':now')
|
$qb->expr()->orX(
|
||||||
)
|
$qb->expr()->isNull('t.endDate'),
|
||||||
);
|
$qb->expr()->gte('t.endDate - COALESCE(t.warningInterval, :intervalBlank)', ':now')
|
||||||
$qb
|
)
|
||||||
->setParameter('intervalBlank', new \DateInterval('P0D'))
|
);
|
||||||
->setParameter('now', $now)
|
$qb
|
||||||
;
|
->setParameter('intervalBlank', new \DateInterval('P0D'))
|
||||||
|
->setParameter('now', $now);
|
||||||
|
break;
|
||||||
|
case 'warning':
|
||||||
|
$orXDate
|
||||||
|
->add(
|
||||||
|
$qb->expr()->andX(
|
||||||
|
$qb->expr()->not($qb->expr()->isNull('t.endDate')),
|
||||||
|
$qb->expr()->not($qb->expr()->isNull('t.warningInterval')),
|
||||||
|
$qb->expr()->gte('t.endDate - t.warningInterval', ':now'),
|
||||||
|
$qb->expr()->lt('t.endDate', ':now')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$qb
|
||||||
|
->setParameter('now', $now);
|
||||||
|
break;
|
||||||
|
case 'alert':
|
||||||
|
$orXDate
|
||||||
|
->add(
|
||||||
|
$qb->expr()->andX(
|
||||||
|
$qb->expr()->not($qb->expr()->isNull('t.endDate')),
|
||||||
|
$qb->expr()->lte('t.endDate', ':now')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$qb
|
||||||
|
->setParameter('now', $now);
|
||||||
|
break;
|
||||||
|
case \substr($flag, 0, 6) === 'state_':
|
||||||
|
$state = \substr($flag, 6);
|
||||||
|
$orXState
|
||||||
|
->add(
|
||||||
|
"JSONB_EXISTS_IN_ARRAY(t.currentStates, :state_$key) = 'TRUE'"
|
||||||
|
);
|
||||||
|
$qb->setParameter("state_$key", $state);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new \LogicException("this flag is not supported: $flag");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\in_array('warning', $flags)) {
|
if ($orXDate->count() > 0) {
|
||||||
$orX
|
$qb->andWhere($orXDate);
|
||||||
->add(
|
|
||||||
$qb->expr()->andX(
|
|
||||||
$qb->expr()->eq('t.closed', "'FALSE'"),
|
|
||||||
$qb->expr()->not($qb->expr()->isNull('t.endDate')),
|
|
||||||
$qb->expr()->not($qb->expr()->isNull('t.warningInterval')),
|
|
||||||
$qb->expr()->lte('t.endDate - t.warningInterval', ':now')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
;
|
|
||||||
$qb
|
|
||||||
->setParameter('now', $now)
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
if ($orXState->count() > 0) {
|
||||||
if (\in_array('alert', $flags)) {
|
$qb->andWhere($orXState);
|
||||||
$orX
|
|
||||||
->add(
|
|
||||||
$qb->expr()->andX(
|
|
||||||
$qb->expr()->eq('t.closed', "'FALSE'"),
|
|
||||||
$qb->expr()->not($qb->expr()->isNull('t.endDate')),
|
|
||||||
$qb->expr()->lte('t.endDate', ':now')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
;
|
|
||||||
$qb
|
|
||||||
->setParameter('now', $now)
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$qb->andWhere($orX);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $qb;
|
return $qb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ Are you sure you want to start this task ?: Êtes-vous sûrs de vouloir démarre
|
|||||||
|
|
||||||
Tasks near deadline: Tâches à échéance proche
|
Tasks near deadline: Tâches à échéance proche
|
||||||
Tasks over deadline: Tâches à échéance dépassée
|
Tasks over deadline: Tâches à échéance dépassée
|
||||||
Tasks without alert: Tâches sans alerte
|
Tasks without alert: Tâches à échéance future ou sans échéance
|
||||||
|
|
||||||
#title
|
#title
|
||||||
My tasks near deadline: Mes tâches à échéance proche
|
My tasks near deadline: Mes tâches à échéance proche
|
||||||
|
Loading…
x
Reference in New Issue
Block a user