mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
do not show filter by user on 'my tasks' page, and show different states
dynamically
This commit is contained in:
parent
c0901947ca
commit
872d5e8ebf
@ -26,6 +26,7 @@ use Chill\TaskBundle\Event\TaskEvent;
|
|||||||
use Chill\TaskBundle\Event\UI\UIEvent;
|
use Chill\TaskBundle\Event\UI\UIEvent;
|
||||||
use Chill\TaskBundle\Form\SingleTaskType;
|
use Chill\TaskBundle\Form\SingleTaskType;
|
||||||
use Chill\TaskBundle\Repository\SingleTaskAclAwareRepositoryInterface;
|
use Chill\TaskBundle\Repository\SingleTaskAclAwareRepositoryInterface;
|
||||||
|
use Chill\TaskBundle\Repository\SingleTaskStateRepository;
|
||||||
use Chill\TaskBundle\Security\Authorization\TaskVoter;
|
use Chill\TaskBundle\Security\Authorization\TaskVoter;
|
||||||
use LogicException;
|
use LogicException;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
@ -71,7 +72,8 @@ final class SingleTaskController extends AbstractController
|
|||||||
EventDispatcherInterface $eventDispatcher,
|
EventDispatcherInterface $eventDispatcher,
|
||||||
TimelineBuilder $timelineBuilder,
|
TimelineBuilder $timelineBuilder,
|
||||||
LoggerInterface $logger,
|
LoggerInterface $logger,
|
||||||
FilterOrderHelperFactoryInterface $filterOrderHelperFactory
|
FilterOrderHelperFactoryInterface $filterOrderHelperFactory,
|
||||||
|
private SingleTaskStateRepository $singleTaskStateRepository
|
||||||
) {
|
) {
|
||||||
$this->eventDispatcher = $eventDispatcher;
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
$this->timelineBuilder = $timelineBuilder;
|
$this->timelineBuilder = $timelineBuilder;
|
||||||
@ -452,7 +454,7 @@ final class SingleTaskController extends AbstractController
|
|||||||
{
|
{
|
||||||
$this->denyAccessUnlessGranted('ROLE_USER');
|
$this->denyAccessUnlessGranted('ROLE_USER');
|
||||||
|
|
||||||
$filterOrder = $this->buildFilterOrder();
|
$filterOrder = $this->buildFilterOrder(false);
|
||||||
$flags = array_merge(
|
$flags = array_merge(
|
||||||
$filterOrder->getCheckboxData('status'),
|
$filterOrder->getCheckboxData('status'),
|
||||||
array_map(static fn ($i) => 'state_' . $i, $filterOrder->getCheckboxData('states'))
|
array_map(static fn ($i) => 'state_' . $i, $filterOrder->getCheckboxData('states'))
|
||||||
@ -667,7 +669,7 @@ final class SingleTaskController extends AbstractController
|
|||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildFilterOrder(): FilterOrderHelper
|
private function buildFilterOrder($includeFilterByUser = true): FilterOrderHelper
|
||||||
{
|
{
|
||||||
$statuses = ['no-alert', 'warning', 'alert'];
|
$statuses = ['no-alert', 'warning', 'alert'];
|
||||||
$statusTrans = [
|
$statusTrans = [
|
||||||
@ -675,18 +677,22 @@ final class SingleTaskController extends AbstractController
|
|||||||
'Tasks near deadline',
|
'Tasks near deadline',
|
||||||
'Tasks over deadline',
|
'Tasks over deadline',
|
||||||
];
|
];
|
||||||
$states = [
|
$states = $this->singleTaskStateRepository->findAllExistingStates();
|
||||||
// todo: get a list of possible states dynamically
|
$checked = array_values(array_filter($states, fn (string $state) => !in_array($state, ['closed', 'canceled', 'validated'], true)));
|
||||||
'new', 'in_progress', 'closed', 'canceled',
|
|
||||||
];
|
|
||||||
|
|
||||||
return $this->filterOrderHelperFactory
|
$filterBuilder = $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'])
|
->addCheckbox('states', $states, $checked)
|
||||||
->addUserPicker('userPicker', 'Filter by user', ['multiple' => true, 'required' => false])
|
;
|
||||||
->build();
|
|
||||||
|
if ($includeFilterByUser) {
|
||||||
|
$filterBuilder
|
||||||
|
->addUserPicker('userPicker', 'Filter by user', ['multiple' => true, 'required' => false]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $filterBuilder->build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\TaskBundle\Repository;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Connection;
|
||||||
|
use Doctrine\DBAL\Exception;
|
||||||
|
|
||||||
|
class SingleTaskStateRepository
|
||||||
|
{
|
||||||
|
private const FIND_ALL_STATES = <<<'SQL'
|
||||||
|
SELECT DISTINCT jsonb_array_elements_text(current_states) FROM chill_task.single_task
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private Connection $connection
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a list of all states associated to at least one single task in the database
|
||||||
|
*
|
||||||
|
* @return list<string>
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function findAllExistingStates(): array
|
||||||
|
{
|
||||||
|
$states = [];
|
||||||
|
|
||||||
|
foreach ($this->connection->fetchAllNumeric(self::FIND_ALL_STATES) as $row) {
|
||||||
|
if ('' !== $row[0] && null !== $row[0]) {
|
||||||
|
$states[] = $row[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $states;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,8 @@
|
|||||||
services:
|
services:
|
||||||
|
_defaults:
|
||||||
|
autowire: true
|
||||||
|
autoconfigure: true
|
||||||
|
|
||||||
chill_task.single_task_repository:
|
chill_task.single_task_repository:
|
||||||
class: Chill\TaskBundle\Repository\SingleTaskRepository
|
class: Chill\TaskBundle\Repository\SingleTaskRepository
|
||||||
factory: ['@doctrine.orm.entity_manager', getRepository]
|
factory: ['@doctrine.orm.entity_manager', getRepository]
|
||||||
@ -10,8 +14,8 @@ services:
|
|||||||
- "@chill.main.security.authorization.helper"
|
- "@chill.main.security.authorization.helper"
|
||||||
Chill\TaskBundle\Repository\SingleTaskRepository: '@chill_task.single_task_repository'
|
Chill\TaskBundle\Repository\SingleTaskRepository: '@chill_task.single_task_repository'
|
||||||
|
|
||||||
Chill\TaskBundle\Repository\SingleTaskAclAwareRepository:
|
Chill\TaskBundle\Repository\SingleTaskAclAwareRepository: ~
|
||||||
autowire: true
|
|
||||||
autoconfigure: true
|
|
||||||
|
|
||||||
Chill\TaskBundle\Repository\SingleTaskAclAwareRepositoryInterface: '@Chill\TaskBundle\Repository\SingleTaskAclAwareRepository'
|
Chill\TaskBundle\Repository\SingleTaskAclAwareRepositoryInterface: '@Chill\TaskBundle\Repository\SingleTaskAclAwareRepository'
|
||||||
|
|
||||||
|
Chill\TaskBundle\Repository\SingleTaskStateRepository: ~
|
||||||
|
Loading…
x
Reference in New Issue
Block a user