From 2c1ae9c2713a0cd670852dbb19ec68c72255c45e Mon Sep 17 00:00:00 2001 From: benatespina Date: Fri, 11 Sep 2015 17:07:59 +0200 Subject: [PATCH 1/4] Get worfklows now returns all the workflows that exist into the application --- .../Controller/WorkflowController.php | 20 ++++------------- .../Controller/WorkflowControllerSpec.php | 22 ++----------------- 2 files changed, 6 insertions(+), 36 deletions(-) diff --git a/Bundle/WorkflowBundle/Controller/WorkflowController.php b/Bundle/WorkflowBundle/Controller/WorkflowController.php index 336d329c..6987505c 100644 --- a/Bundle/WorkflowBundle/Controller/WorkflowController.php +++ b/Bundle/WorkflowBundle/Controller/WorkflowController.php @@ -11,9 +11,7 @@ namespace Kreta\Bundle\WorkflowBundle\Controller; -use FOS\RestBundle\Controller\Annotations\QueryParam; use FOS\RestBundle\Controller\Annotations\View; -use FOS\RestBundle\Request\ParamFetcher; use Kreta\Component\Core\Annotation\ResourceIfAllowed as Workflow; use Kreta\SimpleApiDocBundle\Annotation\ApiDoc; use Symfony\Bundle\FrameworkBundle\Controller\Controller; @@ -27,27 +25,16 @@ class WorkflowController extends Controller { /** - * Returns all the workflows of current user, it admits sort, limit and offset. - * - * @param \FOS\RestBundle\Request\ParamFetcher $paramFetcher The param fetcher - * - * @QueryParam(name="sort", requirements="(name|createdAt)", default="name", description="Sort") - * @QueryParam(name="limit", requirements="\d+", default="9999", description="Amount of workflows to be returned") - * @QueryParam(name="offset", requirements="\d+", default="0", description="Offset in pages") + * Returns all the workflows. * * @ApiDoc(resource=true, statusCodes={200}) * @View(statusCode=200, serializerGroups={"workflowList"}) * * @return \Kreta\Component\Workflow\Model\Interfaces\WorkflowInterface[] */ - public function getWorkflowsAction(ParamFetcher $paramFetcher) + public function getWorkflowsAction() { - return $this->get('kreta_workflow.repository.workflow')->findBy( - ['creator' => $this->getUser()], - [$paramFetcher->get('sort') => 'ASC'], - $paramFetcher->get('limit'), - $paramFetcher->get('offset') - ); + return $this->get('kreta_workflow.repository.workflow')->findAll(); } /** @@ -91,6 +78,7 @@ public function postWorkflowAction(Request $request) * @ApiDoc(statusCodes={200, 400, 403, 404}) * @View(statusCode=200, serializerGroups={"workflow"}) * @Workflow("edit") + * * @return \Kreta\Component\Workflow\Model\Interfaces\WorkflowInterface */ public function putWorkflowAction(Request $request, $workflowId) diff --git a/Bundle/WorkflowBundle/spec/Kreta/Bundle/WorkflowBundle/Controller/WorkflowControllerSpec.php b/Bundle/WorkflowBundle/spec/Kreta/Bundle/WorkflowBundle/Controller/WorkflowControllerSpec.php index e761d7ee..0755e10f 100644 --- a/Bundle/WorkflowBundle/spec/Kreta/Bundle/WorkflowBundle/Controller/WorkflowControllerSpec.php +++ b/Bundle/WorkflowBundle/spec/Kreta/Bundle/WorkflowBundle/Controller/WorkflowControllerSpec.php @@ -11,9 +11,7 @@ namespace spec\Kreta\Bundle\WorkflowBundle\Controller; -use FOS\RestBundle\Request\ParamFetcher; use Kreta\Component\Core\Form\Handler\Handler; -use Kreta\Component\User\Model\Interfaces\UserInterface; use Kreta\Component\Workflow\Model\Interfaces\WorkflowInterface; use Kreta\Component\Workflow\Repository\WorkflowRepository; use PhpSpec\ObjectBehavior; @@ -21,7 +19,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; -use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; /** * Class WorkflowControllerSpec. @@ -48,28 +45,13 @@ function it_extends_controller() function it_gets_workflows( ContainerInterface $container, WorkflowRepository $workflowRepository, - TokenStorageInterface $context, - TokenInterface $token, - UserInterface $user, - ParamFetcher $paramFetcher, WorkflowInterface $workflow ) { $container->get('kreta_workflow.repository.workflow')->shouldBeCalled()->willReturn($workflowRepository); + $workflowRepository->findAll()->shouldBeCalled()->willReturn([$workflow]); - $container->has('security.token_storage')->shouldBeCalled()->willReturn(true); - $container->get('security.token_storage')->shouldBeCalled()->willReturn($context); - - $context->getToken()->shouldBeCalled()->willReturn($token); - $token->getUser()->shouldBeCalled()->willReturn($user); - - $paramFetcher->get('sort')->shouldBeCalled()->willReturn('createdAt'); - $paramFetcher->get('limit')->shouldBeCalled()->willReturn(10); - $paramFetcher->get('offset')->shouldBeCalled()->willReturn(1); - $workflowRepository->findBy(['creator' => $user], ['createdAt' => 'ASC'], 10, 1) - ->shouldBeCalled()->willReturn([$workflow]); - - $this->getWorkflowsAction($paramFetcher)->shouldReturn([$workflow]); + $this->getWorkflowsAction()->shouldReturn([$workflow]); } function it_gets_workflow(Request $request, WorkflowInterface $workflow) From ccee1e4630f82703d45e04f9397ed86977badbb9 Mon Sep 17 00:00:00 2001 From: benatespina Date: Fri, 11 Sep 2015 17:22:27 +0200 Subject: [PATCH 2/4] Now Workflows serializes its statuses and transitions too --- Bundle/WorkflowBundle/Behat/workflow.feature | 687 +++++++++--------- .../config/serializer/Model.Status.yml | 14 +- .../serializer/Model.StatusTransition.yml | 10 +- .../config/serializer/Model.Workflow.yml | 22 +- 4 files changed, 356 insertions(+), 377 deletions(-) diff --git a/Bundle/WorkflowBundle/Behat/workflow.feature b/Bundle/WorkflowBundle/Behat/workflow.feature index 6fc7be5f..8c82df40 100644 --- a/Bundle/WorkflowBundle/Behat/workflow.feature +++ b/Bundle/WorkflowBundle/Behat/workflow.feature @@ -34,6 +34,11 @@ Feature: Manage workflow | 0 | #27ae60 | Open | Workflow 1 | | 1 | #2c3e50 | In progress | Workflow 1 | | 2 | #f1c40f | Resolved | Workflow 1 | + And the following status transitions exist: + | id | name | status | initialStates | + | 0 | Start progress | Open | In progress | + | 1 | Reopen progress | In progress | Open,Resolved | + | 2 | Finish progress | Resolved | Open,In progress | And the following participants exist: | project | user | role | | Test project 1 | user3@kreta.com | ROLE_PARTICIPANT | @@ -45,7 +50,7 @@ Feature: Manage workflow | access-token-1 | null | user | user2@kreta.com | | access-token-2 | null | user | user3@kreta.com | - Scenario: Getting all the workflows that can see user@kreta.com + Scenario: Getting all the workflows Given I am authenticating with "access-token-0" token When I send a GET request to "/app_test.php/api/workflows" Then the response code should be 200 @@ -55,405 +60,245 @@ Feature: Manage workflow "id": "0", "created_at": "2014-11-29T00:00:00+0100", "name": "Workflow 1", + "statuses": [ + { + "type": "normal", + "name": "Open", + "id": "0", + "color": "#27ae60", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses/0" + }, + "statuses": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses" + } + } + }, + { + "type": "normal", + "name": "In progress", + "id": "1", + "color": "#2c3e50", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses/1" + }, + "statuses": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses" + } + } + }, + { + "type": "normal", + "name": "Resolved", + "id": "2", + "color": "#f1c40f", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses/2" + }, + "statuses": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses" + } + } + } + ], + "status_transitions": [ + { + "initial_states": [ + { + "type": "normal", + "name": "In progress", + "id": "1", + "color": "#2c3e50", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses/1" + }, + "statuses": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses" + } + } + } + ], + "name": "Start progress", + "id": "0", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/transitions/0" + }, + "transitions": { + "href": "http://localhost/app_test.php/api/workflows/0/transitions" + } + } + }, + { + "initial_states": [ + { + "type": "normal", + "name": "Open", + "id": "0", + "color": "#27ae60", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses/0" + }, + "statuses": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses" + } + } + }, + { + "type": "normal", + "name": "Resolved", + "id": "2", + "color": "#f1c40f", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses/2" + }, + "statuses": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses" + } + } + } + ], + "name": "Reopen progress", + "id": "1", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/transitions/1" + }, + "transitions": { + "href": "http://localhost/app_test.php/api/workflows/0/transitions" + } + } + }, + { + "initial_states": [ + { + "type": "normal", + "name": "Open", + "id": "0", + "color": "#27ae60", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses/0" + }, + "statuses": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses" + } + } + }, + { + "type": "normal", + "name": "In progress", + "id": "1", + "color": "#2c3e50", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses/1" + }, + "statuses": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses" + } + } + } + ], + "name": "Finish progress", + "id": "2", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/transitions/2" + }, + "transitions": { + "href": "http://localhost/app_test.php/api/workflows/0/transitions" + } + } + } + ], "_links": { "self": { "href": "http://localhost/app_test.php/api/workflows/0" }, "workflows": { "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/0/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/0/statuses" } } - }, { + }, + { "id": "1", "created_at": "2014-11-30T00:00:00+0100", "name": "Workflow 2", + "statuses": [], + "status_transitions": [], "_links": { "self": { "href": "http://localhost/app_test.php/api/workflows/1" }, "workflows": { "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/1/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/1/statuses" - } - } - }, { - "id": "3", - "created_at": "2014-12-30T00:00:00+0100", - "name": "Workflow 4", - "_links": { - "self": { - "href": "http://localhost/app_test.php/api/workflows/3" - }, - "workflows": { - "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/3/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/3/statuses" } } - }, { - "id": "4", - "created_at": "2014-09-17T00:00:00+0200", - "name": "Workflow 5", - "_links": { - "self": { - "href": "http://localhost/app_test.php/api/workflows/4" - }, - "workflows": { - "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/4/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/4/statuses" - } - } - }, { - "id": "5", - "created_at": "2014-10-20T00:00:00+0200", - "name": "Workflow 6", - "_links": { - "self": { - "href": "http://localhost/app_test.php/api/workflows/5" - }, - "workflows": { - "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/5/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/5/statuses" - } - } - }] - """ - - Scenario: Getting all the workflows that can see user2@kreta.com - Given I am authenticating with "access-token-1" token - When I send a GET request to "/app_test.php/api/workflows" - Then the response code should be 200 - And the response should contain json: - """ - [{ + }, + { "id": "2", "created_at": "2014-11-20T00:00:00+0100", "name": "Workflow 3", + "statuses": [], + "status_transitions": [], "_links": { "self": { "href": "http://localhost/app_test.php/api/workflows/2" }, "workflows": { "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/2/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/2/statuses" } } - }] - """ - - Scenario: Getting all the workflows that can see user@kreta.com with limit 3 - Given I am authenticating with "access-token-0" token - When I send a GET request to "/app_test.php/api/workflows?limit=3" - Then the response code should be 200 - And the response should contain json: - """ - [{ - "id": "0", - "created_at": "2014-11-29T00:00:00+0100", - "name": "Workflow 1", - "_links": { - "self": { - "href": "http://localhost/app_test.php/api/workflows/0" - }, - "workflows": { - "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/0/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/0/statuses" - } - } - }, { - "id": "1", - "created_at": "2014-11-30T00:00:00+0100", - "name": "Workflow 2", - "_links": { - "self": { - "href": "http://localhost/app_test.php/api/workflows/1" - }, - "workflows": { - "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/1/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/1/statuses" - } - } - }, { - "id": "3", - "created_at": "2014-12-30T00:00:00+0100", - "name": "Workflow 4", - "_links": { - "self": { - "href": "http://localhost/app_test.php/api/workflows/3" - }, - "workflows": { - "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/3/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/3/statuses" - } - } - }] - """ - - Scenario: Getting all the workflows that can see user@kreta.com with offset 2 - Given I am authenticating with "access-token-0" token - When I send a GET request to "/app_test.php/api/workflows?offset=2" - Then the response code should be 200 - And the response should contain json: - """ - [{ + }, + { "id": "3", "created_at": "2014-12-30T00:00:00+0100", "name": "Workflow 4", + "statuses": [], + "status_transitions": [], "_links": { "self": { "href": "http://localhost/app_test.php/api/workflows/3" }, "workflows": { "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/3/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/3/statuses" - } - } - }, { - "id": "4", - "created_at": "2014-09-17T00:00:00+0200", - "name": "Workflow 5", - "_links": { - "self": { - "href": "http://localhost/app_test.php/api/workflows/4" - }, - "workflows": { - "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/4/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/4/statuses" - } - } - }, { - "id": "5", - "created_at": "2014-10-20T00:00:00+0200", - "name": "Workflow 6", - "_links": { - "self": { - "href": "http://localhost/app_test.php/api/workflows/5" - }, - "workflows": { - "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/5/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/5/statuses" } } - }] - """ - - Scenario: Getting all the workflows that can see user@kreta.com sort by createdAt - Given I am authenticating with "access-token-0" token - When I send a GET request to "/app_test.php/api/workflows?sort=createdAt" - Then the response code should be 200 - And the response should contain json: - """ - [{ + }, + { "id": "4", "created_at": "2014-09-17T00:00:00+0200", "name": "Workflow 5", + "statuses": [], + "status_transitions": [], "_links": { "self": { "href": "http://localhost/app_test.php/api/workflows/4" }, "workflows": { "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/4/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/4/statuses" } } - }, { - "id": "5", - "created_at": "2014-10-20T00:00:00+0200", - "name": "Workflow 6", - "_links": { - "self": { - "href": "http://localhost/app_test.php/api/workflows/5" - }, - "workflows": { - "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/5/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/5/statuses" - } - } - }, { - "id": "0", - "created_at": "2014-11-29T00:00:00+0100", - "name": "Workflow 1", - "_links": { - "self": { - "href": "http://localhost/app_test.php/api/workflows/0" - }, - "workflows": { - "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/0/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/0/statuses" - } - } - }, { - "id": "1", - "created_at": "2014-11-30T00:00:00+0100", - "name": "Workflow 2", - "_links": { - "self": { - "href": "http://localhost/app_test.php/api/workflows/1" - }, - "workflows": { - "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/1/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/1/statuses" - } - } - }, { - "id": "3", - "created_at": "2014-12-30T00:00:00+0100", - "name": "Workflow 4", - "_links": { - "self": { - "href": "http://localhost/app_test.php/api/workflows/3" - }, - "workflows": { - "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/3/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/3/statuses" - } - } - }] - """ - - Scenario: Getting all the workflows that can see user@kreta.com sort by createdAt with limit 3 and offset 1 - Given I am authenticating with "access-token-0" token - When I send a GET request to "/app_test.php/api/workflows?sort=createdAt&limit=3&offset=1" - Then the response code should be 200 - And the response should contain json: - """ - [{ + }, + { "id": "5", "created_at": "2014-10-20T00:00:00+0200", "name": "Workflow 6", + "statuses": [], + "status_transitions": [], "_links": { "self": { "href": "http://localhost/app_test.php/api/workflows/5" }, "workflows": { "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/5/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/5/statuses" - } - } - }, { - "id": "0", - "created_at": "2014-11-29T00:00:00+0100", - "name": "Workflow 1", - "_links": { - "self": { - "href": "http://localhost/app_test.php/api/workflows/0" - }, - "workflows": { - "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/0/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/0/statuses" - } - } - }, { - "id": "1", - "created_at": "2014-11-30T00:00:00+0100", - "name": "Workflow 2", - "_links": { - "self": { - "href": "http://localhost/app_test.php/api/workflows/1" - }, - "workflows": { - "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/1/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/1/statuses" } } }] @@ -469,18 +314,170 @@ Feature: Manage workflow "id": "0", "created_at": "2014-11-29T00:00:00+0100", "name": "Workflow 1", + "statuses": [ + { + "type": "normal", + "name": "Open", + "id": "0", + "color": "#27ae60", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses/0" + }, + "statuses": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses" + } + } + }, + { + "type": "normal", + "name": "In progress", + "id": "1", + "color": "#2c3e50", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses/1" + }, + "statuses": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses" + } + } + }, + { + "type": "normal", + "name": "Resolved", + "id": "2", + "color": "#f1c40f", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses/2" + }, + "statuses": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses" + } + } + } + ], + "status_transitions": [ + { + "initial_states": [ + { + "type": "normal", + "name": "In progress", + "id": "1", + "color": "#2c3e50", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses/1" + }, + "statuses": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses" + } + } + } + ], + "name": "Start progress", + "id": "0", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/transitions/0" + }, + "transitions": { + "href": "http://localhost/app_test.php/api/workflows/0/transitions" + } + } + }, + { + "initial_states": [ + { + "type": "normal", + "name": "Open", + "id": "0", + "color": "#27ae60", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses/0" + }, + "statuses": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses" + } + } + }, + { + "type": "normal", + "name": "Resolved", + "id": "2", + "color": "#f1c40f", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses/2" + }, + "statuses": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses" + } + } + } + ], + "name": "Reopen progress", + "id": "1", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/transitions/1" + }, + "transitions": { + "href": "http://localhost/app_test.php/api/workflows/0/transitions" + } + } + }, + { + "initial_states": [ + { + "type": "normal", + "name": "Open", + "id": "0", + "color": "#27ae60", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses/0" + }, + "statuses": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses" + } + } + }, + { + "type": "normal", + "name": "In progress", + "id": "1", + "color": "#2c3e50", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses/1" + }, + "statuses": { + "href": "http://localhost/app_test.php/api/workflows/0/statuses" + } + } + } + ], + "name": "Finish progress", + "id": "2", + "_links": { + "self": { + "href": "http://localhost/app_test.php/api/workflows/0/transitions/2" + }, + "transitions": { + "href": "http://localhost/app_test.php/api/workflows/0/transitions" + } + } + } + ], "_links": { "self": { "href": "http://localhost/app_test.php/api/workflows/0" }, "workflows": { "href": "http://localhost/app_test.php/api/workflows" - }, - "transitions": { - "href": "http://localhost/app_test.php/api/workflows/0/transitions" - }, - "statuses": { - "href": "http://localhost/app_test.php/api/workflows/0/statuses" } } } diff --git a/Bundle/WorkflowBundle/Resources/config/serializer/Model.Status.yml b/Bundle/WorkflowBundle/Resources/config/serializer/Model.Status.yml index 8ee16183..a6b14e0f 100644 --- a/Bundle/WorkflowBundle/Resources/config/serializer/Model.Status.yml +++ b/Bundle/WorkflowBundle/Resources/config/serializer/Model.Status.yml @@ -17,7 +17,7 @@ Kreta\Component\Workflow\Model\Status: statusId: expr(object.getId()) absolute: true exclusion: - groups: [statusList, status] + groups: [workflowList, workflow, statusList, status] - rel: statuses href: @@ -26,7 +26,7 @@ Kreta\Component\Workflow\Model\Status: workflowId: expr(object.getWorkflow().getId()) absolute: true exclusion: - groups: [statusList, status] + groups: [workflowList, workflow, statusList, status] - rel: workflow href: @@ -39,19 +39,19 @@ Kreta\Component\Workflow\Model\Status: properties: id: expose: true - groups: [projectList, project, issueList, issue, statusList, status, transitionList, transition] + groups: [workflowList, workflow, projectList, project, issueList, issue, statusList, status, transitionList, transition] color: expose: true - groups: [projectList, project, issueList, issue, statusList, status, transitionList, transition] + groups: [workflowList, workflow, projectList, project, issueList, issue, statusList, status, transitionList, transition] name: expose: true - groups: [projectList, project, issueList, issue, statusList, status, transitionList, transition] + groups: [workflowList, workflow, projectList, project, issueList, issue, statusList, status, transitionList, transition] type: expose: true - groups: [projectList, project, issueList, issue, statusList, status, transitionList, transition] + groups: [workflowList, workflow, projectList, project, issueList, issue, statusList, status, transitionList, transition] transitions: expose: true - groups: [projectList, project, statusList, status] + groups: [workflowList, workflow, projectList, project, statusList, status] workflow: expose: true groups: [] diff --git a/Bundle/WorkflowBundle/Resources/config/serializer/Model.StatusTransition.yml b/Bundle/WorkflowBundle/Resources/config/serializer/Model.StatusTransition.yml index 345cdb92..2f7094d4 100644 --- a/Bundle/WorkflowBundle/Resources/config/serializer/Model.StatusTransition.yml +++ b/Bundle/WorkflowBundle/Resources/config/serializer/Model.StatusTransition.yml @@ -17,7 +17,7 @@ Kreta\Component\Workflow\Model\StatusTransition: transitionId: expr(object.getId()) absolute: true exclusion: - groups: [transitionList, transition] + groups: [workflowList, workflow, transitionList, transition] - rel: transitions href: @@ -26,7 +26,7 @@ Kreta\Component\Workflow\Model\StatusTransition: workflowId: expr(object.getWorkflow().getId()) absolute: true exclusion: - groups: [transitionList, transition] + groups: [workflowList, workflow, transitionList, transition] - rel: workflow href: @@ -39,13 +39,13 @@ Kreta\Component\Workflow\Model\StatusTransition: properties: id: expose: true - groups: [transitionList, transition] + groups: [workflowList, workflow, transitionList, transition] initialStates: expose: true - groups: [transitionList, transition] + groups: [workflowList, workflow, transitionList, transition] name: expose: true - groups: [transitionList, transition] + groups: [workflowList, workflow, transitionList, transition] state: expose: true groups: [] diff --git a/Bundle/WorkflowBundle/Resources/config/serializer/Model.Workflow.yml b/Bundle/WorkflowBundle/Resources/config/serializer/Model.Workflow.yml index 40833f03..a7ee48a0 100644 --- a/Bundle/WorkflowBundle/Resources/config/serializer/Model.Workflow.yml +++ b/Bundle/WorkflowBundle/Resources/config/serializer/Model.Workflow.yml @@ -24,24 +24,6 @@ Kreta\Component\Workflow\Model\Workflow: absolute: true exclusion: groups: [workflowList, workflow] - - - rel: transitions - href: - route: get_workflow_transitions - parameters: - workflowId: expr(object.getId()) - absolute: true - exclusion: - groups: [workflowList, workflow] - - - rel: statuses - href: - route: get_workflow_statuses - parameters: - workflowId: expr(object.getId()) - absolute: true - exclusion: - groups: [workflowList, workflow] properties: createdAt: expose: true @@ -51,7 +33,7 @@ Kreta\Component\Workflow\Model\Workflow: groups: [workflowList, workflow, projectList, project] statuses: expose: true - groups: [] + groups: [workflowList, workflow] statusTransitions: expose: true - groups: [] + groups: [workflowList, workflow] From 0f923a4f9b2947e7b30e89ee609080dcb33e176d Mon Sep 17 00:00:00 2001 From: Gorka Laucirica Date: Fri, 11 Sep 2015 17:36:32 +0200 Subject: [PATCH 3/4] Show allowed transitions in issue show view --- Bundle/WebBundle/Resources/public/js/app.js | 5 ++++- .../public/js/collections/workflow.js | 19 ++++++++++++++++++ .../Resources/public/js/models/issue.js | 20 +++++++++++++++++++ .../Resources/public/js/models/workflow.js | 16 +++++++++++++++ .../public/js/views/page/issue/show.js | 1 + .../Default/templates/issue/show.html.twig | 7 +++++++ 6 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 Bundle/WebBundle/Resources/public/js/collections/workflow.js create mode 100644 Bundle/WebBundle/Resources/public/js/models/workflow.js diff --git a/Bundle/WebBundle/Resources/public/js/app.js b/Bundle/WebBundle/Resources/public/js/app.js index 8c141576..a6de8625 100644 --- a/Bundle/WebBundle/Resources/public/js/app.js +++ b/Bundle/WebBundle/Resources/public/js/app.js @@ -17,6 +17,7 @@ import {IssueController} from 'controllers/issue'; import {ProjectCollection} from 'collections/project'; import {UserCollection} from 'collections/user'; +import {WorkflowCollection} from 'collections/workflow'; import {Profile} from 'models/profile'; @@ -41,11 +42,13 @@ export class App extends Backbone.Marionette.Application { this.collection = { project: new ProjectCollection(), - user: new UserCollection() + user: new UserCollection(), + workflow: new WorkflowCollection() }; this.collection.project.fetch(); this.collection.user.fetch(); + this.collection.workflow.fetch(); } loadLayout() { diff --git a/Bundle/WebBundle/Resources/public/js/collections/workflow.js b/Bundle/WebBundle/Resources/public/js/collections/workflow.js new file mode 100644 index 00000000..516219d5 --- /dev/null +++ b/Bundle/WebBundle/Resources/public/js/collections/workflow.js @@ -0,0 +1,19 @@ +/* + * This file belongs to Kreta. + * The source code of application includes a LICENSE file + * with all information about license. + * + * @author benatespina + * @author gorkalaucirica + */ + +import {Config} from '../config'; +import {Workflow} from '../models/workflow'; + +export class WorkflowCollection extends Backbone.Collection { + constructor (models, options) { + this.url = Config.baseUrl + '/workflows'; + this.model = Workflow; + super(models, options); + } +} diff --git a/Bundle/WebBundle/Resources/public/js/models/issue.js b/Bundle/WebBundle/Resources/public/js/models/issue.js index 42c9dea2..91ede60f 100644 --- a/Bundle/WebBundle/Resources/public/js/models/issue.js +++ b/Bundle/WebBundle/Resources/public/js/models/issue.js @@ -53,4 +53,24 @@ export class Issue extends Backbone.Model { return data; } + + getAllowedTransitions() { + var projectHref = this.attributes._links.project.href; + var projectId = projectHref.substring(projectHref.lastIndexOf('/') + 1); + var project = App.collection.project.get(projectId); + + var workflowHref = project.attributes._links.workflow.href; + var workflowId = workflowHref.substring(workflowHref.lastIndexOf('/') + 1); + + var allowedTransitions = []; + App.collection.workflow.get(workflowId).attributes.status_transitions.forEach((transition) => { + transition.initial_states.forEach((state) => { + if(state.id === this.get('status').id) { + allowedTransitions.push(transition); + } + }); + }); + + return allowedTransitions; + } } diff --git a/Bundle/WebBundle/Resources/public/js/models/workflow.js b/Bundle/WebBundle/Resources/public/js/models/workflow.js new file mode 100644 index 00000000..fd06ebdd --- /dev/null +++ b/Bundle/WebBundle/Resources/public/js/models/workflow.js @@ -0,0 +1,16 @@ +/* + * This file belongs to Kreta. + * The source code of application includes a LICENSE file + * with all information about license. + * + * @author benatespina + * @author gorkalaucirica + */ + +import {Config} from '../config'; + +export class Workflow extends Backbone.Model { + urlRoot() { + return Config.baseUrl + '/workflows'; + } +} diff --git a/Bundle/WebBundle/Resources/public/js/views/page/issue/show.js b/Bundle/WebBundle/Resources/public/js/views/page/issue/show.js index f3113431..069bc793 100644 --- a/Bundle/WebBundle/Resources/public/js/views/page/issue/show.js +++ b/Bundle/WebBundle/Resources/public/js/views/page/issue/show.js @@ -30,6 +30,7 @@ export class IssueShowView extends Backbone.Marionette.ItemView { serializeData() { var data = this.model.toJSON(); + data['transitions'] = this.model.getAllowedTransitions(); data['canEdit'] = this.model.canEdit(App.currentUser); return data; } diff --git a/Bundle/WebBundle/Resources/views/Default/templates/issue/show.html.twig b/Bundle/WebBundle/Resources/views/Default/templates/issue/show.html.twig index 7b92e3ce..4ce39904 100644 --- a/Bundle/WebBundle/Resources/views/Default/templates/issue/show.html.twig +++ b/Bundle/WebBundle/Resources/views/Default/templates/issue/show.html.twig @@ -5,6 +5,13 @@ Edit <% } %> +
+ <% transitions.forEach(function(transition) { %> + + <%= transition.name %> + + <% }) %> +

