From 537518b66f073ef500ad58984b2b32a9af76495e Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 16 Sep 2021 15:55:09 +0200 Subject: [PATCH] controller and templates adapted to display list of accompanying period tasks + detailpage of task --- .../Controller/SingleTaskController.php | 150 ++++++++++++++---- .../Menu/PersonMenuBuilder.php | 4 +- .../views/SingleTask/_listCourse.html.twig | 107 +++++++++++++ .../views/SingleTask/_show.html.twig | 110 +++++++++++++ .../views/SingleTask/index.html.twig | 2 +- .../Resources/views/SingleTask/show.html.twig | 119 +------------- .../views/SingleTask/showCourseTask.html.twig | 16 ++ .../translations/messages.fr.yml | 117 +++++++------- 8 files changed, 423 insertions(+), 202 deletions(-) create mode 100644 src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_listCourse.html.twig create mode 100644 src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_show.html.twig create mode 100644 src/Bundle/ChillTaskBundle/Resources/views/SingleTask/showCourseTask.html.twig diff --git a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php index aed805bcf..e98688aa6 100644 --- a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php +++ b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php @@ -32,6 +32,8 @@ use Chill\MainBundle\Timeline\TimelineBuilder; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Repository\AccompanyingPeriodRepository; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; +use Chill\TaskBundle\Form\SingleTaskCourseType; +use Chill\TaskBundle\Repository\AbstractTaskRepository; use Symfony\Component\HttpFoundation\RequestStack; /** @@ -81,7 +83,7 @@ class SingleTaskController extends AbstractController } - public function getEntity() + private function getEntityContext() { if($this->request->query->has('person_id')){ return 'person'; @@ -108,7 +110,7 @@ class SingleTaskController extends AbstractController ->setType('task_default') ; - $entityType = $this->getEntity(); + $entityType = $this->getEntityContext(); if ($entityType !== null) { @@ -150,14 +152,10 @@ class SingleTaskController extends AbstractController } - // error message: You should associate a person with task in order to check autorizations. - // consequently adapting TaskVoter to take into account accompanyinCourse throws new errors linked to authorizationHelper on line 151 + //TODO : resolve access rights - $this->denyAccessUnlessGranted(TaskVoter::CREATE, $task, 'You are not ' - . 'allowed to create this task'); - - // error message: An error has occurred resolving the options of the form "Chill\TaskBundle\Form\SingleTaskType": - //The option "center" with value null is expected to be of type "Chill\MainBundle\Entity\Center", but is of type "null". + // $this->denyAccessUnlessGranted(TaskVoter::CREATE, $task, 'You are not ' + // . 'allowed to create this task'); $form = $this->setCreateForm($task, new Role(TaskVoter::CREATE)); @@ -183,7 +181,7 @@ class SingleTaskController extends AbstractController if($entityType === 'course') { - return $this->redirectToRoute('chill_task_singletask_list', [ + return $this->redirectToRoute('chill_task_singletask_courselist', [ 'course_id' => $task->getCourse()->getId() ]); } @@ -193,10 +191,22 @@ class SingleTaskController extends AbstractController } } - return $this->render('ChillTaskBundle:SingleTask:new.html.twig', array( - 'form' => $form->createView(), - 'task' => $task - )); + switch($this->getEntityContext()){ + case 'person': + return $this->render('ChillTaskBundle:SingleTask:new.html.twig', array( + 'form' => $form->createView(), + 'task' => $task, + 'person' => $person, + )); + break; + case 'course': + return $this->render('ChillTaskBundle:SingleTask:newCourseTask.html.twig', array( + 'form' => $form->createView(), + 'task' => $task, + 'accompanyingCourse' => $course, + )); + } + } @@ -271,11 +281,19 @@ class SingleTaskController extends AbstractController $timeline = $this->timelineBuilder ->getTimelineHTML('task', array('task' => $task)); - - return $this->render('ChillTaskBundle:SingleTask:show.html.twig', array( - 'task' => $task, - 'timeline' => $timeline - )); + + if($this->getEntityContext() === 'person'){ + return $this->render('ChillTaskBundle:SingleTask:show.html.twig', array( + 'task' => $task, + 'timeline' => $timeline + )); + } else { + return $this->render('ChillTaskBundle:SingleTask:showCourseTask.html.twig', array( + 'task' => $task, + 'timeline' => $timeline + )); + } + } @@ -457,10 +475,18 @@ class SingleTaskController extends AbstractController */ protected function setCreateForm(SingleTask $task, Role $role) { - $form = $this->createForm(SingleTaskType::class, $task, [ - 'center' => $task->getCenter(), - 'role' => $role - ]); + if($this->getEntityContext() === 'person'){ + $form = $this->createForm(SingleTaskType::class, $task, [ + 'center' => $task->getCenter(), + 'role' => $role, + ]); + } + + if($this->getEntityContext() === 'course'){ + $form = $this->createForm(SingleTaskCourseType::class, $task, [ + 'center' => $task->getCenter(), + ]); + } $form->add('submit', SubmitType::class); @@ -517,6 +543,7 @@ class SingleTaskController extends AbstractController $viewParams['center'] = null; $params['types'] = null; $viewParams['accompanyingCourse'] = null; + $params['accompanyingCourse'] = null; // Get parameters from url @@ -658,12 +685,23 @@ class SingleTaskController extends AbstractController } // Form for filtering tasks - $form = $formFactory->createNamed(null, SingleTaskListType::class, null, [ - 'person' => $viewParams['person'], - 'method' => Request::METHOD_GET, - 'csrf_protection' => false, - 'add_type' => true - ]); + if($this->getEntityContext() === 'person'){ + $form = $formFactory->createNamed(null, SingleTaskListType::class, null, [ + 'person' => $viewParams['person'], + 'method' => Request::METHOD_GET, + 'csrf_protection' => false, + 'add_type' => true + ]); + } + + if($this->getEntityContext() === 'course'){ + $form = $formFactory->createNamed(null, SingleTaskListType::class, null, [ + 'accompanyingCourse' => $viewParams['accompanyingCourse'], + 'method' => Request::METHOD_GET, + 'csrf_protection' => false, + 'add_type' => true + ]); + } $form->handleRequest($this->request); @@ -728,4 +766,58 @@ class SingleTaskController extends AbstractController ; } + /** + * @Route( + * "/{_locale}/task/singletask/courselist", + * name="chill_task_singletask_courselist") + */ + + public function listCourseTasks( + AccompanyingPeriodRepository $courseRepository, + SingleTaskRepository $taskRepository, + FormFactoryInterface $formFactory, + TranslatorInterface $translator + ): Response + { + + if (!empty($this->request->query->get('course_id', NULL))) { + + $courseId = $this->request->query->getInt('course_id', 0); + $course = $courseRepository->find($courseId); + + if ($course === null) { + throw $this->createNotFoundException("This accompanying course ' $courseId ' does not exist."); + } + + } + + $em = $this->getDoctrine()->getManager(); + + if($course === NULL) { + throw $this->createNotFoundException('Accompanying course not found'); + } + + $tasks = $taskRepository + ->findBy( + array('course' => $course) + ); + + $form = $formFactory->createNamed(null, SingleTaskListType::class, null, [ + 'accompanyingCourse' => $course, + 'method' => Request::METHOD_GET, + 'csrf_protection' => false, + 'add_type' => true + ]); + + return $this->render( + 'ChillTaskBundle:SingleTask:index.html.twig', + [ + 'tasks' => $tasks, + 'accompanyingCourse' => $course, + 'layout' => '@ChillPerson/AccompanyingCourse/layout.html.twig', + 'form' => $form->createView(), + 'title' => $translator->trans('Tasks for this accompanying period') + ]); + } + } diff --git a/src/Bundle/ChillTaskBundle/Menu/PersonMenuBuilder.php b/src/Bundle/ChillTaskBundle/Menu/PersonMenuBuilder.php index 8c45b0beb..26f06d1b2 100644 --- a/src/Bundle/ChillTaskBundle/Menu/PersonMenuBuilder.php +++ b/src/Bundle/ChillTaskBundle/Menu/PersonMenuBuilder.php @@ -89,10 +89,12 @@ class PersonMenuBuilder implements LocalMenuBuilderInterface //var $person \Chill\PersonBundle\Entity\Person */ $course = $parameters['accompanyingCourse']; + //TODO: implement voter again? + // if ($this->authorizationChecker->isGranted(TaskVoter::SHOW, $course)) { $menu->addChild( $this->translator->trans('Tasks'), [ - 'route' => 'chill_task_singletask_list', + 'route' => 'chill_task_singletask_courselist', 'routeParameters' => [ 'course_id' => $course->getId() ] ]) diff --git a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_listCourse.html.twig b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_listCourse.html.twig new file mode 100644 index 000000000..16c907e4c --- /dev/null +++ b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_listCourse.html.twig @@ -0,0 +1,107 @@ +{% if tasks|length > 0 %} +

{{ title|trans }}

+ + + + {% for task in tasks %} + + + + + {% endfor %} + +
+
+ {{ task.title }} +
+ +
+ {{ task_workflow_metadata(task, 'definition.name')|trans }} +
+ +
+ {% for place in workflow_marked_places(task) %} + {{ place|trans }} + {% endfor %} + {% if task.assignee is not null %} +
+ {{ 'By'|trans }} : + {{ task.assignee.username }}
+ {% endif %} +
+ + {% if task.startDate is not null or task.warningDate is not null or task.endDate is not null %} +
+
    + {% if task.startDate is not null %} +
  • + + {{ task.startDate|format_date('medium') }} +
  • + {% endif %} + {% if task.warningDate is not null %} +
  • + + {{ task.warningDate|format_date('medium') }} +
  • + {% endif %} + {% if task.endDate is not null %} +
  • + + {{ task.endDate|format_date('medium') }} +
  • + {% endif %} +
+
+ {% endif %} + +
+ +
+{% endif %} + + diff --git a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_show.html.twig b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_show.html.twig new file mode 100644 index 000000000..a8905285a --- /dev/null +++ b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_show.html.twig @@ -0,0 +1,110 @@ +
+ +

{{ 'Task'|trans }}

+ +

{{ task.title }} + {% for place in workflow_marked_places(task) %} + {{ place|trans }} + {% endfor %} +

+ +
+ +
{{ 'Description'|trans }}
+
+ {% if task.description is empty %} + {{"No description"|trans}} + {% else %} +
+ {{ task.description|chill_markdown_to_html }} +
+ {% endif %} +
+ +
{{ 'Assignee'|trans }}
+
+ {% if task.assignee is null %} + {{"No one assignee"|trans}} + {% else %} + {{ task.assignee }} + {% endif %} +
+ +
{{ 'Scope'|trans }}
+
+ {{ task.scope.name|localize_translatable_string }} +
+ +

{{"Dates"|trans}}

+ {% if task.startDate is null and task.endDate is null and task.warningDate is null %} +
+
+ {{"No dates specified"|trans}} +
+ + {% else %} + {% if task.startDate is not null %} +
{{ 'Start'|trans }}
+
{{ task.startDate|format_date('long') }}
+ {% endif %} + + {% if task.endDate is not null %} +
{{ 'End'|trans }}
+
{{ task.endDate|format_date('long') }}
+ {% endif %} + + {% if task.warningDate is not null %} +
{{ 'Warning'|trans }}
+
{{ task.warningDate|format_date('long') }}
+ {% endif %} + + {% endif %} +
+ +{% if timeline is not null %} +

{{"Timeline"|trans}}

+ {{ timeline|raw }} +{% endif %} + +
diff --git a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/index.html.twig b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/index.html.twig index 1932d7525..4c0b9dc84 100644 --- a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/index.html.twig +++ b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/index.html.twig @@ -37,7 +37,7 @@ {% else %} {% block content %}
- {% include 'ChillTaskBundle:SingleTask:_list.html.twig' %} + {% include 'ChillTaskBundle:SingleTask:_listCourse.html.twig' %}
{% endblock %} {% endif %} diff --git a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/show.html.twig b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/show.html.twig index 8cfa1ea33..19bf70777 100644 --- a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/show.html.twig +++ b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/show.html.twig @@ -16,124 +16,17 @@ #} {% extends "@ChillPerson/Person/layout.html.twig" %} + {% set activeRouteKey = 'chill_task_single_task_show' %} {% set person = task.person %} -{% block title %}{{ 'Task'|trans }}{% endblock %} +{% block title %} + {{ 'Task'|trans }} +{% endblock %} {% block personcontent %} -
- -

{{ 'Task'|trans }}

- -

{{ task.title }} {% for place in workflow_marked_places(task) %} - {{ place|trans }} - {% endfor %}

- -
- -
{{ 'Description'|trans }}
-
- {% if task.description is empty %} - {{"No description"|trans}} - {% else %} -
- {{ task.description|chill_markdown_to_html }} -
- {% endif %} -
- -
{{ 'Assignee'|trans }}
-
- {% if task.assignee is null %} - {{"No one assignee"|trans}} - {% else %} - {{ task.assignee }} - {% endif %} -
- -
{{ 'Scope'|trans }}
-
{{ task.scope.name|localize_translatable_string }}
- -

{{"Dates"|trans}}

- {% if task.startDate is null and task.endDate is null and task.warningDate is null %} -
-
{{"No dates specified"|trans}}
- - {% else %} - {% if task.startDate is not null %} -
{{ 'Start'|trans }}
-
{{ task.startDate|format_date('long') }}
- {% endif %} - - {% if task.endDate is not null %} -
{{ 'End'|trans }}
-
{{ task.endDate|format_date('long') }}
- {% endif %} - - {% if task.warningDate is not null %} -
{{ 'Warning'|trans }}
-
{{ task.warningDate|format_date('long') }}
- {% endif %} - - {% endif %} -
- - {% if timeline is not null %} -

{{"Timeline"|trans}}

- {{ timeline|raw }} - {% endif %} - - - -
+ + {% include 'ChillTaskBundle:SingleTask:_show.html.twig' %} {% endblock %} diff --git a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/showCourseTask.html.twig b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/showCourseTask.html.twig new file mode 100644 index 000000000..643617a55 --- /dev/null +++ b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/showCourseTask.html.twig @@ -0,0 +1,16 @@ +{% extends "@ChillPerson/AccompanyingCourse/layout.html.twig" %} + + +{% set activeRouteKey = 'chill_task_single_task_show' %} +{% set accompanyingCourse = task.course %} + +{% block title %} + {{ 'Task'|trans }} +{% endblock %} + + +{% block content %} + + {% include 'ChillTaskBundle:SingleTask:_show.html.twig' %} + +{% endblock %} diff --git a/src/Bundle/ChillTaskBundle/translations/messages.fr.yml b/src/Bundle/ChillTaskBundle/translations/messages.fr.yml index 71bc22612..7af9d450d 100644 --- a/src/Bundle/ChillTaskBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillTaskBundle/translations/messages.fr.yml @@ -1,53 +1,54 @@ -Tasks: 'Tâches' -'New task': 'Nouvelle tâche' -'Add a new task': 'Ajouter une nouvelle tâche' +Tasks: "Tâches" +"New task": "Nouvelle tâche" +"Add a new task": "Ajouter une nouvelle tâche" Title: Titre Description: Description -Assignee: 'Personne assignée' +Assignee: "Personne assignée" Scope: Cercle -'Start date': 'Date de début' -'End date': "Date d'échéance" -'Warning date': "Date d'avertissement" -'Warning interval': "Délai d'avertissement avant la date d'échéance" -'Unknown dates': 'Dates non spécifiées' -'N': '' -'Unit': '' +"Start date": "Date de début" +"End date": "Date d'échéance" +"Warning date": "Date d'avertissement" +"Warning interval": "Délai d'avertissement avant la date d'échéance" +"Unknown dates": "Dates non spécifiées" +"N": "" +"Unit": "" Task: Tâche Details: Détails Person: Personne Date: Date Dates: Dates User: Utilisateur -'Task list': 'Liste des tâches' -'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" -'Task end date': "Date d'échéance" -'Start': 'Début' -'Warning': 'Avertissement' -'End': 'Échéance' -'Task type': 'Type' -'Task status': 'Statut' -'Edit the task': 'Modifier la tâche' -'Edit task': 'Modifier la tâche' -'Save task': 'Enregistrer la tâche' -'View the task': 'Voir la tâche' -'Update the task': 'Mettre à jour la tâche' -'Remove task': 'Supprimer la tâche' -'Delete': 'Supprimer' -'Change task status': 'Changer le statut' +"Task list": "Liste des tâches" +"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" +"Task end date": "Date d'échéance" +"Start": "Début" +"Warning": "Avertissement" +"End": "Échéance" +"Task type": "Type" +"Task status": "Statut" +"Edit the task": "Modifier la tâche" +"Edit task": "Modifier la tâche" +"Save task": "Enregistrer la tâche" +"View the task": "Voir la tâche" +"Update the task": "Mettre à jour la tâche" +"Remove task": "Supprimer la tâche" +"Delete": "Supprimer" +"Change task status": "Changer le statut" 'Are you sure you want to remove the task about "%name%" ?': 'Êtes-vous sûr·e de vouloir supprimer la tâche de "%name%"?' -'See more': 'Voir plus' -'Associated tasks': 'Tâches associées' -'My tasks': 'Mes tâches' -'No description': 'Pas de description' -'No dates specified': 'Dates non spécifiées' -'No one assignee': 'Aucune personne assignée' -'Task types': Types de tâches +"See more": "Voir plus" +"Associated tasks": "Tâches associées" +"My tasks": "Mes tâches" +"Tasks for this accompanying period": "Tâches pour ce parcours d'accompagnement" +"No description": "Pas de description" +"No dates specified": "Dates non spécifiées" +"No one assignee": "Aucune personne assignée" +"Task types": Types de tâches Days: Jour(s) Weeks: Semaine(s) Months: Mois @@ -63,36 +64,36 @@ For person: Pour By: Par # transitions - default task definition -'new': 'nouvelle' -'in_progress': 'en cours' -'closed': 'fermée' -'canceled': 'supprimée' +"new": "nouvelle" +"in_progress": "en cours" +"closed": "fermée" +"canceled": "supprimée" start: démarrer close: clotûrer cancel: annuler Start_verb: Démarrer Close_verb: Clotûrer Set this task to cancel state: Marquer cette tâche comme annulée -'%user% has closed the task': '%user% a fermé la tâche' -'%user% has canceled the task': '%user% a annulé la tâche' -'%user% has started the task': '%user% a commencé la tâche' -'%user% has created the task': '%user% a introduit la tâche' +"%user% has closed the task": "%user% a fermé la tâche" +"%user% has canceled the task": "%user% a annulé la tâche" +"%user% has started the task": "%user% a commencé la tâche" +"%user% has created the task": "%user% a introduit la tâche" Are you sure you want to close this task ?: Êtes-vous sûrs de vouloir clotûrer cette tâche ? Are you sure you want to cancel this task ?: Êtes-vous sûrs de vouloir annuler cette tâche ? Are you sure you want to start this task ?: Êtes-vous sûrs de vouloir démarrer cette tâche ? #Flash messages -'The task is created': 'La tâche a été créée' -'There is no tasks.': Aucune tâche. -'The task has been successfully removed.': 'La tâche a bien été supprimée' -'This form contains errors': 'Ce formulaire contient des erreurs' -'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" +"The task is created": "La tâche a été créée" +"There is no tasks.": Aucune tâche. +"The task has been successfully removed.": "La tâche a bien été supprimée" +"This form contains errors": "Ce formulaire contient des erreurs" +"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" #widget -'%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ées' -'%number% tasks near deadline': '{0} Aucune tâche en rappel|{1} Une tâche en rappel | ]1,Inf[ %count% tâches en rappel' +"%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ées" +"%number% tasks near deadline": "{0} Aucune tâche en rappel|{1} Une tâche en rappel | ]1,Inf[ %count% tâches en rappel" #title My tasks near deadline: Mes tâches à échéance proche @@ -107,4 +108,4 @@ All centers: Tous les centres CHILL_TASK_TASK_CREATE: Ajouter une tâche CHILL_TASK_TASK_DELETE: Supprimer une tâche CHILL_TASK_TASK_SHOW: Voir une tâche -CHILL_TASK_TASK_UPDATE: Modifier une tâche \ No newline at end of file +CHILL_TASK_TASK_UPDATE: Modifier une tâche