improve filter form

- hide form in some places ;
- i18n
- hide status filtering with a parameter (redundant)
This commit is contained in:
Julien Fastré 2018-05-08 22:56:45 +02:00
parent 650f2c8e18
commit 69eb9648c9
8 changed files with 103 additions and 32 deletions

View File

@ -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'))) {

View File

@ -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;

View File

@ -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'])
;
}
}

View File

@ -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'],

View File

@ -82,7 +82,8 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
'status' => [
SingleTaskRepository::DATE_STATUS_WARNING,
SingleTaskRepository::DATE_STATUS_ENDED
]
],
'hide_form' => true
]
])
->setExtras([

View File

@ -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'));

View File

@ -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

View File

@ -6,7 +6,7 @@
<thead>
<tr>
<th class="chill-red">{{ 'Title'|trans }}</th>
<th class="chill-green">{{ 'Task type'|trans }}</th>
{# <th class="chill-green">{{ 'Task type'|trans }}</th> #}
{% if person is null %}
<th>{{ 'Person'|trans }}</th>
{% endif %}
@ -18,7 +18,7 @@
{% for task in tasks %}
<tr>
<td>{{ task.title }}</td>
<td>{{ task.type }}</td>
{# <td>{{ task.type }}</td> #}
{% if person is null %}
<td><a href="{{ path('chill_person_view', {person_id : task.person.Id}) }}">{{ task.person}}</a></td>
{% endif %}
@ -141,16 +141,26 @@
<h1>{{ 'Task list'|trans }}</h1>
<p>Filter the tasks</p>
{% if false == app.request.query.boolean('hide_form', false) %}
<h3>{{ 'Filter the tasks'|trans }}</h3>
{{ 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 %}
<button type="submit">{{ 'Filter'|trans }}</button>
<ul class="record_actions">
<li>
<button type="submit" class="sc-button">{{ 'Filter'|trans }}</button>
</li>
</ul>
{{ form_end(form)}}
{% endif %}