{"action":"created","comment":{"url":"https://api.github.com/repos/guardian/grid/pulls/comments/47086019","id":47086019,"diff_hunk":"@@ -0,0 +1,60 @@\n+import angular from 'angular';\n+import Immutable from 'immutable';\n+\n+import Rx from 'rx';\n+\n+export const imageUsagesService = angular.module('gr.image-usages.service', ['kahuna.edits.service']);\n+\n+\n+imageUsagesService.factory('imageUsagesService', [function() {\n+\n+    function forImage(imageResource) {\n+        function usageTitle(usage) {\n+            const referenceType =\n+                usage.get('platform') == 'print' ? 'indesign' : 'frontend';\n+\n+            const build = (usage, referenceType) => {\n+                const reference = usage.get('references').find(u =>\n+                    u.get('type') == referenceType);\n+\n+                return (reference && reference.get('name')) ? reference.get('name') : 'No title found.';\n+            };\n+\n+            return build(usage, referenceType);\n+        }\n+\n+        const image$ = Rx.Observable.fromPromise(imageResource.getData());\n+        const usages$ = image$\n+            .flatMap((image) =>\n+                Rx.Observable.fromPromise(image.usages.getData()))\n+            .flatMap((usages) => usages.map(usage => usage.getData()))\n+            .flatMap(Rx.Observable.fromPromise)\n+            .toArray()\n+            .map((usages) => {\n+\n+                const usagesList =\n+                    Immutable.fromJS(usages).map(usage =>\n+                        usage.set('title', usageTitle(usage)));\n+\n+                const groupedByState = usagesList.groupBy(usage =>\n+                    usage.get('status'));\n+\n+                const filterByPlatform = (platform) =>\n+                    usagesList.filter(usage =>\n+                        usage.get('platform') == platform);\n+\n+                return {\n+                    usages: usagesList.toJS(),\n+                    groupedByState: groupedByState.toJS(),\n+                    hasPrintUsages: !filterByPlatform('print').isEmpty(),\n+                    hasDigitalUsages: !filterByPlatform('digital').isEmpty()\n+                };\n+\n+            });\n+\n+        return usages$\n+\n+    }\n+\n+    return image => forImage(image);","path":"kahuna/public/js/services/image/usages.js","position":56,"original_position":59,"commit_id":"21d4942b0a238814e4ba8f605f27695b5f731cf5","original_commit_id":"3672d7162fc0653ab86d48b248a9dab11048ae00","user":{"login":"kenoir","id":953792,"avatar_url":"https://avatars.githubusercontent.com/u/953792?v=3","gravatar_id":"","url":"https://api.github.com/users/kenoir","html_url":"https://github.com/kenoir","followers_url":"https://api.github.com/users/kenoir/followers","following_url":"https://api.github.com/users/kenoir/following{/other_user}","gists_url":"https://api.github.com/users/kenoir/gists{/gist_id}","starred_url":"https://api.github.com/users/kenoir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kenoir/subscriptions","organizations_url":"https://api.github.com/users/kenoir/orgs","repos_url":"https://api.github.com/users/kenoir/repos","events_url":"https://api.github.com/users/kenoir/events{/privacy}","received_events_url":"https://api.github.com/users/kenoir/received_events","type":"User","site_admin":false},"body":"@theefer like this? https://gist.github.com/kenoir/63beadb9f00310f261a2","created_at":"2015-12-09T12:53:12Z","updated_at":"2015-12-09T12:53:12Z","html_url":"https://github.com/guardian/grid/pull/1447#discussion_r47086019","pull_request_url":"https://api.github.com/repos/guardian/grid/pulls/1447","_links":{"self":{"href":"https://api.github.com/repos/guardian/grid/pulls/comments/47086019"},"html":{"href":"https://github.com/guardian/grid/pull/1447#discussion_r47086019"},"pull_request":{"href":"https://api.github.com/repos/guardian/grid/pulls/1447"}}},"pull_request":{"url":"https://api.github.com/repos/guardian/grid/pulls/1447","id":50244559,"html_url":"https://github.com/guardian/grid/pull/1447","diff_url":"https://github.com/guardian/grid/pull/1447.diff","patch_url":"https://github.com/guardian/grid/pull/1447.patch","issue_url":"https://api.github.com/repos/guardian/grid/issues/1447","number":1447,"state":"open","locked":false,"title":"Store and present media usage from Elastic","user":{"login":"kenoir","id":953792,"avatar_url":"https://avatars.githubusercontent.com/u/953792?v=3","gravatar_id":"","url":"https://api.github.com/users/kenoir","html_url":"https://github.com/kenoir","followers_url":"https://api.github.com/users/kenoir/followers","following_url":"https://api.github.com/users/kenoir/following{/other_user}","gists_url":"https://api.github.com/users/kenoir/gists{/gist_id}","starred_url":"https://api.github.com/users/kenoir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kenoir/subscriptions","organizations_url":"https://api.github.com/users/kenoir/orgs","repos_url":"https://api.github.com/users/kenoir/repos","events_url":"https://api.github.com/users/kenoir/events{/privacy}","received_events_url":"https://api.github.com/users/kenoir/received_events","type":"User","site_admin":false},"body":"This PR allows the grid to store usages in ES and present them via the Media API. This in turn allows us to sensibly present (and search) usage data across large numbers of images.\r\n\r\n**Image page:**\r\n![usage-image](https://cloud.githubusercontent.com/assets/953792/11657445/add21950-9db4-11e5-9978-9accc76b2a7e.png)\r\n\r\n**Search view:**\r\n![usage-search](https://cloud.githubusercontent.com/assets/953792/11657451/b6901286-9db4-11e5-88fe-cf8e1a7fbccf.png)\r\n\r\n[API Examples](https://github.com/guardian/grid/blob/usage-event-stream-lambda/usage/api-examples.md)\r\n\r\n**Deployment strategy:**\r\n\r\nApps should be deployed in the following manner to avoid service disruption:\r\n\r\nPreperation:\r\n- Turn off Usage by scaling ASG to 0\r\n- Drop & Recreate Usage Table\r\n\r\nDeployment:\r\n- Thrall\r\n- Image Loader\r\n- Media API\r\n- Kahuna\r\n- Usage\r\n\r\n\r\n","created_at":"2015-11-10T11:50:55Z","updated_at":"2015-12-09T12:53:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"98a758f8a3a58c249240dc77beeb570d788b5a2d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/guardian/grid/pulls/1447/commits","review_comments_url":"https://api.github.com/repos/guardian/grid/pulls/1447/comments","review_comment_url":"https://api.github.com/repos/guardian/grid/pulls/comments{/number}","comments_url":"https://api.github.com/repos/guardian/grid/issues/1447/comments","statuses_url":"https://api.github.com/repos/guardian/grid/statuses/21d4942b0a238814e4ba8f605f27695b5f731cf5","head":{"label":"guardian:usage-event-stream-lambda","ref":"usage-event-stream-lambda","sha":"21d4942b0a238814e4ba8f605f27695b5f731cf5","user":{"login":"guardian","id":164318,"avatar_url":"https://avatars.githubusercontent.com/u/164318?v=3","gravatar_id":"","url":"https://api.github.com/users/guardian","html_url":"https://github.com/guardian","followers_url":"https://api.github.com/users/guardian/followers","following_url":"https://api.github.com/users/guardian/following{/other_user}","gists_url":"https://api.github.com/users/guardian/gists{/gist_id}","starred_url":"https://api.github.com/users/guardian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guardian/subscriptions","organizations_url":"https://api.github.com/users/guardian/orgs","repos_url":"https://api.github.com/users/guardian/repos","events_url":"https://api.github.com/users/guardian/events{/privacy}","received_events_url":"https://api.github.com/users/guardian/received_events","type":"Organization","site_admin":false},"repo":{"id":12298112,"name":"grid","full_name":"guardian/grid","owner":{"login":"guardian","id":164318,"avatar_url":"https://avatars.githubusercontent.com/u/164318?v=3","gravatar_id":"","url":"https://api.github.com/users/guardian","html_url":"https://github.com/guardian","followers_url":"https://api.github.com/users/guardian/followers","following_url":"https://api.github.com/users/guardian/following{/other_user}","gists_url":"https://api.github.com/users/guardian/gists{/gist_id}","starred_url":"https://api.github.com/users/guardian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guardian/subscriptions","organizations_url":"https://api.github.com/users/guardian/orgs","repos_url":"https://api.github.com/users/guardian/repos","events_url":"https://api.github.com/users/guardian/events{/privacy}","received_events_url":"https://api.github.com/users/guardian/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/guardian/grid","description":"The Guardian’s new image management system","fork":false,"url":"https://api.github.com/repos/guardian/grid","forks_url":"https://api.github.com/repos/guardian/grid/forks","keys_url":"https://api.github.com/repos/guardian/grid/keys{/key_id}","collaborators_url":"https://api.github.com/repos/guardian/grid/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/guardian/grid/teams","hooks_url":"https://api.github.com/repos/guardian/grid/hooks","issue_events_url":"https://api.github.com/repos/guardian/grid/issues/events{/number}","events_url":"https://api.github.com/repos/guardian/grid/events","assignees_url":"https://api.github.com/repos/guardian/grid/assignees{/user}","branches_url":"https://api.github.com/repos/guardian/grid/branches{/branch}","tags_url":"https://api.github.com/repos/guardian/grid/tags","blobs_url":"https://api.github.com/repos/guardian/grid/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/guardian/grid/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/guardian/grid/git/refs{/sha}","trees_url":"https://api.github.com/repos/guardian/grid/git/trees{/sha}","statuses_url":"https://api.github.com/repos/guardian/grid/statuses/{sha}","languages_url":"https://api.github.com/repos/guardian/grid/languages","stargazers_url":"https://api.github.com/repos/guardian/grid/stargazers","contributors_url":"https://api.github.com/repos/guardian/grid/contributors","subscribers_url":"https://api.github.com/repos/guardian/grid/subscribers","subscription_url":"https://api.github.com/repos/guardian/grid/subscription","commits_url":"https://api.github.com/repos/guardian/grid/commits{/sha}","git_commits_url":"https://api.github.com/repos/guardian/grid/git/commits{/sha}","comments_url":"https://api.github.com/repos/guardian/grid/comments{/number}","issue_comment_url":"https://api.github.com/repos/guardian/grid/issues/comments{/number}","contents_url":"https://api.github.com/repos/guardian/grid/contents/{+path}","compare_url":"https://api.github.com/repos/guardian/grid/compare/{base}...{head}","merges_url":"https://api.github.com/repos/guardian/grid/merges","archive_url":"https://api.github.com/repos/guardian/grid/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/guardian/grid/downloads","issues_url":"https://api.github.com/repos/guardian/grid/issues{/number}","pulls_url":"https://api.github.com/repos/guardian/grid/pulls{/number}","milestones_url":"https://api.github.com/repos/guardian/grid/milestones{/number}","notifications_url":"https://api.github.com/repos/guardian/grid/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/guardian/grid/labels{/name}","releases_url":"https://api.github.com/repos/guardian/grid/releases{/id}","created_at":"2013-08-22T13:49:31Z","updated_at":"2015-12-09T12:07:15Z","pushed_at":"2015-12-09T12:30:07Z","git_url":"git://github.com/guardian/grid.git","ssh_url":"git@github.com:guardian/grid.git","clone_url":"https://github.com/guardian/grid.git","svn_url":"https://github.com/guardian/grid","homepage":"","size":12938,"stargazers_count":977,"watchers_count":977,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":52,"mirror_url":null,"open_issues_count":64,"forks":52,"open_issues":64,"watchers":977,"default_branch":"master"}},"base":{"label":"guardian:master","ref":"master","sha":"5bd6d62d7d2b2fd505a04298750ed5addfb82df3","user":{"login":"guardian","id":164318,"avatar_url":"https://avatars.githubusercontent.com/u/164318?v=3","gravatar_id":"","url":"https://api.github.com/users/guardian","html_url":"https://github.com/guardian","followers_url":"https://api.github.com/users/guardian/followers","following_url":"https://api.github.com/users/guardian/following{/other_user}","gists_url":"https://api.github.com/users/guardian/gists{/gist_id}","starred_url":"https://api.github.com/users/guardian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guardian/subscriptions","organizations_url":"https://api.github.com/users/guardian/orgs","repos_url":"https://api.github.com/users/guardian/repos","events_url":"https://api.github.com/users/guardian/events{/privacy}","received_events_url":"https://api.github.com/users/guardian/received_events","type":"Organization","site_admin":false},"repo":{"id":12298112,"name":"grid","full_name":"guardian/grid","owner":{"login":"guardian","id":164318,"avatar_url":"https://avatars.githubusercontent.com/u/164318?v=3","gravatar_id":"","url":"https://api.github.com/users/guardian","html_url":"https://github.com/guardian","followers_url":"https://api.github.com/users/guardian/followers","following_url":"https://api.github.com/users/guardian/following{/other_user}","gists_url":"https://api.github.com/users/guardian/gists{/gist_id}","starred_url":"https://api.github.com/users/guardian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guardian/subscriptions","organizations_url":"https://api.github.com/users/guardian/orgs","repos_url":"https://api.github.com/users/guardian/repos","events_url":"https://api.github.com/users/guardian/events{/privacy}","received_events_url":"https://api.github.com/users/guardian/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/guardian/grid","description":"The Guardian’s new image management system","fork":false,"url":"https://api.github.com/repos/guardian/grid","forks_url":"https://api.github.com/repos/guardian/grid/forks","keys_url":"https://api.github.com/repos/guardian/grid/keys{/key_id}","collaborators_url":"https://api.github.com/repos/guardian/grid/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/guardian/grid/teams","hooks_url":"https://api.github.com/repos/guardian/grid/hooks","issue_events_url":"https://api.github.com/repos/guardian/grid/issues/events{/number}","events_url":"https://api.github.com/repos/guardian/grid/events","assignees_url":"https://api.github.com/repos/guardian/grid/assignees{/user}","branches_url":"https://api.github.com/repos/guardian/grid/branches{/branch}","tags_url":"https://api.github.com/repos/guardian/grid/tags","blobs_url":"https://api.github.com/repos/guardian/grid/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/guardian/grid/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/guardian/grid/git/refs{/sha}","trees_url":"https://api.github.com/repos/guardian/grid/git/trees{/sha}","statuses_url":"https://api.github.com/repos/guardian/grid/statuses/{sha}","languages_url":"https://api.github.com/repos/guardian/grid/languages","stargazers_url":"https://api.github.com/repos/guardian/grid/stargazers","contributors_url":"https://api.github.com/repos/guardian/grid/contributors","subscribers_url":"https://api.github.com/repos/guardian/grid/subscribers","subscription_url":"https://api.github.com/repos/guardian/grid/subscription","commits_url":"https://api.github.com/repos/guardian/grid/commits{/sha}","git_commits_url":"https://api.github.com/repos/guardian/grid/git/commits{/sha}","comments_url":"https://api.github.com/repos/guardian/grid/comments{/number}","issue_comment_url":"https://api.github.com/repos/guardian/grid/issues/comments{/number}","contents_url":"https://api.github.com/repos/guardian/grid/contents/{+path}","compare_url":"https://api.github.com/repos/guardian/grid/compare/{base}...{head}","merges_url":"https://api.github.com/repos/guardian/grid/merges","archive_url":"https://api.github.com/repos/guardian/grid/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/guardian/grid/downloads","issues_url":"https://api.github.com/repos/guardian/grid/issues{/number}","pulls_url":"https://api.github.com/repos/guardian/grid/pulls{/number}","milestones_url":"https://api.github.com/repos/guardian/grid/milestones{/number}","notifications_url":"https://api.github.com/repos/guardian/grid/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/guardian/grid/labels{/name}","releases_url":"https://api.github.com/repos/guardian/grid/releases{/id}","created_at":"2013-08-22T13:49:31Z","updated_at":"2015-12-09T12:07:15Z","pushed_at":"2015-12-09T12:30:07Z","git_url":"git://github.com/guardian/grid.git","ssh_url":"git@github.com:guardian/grid.git","clone_url":"https://github.com/guardian/grid.git","svn_url":"https://github.com/guardian/grid","homepage":"","size":12938,"stargazers_count":977,"watchers_count":977,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":52,"mirror_url":null,"open_issues_count":64,"forks":52,"open_issues":64,"watchers":977,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/guardian/grid/pulls/1447"},"html":{"href":"https://github.com/guardian/grid/pull/1447"},"issue":{"href":"https://api.github.com/repos/guardian/grid/issues/1447"},"comments":{"href":"https://api.github.com/repos/guardian/grid/issues/1447/comments"},"review_comments":{"href":"https://api.github.com/repos/guardian/grid/pulls/1447/comments"},"review_comment":{"href":"https://api.github.com/repos/guardian/grid/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/guardian/grid/pulls/1447/commits"},"statuses":{"href":"https://api.github.com/repos/guardian/grid/statuses/21d4942b0a238814e4ba8f605f27695b5f731cf5"}}}}