From ab02dd63e14e91a742e767a5fb857f1fac045a9e Mon Sep 17 00:00:00 2001 From: Gorka Laucirica Date: Fri, 11 Sep 2015 18:21:12 +0200 Subject: [PATCH 4/4] Change event status and update event info --- .../Resources/public/js/models/issue.js | 21 +++++++++++++++++++ .../public/js/views/component/issuePreview.js | 7 +++++++ .../public/js/views/page/issue/show.js | 20 +++++++++++++++--- .../Default/templates/issue/show.html.twig | 4 ++-- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/Bundle/WebBundle/Resources/public/js/models/issue.js b/Bundle/WebBundle/Resources/public/js/models/issue.js index 91ede60f..eaaaa354 100644 --- a/Bundle/WebBundle/Resources/public/js/models/issue.js +++ b/Bundle/WebBundle/Resources/public/js/models/issue.js @@ -14,6 +14,10 @@ export class Issue extends Backbone.Model { return Config.baseUrl + '/issues'; } + urlTransition() { + return Config.baseUrl + '/issues/' + this.id + '/transitions'; + } + defaults() { return { title: '', @@ -54,6 +58,23 @@ export class Issue extends Backbone.Model { return data; } + doTransition(transitionId, options = {}) { + var defaultOptions = { + success: null, + error: null + }; + + options = $.extend(defaultOptions, options); + Backbone.$.ajax(this.urlTransition(), { + method: 'PATCH', + data: { + 'transition': transitionId + }, + success: options.success, + error: options.error + }); + } + getAllowedTransitions() { var projectHref = this.attributes._links.project.href; var projectId = projectHref.substring(projectHref.lastIndexOf('/') + 1); diff --git a/Bundle/WebBundle/Resources/public/js/views/component/issuePreview.js b/Bundle/WebBundle/Resources/public/js/views/component/issuePreview.js index b7085bef..d9538a65 100644 --- a/Bundle/WebBundle/Resources/public/js/views/component/issuePreview.js +++ b/Bundle/WebBundle/Resources/public/js/views/component/issuePreview.js @@ -22,6 +22,13 @@ export class IssuePreviewView extends Backbone.Marionette.ItemView { this.listenTo(App.vent, 'issue:highlight', (issueId) => { this.highlightIssue(issueId); }); + + this.listenTo(App.vent, 'issue:updated', (issue) => { + if(this.model.id === issue.id) { + this.model.set(issue); + this.render(); + } + }); } showFullIssue() { diff --git a/Bundle/WebBundle/Resources/public/js/views/page/issue/show.js b/Bundle/WebBundle/Resources/public/js/views/page/issue/show.js index 069bc793..7dc92548 100644 --- a/Bundle/WebBundle/Resources/public/js/views/page/issue/show.js +++ b/Bundle/WebBundle/Resources/public/js/views/page/issue/show.js @@ -13,17 +13,19 @@ export class IssueShowView extends Backbone.Marionette.ItemView { this.template = '#issue-show-template'; this.ui = { - 'tabContent': '.full-issue-tab-content' + 'tabContent': '.full-issue-tab-content', + 'transitions': '.full-issue-transitions' }; this.events = { 'click .full-issue-edit': 'editClicked', - 'click .full-issue-tab': 'tabClicked' + 'click .full-issue-tab': 'tabClicked', + 'click .full-issue-transition': 'doTransition' }; super(options); - this.model.on('sync', this.render, this); + this.model.on('change', this.render, this); App.vent.trigger('issue:highlight', this.model.id); } @@ -49,4 +51,16 @@ export class IssueShowView extends Backbone.Marionette.ItemView { return false; } + + doTransition(ev) { + this.ui.transitions.hide(); + this.model.doTransition($($(ev)[0].currentTarget).attr('data-transition'), { + success : (data) => { + this.model.set(data); + App.vent.trigger('issue:updated', data) + } + }); + + return false + } } diff --git a/Bundle/WebBundle/Resources/views/Default/templates/issue/show.html.twig b/Bundle/WebBundle/Resources/views/Default/templates/issue/show.html.twig index 4ce39904..6148d03b 100644 --- a/Bundle/WebBundle/Resources/views/Default/templates/issue/show.html.twig +++ b/Bundle/WebBundle/Resources/views/Default/templates/issue/show.html.twig @@ -7,9 +7,9 @@

<% transitions.forEach(function(transition) { %> - + <% }) %>