mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
add a timeline in view pages for viewing task transitions
This commit is contained in:
parent
f829dccbdd
commit
d4d730ea02
@ -75,7 +75,7 @@ class SingleTaskController extends Controller
|
|||||||
if ($form->isValid()) {
|
if ($form->isValid()) {
|
||||||
$em = $this->getDoctrine()->getManager();
|
$em = $this->getDoctrine()->getManager();
|
||||||
$em->persist($task);
|
$em->persist($task);
|
||||||
|
|
||||||
$dispatcher->dispatch(TaskEvent::PERSIST, new TaskEvent($task));
|
$dispatcher->dispatch(TaskEvent::PERSIST, new TaskEvent($task));
|
||||||
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
@ -133,8 +133,12 @@ class SingleTaskController extends Controller
|
|||||||
throw $this->createNotFoundException('Unable to find Task entity.');
|
throw $this->createNotFoundException('Unable to find Task entity.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$timeline = $this->get('chill.main.timeline_builder')
|
||||||
|
->getTimelineHTML('task', array('task' => $task));
|
||||||
|
|
||||||
return $this->render('ChillTaskBundle:SingleTask:show.html.twig', array(
|
return $this->render('ChillTaskBundle:SingleTask:show.html.twig', array(
|
||||||
'task' => $task,
|
'task' => $task,
|
||||||
|
'timeline' => $timeline
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,8 +150,8 @@ class SingleTaskController extends Controller
|
|||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function editAction(
|
public function editAction(
|
||||||
Request $request,
|
Request $request,
|
||||||
$id,
|
$id,
|
||||||
TranslatorInterface $translator
|
TranslatorInterface $translator
|
||||||
) {
|
) {
|
||||||
/* @var $taskRepository SingleTaskRepository */
|
/* @var $taskRepository SingleTaskRepository */
|
||||||
@ -213,7 +217,7 @@ class SingleTaskController extends Controller
|
|||||||
* )
|
* )
|
||||||
*/
|
*/
|
||||||
public function deleteAction(
|
public function deleteAction(
|
||||||
Request $request,
|
Request $request,
|
||||||
$id,
|
$id,
|
||||||
TranslatorInterface $translator
|
TranslatorInterface $translator
|
||||||
) {
|
) {
|
||||||
@ -221,7 +225,7 @@ class SingleTaskController extends Controller
|
|||||||
$taskRepository = $this->get('chill_task.single_task_repository');
|
$taskRepository = $this->get('chill_task.single_task_repository');
|
||||||
|
|
||||||
$task = $taskRepository->find($id);
|
$task = $taskRepository->find($id);
|
||||||
|
|
||||||
if (!$task) {
|
if (!$task) {
|
||||||
throw $this->createNotFoundException('Unable to find Task entity.');
|
throw $this->createNotFoundException('Unable to find Task entity.');
|
||||||
}
|
}
|
||||||
@ -321,18 +325,18 @@ class SingleTaskController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Arguments:
|
* Arguments:
|
||||||
* - user_id
|
* - user_id
|
||||||
* - scope_id
|
* - scope_id
|
||||||
* - person_id
|
* - person_id
|
||||||
* - hide_form (hide the form to filter the tasks)
|
* - hide_form (hide the form to filter the tasks)
|
||||||
* - status: date state, amongst SingleTaskRepository::DATE_STATUSES, or 'closed'
|
* - status: date state, amongst SingleTaskRepository::DATE_STATUSES, or 'closed'
|
||||||
*
|
*
|
||||||
* @Route(
|
* @Route(
|
||||||
* "/{_locale}/task/singletask/list",
|
* "/{_locale}/task/singletask/list",
|
||||||
* name="chill_task_singletask_list",
|
* name="chill_task_singletask_list",
|
||||||
* options={ "menus": {
|
* options={ "menus": {
|
||||||
* "person" : { "order": 400, "label": "Associated tasks" } ,
|
* "person" : { "order": 400, "label": "Associated tasks" } ,
|
||||||
* "section": { "order": 400, "label": "Tasks", "icons": "tasks" }
|
* "section": { "order": 400, "label": "Tasks", "icons": "tasks" }
|
||||||
* }}
|
* }}
|
||||||
@ -354,7 +358,7 @@ class SingleTaskController extends Controller
|
|||||||
$params['user'] = null;
|
$params['user'] = null;
|
||||||
$viewParams['center'] = null;
|
$viewParams['center'] = null;
|
||||||
$params['center'] = null;
|
$params['center'] = null;
|
||||||
|
|
||||||
// Get parameters from url
|
// Get parameters from url
|
||||||
if (!empty($request->query->get('person_id', NULL))) {
|
if (!empty($request->query->get('person_id', NULL))) {
|
||||||
$personId = $request->query->getInt('person_id');
|
$personId = $request->query->getInt('person_id');
|
||||||
@ -469,7 +473,7 @@ class SingleTaskController extends Controller
|
|||||||
|
|
||||||
$form->handleRequest($request);
|
$form->handleRequest($request);
|
||||||
|
|
||||||
return $this->render('ChillTaskBundle:SingleTask:index.html.twig',
|
return $this->render('ChillTaskBundle:SingleTask:index.html.twig',
|
||||||
\array_merge($viewParams, [ 'form' => $form->createView() ]));
|
\array_merge($viewParams, [ 'form' => $form->createView() ]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,4 +5,9 @@ services:
|
|||||||
$registry: '@Symfony\Component\Workflow\Registry'
|
$registry: '@Symfony\Component\Workflow\Registry'
|
||||||
tags:
|
tags:
|
||||||
- { name: 'chill.timeline', context: 'person' }
|
- { name: 'chill.timeline', context: 'person' }
|
||||||
|
Chill\TaskBundle\Timeline\SingleTaskTaskLifeCycleEventTimelineProvider:
|
||||||
|
arguments:
|
||||||
|
$em: '@Doctrine\ORM\EntityManagerInterface'
|
||||||
|
$registry: '@Symfony\Component\Workflow\Registry'
|
||||||
|
tags:
|
||||||
|
- { name: 'chill.timeline', context: 'task' }
|
||||||
|
@ -81,6 +81,11 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
|
{% if timeline is not null %}
|
||||||
|
<h3>{{"Timeline"|trans}}</h3>
|
||||||
|
{{ timeline|raw }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<ul class="record_actions">
|
<ul class="record_actions">
|
||||||
<li class="cancel">
|
<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', { 'person_id': person.id } ) }}">
|
||||||
@ -114,5 +119,4 @@
|
|||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
<div>
|
||||||
|
<h3 class="single-line">
|
||||||
|
{{ event.datetime|localizeddate('long', 'short') }}
|
||||||
|
<span class="task"> / {{ 'Task'|trans }}</span> /
|
||||||
|
{% if transition is not null %}
|
||||||
|
<span class="statement">{{ task_workflow_metadata(event.task, 'transition.sentence', transition)|trans({ '%user%': event.author.username }) }}</span>
|
||||||
|
<span>"{{ event.task.title }}"</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="statement">{{ '%user% has created the task'|trans({ '%user%': event.author.username }) }}</span>
|
||||||
|
<span>"{{ event.task.title }}"</span>
|
||||||
|
{% endif %}
|
||||||
|
</h3>
|
||||||
|
</div>
|
132
Timeline/SingleTaskTaskLifeCycleEventTimelineProvider.php
Normal file
132
Timeline/SingleTaskTaskLifeCycleEventTimelineProvider.php
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2018 Champs Libres Cooperative <info@champs-libres.coop>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
namespace Chill\TaskBundle\Timeline;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Timeline\TimelineProviderInterface;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Chill\TaskBundle\Entity\Task\SingleTaskPlaceEvent;
|
||||||
|
use Chill\TaskBundle\Entity\SingleTask;
|
||||||
|
use Symfony\Component\Workflow\Registry;
|
||||||
|
use Symfony\Component\Workflow\Workflow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||||
|
*/
|
||||||
|
class SingleTaskTaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var EntityManagerInterface
|
||||||
|
*/
|
||||||
|
protected $em;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var Registry
|
||||||
|
*/
|
||||||
|
protected $registry;
|
||||||
|
|
||||||
|
const TYPE = 'chill_task.transition';
|
||||||
|
|
||||||
|
public function __construct(EntityManagerInterface $em, Registry $registry)
|
||||||
|
{
|
||||||
|
$this->em = $em;
|
||||||
|
$this->registry = $registry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fetchQuery($context, $args)
|
||||||
|
{
|
||||||
|
if ($context !== 'task') {
|
||||||
|
throw new \LogicException(sprintf('%s is not able '
|
||||||
|
. 'to render context %s', self::class, $context));
|
||||||
|
}
|
||||||
|
|
||||||
|
$metadata = $this->em
|
||||||
|
->getClassMetadata(SingleTaskPlaceEvent::class);
|
||||||
|
$singleTaskMetadata = $this->em
|
||||||
|
->getClassMetadata(SingleTask::class);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => sprintf('%s.%s.%s', $metadata->getSchemaName(), $metadata->getTableName(), $metadata->getColumnName('id')),
|
||||||
|
'type' => self::TYPE,
|
||||||
|
'date' => $metadata->getColumnName('datetime'),
|
||||||
|
'FROM' => sprintf('%s JOIN %s ON %s = %s',
|
||||||
|
sprintf('%s.%s', $metadata->getSchemaName(), $metadata->getTableName()),
|
||||||
|
sprintf('%s.%s', $singleTaskMetadata->getSchemaName(), $singleTaskMetadata->getTableName()),
|
||||||
|
$metadata->getAssociationMapping('task')['joinColumns'][0]['name'],
|
||||||
|
sprintf('%s.%s.%s', $singleTaskMetadata->getSchemaName(), $singleTaskMetadata->getTableName(), $singleTaskMetadata->getColumnName('id'))
|
||||||
|
),
|
||||||
|
'WHERE' => sprintf('%s.%s = %d',
|
||||||
|
sprintf('%s.%s', $singleTaskMetadata->getSchemaName(), $singleTaskMetadata->getTableName()),
|
||||||
|
$singleTaskMetadata->getColumnName('id'),
|
||||||
|
$args['task']->getId()
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEntities(array $ids)
|
||||||
|
{
|
||||||
|
$events = $this->em
|
||||||
|
->getRepository(SingleTaskPlaceEvent::class)
|
||||||
|
->findBy([ 'id' => $ids ])
|
||||||
|
;
|
||||||
|
|
||||||
|
return \array_combine(
|
||||||
|
\array_map(function($e) { return $e->getId(); }, $events ),
|
||||||
|
$events
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEntityTemplate($entity, $context, array $args)
|
||||||
|
{
|
||||||
|
$workflow = $this->registry->get($entity->getTask(), $entity->getData['workflow']);
|
||||||
|
$transition = $this->getTransitionByName($entity->getTransition(), $workflow);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'template' => 'ChillTaskBundle:Timeline:single_task_transition_task_context.html.twig',
|
||||||
|
'template_data' => [
|
||||||
|
'task' => $args['task'],
|
||||||
|
'event' => $entity,
|
||||||
|
'transition' => $transition
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param Workflow $workflow
|
||||||
|
* @return \Symfony\Component\Workflow\Transition
|
||||||
|
*/
|
||||||
|
protected function getTransitionByName($name, Workflow $workflow)
|
||||||
|
{
|
||||||
|
foreach ($workflow->getDefinition()->getTransitions() as $transition) {
|
||||||
|
if ($transition->getName() === $name) {
|
||||||
|
return $transition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supportsType($type): bool
|
||||||
|
{
|
||||||
|
return $type === self::TYPE;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user