diff --git a/Controller/SingleTaskController.php b/Controller/SingleTaskController.php index a5baa16a2..8456e0e5b 100644 --- a/Controller/SingleTaskController.php +++ b/Controller/SingleTaskController.php @@ -315,15 +315,27 @@ class SingleTaskController extends Controller public function myTasksAction() { return $this->redirectToRoute('chill_task_singletask_list', [ - 'user_id' => $this->getUser()->getId() + 'user_id' => $this->getUser()->getId(), + 'hide_form' => true ]); } /** + * + * Arguments: + * - user_id + * - scope_id + * - person_id + * - hide_form (hide the form to filter the tasks) + * - status: date state, amongst SingleTaskRepository::DATE_STATUSES, or 'closed' + * * @Route( * "/{_locale}/task/singletask/list", * name="chill_task_singletask_list", - * options={ "menus": { "person" : { "order": 400, "label": "Associated tasks" } } } + * options={ "menus": { + * "person" : { "order": 400, "label": "Associated tasks" } , + * "section": { "order": 400, "label": "Tasks", "icons": "tasks" } + * }} * ) */ public function listAction( @@ -359,18 +371,21 @@ class SingleTaskController extends Controller } if (!empty($request->query->get('user_id', null))) { + if ($request->query->get('user_id') === '_unassigned') { + $params['unassigned'] = true; + } else { + $userId = $request->query->getInt('user_id', null); + $user = $this->getDoctrine()->getManager() + ->getRepository('ChillMainBundle:User') + ->find($userId); - $userId = $request->query->getInt('user_id', null); - $user = $this->getDoctrine()->getManager() - ->getRepository('ChillMainBundle:User') - ->find($userId); + if ($user === null) { + throw $this->createNotFoundException("This user ' $userId ' does not exist."); + } - if ($user === null) { - throw $this->createNotFoundException("This user ' $userId ' does not exist."); + $viewParams['user'] = $user; + $params['user'] = $user; } - - $viewParams['user'] = $user; - $params['user'] = $user; } if (!empty($request->query->get('scope_id'))) { diff --git a/Entity/AbstractTask.php b/Entity/AbstractTask.php index 1f71d935e..73e98c0dd 100644 --- a/Entity/AbstractTask.php +++ b/Entity/AbstractTask.php @@ -207,7 +207,7 @@ abstract class AbstractTask implements HasScopeInterface, HasCenterInterface return $this->circle; } - public function setAssignee(User $assignee) + public function setAssignee(User $assignee = null) { $this->assignee = $assignee; return $this; diff --git a/Form/SingleTaskListType.php b/Form/SingleTaskListType.php index e4385d63b..3f0a4aeed 100644 --- a/Form/SingleTaskListType.php +++ b/Form/SingleTaskListType.php @@ -73,22 +73,33 @@ class SingleTaskListType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { - $statuses = \array_merge(SingleTaskRepository::DATE_STATUSES, [ 'closed' ]); + $statuses = [ + 'Tasks not started' => SingleTaskRepository::DATE_STATUS_NOT_STARTED, + 'Tasks with expired deadline' => SingleTaskRepository::DATE_STATUS_ENDED, + 'Tasks with warning deadline reached' => SingleTaskRepository::DATE_STATUS_WARNING, + 'Current tasks' => SingleTaskRepository::DATE_STATUS_CURRENT, + 'Closed tasks' => 'closed' + ]; $builder - ->add('user_id', EntityType::class, [ - 'class' => User::class, - 'choices' => $this->getUsersAssigneedToTask($options), - 'placeholder' => 'Choose a user', - 'required' => false - ]) - ->add('status', ChoiceType::class, [ - 'choices' => array_combine($statuses, $statuses), - 'expanded' => true, - 'multiple' => true - ]) + ->add('user_id', ChoiceType::class, [ + 'choices' => $this->getUserChoices($options), + 'placeholder' => 'Any user', + 'required' => false, + 'label' => 'Assignee' + ]) ; + if ($options['add_status'] === true) { + $builder + ->add('status', ChoiceType::class, [ + 'choices' => $statuses, + 'expanded' => true, + 'multiple' => true, + 'label' => 'status' + ]); + } + if ($options['person'] === null) { $builder ->add('person_id', PickPersonType::class, [ @@ -97,7 +108,8 @@ class SingleTaskListType extends AbstractType $this->tokenStorage->getToken()->getUser(), new Role(TaskVoter::SHOW) ), - 'required' => false + 'required' => false, + 'label' => 'Associated person' ]) ; } else { @@ -110,6 +122,20 @@ class SingleTaskListType extends AbstractType } } + protected function getUserChoices($options) + { + $users = $this->getUsersAssigneedToTask($options); + $choices = \array_combine( + // get usernames + \array_map(function(User $user) { return $user->getUsername(); }, $users), + // get ids + \array_map(function(User $user) { return $user->getId(); }, $users) + ); + $choices['Unassigned'] = '_unassigned'; + + return $choices; + } + /** * Return a list of user having a task assigned. * @@ -162,6 +188,9 @@ class SingleTaskListType extends AbstractType ->setDefined('person') ->setDefault('person', null) ->setAllowedTypes('person', [Person::class, 'null']) + ->setDefined('add_status') + ->setDefault('add_status', false) + ->setAllowedTypes('add_status', ['bool']) ; } } diff --git a/Form/SingleTaskType.php b/Form/SingleTaskType.php index b2c884496..d215c2b75 100644 --- a/Form/SingleTaskType.php +++ b/Form/SingleTaskType.php @@ -49,7 +49,8 @@ class SingleTaskType extends AbstractType ->add('assignee', UserPickerType::class, [ 'required' => false, 'center' => $options['center'], - 'role' => $options['role'] + 'role' => $options['role'], + 'placeholder' => 'Not assigned' ]) ->add('circle', ScopePickerType::class, [ 'center' => $options['center'], diff --git a/Menu/UserMenuBuilder.php b/Menu/UserMenuBuilder.php index 2d2c71b64..e4c5e6084 100644 --- a/Menu/UserMenuBuilder.php +++ b/Menu/UserMenuBuilder.php @@ -82,7 +82,8 @@ class UserMenuBuilder implements LocalMenuBuilderInterface 'status' => [ SingleTaskRepository::DATE_STATUS_WARNING, SingleTaskRepository::DATE_STATUS_ENDED - ] + ], + 'hide_form' => true ] ]) ->setExtras([ diff --git a/Repository/SingleTaskRepository.php b/Repository/SingleTaskRepository.php index c5980d5b0..68ba7f5ca 100644 --- a/Repository/SingleTaskRepository.php +++ b/Repository/SingleTaskRepository.php @@ -107,6 +107,15 @@ class SingleTaskRepository extends \Doctrine\ORM\EntityRepository $qb->andWhere($qb->expr()->eq('st.person', ':person')); $qb->setParameter('person', $params['person']); } + + if (\array_key_exists('unassigned', $params) and $params['unassigned'] === true) { + if (\array_key_exists('user', $params) and !empty($params['user'])) { + throw new \UnexpectedValueException("You should not require for " + . "unassigned tasks and tasks assigned to some user."); + } + + $qb->andWhere($qb->expr()->isNull('st.assignee')); + } if (\array_key_exists('user', $params) and !empty($params['user'])) { $qb->andWhere($qb->expr()->eq('st.assignee', ':user')); diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 81845826c..9e5b68632 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -1,3 +1,4 @@ +Tasks: 'Tâches' 'New task': 'Nouvelle tâche' 'Add a new task': 'Ajouter une nouvelle tâche' Title: Titre @@ -22,6 +23,7 @@ User: Utilisateur 'Tasks with expired deadline': "Tâches avec une date d'échéance dépassée" 'Tasks with warning deadline reached': "Tâches avec une date d'avertissement atteinte" 'Current tasks': 'Tâches en cours' +'Closed tasks': Tâches terminées 'Tasks not started': 'Tâches non commencées' 'Task start date': 'Date de début' 'Task warning date': "Date d'avertissement" @@ -50,7 +52,11 @@ Days: Jour(s) Weeks: Semaine(s) Months: Mois Year: Année(s) - +Filter the tasks: Filtrer les tâches +Filter: Filtrer +Any user: Tous les utilisateurs +Unassigned: Non assigné +Associated person: Personne associée # transitions diff --git a/Resources/views/SingleTask/_list.html.twig b/Resources/views/SingleTask/_list.html.twig index fd8797c88..7552035e6 100644 --- a/Resources/views/SingleTask/_list.html.twig +++ b/Resources/views/SingleTask/_list.html.twig @@ -6,7 +6,7 @@ {{ 'Title'|trans }} - {{ 'Task type'|trans }} + {# {{ 'Task type'|trans }} #} {% if person is null %} {{ 'Person'|trans }} {% endif %} @@ -18,7 +18,7 @@ {% for task in tasks %} {{ task.title }} - {{ task.type }} + {# {{ task.type }} #} {% if person is null %} {{ task.person}} {% endif %} @@ -141,16 +141,26 @@

{{ 'Task list'|trans }}

-

Filter the tasks

+ {% if false == app.request.query.boolean('hide_form', false) %} +

{{ 'Filter the tasks'|trans }}

{{ form_start(form) }} {{ form_row(form.user_id) }} + + {% if form.status is defined %} {{ form_row(form.status) }} + {% endif %} {% if form.person_id is defined %} {{ form_row(form.person_id) }} {% endif %} - + + {{ form_end(form)}} + {% endif %}