back to the list keep the query parameters required by the list

This commit is contained in:
Julien Fastré 2018-07-05 16:37:59 +02:00
parent 066efdc042
commit 39e166eb5b
8 changed files with 57 additions and 34 deletions

View File

@ -194,9 +194,10 @@ class SingleTaskController extends Controller
$this->addFlash('success', $translator
->trans("The task has been updated"));
return $this->redirectToRoute('chill_task_singletask_list', [
'person_id' => $task->getPerson()->getId()
]);
return $this->redirectToRoute(
'chill_task_singletask_list',
$request->query->get('list_params', [])
);
} else {
$this->addFlash('error', $translator->trans("This form contains errors"));
@ -277,9 +278,10 @@ class SingleTaskController extends Controller
->trans("The task has been successfully removed."));
return $this->redirect($this->generateUrl(
'chill_task_singletask_list', array(
'person_id' => $personId
)));
'chill_task_singletask_list',
$request->query->get('list_params', [
'person_id' => $person->getId()
])));
}
}

View File

@ -23,6 +23,7 @@ use Chill\TaskBundle\Templating\UI\CountNotificationTask;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Chill\TaskBundle\Repository\SingleTaskRepository;
use Symfony\Component\Translation\TranslatorInterface;
use Chill\MainBundle\Entity\User;
/**
*
@ -66,19 +67,28 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
public function buildMenu($menuId, MenuItem $menu, array $parameters)
{
$number = $this->counter->countNotification($this->tokenStorage->getToken()
->getUser());
$user = $this->tokenStorage->getToken()->getUser();
$ended = $this->counter->countNotificationEnded($user);
$warning = $this->counter->countNotificationWarning($user);
if ($ended > 0) {
$this->addItemInMenu($menu, $user, '%number% tasks over deadline', $ended, -15);
}
if ($warning > 0) {
$this->addItemInMenu($menu, $user, '%number% tasks near deadline', $warning, -14);
}
}
protected function addItemInMenu(MenuItem $menu, User $u, $message, $number, $order)
{
if ($number > 0) {
$menu->addChild(
$this->translator->transChoice('%number% tasks near deadline', $number),
$this->translator->transChoice($message, $number),
[
'route' => 'chill_task_singletask_list',
'routeParameters' => [
'user_id' => $this->tokenStorage
->getToken()
->getUser()
->getId(),
'user_id' => $u->getId(),
'status' => [
SingleTaskRepository::DATE_STATUS_WARNING,
SingleTaskRepository::DATE_STATUS_ENDED
@ -87,7 +97,7 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
]
])
->setExtras([
'order'=> -15,
'order'=> $order,
'icon' => 'exclamation-triangle',
'entryclass' => 'user_menu__entry--warning-entry'
]);

View File

@ -81,4 +81,5 @@ cancel: annuler
'The task has been updated': 'La tâche a été mise à jour'
'The transition is successfully applied': 'La transition a bien été effectuée'
'The transition could not be applied': "La transition n'a pas pu être appliquée"
'%number% tasks near deadline': '{0} Aucune tâche à échance|{1} Une tâche à échéance | ]1,Inf[ %count% tâches à échéance'
'%number% tasks over deadline': '{0} Aucune tâche dépassée|{1} Une tâche dépassée | ]1,Inf[ %count% tâches dépassée'
'%number% tasks near deadline': '{0} Aucune tâche en rappel|{1} Une tâche en rappel | ]1,Inf[ %count% tâches en rappel'

View File

@ -65,16 +65,16 @@
</li>
{% endif %}
<li>
<a href="{{ path('chill_task_single_task_show', { 'id': task.id }) }}" class="sc-button bt-show "></a>
<a href="{{ path('chill_task_single_task_show', { 'id': task.id, 'list_params': app.request.query.all }) }}" class="sc-button bt-show "></a>
</li>
{% if is_granted('CHILL_TASK_TASK_UPDATE', task) %}
<li>
<a href="{{ path('chill_task_single_task_edit', { 'id': task.id }) }}" class="sc-button bt-update "></a>
<a href="{{ path('chill_task_single_task_edit', { 'id': task.id, 'list_params': app.request.query.all }) }}" class="sc-button bt-update "></a>
</li>
{% endif %}
{% if is_granted('CHILL_TASK_TASK_DELETE', task) %}
<li>
<a href="{{ path('chill_task_single_task_delete', { 'id': task.id } ) }}" class="sc-button bt-delete "></a>
<a href="{{ path('chill_task_single_task_delete', { 'id': task.id, 'list_params': app.request.query.all } ) }}" class="sc-button bt-delete "></a>
</li>
{% endif %}
</ul>

View File

@ -12,7 +12,7 @@
'title' : 'Remove task'|trans,
'confirm_question' : 'Are you sure you want to remove the task about "%name%" ?'|trans({ '%name%' : person.firstname ~ ' ' ~ person.lastname } ),
'cancel_route' : 'chill_task_singletask_list',
'cancel_parameters' : { 'person_id' : task.person.id, 'id' : task.id },
'cancel_parameters' : app.request.query.get('list_params', { } ),
'form' : delete_form
} ) }}

View File

@ -41,7 +41,7 @@
</a>
</li>
<li class="cancel">
<a href="{{ path('chill_task_single_task_show', { 'id': task.id } ) }}" class="sc-button">
<a href="{{ path('chill_task_single_task_show', { 'id': task.id, 'list_params': app.request.query.get('list_params', { } )} ) }}" class="sc-button">
{{ 'Cancel'|trans }}
</a>
</li>

View File

@ -90,7 +90,7 @@
<ul class="record_actions">
<li class="cancel">
<a class="sc-button bt-cancel" href="{{ path('chill_task_singletask_list', { 'person_id': person.id } ) }}">
<a class="sc-button bt-cancel" href="{{ path('chill_task_singletask_list', app.request.query.get('list_params', {}) ) }}">
{{ 'Back to the list'|trans }}
</a>
</li>

View File

@ -43,7 +43,7 @@ class CountNotificationTask implements NotificationCounterInterface
*/
protected $cachePool;
const CACHE_KEY = 'chill_task.count_notifications.user.%d';
const CACHE_KEY = 'chill_task.count_notifications.user.%d.%s';
public function __construct(
SingleTaskRepository $singleTaskRepository,
@ -54,12 +54,29 @@ class CountNotificationTask implements NotificationCounterInterface
}
public function countNotification(UserInterface $u): int
{
return
$this->countNotificationEnded($u)
+ $this->countNotificationWarning($u);
}
public function countNotificationEnded(UserInterface $u): int
{
return $this->_countNotification($u, SingleTaskRepository::DATE_STATUS_ENDED);
}
public function countNotificationWarning(UserInterface $u): int
{
return $this->_countNotification($u, SingleTaskRepository::DATE_STATUS_WARNING);
}
protected function _countNotification(UserInterface $u, $status)
{
if (!$u instanceof User) {
return 0;
}
$sumCache = $this->cachePool->getItem($this->getCacheKey($u));
$sumCache = $this->cachePool->getItem($this->getCacheKey($u, $status));
if ($sumCache->isHit()) {
return $sumCache->get();
@ -70,16 +87,9 @@ class CountNotificationTask implements NotificationCounterInterface
'is_closed' => false
];
$sum = 0;
foreach ([
SingleTaskRepository::DATE_STATUS_ENDED,
SingleTaskRepository::DATE_STATUS_WARNING] as $status) {
$sum += $this->singleTaskRepository->countByParameters(
$sum = $this->singleTaskRepository->countByParameters(
\array_merge($params, [ 'date_status' => $status ])
);
}
);
$sumCache->set($sum);
$this->cachePool->save($sumCache);
@ -106,8 +116,8 @@ class CountNotificationTask implements NotificationCounterInterface
}
}
private function getCacheKey(User $u)
private function getCacheKey(User $u, $status)
{
return sprintf(self::CACHE_KEY, $u->getId());
return sprintf(self::CACHE_KEY, $u->getId(), $status);
}
}