{"action":"created","comment":{"url":"https://api.github.com/repos/guardian/grid/pulls/comments/39967248","id":39967248,"diff_hunk":"@@ -134,70 +124,60 @@ usageRightsEditor.controller(\n         return property.optionsMap[val] || [];\n     };\n \n-    ctrl.isOtherValue = property => {\n-        if (!ctrl.model[property.name]) {\n-            // if we haven't set a value, it won't be in the list of available values,\n-            // but this isn't considered \"other\", it's \"not set\".\n-            return false;\n-        } else {\n-            const missingVal =\n-                !ctrl.getOptionsFor(property)\n-                    .find(option => option === ctrl.model[property.name]);\n+    ctrl.save = () => {\n+        ctrl.saving = true;\n+        // we save as `{}` if category isn't defined.\n+        const data = ctrl.category.value ?\n+            angular.extend({}, ctrl.model, { category: ctrl.category.value }) : {};\n \n-            return missingVal;\n-        }\n+        save(data).\n+        catch(uiError).\n+        finally(() => ctrl.saving = false);\n     };\n \n-    ctrl.isRestricted = prop =>\n-        ctrl.showRestrictions || ctrl.category.defaultRestrictions || prop.required;\n-\n-    $scope.$watch(() => ctrl.showRestrictions, onValChange(isRestricted => {\n-        if (!isRestricted) {\n-            delete ctrl.model.restrictions;\n-        }\n-    }));\n-\n-    function setCategory(val) {\n-        ctrl.category = ctrl.categories.find(cat => cat.value === val);\n-    }\n-\n-    function modelToData(model) {\n-        const modelWithCat = angular.extend({},\n-            model, { category: ctrl.category && ctrl.category.value });\n-\n-        return Object.keys(modelWithCat).reduce((clean, key) => {\n-            // remove everything !thing including \"\"\n-            if (modelWithCat[key]) {\n-                clean[key] = modelWithCat[key];\n-            }\n+    ctrl.reset = () => {\n+        ctrl.model = {};\n+        ctrl.showRestrictions = undefined;\n+    };\n \n-            return clean;\n-        }, {});\n-    }\n+    ctrl.cancel = () => ctrl.onCancel();\n \n     function save(data) {\n-        ctrl.error = null;\n-        ctrl.saving = true;\n-        $q.all(ctrl.usageRights.map((usageRights) => {\n+        return $q.all(ctrl.usageRights.map(usageRights => {\n             const image = usageRights.image;\n             const resource = image.data.userMetadata.data.usageRights;\n             return editsService.update(resource, data, image).\n                 then(resource => resource.data);\n-        })).catch(uiError).\n-            finally(() => updateSuccess(data));\n+        }));\n+    }\n+\n+    function getUniqueCats(usageRights) {\n+        return unique(usageRights.map(ur => ur.data.category));\n     }\n \n-    function updateSuccess(data) {\n-        ctrl.model = data;\n-        ctrl.onSave();\n-        setCategory(data.category);\n-        uiSaved();\n-        ctrl.saving = false;\n+    function unique(arr) {\n+        return arr.reduce((prev, curr) =>\n+            prev.indexOf(curr) !== -1 ? prev : prev.concat([curr]), []);","path":"kahuna/public/js/usage-rights/usage-rights-editor.js","position":293,"original_position":293,"commit_id":"aedc8a164b0030b0244ab1f51d25dbac19b38177","original_commit_id":"aedc8a164b0030b0244ab1f51d25dbac19b38177","user":{"login":"theefer","id":36964,"avatar_url":"https://avatars.githubusercontent.com/u/36964?v=3","gravatar_id":"","url":"https://api.github.com/users/theefer","html_url":"https://github.com/theefer","followers_url":"https://api.github.com/users/theefer/followers","following_url":"https://api.github.com/users/theefer/following{/other_user}","gists_url":"https://api.github.com/users/theefer/gists{/gist_id}","starred_url":"https://api.github.com/users/theefer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theefer/subscriptions","organizations_url":"https://api.github.com/users/theefer/orgs","repos_url":"https://api.github.com/users/theefer/repos","events_url":"https://api.github.com/users/theefer/events{/privacy}","received_events_url":"https://api.github.com/users/theefer/received_events","type":"User","site_admin":false},"body":"Note that you can pass items to `concat`, e.g. `prev.concat(curr)`.","created_at":"2015-09-21T13:03:04Z","updated_at":"2015-09-21T13:03:04Z","html_url":"https://github.com/guardian/grid/pull/1277#discussion_r39967248","pull_request_url":"https://api.github.com/repos/guardian/grid/pulls/1277","_links":{"self":{"href":"https://api.github.com/repos/guardian/grid/pulls/comments/39967248"},"html":{"href":"https://github.com/guardian/grid/pull/1277#discussion_r39967248"},"pull_request":{"href":"https://api.github.com/repos/guardian/grid/pulls/1277"}}},"pull_request":{"url":"https://api.github.com/repos/guardian/grid/pulls/1277","id":45430889,"html_url":"https://github.com/guardian/grid/pull/1277","diff_url":"https://github.com/guardian/grid/pull/1277.diff","patch_url":"https://github.com/guardian/grid/pull/1277.patch","issue_url":"https://api.github.com/repos/guardian/grid/issues/1277","number":1277,"state":"open","locked":false,"title":"No usage rights","user":{"login":"jamesgorrie","id":31692,"avatar_url":"https://avatars.githubusercontent.com/u/31692?v=3","gravatar_id":"","url":"https://api.github.com/users/jamesgorrie","html_url":"https://github.com/jamesgorrie","followers_url":"https://api.github.com/users/jamesgorrie/followers","following_url":"https://api.github.com/users/jamesgorrie/following{/other_user}","gists_url":"https://api.github.com/users/jamesgorrie/gists{/gist_id}","starred_url":"https://api.github.com/users/jamesgorrie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamesgorrie/subscriptions","organizations_url":"https://api.github.com/users/jamesgorrie/orgs","repos_url":"https://api.github.com/users/jamesgorrie/repos","events_url":"https://api.github.com/users/jamesgorrie/events{/privacy}","received_events_url":"https://api.github.com/users/jamesgorrie/received_events","type":"User","site_admin":false},"body":"When embarking on doing this, I was left trying to figure out what changed what state, which is a little frustrating.\r\n\r\nThis hopefully makes things a lot more understandable and leaves us able to enhance this in the future.\r\n\r\nWeirdly I noticed that I am doing things similar to what's being done in [`gr-panel`](https://github.com/guardian/grid/blob/master/kahuna/public/js/components/gr-panel/gr-panel.js#L108-L135). Hopefully these will bring us closer to one abstraction to manage this (and coming to the same solution twice is mostly a good sign).\r\n\r\nAnother addition is we can now have a more correct model i.e. If two images are of different categories, but have they same restrictions - this will be reflected.\r\n\r\n__TODO__\r\n- [x] Make sure we have feature parity\r\n- [x] remove legacy code\r\n\r\n","created_at":"2015-09-18T17:22:11Z","updated_at":"2015-09-21T13:03:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"81e5ad911a2b466a6cb685c797d90dcb75242833","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/guardian/grid/pulls/1277/commits","review_comments_url":"https://api.github.com/repos/guardian/grid/pulls/1277/comments","review_comment_url":"https://api.github.com/repos/guardian/grid/pulls/comments{/number}","comments_url":"https://api.github.com/repos/guardian/grid/issues/1277/comments","statuses_url":"https://api.github.com/repos/guardian/grid/statuses/aedc8a164b0030b0244ab1f51d25dbac19b38177","head":{"label":"guardian:nousagerights","ref":"nousagerights","sha":"aedc8a164b0030b0244ab1f51d25dbac19b38177","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-09-21T04:45:13Z","pushed_at":"2015-09-21T12:34:20Z","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":22644,"stargazers_count":918,"watchers_count":918,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":43,"mirror_url":null,"open_issues_count":63,"forks":43,"open_issues":63,"watchers":918,"default_branch":"master"}},"base":{"label":"guardian:master","ref":"master","sha":"4bc0a61dd8f3d2f3550d99a8898dd73a81e93502","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-09-21T04:45:13Z","pushed_at":"2015-09-21T12:34:20Z","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":22644,"stargazers_count":918,"watchers_count":918,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":43,"mirror_url":null,"open_issues_count":63,"forks":43,"open_issues":63,"watchers":918,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/guardian/grid/pulls/1277"},"html":{"href":"https://github.com/guardian/grid/pull/1277"},"issue":{"href":"https://api.github.com/repos/guardian/grid/issues/1277"},"comments":{"href":"https://api.github.com/repos/guardian/grid/issues/1277/comments"},"review_comments":{"href":"https://api.github.com/repos/guardian/grid/pulls/1277/comments"},"review_comment":{"href":"https://api.github.com/repos/guardian/grid/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/guardian/grid/pulls/1277/commits"},"statuses":{"href":"https://api.github.com/repos/guardian/grid/statuses/aedc8a164b0030b0244ab1f51d25dbac19b38177"}}}}