{"action":"created","comment":{"url":"https://api.github.com/repos/openshift/origin/pulls/comments/23844601","id":23844601,"diff_hunk":"@@ -0,0 +1,337 @@\n+'use strict';\n+\n+angular.module('openshiftConsole')\n+.factory('LabelFilter', [function() {\n+  function LabelFilter() {\n+    this._existingLabels = {};\n+    this._activeFilters = {};\n+    this._onActiveFiltersChangedCallbacks = $.Callbacks();\n+  }\n+\n+  LabelFilter.prototype.createLabelSuggestionsFromResources = function(items, map) {\n+    // check if we are extracting from a single item or a hash of items\n+    if (items.id || (items.metadata && items.metadata.name)) {\n+      this._extractLabelsFromItem(items, map);\n+    }\n+    else {\n+      var self = this;\n+      $each(items, function(key, item) {\n+        self._extractLabelsFromItem(item, map);\n+      });\n+    }\n+  };\n+\n+  LabelFilter.prototype.setLabelSuggestions = function(suggestions) {\n+    this._existingLabels = suggestions;\n+  };\n+\n+  LabelFilter.prototype._extractLabelsFromItem = function(item, map) {\n+    // TODO temporary until we handle everything with item.metadata.labels\n+    var labels = item.labels;\n+    if (item.metadata) {\n+      labels = item.metadata.labels;\n+    }\n+\n+    var self = this;\n+    $each(labels, function(key, value) {\n+      if (!map[key]) {\n+        map[key] = [];\n+      }\n+      map[key].push({value: value});\n+    });\n+  };\n+\n+  LabelFilter.prototype.onActiveFiltersChanged = function(callback) {\n+    this._onActiveFiltersChangedCallbacks.add(callback);\n+  };\n+\n+  LabelFilter.prototype.filterResources = function(resources) {\n+    var filteredResources = {};\n+    var self = this;\n+    $each(resources, function(resId, resource) {\n+      if (self.isResourceIncludedInActiveFilters(resource)) {\n+        filteredResources[resId] = resource;\n+      }\n+    });\n+    return filteredResources;\n+  };\n+\n+  LabelFilter.prototype.isResourceIncludedInActiveFilters = function(resource) {\n+    if (!resource) {\n+      return false;\n+    }\n+    var labels = resource.labels || {};\n+    if (resource.metadata) {\n+      labels = resource.metadata.labels || {};\n+    }\n+    for (var id in this._activeFilters) {","path":"assets/app/scripts/services/labelFilter.js","position":67,"original_position":67,"commit_id":"01a5bd5baa4fba40fb74673622cf8c93213ab77f","original_commit_id":"01a5bd5baa4fba40fb74673622cf8c93213ab77f","user":{"login":"liggitt","id":980082,"avatar_url":"https://avatars.githubusercontent.com/u/980082?v=3","gravatar_id":"","url":"https://api.github.com/users/liggitt","html_url":"https://github.com/liggitt","followers_url":"https://api.github.com/users/liggitt/followers","following_url":"https://api.github.com/users/liggitt/following{/other_user}","gists_url":"https://api.github.com/users/liggitt/gists{/gist_id}","starred_url":"https://api.github.com/users/liggitt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liggitt/subscriptions","organizations_url":"https://api.github.com/users/liggitt/orgs","repos_url":"https://api.github.com/users/liggitt/repos","events_url":"https://api.github.com/users/liggitt/events{/privacy}","received_events_url":"https://api.github.com/users/liggitt/received_events","type":"User","site_admin":false},"body":"Separate out the object that represents a label selector, and the logic to decide whether that matches a set of labels. Shouldn't be tied so closely to a LabelFilter widget (we'll want to be able to parse a label selector from an API object later). A LabelFilter widget should be able to return a LabelSelector object representing its active filters. Then `LabelSelector.select(resources)` can select resources (probably calling `LabelSelector.matches(resource)` internally)","created_at":"2015-01-30T14:22:19Z","updated_at":"2015-01-30T14:22:19Z","html_url":"https://github.com/openshift/origin/pull/801#discussion_r23844601","pull_request_url":"https://api.github.com/repos/openshift/origin/pulls/801","_links":{"self":{"href":"https://api.github.com/repos/openshift/origin/pulls/comments/23844601"},"html":{"href":"https://github.com/openshift/origin/pull/801#discussion_r23844601"},"pull_request":{"href":"https://api.github.com/repos/openshift/origin/pulls/801"}}},"pull_request":{"url":"https://api.github.com/repos/openshift/origin/pulls/801","id":28362800,"html_url":"https://github.com/openshift/origin/pull/801","diff_url":"https://github.com/openshift/origin/pull/801.diff","patch_url":"https://github.com/openshift/origin/pull/801.patch","issue_url":"https://api.github.com/repos/openshift/origin/issues/801","number":801,"state":"open","locked":false,"title":"[WIP] Label filter widget in mgmt console","user":{"login":"jwforres","id":1467629,"avatar_url":"https://avatars.githubusercontent.com/u/1467629?v=3","gravatar_id":"","url":"https://api.github.com/users/jwforres","html_url":"https://github.com/jwforres","followers_url":"https://api.github.com/users/jwforres/followers","following_url":"https://api.github.com/users/jwforres/following{/other_user}","gists_url":"https://api.github.com/users/jwforres/gists{/gist_id}","starred_url":"https://api.github.com/users/jwforres/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwforres/subscriptions","organizations_url":"https://api.github.com/users/jwforres/orgs","repos_url":"https://api.github.com/users/jwforres/repos","events_url":"https://api.github.com/users/jwforres/events{/privacy}","received_events_url":"https://api.github.com/users/jwforres/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-01-30T14:01:00Z","updated_at":"2015-01-30T14:22:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fe308c8b74a3a847132952b5dc323ab08d8c3cce","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openshift/origin/pulls/801/commits","review_comments_url":"https://api.github.com/repos/openshift/origin/pulls/801/comments","review_comment_url":"https://api.github.com/repos/openshift/origin/pulls/comments/{number}","comments_url":"https://api.github.com/repos/openshift/origin/issues/801/comments","statuses_url":"https://api.github.com/repos/openshift/origin/statuses/01a5bd5baa4fba40fb74673622cf8c93213ab77f","head":{"label":"jwforres:filter_widget","ref":"filter_widget","sha":"01a5bd5baa4fba40fb74673622cf8c93213ab77f","user":{"login":"jwforres","id":1467629,"avatar_url":"https://avatars.githubusercontent.com/u/1467629?v=3","gravatar_id":"","url":"https://api.github.com/users/jwforres","html_url":"https://github.com/jwforres","followers_url":"https://api.github.com/users/jwforres/followers","following_url":"https://api.github.com/users/jwforres/following{/other_user}","gists_url":"https://api.github.com/users/jwforres/gists{/gist_id}","starred_url":"https://api.github.com/users/jwforres/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwforres/subscriptions","organizations_url":"https://api.github.com/users/jwforres/orgs","repos_url":"https://api.github.com/users/jwforres/repos","events_url":"https://api.github.com/users/jwforres/events{/privacy}","received_events_url":"https://api.github.com/users/jwforres/received_events","type":"User","site_admin":false},"repo":{"id":22971182,"name":"origin","full_name":"jwforres/origin","owner":{"login":"jwforres","id":1467629,"avatar_url":"https://avatars.githubusercontent.com/u/1467629?v=3","gravatar_id":"","url":"https://api.github.com/users/jwforres","html_url":"https://github.com/jwforres","followers_url":"https://api.github.com/users/jwforres/followers","following_url":"https://api.github.com/users/jwforres/following{/other_user}","gists_url":"https://api.github.com/users/jwforres/gists{/gist_id}","starred_url":"https://api.github.com/users/jwforres/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwforres/subscriptions","organizations_url":"https://api.github.com/users/jwforres/orgs","repos_url":"https://api.github.com/users/jwforres/repos","events_url":"https://api.github.com/users/jwforres/events{/privacy}","received_events_url":"https://api.github.com/users/jwforres/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jwforres/origin","description":"OpenShift 3 - build, deploy, and manage your applications with Docker and Kubernetes","fork":true,"url":"https://api.github.com/repos/jwforres/origin","forks_url":"https://api.github.com/repos/jwforres/origin/forks","keys_url":"https://api.github.com/repos/jwforres/origin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jwforres/origin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jwforres/origin/teams","hooks_url":"https://api.github.com/repos/jwforres/origin/hooks","issue_events_url":"https://api.github.com/repos/jwforres/origin/issues/events{/number}","events_url":"https://api.github.com/repos/jwforres/origin/events","assignees_url":"https://api.github.com/repos/jwforres/origin/assignees{/user}","branches_url":"https://api.github.com/repos/jwforres/origin/branches{/branch}","tags_url":"https://api.github.com/repos/jwforres/origin/tags","blobs_url":"https://api.github.com/repos/jwforres/origin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jwforres/origin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jwforres/origin/git/refs{/sha}","trees_url":"https://api.github.com/repos/jwforres/origin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jwforres/origin/statuses/{sha}","languages_url":"https://api.github.com/repos/jwforres/origin/languages","stargazers_url":"https://api.github.com/repos/jwforres/origin/stargazers","contributors_url":"https://api.github.com/repos/jwforres/origin/contributors","subscribers_url":"https://api.github.com/repos/jwforres/origin/subscribers","subscription_url":"https://api.github.com/repos/jwforres/origin/subscription","commits_url":"https://api.github.com/repos/jwforres/origin/commits{/sha}","git_commits_url":"https://api.github.com/repos/jwforres/origin/git/commits{/sha}","comments_url":"https://api.github.com/repos/jwforres/origin/comments{/number}","issue_comment_url":"https://api.github.com/repos/jwforres/origin/issues/comments/{number}","contents_url":"https://api.github.com/repos/jwforres/origin/contents/{+path}","compare_url":"https://api.github.com/repos/jwforres/origin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jwforres/origin/merges","archive_url":"https://api.github.com/repos/jwforres/origin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jwforres/origin/downloads","issues_url":"https://api.github.com/repos/jwforres/origin/issues{/number}","pulls_url":"https://api.github.com/repos/jwforres/origin/pulls{/number}","milestones_url":"https://api.github.com/repos/jwforres/origin/milestones{/number}","notifications_url":"https://api.github.com/repos/jwforres/origin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jwforres/origin/labels{/name}","releases_url":"https://api.github.com/repos/jwforres/origin/releases{/id}","created_at":"2014-08-14T22:53:50Z","updated_at":"2015-01-15T19:24:31Z","pushed_at":"2015-01-30T13:59:36Z","git_url":"git://github.com/jwforres/origin.git","ssh_url":"git@github.com:jwforres/origin.git","clone_url":"https://github.com/jwforres/origin.git","svn_url":"https://github.com/jwforres/origin","homepage":"https://openshift.github.io","size":29182,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"openshift:master","ref":"master","sha":"daeb842fa57b52054a54e53f1844a9e1bdd5aa14","user":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"repo":{"id":22442668,"name":"origin","full_name":"openshift/origin","owner":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openshift/origin","description":"OpenShift 3 - build, deploy, and manage your applications with Docker and Kubernetes","fork":false,"url":"https://api.github.com/repos/openshift/origin","forks_url":"https://api.github.com/repos/openshift/origin/forks","keys_url":"https://api.github.com/repos/openshift/origin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openshift/origin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openshift/origin/teams","hooks_url":"https://api.github.com/repos/openshift/origin/hooks","issue_events_url":"https://api.github.com/repos/openshift/origin/issues/events{/number}","events_url":"https://api.github.com/repos/openshift/origin/events","assignees_url":"https://api.github.com/repos/openshift/origin/assignees{/user}","branches_url":"https://api.github.com/repos/openshift/origin/branches{/branch}","tags_url":"https://api.github.com/repos/openshift/origin/tags","blobs_url":"https://api.github.com/repos/openshift/origin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openshift/origin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openshift/origin/git/refs{/sha}","trees_url":"https://api.github.com/repos/openshift/origin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openshift/origin/statuses/{sha}","languages_url":"https://api.github.com/repos/openshift/origin/languages","stargazers_url":"https://api.github.com/repos/openshift/origin/stargazers","contributors_url":"https://api.github.com/repos/openshift/origin/contributors","subscribers_url":"https://api.github.com/repos/openshift/origin/subscribers","subscription_url":"https://api.github.com/repos/openshift/origin/subscription","commits_url":"https://api.github.com/repos/openshift/origin/commits{/sha}","git_commits_url":"https://api.github.com/repos/openshift/origin/git/commits{/sha}","comments_url":"https://api.github.com/repos/openshift/origin/comments{/number}","issue_comment_url":"https://api.github.com/repos/openshift/origin/issues/comments/{number}","contents_url":"https://api.github.com/repos/openshift/origin/contents/{+path}","compare_url":"https://api.github.com/repos/openshift/origin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openshift/origin/merges","archive_url":"https://api.github.com/repos/openshift/origin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openshift/origin/downloads","issues_url":"https://api.github.com/repos/openshift/origin/issues{/number}","pulls_url":"https://api.github.com/repos/openshift/origin/pulls{/number}","milestones_url":"https://api.github.com/repos/openshift/origin/milestones{/number}","notifications_url":"https://api.github.com/repos/openshift/origin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openshift/origin/labels{/name}","releases_url":"https://api.github.com/repos/openshift/origin/releases{/id}","created_at":"2014-07-30T20:04:05Z","updated_at":"2015-01-30T08:10:31Z","pushed_at":"2015-01-30T08:10:30Z","git_url":"git://github.com/openshift/origin.git","ssh_url":"git@github.com:openshift/origin.git","clone_url":"https://github.com/openshift/origin.git","svn_url":"https://github.com/openshift/origin","homepage":"https://openshift.github.io","size":39724,"stargazers_count":254,"watchers_count":254,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":138,"mirror_url":null,"open_issues_count":81,"forks":138,"open_issues":81,"watchers":254,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openshift/origin/pulls/801"},"html":{"href":"https://github.com/openshift/origin/pull/801"},"issue":{"href":"https://api.github.com/repos/openshift/origin/issues/801"},"comments":{"href":"https://api.github.com/repos/openshift/origin/issues/801/comments"},"review_comments":{"href":"https://api.github.com/repos/openshift/origin/pulls/801/comments"},"review_comment":{"href":"https://api.github.com/repos/openshift/origin/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/openshift/origin/pulls/801/commits"},"statuses":{"href":"https://api.github.com/repos/openshift/origin/statuses/01a5bd5baa4fba40fb74673622cf8c93213ab77f"}}}}