{"action":"created","comment":{"url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/pulls/comments/62813831","id":62813831,"diff_hunk":"@@ -0,0 +1,217 @@\n+/*\n+ * Copyright (C) eZ Systems AS. All rights reserved.\n+ * For full copyright and license information view LICENSE file distributed with this source code.\n+ */\n+YUI.add('ez-dashboardblockbasedview', function (Y) {\n+    'use strict';\n+    /**\n+     * Provides the Dashboard Block Based View class\n+     *\n+     * @module ez-dashboardblockbasedview\n+     */\n+    Y.namespace('eZ');\n+\n+    var SELECTOR_CONTENT = '.dashboard-content';\n+\n+    /**\n+     * The dashboard view\n+     *\n+     * @namespace eZ\n+     * @class DashboardBlockBasedView\n+     * @constructor\n+     * @extends eZ.TemplateBasedView\n+     */\n+    Y.eZ.DashboardBlockBasedView = Y.Base.create('dashboardBlockBasedView', Y.eZ.TemplateBasedView, [], {\n+        initializer: function () {\n+            this.after('activeChange', function () {\n+                this.after('blocksChange', this._renderBlocks, this);\n+\n+                this._makeBlocksActive();\n+            }, this);\n+        },\n+\n+        /**\n+         * Renders the dashboard view\n+         *\n+         * @method render\n+         * @return {eZ.DashboardBlockBasedView} the view itself\n+         */\n+        render: function () {\n+            this.get('container').setHTML(this.template({dashboardTitle: this.get('dashboardTitle')}));\n+            this._renderBlocks();\n+\n+            return this;\n+        },\n+\n+        /**\n+         * Activates all the blocks to allow communication between blocks and service\n+         *\n+         * @method _makeBlocksActive\n+         * @protected\n+         */\n+        _makeBlocksActive: function () {\n+            var blocks = this.get('blocks');\n+\n+            Object.keys(blocks).forEach(function (key) {\n+                blocks[key].set('active', true);\n+            });\n+        },\n+\n+        /**\n+         * Renders blocks on the dashboard\n+         *\n+         * @method _renderBlocks\n+         * @protected\n+         */\n+        _renderBlocks: function () {\n+            var fragment = Y.one(document.createDocumentFragment());\n+\n+            this._sortBlocks(this.get('blocks')).forEach(Y.bind(function (block) {\n+                var targets = block.getTargets();\n+\n+                if (targets.indexOf(this) === -1) {\n+                    block.addTarget(this);\n+                }\n+\n+                fragment.append(block.render().get('container'));\n+            }, this));\n+\n+            this.get('container').one(SELECTOR_CONTENT).setHTML(fragment);\n+        },\n+\n+        /**\n+         * Sorts the provided hash of blocks either by priority\n+         * or alphabetically when both blocks have the same priority.\n+         *\n+         * @method _sortBlocks\n+         * @protected\n+         * @param blocks {Object} hash of blocks\n+         * @return {Array} sorted list of blocks\n+         */\n+        _sortBlocks: function (blocks) {\n+            var list = [];\n+\n+            Object.keys(blocks).forEach(function (key) {\n+                list.push(blocks[key]);\n+            });\n+\n+            list.sort(function (a, b) {\n+                var priorityA = a.get('priority'),\n+                    priorityB = b.get('priority');\n+\n+                if (priorityA === priorityB) {\n+                    // sort alphabetically (from A to B)\n+                    return a.get('identifier') < b.get('identifier');\n+                } else {\n+                    // sort by priority (max to 0)\n+                    return priorityA > priorityB;\n+                }\n+            });\n+\n+            return list;\n+        },\n+\n+        /**\n+         * Verifies provided `blocks` attribute value\n+         * by checking whether provided values are dashboard block view instances\n+         *\n+         * @method _checkBlocks\n+         * @protected\n+         * @param value {Any} new vaue of `blocks` attribute\n+         * @return {Object}\n+         */\n+        _checkBlocks: function (value) {\n+            var blocks = {};\n+\n+            if (typeof value !== 'object' || Array.isArray(value)) {\n+                return blocks;\n+            }\n+\n+            Object.keys(value).forEach(function (key) {\n+                if (value[key] instanceof Y.eZ.BaseDashboardBlockView) {\n+                    blocks[key] = value[key];\n+                }\n+            });\n+\n+            return blocks;\n+        },\n+\n+        /**\n+         * Adds a block to the dashboard\n+         *\n+         * @method addBlock\n+         * @param view {Y.eZ.BaseDashboardBlockView} dashboard block view instance\n+         * @return {Object} the hash of blocks\n+         */\n+        addBlock: function (view) {\n+            var blocks = this.get('blocks'),\n+                identifier = view.get('identifier');\n+\n+            if (!identifier) {\n+                return blocks;\n+            }\n+\n+            if (blocks[identifier]) {","path":"Resources/public/js/views/ez-dashboardblockbasedview.js","position":154,"original_position":154,"commit_id":"6ad18f28e9d95c1f68bd7322556c3aac4ccdb9b2","original_commit_id":"6ad18f28e9d95c1f68bd7322556c3aac4ccdb9b2","user":{"login":"dpobel","id":305563,"avatar_url":"https://avatars.githubusercontent.com/u/305563?v=3","gravatar_id":"","url":"https://api.github.com/users/dpobel","html_url":"https://github.com/dpobel","followers_url":"https://api.github.com/users/dpobel/followers","following_url":"https://api.github.com/users/dpobel/following{/other_user}","gists_url":"https://api.github.com/users/dpobel/gists{/gist_id}","starred_url":"https://api.github.com/users/dpobel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpobel/subscriptions","organizations_url":"https://api.github.com/users/dpobel/orgs","repos_url":"https://api.github.com/users/dpobel/repos","events_url":"https://api.github.com/users/dpobel/events{/privacy}","received_events_url":"https://api.github.com/users/dpobel/received_events","type":"User","site_admin":false},"body":"good point, without unique identifier, `removeBlock` will have problems :) that said, I would still not check that in `addView` but if you want to keep it just make sure it's properly unit tested.","created_at":"2016-05-11T09:03:56Z","updated_at":"2016-05-11T09:03:56Z","html_url":"https://github.com/ezsystems/PlatformUIBundle/pull/584#discussion_r62813831","pull_request_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/pulls/584","_links":{"self":{"href":"https://api.github.com/repos/ezsystems/PlatformUIBundle/pulls/comments/62813831"},"html":{"href":"https://github.com/ezsystems/PlatformUIBundle/pull/584#discussion_r62813831"},"pull_request":{"href":"https://api.github.com/repos/ezsystems/PlatformUIBundle/pulls/584"}}},"pull_request":{"url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/pulls/584","id":69505739,"html_url":"https://github.com/ezsystems/PlatformUIBundle/pull/584","diff_url":"https://github.com/ezsystems/PlatformUIBundle/pull/584.diff","patch_url":"https://github.com/ezsystems/PlatformUIBundle/pull/584.patch","issue_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/issues/584","number":584,"state":"open","locked":false,"title":"[WIP] EZP-25762: Replace old iframe-based dashboard view with new block-based dashboard view","user":{"login":"sunpietro","id":1736658,"avatar_url":"https://avatars.githubusercontent.com/u/1736658?v=3","gravatar_id":"","url":"https://api.github.com/users/sunpietro","html_url":"https://github.com/sunpietro","followers_url":"https://api.github.com/users/sunpietro/followers","following_url":"https://api.github.com/users/sunpietro/following{/other_user}","gists_url":"https://api.github.com/users/sunpietro/gists{/gist_id}","starred_url":"https://api.github.com/users/sunpietro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sunpietro/subscriptions","organizations_url":"https://api.github.com/users/sunpietro/orgs","repos_url":"https://api.github.com/users/sunpietro/repos","events_url":"https://api.github.com/users/sunpietro/events{/privacy}","received_events_url":"https://api.github.com/users/sunpietro/received_events","type":"User","site_admin":false},"body":"https://jira.ez.no/browse/EZP-25762\r\n\r\n## The new extensible Dashboard\r\nIt allows to add new blocks to dashboard by creating plugins applied to the `eZ.DashboardView` instance.\r\nEach block will require its own view followed by a `eZ.DashboardViewService` plugin that handles actions of getting data to blocks. The service plugin is optional.\r\n\r\nTo add a new block you have to define:\r\n- [x] block view,\r\n- [x] `eZ.DashboardBlockBasedView` plugin that adds a block to a dashboard view instance,\r\n- [x] `eZ.DashboardBlockBasedViewService` plugin required for fetching data used by a block (**optional**).\r\n\r\nIn a `eZ.DashboardBlockBasedView` plugin a new block can be added by using `addBlock` method: `this.get('host').addBlock(blockViewInstance);`\r\n\r\nThe `this.get('host')` refers to `eZ.DashboardBlockBasedView` view instance.\r\n\r\nAny block can be removed from the dashboard by calling: `this.get('host').removeBlock(blockIdentifier);`\r\n\r\nThe `blockIdentifier` comes from `blockViewInstance.get('identifier');`\r\n\r\n**Important:** This will require Behat tests rebuilding as it changes how the dashboard behaves.\r\n\r\n**TO DO:**\r\n- [x] create extensibility points for adding/removing/showing/hiding blocks in the dashboard,\r\n- [x] create the dashboard view service,\r\n- [ ] JS unit tests","created_at":"2016-05-10T13:27:53Z","updated_at":"2016-05-11T09:03:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9708b86f900c6db93d5ac113418de07e15dea1bf","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/pulls/584/commits","review_comments_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/pulls/584/comments","review_comment_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/issues/584/comments","statuses_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/statuses/6ad18f28e9d95c1f68bd7322556c3aac4ccdb9b2","head":{"label":"sunpietro:ezp-25762-new-block-based-dashboard","ref":"ezp-25762-new-block-based-dashboard","sha":"6ad18f28e9d95c1f68bd7322556c3aac4ccdb9b2","user":{"login":"sunpietro","id":1736658,"avatar_url":"https://avatars.githubusercontent.com/u/1736658?v=3","gravatar_id":"","url":"https://api.github.com/users/sunpietro","html_url":"https://github.com/sunpietro","followers_url":"https://api.github.com/users/sunpietro/followers","following_url":"https://api.github.com/users/sunpietro/following{/other_user}","gists_url":"https://api.github.com/users/sunpietro/gists{/gist_id}","starred_url":"https://api.github.com/users/sunpietro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sunpietro/subscriptions","organizations_url":"https://api.github.com/users/sunpietro/orgs","repos_url":"https://api.github.com/users/sunpietro/repos","events_url":"https://api.github.com/users/sunpietro/events{/privacy}","received_events_url":"https://api.github.com/users/sunpietro/received_events","type":"User","site_admin":false},"repo":{"id":53435477,"name":"PlatformUIBundle","full_name":"sunpietro/PlatformUIBundle","owner":{"login":"sunpietro","id":1736658,"avatar_url":"https://avatars.githubusercontent.com/u/1736658?v=3","gravatar_id":"","url":"https://api.github.com/users/sunpietro","html_url":"https://github.com/sunpietro","followers_url":"https://api.github.com/users/sunpietro/followers","following_url":"https://api.github.com/users/sunpietro/following{/other_user}","gists_url":"https://api.github.com/users/sunpietro/gists{/gist_id}","starred_url":"https://api.github.com/users/sunpietro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sunpietro/subscriptions","organizations_url":"https://api.github.com/users/sunpietro/orgs","repos_url":"https://api.github.com/users/sunpietro/repos","events_url":"https://api.github.com/users/sunpietro/events{/privacy}","received_events_url":"https://api.github.com/users/sunpietro/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sunpietro/PlatformUIBundle","description":"Main Bundle to provide editorial/admin UI for eZ Platform","fork":true,"url":"https://api.github.com/repos/sunpietro/PlatformUIBundle","forks_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/forks","keys_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/teams","hooks_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/hooks","issue_events_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/issues/events{/number}","events_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/events","assignees_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/assignees{/user}","branches_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/branches{/branch}","tags_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/tags","blobs_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/languages","stargazers_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/stargazers","contributors_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/contributors","subscribers_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/subscribers","subscription_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/subscription","commits_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/contents/{+path}","compare_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/merges","archive_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/downloads","issues_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/issues{/number}","pulls_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/labels{/name}","releases_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/releases{/id}","deployments_url":"https://api.github.com/repos/sunpietro/PlatformUIBundle/deployments","created_at":"2016-03-08T18:31:31Z","updated_at":"2016-03-08T18:31:34Z","pushed_at":"2016-05-10T13:31:09Z","git_url":"git://github.com/sunpietro/PlatformUIBundle.git","ssh_url":"git@github.com:sunpietro/PlatformUIBundle.git","clone_url":"https://github.com/sunpietro/PlatformUIBundle.git","svn_url":"https://github.com/sunpietro/PlatformUIBundle","homepage":"http://ezplatform.com/","size":5481,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ezsystems:master","ref":"master","sha":"de2ee2911f7434aa9608b43af2ca7aac5bcda186","user":{"login":"ezsystems","id":295311,"avatar_url":"https://avatars.githubusercontent.com/u/295311?v=3","gravatar_id":"","url":"https://api.github.com/users/ezsystems","html_url":"https://github.com/ezsystems","followers_url":"https://api.github.com/users/ezsystems/followers","following_url":"https://api.github.com/users/ezsystems/following{/other_user}","gists_url":"https://api.github.com/users/ezsystems/gists{/gist_id}","starred_url":"https://api.github.com/users/ezsystems/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezsystems/subscriptions","organizations_url":"https://api.github.com/users/ezsystems/orgs","repos_url":"https://api.github.com/users/ezsystems/repos","events_url":"https://api.github.com/users/ezsystems/events{/privacy}","received_events_url":"https://api.github.com/users/ezsystems/received_events","type":"Organization","site_admin":false},"repo":{"id":11221607,"name":"PlatformUIBundle","full_name":"ezsystems/PlatformUIBundle","owner":{"login":"ezsystems","id":295311,"avatar_url":"https://avatars.githubusercontent.com/u/295311?v=3","gravatar_id":"","url":"https://api.github.com/users/ezsystems","html_url":"https://github.com/ezsystems","followers_url":"https://api.github.com/users/ezsystems/followers","following_url":"https://api.github.com/users/ezsystems/following{/other_user}","gists_url":"https://api.github.com/users/ezsystems/gists{/gist_id}","starred_url":"https://api.github.com/users/ezsystems/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ezsystems/subscriptions","organizations_url":"https://api.github.com/users/ezsystems/orgs","repos_url":"https://api.github.com/users/ezsystems/repos","events_url":"https://api.github.com/users/ezsystems/events{/privacy}","received_events_url":"https://api.github.com/users/ezsystems/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ezsystems/PlatformUIBundle","description":"Main Bundle to provide editorial/admin UI for eZ Platform","fork":false,"url":"https://api.github.com/repos/ezsystems/PlatformUIBundle","forks_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/forks","keys_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/teams","hooks_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/hooks","issue_events_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/issues/events{/number}","events_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/events","assignees_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/assignees{/user}","branches_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/branches{/branch}","tags_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/tags","blobs_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/languages","stargazers_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/stargazers","contributors_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/contributors","subscribers_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/subscribers","subscription_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/subscription","commits_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/contents/{+path}","compare_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/merges","archive_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/downloads","issues_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/issues{/number}","pulls_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/labels{/name}","releases_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/releases{/id}","deployments_url":"https://api.github.com/repos/ezsystems/PlatformUIBundle/deployments","created_at":"2013-07-06T17:21:40Z","updated_at":"2016-05-09T21:15:01Z","pushed_at":"2016-05-10T13:31:11Z","git_url":"git://github.com/ezsystems/PlatformUIBundle.git","ssh_url":"git@github.com:ezsystems/PlatformUIBundle.git","clone_url":"https://github.com/ezsystems/PlatformUIBundle.git","svn_url":"https://github.com/ezsystems/PlatformUIBundle","homepage":"http://ezplatform.com/","size":6521,"stargazers_count":27,"watchers_count":27,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":30,"mirror_url":null,"open_issues_count":21,"forks":30,"open_issues":21,"watchers":27,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ezsystems/PlatformUIBundle/pulls/584"},"html":{"href":"https://github.com/ezsystems/PlatformUIBundle/pull/584"},"issue":{"href":"https://api.github.com/repos/ezsystems/PlatformUIBundle/issues/584"},"comments":{"href":"https://api.github.com/repos/ezsystems/PlatformUIBundle/issues/584/comments"},"review_comments":{"href":"https://api.github.com/repos/ezsystems/PlatformUIBundle/pulls/584/comments"},"review_comment":{"href":"https://api.github.com/repos/ezsystems/PlatformUIBundle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ezsystems/PlatformUIBundle/pulls/584/commits"},"statuses":{"href":"https://api.github.com/repos/ezsystems/PlatformUIBundle/statuses/6ad18f28e9d95c1f68bd7322556c3aac4ccdb9b2"}}}}