{"action":"created","comment":{"url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments/81148427","pull_request_review_id":2149341,"id":81148427,"diff_hunk":"@@ -0,0 +1,255 @@\n+<?php\n+\n+namespace Pim\\Bundle\\DataGridBundle\\Controller\\Rest;\n+\n+use Akeneo\\Component\\StorageUtils\\Saver\\SaverInterface;\n+use Pim\\Bundle\\DataGridBundle\\Entity\\DatagridView;\n+use Pim\\Bundle\\DataGridBundle\\Manager\\DatagridViewManager;\n+use Pim\\Bundle\\DataGridBundle\\Repository\\DatagridViewRepositoryInterface;\n+use Pim\\Bundle\\EnrichBundle\\Exception\\DeleteException;\n+use Pim\\Bundle\\EnrichBundle\\Flash\\Message;\n+use Symfony\\Component\\HttpFoundation\\JsonResponse;\n+use Symfony\\Component\\HttpFoundation\\Request;\n+use Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface;\n+use Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface;\n+use Symfony\\Component\\Translation\\TranslatorInterface;\n+use Symfony\\Component\\Validator\\Validator\\ValidatorInterface;\n+\n+/**\n+ * REST Controller for Datagrid Views.\n+ * Handle basic CRUD actions.\n+ *\n+ * @author    Adrien Pétremann <adrien.petremann@akeneo.com>\n+ * @copyright 2016 Akeneo SAS (http://www.akeneo.com)\n+ * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)\n+ */\n+class DatagridViewController\n+{\n+    /** @var NormalizerInterface */\n+    protected $normalizer;\n+\n+    /** @var DatagridViewRepositoryInterface */\n+    protected $datagridViewRepo;\n+\n+    /** @var TokenStorageInterface */\n+    protected $tokenStorage;\n+\n+    /** @var DatagridViewManager */\n+    protected $datagridViewManager;\n+\n+    /** @var SaverInterface */\n+    protected $saver;\n+\n+    /** @var ValidatorInterface */\n+    protected $validator;\n+\n+    /** @var TranslatorInterface */\n+    protected $translator;\n+\n+    /**\n+     * @param NormalizerInterface             $normalizer\n+     * @param DatagridViewRepositoryInterface $datagridViewRepo\n+     * @param TokenStorageInterface           $tokenStorage\n+     * @param DatagridViewManager             $datagridViewManager\n+     * @param SaverInterface                  $saver\n+     * @param ValidatorInterface              $validator\n+     * @param TranslatorInterface             $translator\n+     */\n+    public function __construct(\n+        NormalizerInterface $normalizer,\n+        DatagridViewRepositoryInterface $datagridViewRepo,\n+        TokenStorageInterface $tokenStorage,\n+        DatagridViewManager $datagridViewManager,\n+        SaverInterface $saver,\n+        ValidatorInterface $validator,\n+        TranslatorInterface $translator\n+    ) {\n+        $this->normalizer = $normalizer;\n+        $this->datagridViewRepo = $datagridViewRepo;\n+        $this->tokenStorage = $tokenStorage;\n+        $this->datagridViewManager = $datagridViewManager;\n+        $this->saver = $saver;\n+        $this->validator = $validator;\n+        $this->translator = $translator;\n+    }\n+\n+    /**\n+     * Return the list of all Datagrid Views that belong to the current user for the given $alias grid.\n+     * Response data is in Json format and is paginated.\n+     *\n+     * @param Request $request\n+     * @param string  $alias\n+     *\n+     * @return JsonResponse\n+     */\n+    public function indexAction(Request $request, $alias)\n+    {\n+        $user = $this->tokenStorage->getToken()->getUser();\n+\n+        $options = $request->query->get('options', ['limit' => 20, 'page' => 1]);\n+        $term = $request->query->get('search', '');\n+\n+        $views = $this->datagridViewRepo->findDatagridViewBySearch($user, $alias, $term, $options);\n+        $normalizedViews = $this->normalizer->normalize($views, 'internal_api');\n+\n+        return new JsonResponse($normalizedViews);\n+    }\n+\n+    /**\n+     * Return the Datagrid View that belongs to the current user, with the given view $identifier.\n+     * Response data is in Json format, 404 is sent if there is no result.\n+     *\n+     * @param string $identifier\n+     *\n+     * @return JsonResponse\n+     */\n+    public function getAction($identifier)\n+    {\n+        $user = $this->tokenStorage->getToken()->getUser();\n+        $view = $this->datagridViewRepo->findOneBy([\n+            'owner' => $user,\n+            'id'    => $identifier\n+        ]);\n+\n+        if (null === $view) {\n+            return new JsonResponse('', 404);\n+        }\n+\n+        $normalizedView = $this->normalizer->normalize($view, 'internal_api');\n+\n+        return new JsonResponse($normalizedView);\n+    }\n+\n+    /**\n+     * Save the Datagrid View received through the $request for the grid with the given $alias.\n+     *\n+     * If any errors occur during the writing process, a Json response is sent with {'errors' => 'Error message'}.\n+     * If success, return a Json response with the id of the saved View.\n+     *\n+     * @param Request $request\n+     * @param string  $alias\n+     *\n+     * @return JsonResponse\n+     */\n+    public function saveAction(Request $request, $alias)\n+    {\n+        $view = $request->request->get('view', null);\n+\n+        if (null === $view) {\n+            return new JsonResponse();\n+        }\n+\n+        if (isset($view['id'])) {\n+            $creation = false;\n+            $datagridView = $this->datagridViewRepo->find($view['id']);","path":"src/Pim/Bundle/DataGridBundle/Controller/Rest/DatagridViewController.php","position":144,"original_position":144,"commit_id":"007a923e29ae422ba5d3363b802ee8ee702be025","original_commit_id":"007a923e29ae422ba5d3363b802ee8ee702be025","user":{"login":"grena","id":301169,"avatar_url":"https://avatars.githubusercontent.com/u/301169?v=3","gravatar_id":"","url":"https://api.github.com/users/grena","html_url":"https://github.com/grena","followers_url":"https://api.github.com/users/grena/followers","following_url":"https://api.github.com/users/grena/following{/other_user}","gists_url":"https://api.github.com/users/grena/gists{/gist_id}","starred_url":"https://api.github.com/users/grena/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grena/subscriptions","organizations_url":"https://api.github.com/users/grena/orgs","repos_url":"https://api.github.com/users/grena/repos","events_url":"https://api.github.com/users/grena/events{/privacy}","received_events_url":"https://api.github.com/users/grena/received_events","type":"User","site_admin":false},"body":"done","created_at":"2016-09-29T14:24:35Z","updated_at":"2016-09-29T14:24:35Z","html_url":"https://github.com/akeneo/pim-community-dev/pull/5014#discussion_r81148427","pull_request_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/5014","_links":{"self":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments/81148427"},"html":{"href":"https://github.com/akeneo/pim-community-dev/pull/5014#discussion_r81148427"},"pull_request":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/5014"}}},"pull_request":{"url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/5014","id":85360060,"html_url":"https://github.com/akeneo/pim-community-dev/pull/5014","diff_url":"https://github.com/akeneo/pim-community-dev/pull/5014.diff","patch_url":"https://github.com/akeneo/pim-community-dev/pull/5014.patch","issue_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/5014","number":5014,"state":"open","locked":false,"title":"Refactor datagrid view selector to an extensible component","user":{"login":"grena","id":301169,"avatar_url":"https://avatars.githubusercontent.com/u/301169?v=3","gravatar_id":"","url":"https://api.github.com/users/grena","html_url":"https://github.com/grena","followers_url":"https://api.github.com/users/grena/followers","following_url":"https://api.github.com/users/grena/following{/other_user}","gists_url":"https://api.github.com/users/grena/gists{/gist_id}","starred_url":"https://api.github.com/users/grena/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grena/subscriptions","organizations_url":"https://api.github.com/users/grena/orgs","repos_url":"https://api.github.com/users/grena/repos","events_url":"https://api.github.com/users/grena/events{/privacy}","received_events_url":"https://api.github.com/users/grena/received_events","type":"User","site_admin":false},"body":"**Description (for Contributor and Core Developer)**\r\n\r\nThe goal of this PR is to refactor completely the Datagrid View Selector (on the grid) to make it extensible: be able to plug extensions on it, as it is possible to do currently with the PEF.\r\n\r\nThis way, this selector **can scale** (paginated) and **is extensible** (thanks to its extension points).\r\nPreview of the refactor:\r\n\r\n![screenshot from 2016-09-21 17 47 51](https://cloud.githubusercontent.com/assets/301169/18718401/a140d756-8023-11e6-88bc-661d7f47ae28.png)\r\n\r\n**Definition Of Done (for Core Developer only)**\r\n\r\n\r\n| Q                                 | A\r\n| --------------------------------- | ---\r\n| Added Specs                       | Y\r\n| Added Behats                      |\r\n| Changelog updated                 |\r\n| Review and 2 GTM                  |\r\n| Micro Demo to the PO (Story only) |\r\n| Migration script                  | N\r\n| Tech Doc                          |","created_at":"2016-09-15T08:01:00Z","updated_at":"2016-09-29T14:24:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4fe2ffeb3661f3172c189c9f838dec3ba8dc7324","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/5014/commits","review_comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/5014/comments","review_comment_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments{/number}","comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/5014/comments","statuses_url":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/007a923e29ae422ba5d3363b802ee8ee702be025","head":{"label":"akeneo:AM-view-selector","ref":"AM-view-selector","sha":"007a923e29ae422ba5d3363b802ee8ee702be025","user":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"repo":{"id":5367323,"name":"pim-community-dev","full_name":"akeneo/pim-community-dev","owner":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/akeneo/pim-community-dev","description":"[Community Development Repository] The open source Product Information Management (PIM)","fork":false,"url":"https://api.github.com/repos/akeneo/pim-community-dev","forks_url":"https://api.github.com/repos/akeneo/pim-community-dev/forks","keys_url":"https://api.github.com/repos/akeneo/pim-community-dev/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akeneo/pim-community-dev/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akeneo/pim-community-dev/teams","hooks_url":"https://api.github.com/repos/akeneo/pim-community-dev/hooks","issue_events_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/events{/number}","events_url":"https://api.github.com/repos/akeneo/pim-community-dev/events","assignees_url":"https://api.github.com/repos/akeneo/pim-community-dev/assignees{/user}","branches_url":"https://api.github.com/repos/akeneo/pim-community-dev/branches{/branch}","tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/tags","blobs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/refs{/sha}","trees_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/{sha}","languages_url":"https://api.github.com/repos/akeneo/pim-community-dev/languages","stargazers_url":"https://api.github.com/repos/akeneo/pim-community-dev/stargazers","contributors_url":"https://api.github.com/repos/akeneo/pim-community-dev/contributors","subscribers_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscribers","subscription_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscription","commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/commits{/sha}","git_commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/commits{/sha}","comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/comments{/number}","issue_comment_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/comments{/number}","contents_url":"https://api.github.com/repos/akeneo/pim-community-dev/contents/{+path}","compare_url":"https://api.github.com/repos/akeneo/pim-community-dev/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akeneo/pim-community-dev/merges","archive_url":"https://api.github.com/repos/akeneo/pim-community-dev/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akeneo/pim-community-dev/downloads","issues_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues{/number}","pulls_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls{/number}","milestones_url":"https://api.github.com/repos/akeneo/pim-community-dev/milestones{/number}","notifications_url":"https://api.github.com/repos/akeneo/pim-community-dev/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akeneo/pim-community-dev/labels{/name}","releases_url":"https://api.github.com/repos/akeneo/pim-community-dev/releases{/id}","deployments_url":"https://api.github.com/repos/akeneo/pim-community-dev/deployments","created_at":"2012-08-10T09:27:26Z","updated_at":"2016-09-17T14:50:58Z","pushed_at":"2016-09-29T14:10:55Z","git_url":"git://github.com/akeneo/pim-community-dev.git","ssh_url":"git@github.com:akeneo/pim-community-dev.git","clone_url":"https://github.com/akeneo/pim-community-dev.git","svn_url":"https://github.com/akeneo/pim-community-dev","homepage":"http://www.akeneo.com","size":153125,"stargazers_count":339,"watchers_count":339,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":172,"mirror_url":null,"open_issues_count":121,"forks":172,"open_issues":121,"watchers":339,"default_branch":"master"}},"base":{"label":"akeneo:master","ref":"master","sha":"38112a20a37fefcbfdb311e6be41a1559359a583","user":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"repo":{"id":5367323,"name":"pim-community-dev","full_name":"akeneo/pim-community-dev","owner":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/akeneo/pim-community-dev","description":"[Community Development Repository] The open source Product Information Management (PIM)","fork":false,"url":"https://api.github.com/repos/akeneo/pim-community-dev","forks_url":"https://api.github.com/repos/akeneo/pim-community-dev/forks","keys_url":"https://api.github.com/repos/akeneo/pim-community-dev/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akeneo/pim-community-dev/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akeneo/pim-community-dev/teams","hooks_url":"https://api.github.com/repos/akeneo/pim-community-dev/hooks","issue_events_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/events{/number}","events_url":"https://api.github.com/repos/akeneo/pim-community-dev/events","assignees_url":"https://api.github.com/repos/akeneo/pim-community-dev/assignees{/user}","branches_url":"https://api.github.com/repos/akeneo/pim-community-dev/branches{/branch}","tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/tags","blobs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/refs{/sha}","trees_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/{sha}","languages_url":"https://api.github.com/repos/akeneo/pim-community-dev/languages","stargazers_url":"https://api.github.com/repos/akeneo/pim-community-dev/stargazers","contributors_url":"https://api.github.com/repos/akeneo/pim-community-dev/contributors","subscribers_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscribers","subscription_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscription","commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/commits{/sha}","git_commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/commits{/sha}","comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/comments{/number}","issue_comment_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/comments{/number}","contents_url":"https://api.github.com/repos/akeneo/pim-community-dev/contents/{+path}","compare_url":"https://api.github.com/repos/akeneo/pim-community-dev/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akeneo/pim-community-dev/merges","archive_url":"https://api.github.com/repos/akeneo/pim-community-dev/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akeneo/pim-community-dev/downloads","issues_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues{/number}","pulls_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls{/number}","milestones_url":"https://api.github.com/repos/akeneo/pim-community-dev/milestones{/number}","notifications_url":"https://api.github.com/repos/akeneo/pim-community-dev/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akeneo/pim-community-dev/labels{/name}","releases_url":"https://api.github.com/repos/akeneo/pim-community-dev/releases{/id}","deployments_url":"https://api.github.com/repos/akeneo/pim-community-dev/deployments","created_at":"2012-08-10T09:27:26Z","updated_at":"2016-09-17T14:50:58Z","pushed_at":"2016-09-29T14:10:55Z","git_url":"git://github.com/akeneo/pim-community-dev.git","ssh_url":"git@github.com:akeneo/pim-community-dev.git","clone_url":"https://github.com/akeneo/pim-community-dev.git","svn_url":"https://github.com/akeneo/pim-community-dev","homepage":"http://www.akeneo.com","size":153125,"stargazers_count":339,"watchers_count":339,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":172,"mirror_url":null,"open_issues_count":121,"forks":172,"open_issues":121,"watchers":339,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/5014"},"html":{"href":"https://github.com/akeneo/pim-community-dev/pull/5014"},"issue":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/issues/5014"},"comments":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/issues/5014/comments"},"review_comments":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/5014/comments"},"review_comment":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/5014/commits"},"statuses":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/007a923e29ae422ba5d3363b802ee8ee702be025"}}}}
{"actor":{"display_login":"grena"}}