|
|
@ -20,11 +20,11 @@ use Symfony\Component\Workflow\WorkflowInterface; |
|
|
|
#[Route('/task')]
|
|
|
|
class TaskController extends AbstractController |
|
|
|
{ |
|
|
|
#[Route('/{projectSlug}/create', name: 'app_task_create')]
|
|
|
|
public function create(Request $request, EntityManagerInterface $entityManager, $projectSlug): Response |
|
|
|
#[Route('/create', name: 'app_task_create')]
|
|
|
|
public function create(Request $request, EntityManagerInterface $entityManager, $slug): Response |
|
|
|
{ |
|
|
|
$repository = $entityManager->getRepository(Project::class); |
|
|
|
$project = $repository->findOneBySlug($projectSlug); |
|
|
|
$project = $repository->findOneBySlug($slug); |
|
|
|
|
|
|
|
if (!$project) { |
|
|
|
$this->addFlash( |
|
|
@ -47,6 +47,7 @@ class TaskController extends AbstractController |
|
|
|
$task = $createForm->getData(); |
|
|
|
|
|
|
|
try { |
|
|
|
$task->setCreatedBy($this->getUser()); |
|
|
|
$entityManager->persist($task); |
|
|
|
$entityManager->flush(); |
|
|
|
|
|
|
@ -55,7 +56,7 @@ class TaskController extends AbstractController |
|
|
|
'Tâche créée !' |
|
|
|
); |
|
|
|
|
|
|
|
return $this->redirectToRoute('app_project_show', ['projectSlug' => $projectSlug]); |
|
|
|
return $this->redirectToRoute('app_project_show', ['slug' => $slug]); |
|
|
|
} catch (\Exception $exception) { |
|
|
|
$this->addFlash( |
|
|
|
'danger', |
|
|
@ -71,11 +72,11 @@ class TaskController extends AbstractController |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
#[Route('/{projectSlug}/show/{taskSlug}', name: 'app_task_show')]
|
|
|
|
public function show(EntityManagerInterface $entityManager, GeoJsonManager $geoJsonManager, $projectSlug, $taskSlug): Response |
|
|
|
#[Route('/{slug}', name: 'app_task_show')]
|
|
|
|
public function show(Request $request, EntityManagerInterface $entityManager, GeoJsonManager $geoJsonManager, $slug): Response |
|
|
|
{ |
|
|
|
$repository = $entityManager->getRepository(Task::class); |
|
|
|
$task = $repository->findOneBySlug($taskSlug); |
|
|
|
$task = $repository->findOneBySlug($slug); |
|
|
|
|
|
|
|
if (!$task) { |
|
|
|
$this->addFlash( |
|
|
@ -83,12 +84,12 @@ class TaskController extends AbstractController |
|
|
|
'Tâche non trouvée !' |
|
|
|
); |
|
|
|
|
|
|
|
return $this->redirectToRoute('app_project_show', ['projectSlug' => $projectSlug]); |
|
|
|
return $this->redirect($request->headers->get('Referer')); |
|
|
|
} |
|
|
|
|
|
|
|
$comment = new Comment(); |
|
|
|
$commentForm = $this->createForm(CommentType::class, $comment, [ |
|
|
|
'action' => $this->generateUrl('app_task_comment', ['projectSlug' => $projectSlug, 'taskSlug' => $taskSlug]), |
|
|
|
'action' => $this->generateUrl('app_task_comment', ['slug' => $slug]), |
|
|
|
]); |
|
|
|
$commentForm->add('submit', SubmitType::class, [ |
|
|
|
'label' => 'Commenter', |
|
|
@ -101,11 +102,11 @@ class TaskController extends AbstractController |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
#[Route('/{projectSlug}/comment/{taskSlug}', name: 'app_task_comment')]
|
|
|
|
public function comment(Request $request, EntityManagerInterface $entityManager, $projectSlug, $taskSlug): Response |
|
|
|
#[Route('/{slug}/comment', name: 'app_task_comment')]
|
|
|
|
public function comment(Request $request, EntityManagerInterface $entityManager, $slug): Response |
|
|
|
{ |
|
|
|
$repository = $entityManager->getRepository(Task::class); |
|
|
|
$task = $repository->findOneBySlug($taskSlug); |
|
|
|
$task = $repository->findOneBySlug($slug); |
|
|
|
|
|
|
|
if (!$task) { |
|
|
|
$this->addFlash( |
|
|
@ -113,7 +114,7 @@ class TaskController extends AbstractController |
|
|
|
'Tâche non trouvée !' |
|
|
|
); |
|
|
|
|
|
|
|
return $this->redirectToRoute('app_project_show', ['projectSlug' => $projectSlug]); |
|
|
|
return $this->redirect($request->headers->get('Referer')); |
|
|
|
} |
|
|
|
|
|
|
|
$comment = new Comment(); |
|
|
@ -143,14 +144,14 @@ class TaskController extends AbstractController |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return $this->redirectToRoute('app_task_show', ['projectSlug' => $projectSlug, 'taskSlug' => $taskSlug]); |
|
|
|
return $this->redirectToRoute('app_task_show', ['slug' => $slug]); |
|
|
|
} |
|
|
|
|
|
|
|
#[Route('/{projectSlug}/update/{taskSlug}', name: 'app_task_update')]
|
|
|
|
public function update(Request $request, EntityManagerInterface $entityManager, $projectSlug, $taskSlug): Response |
|
|
|
#[Route('/{slug}/update', name: 'app_task_update')]
|
|
|
|
public function update(Request $request, EntityManagerInterface $entityManager, $slug): Response |
|
|
|
{ |
|
|
|
$repository = $entityManager->getRepository(Task::class); |
|
|
|
$task = $repository->findOneBySlug($taskSlug); |
|
|
|
$task = $repository->findOneBySlug($slug); |
|
|
|
|
|
|
|
if (!$task) { |
|
|
|
$this->addFlash( |
|
|
@ -158,7 +159,7 @@ class TaskController extends AbstractController |
|
|
|
'Tâche non trouvée !' |
|
|
|
); |
|
|
|
|
|
|
|
return $this->redirectToRoute('app_project_show', ['projectSlug' => $projectSlug]); |
|
|
|
return $this->redirect($request->headers->get('Referer')); |
|
|
|
} |
|
|
|
|
|
|
|
$updateForm = $this->createForm(TaskType::class, $task); |
|
|
@ -179,7 +180,7 @@ class TaskController extends AbstractController |
|
|
|
'Tâche modifiée !' |
|
|
|
); |
|
|
|
|
|
|
|
return $this->redirectToRoute('app_task_show', ['projectSlug' => $projectSlug, 'taskSlug' => $taskSlug]); |
|
|
|
return $this->redirectToRoute('app_task_show', ['slug' => $slug]); |
|
|
|
} catch (\Exception $exception) { |
|
|
|
$this->addFlash( |
|
|
|
'danger', |
|
|
@ -195,21 +196,24 @@ class TaskController extends AbstractController |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
|
#[Route('/{projectSlug}/remove/{taskSlug}', name: 'app_task_remove')]
|
|
|
|
public function remove(EntityManagerInterface $entityManager, $projectSlug, $taskSlug): Response |
|
|
|
#[Route('/{slug}/remove', name: 'app_task_remove')]
|
|
|
|
public function remove(Request $request, EntityManagerInterface $entityManager, $slug): Response |
|
|
|
{ |
|
|
|
$repository = $entityManager->getRepository(Task::class); |
|
|
|
$task = $repository->findOneBySlug($taskSlug); |
|
|
|
$task = $repository->findOneBySlug($slug); |
|
|
|
|
|
|
|
if (!$task) { |
|
|
|
$this->addFlash( |
|
|
|
'warning', |
|
|
|
'Tâche non trouvée !' |
|
|
|
); |
|
|
|
return $this->redirectToRoute('app_project_show', ['projectSlug' => $projectSlug]); |
|
|
|
return $this->redirect($request->headers->get('Referer')); |
|
|
|
} |
|
|
|
|
|
|
|
$project = $task->getProject(); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
$entityManager->remove($task); |
|
|
|
$entityManager->flush(); |
|
|
|
|
|
|
@ -218,7 +222,7 @@ class TaskController extends AbstractController |
|
|
|
'Tâche supprimée !' |
|
|
|
); |
|
|
|
|
|
|
|
return $this->redirectToRoute('app_project_show', ['projectSlug' => $projectSlug]); |
|
|
|
return $this->redirectToRoute('app_project_show', ['slug' => $project->getSlug()]); |
|
|
|
} catch (\Exception $exception) { |
|
|
|
$this->addFlash( |
|
|
|
'danger', |
|
|
@ -226,24 +230,41 @@ class TaskController extends AbstractController |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
return $this->redirectToRoute('app_project_show', ['projectSlug' => $projectSlug]); |
|
|
|
return $this->redirectToRoute('app_project_show', ['slug' => $slug]); |
|
|
|
} |
|
|
|
|
|
|
|
private function transition(WorkflowInterface $taskLifecycleStateMachine, EntityManagerInterface $entityManager, $projectSlug, $taskSlug, $status): Response |
|
|
|
private function transition(WorkflowInterface $taskLifecycleStateMachine, EntityManagerInterface $entityManager, $slug, $transitionName): Response |
|
|
|
{ |
|
|
|
$repository = $entityManager->getRepository(Task::class); |
|
|
|
$task = $repository->findOneBySlug($taskSlug); |
|
|
|
$task = $repository->findOneBySlug($slug); |
|
|
|
|
|
|
|
if (!$task) { |
|
|
|
$this->addFlash( |
|
|
|
'warning', |
|
|
|
'Tâche non trouvée !' |
|
|
|
); |
|
|
|
return $this->redirectToRoute('app_project_show', ['projectSlug' => $projectSlug]); |
|
|
|
return $this->redirectToRoute('app_project'); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
$taskLifecycleStateMachine->apply($task, $status); |
|
|
|
// TODO on doit pouvoir faire mieux pour le verrouillage, notamment au niveau des règles de tansition du workflow…
|
|
|
|
$transitions = array_filter( |
|
|
|
$taskLifecycleStateMachine->getDefinition()->getTransitions(), |
|
|
|
function ($transition) use ($transitionName) { |
|
|
|
return $transitionName === $transition->getName(); |
|
|
|
} |
|
|
|
); |
|
|
|
$transition = reset($transitions); |
|
|
|
$shouldTransitionLock = $taskLifecycleStateMachine->getMetadataStore()->getTransitionMetadata($transition)['lock']; |
|
|
|
$shouldTransitionUnlock = $taskLifecycleStateMachine->getMetadataStore()->getTransitionMetadata($transition)['unlock']; |
|
|
|
|
|
|
|
$taskLifecycleStateMachine->apply($task, $transitionName); |
|
|
|
|
|
|
|
if ($shouldTransitionLock) { |
|
|
|
$task->lock($this->getUser()); |
|
|
|
} elseif ($shouldTransitionUnlock) { |
|
|
|
$task->unlock(); |
|
|
|
} |
|
|
|
|
|
|
|
$entityManager->persist($task); |
|
|
|
$entityManager->flush(); |
|
|
@ -259,31 +280,31 @@ class TaskController extends AbstractController |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
return $this->redirectToRoute('app_task_show', ['projectSlug' => $projectSlug, 'taskSlug' => $taskSlug]); |
|
|
|
return $this->redirectToRoute('app_task_show', ['slug' => $slug]); |
|
|
|
} |
|
|
|
|
|
|
|
#[Route('/{projectSlug}/start/{taskSlug}', name: 'app_task_start')]
|
|
|
|
public function start(WorkflowInterface $taskLifecycleStateMachine, EntityManagerInterface $entityManager, $projectSlug, $taskSlug): Response |
|
|
|
|
|
|
|
#[Route('/{slug}/start', name: 'app_task_start')]
|
|
|
|
public function start(WorkflowInterface $taskLifecycleStateMachine, EntityManagerInterface $entityManager, $slug): Response |
|
|
|
{ |
|
|
|
return $this->transition($taskLifecycleStateMachine, $entityManager, $projectSlug, $taskSlug, Task::TRANSITION_START); |
|
|
|
return $this->transition($taskLifecycleStateMachine, $entityManager, $slug, Task::TRANSITION_START); |
|
|
|
} |
|
|
|
|
|
|
|
#[Route('/{projectSlug}/finish/{taskSlug}', name: 'app_task_finish')]
|
|
|
|
public function finish(WorkflowInterface $taskLifecycleStateMachine, EntityManagerInterface $entityManager, $projectSlug, $taskSlug): Response |
|
|
|
#[Route('/{slug}/finish', name: 'app_task_finish')]
|
|
|
|
public function finish(WorkflowInterface $taskLifecycleStateMachine, EntityManagerInterface $entityManager, $slug): Response |
|
|
|
{ |
|
|
|
return $this->transition($taskLifecycleStateMachine, $entityManager, $projectSlug, $taskSlug, Task::TRANSITION_FINISH); |
|
|
|
return $this->transition($taskLifecycleStateMachine, $entityManager, $slug, Task::TRANSITION_FINISH); |
|
|
|
} |
|
|
|
|
|
|
|
#[Route('/{projectSlug}/cancel/{taskSlug}', name: 'app_task_cancel')]
|
|
|
|
public function cancel(WorkflowInterface $taskLifecycleStateMachine, EntityManagerInterface $entityManager, $projectSlug, $taskSlug): Response |
|
|
|
#[Route('/{slug}/cancel', name: 'app_task_cancel')]
|
|
|
|
public function cancel(WorkflowInterface $taskLifecycleStateMachine, EntityManagerInterface $entityManager, $slug): Response |
|
|
|
{ |
|
|
|
return $this->transition($taskLifecycleStateMachine, $entityManager, $projectSlug, $taskSlug, Task::TRANSITION_CANCEL); |
|
|
|
return $this->transition($taskLifecycleStateMachine, $entityManager, $slug, Task::TRANSITION_CANCEL); |
|
|
|
} |
|
|
|
|
|
|
|
#[Route('/{projectSlug}/reset/{taskSlug}', name: 'app_task_reset')]
|
|
|
|
public function reset(WorkflowInterface $taskLifecycleStateMachine, EntityManagerInterface $entityManager, $projectSlug, $taskSlug): Response |
|
|
|
#[Route('/{slug}/reset', name: 'app_task_reset')]
|
|
|
|
public function reset(WorkflowInterface $taskLifecycleStateMachine, EntityManagerInterface $entityManager, $slug): Response |
|
|
|
{ |
|
|
|
return $this->transition($taskLifecycleStateMachine, $entityManager, $projectSlug, $taskSlug, Task::TRANSITION_RESET); |
|
|
|
return $this->transition($taskLifecycleStateMachine, $entityManager, $slug, Task::TRANSITION_RESET); |
|
|
|
} |
|
|
|
|
|
|
|
#[Route('/{slug}.geojson', name: 'app_task_geojson')]
|
|
|
@ -297,7 +318,7 @@ class TaskController extends AbstractController |
|
|
|
'warning', |
|
|
|
'Tâche non trouvée !' |
|
|
|
); |
|
|
|
return $this->redirect($request->headers->get('referer')); |
|
|
|
return $this->redirect($request->headers->get('Referer')); |
|
|
|
} |
|
|
|
|
|
|
|
return JsonResponse::fromJsonString($task->getGeojson()); |
|
|
|