{"action":"created","comment":{"url":"https://api.github.com/repos/MaxFangX/calendar-analytics/pulls/comments/84581447","pull_request_review_id":5353165,"id":84581447,"diff_hunk":"@@ -3,32 +3,120 @@ var analyticsApp = angular.module('analyticsApp', ['nvd3', 'ui.calendar']);\n analyticsApp.controller('LoggedInCtrl', function LoggedInController($scope) {\n });\n \n-// Controller to generate graph data from chart directive, cumulative tags\n analyticsApp.controller('TagsCtrl', function($scope, $http){\n   var url = '/v1/tags.json';\n+  var tagUrl = '/v1/tags/';\n+\n   $scope.url = url;\n   $scope.tags = [];\n \n+  // Generate graph data\n   $http({ method: 'GET', url: url }).\n     success(function successCallback(data) {\n-\n       for (var i = 0; i < data.results.length; i++) {\n         var tag = data.results[i];\n         $scope.tags.push({\n+          id: tag.id,\n           label: tag.label,\n           keywords: tag.keywords,\n           hours: tag.hours\n         });\n       }\n-\n     });\n \n+    this.addTag = function(tag) {\n+      $http({\n+        method: 'POST',\n+        url: url,\n+        data: $.param({\n+          label: tag.label,\n+          keywords: tag.keywords,\n+          csrfmiddlewaretoken: getCookie('csrftoken')\n+        }),\n+        headers: {\n+          'Content-Type': 'application/x-www-form-urlencoded'\n+        }\n+      }).\n+        success(function addToList(data) {\n+          $scope.tags.push({\n+            id: data.id,\n+            label: data.label,\n+            keywords: data.keywords,\n+            hours: data.hours,\n+            showEdit: false\n+          });\n+        });\n+    };\n+\n+    this.editTag = function(tagId) {\n+      var tag = search(tagId, $scope.tags);\n+      tag.new_label = tag.label;\n+      tag.new_keywords = tag.keywords;\n+      tag.showEdit = true;\n+    };\n+\n+    this.submit = function(tagId) {\n+      var tag = search(tagId, $scope.tags);\n+      tag.showEdit = false;\n+\n+      $http({\n+        method: 'POST',\n+        url: tagUrl + tagId,\n+        data: $.param({\n+          label: tag.new_label,\n+          keywords: tag.new_keywords,\n+          csrfmiddlewaretoken: getCookie('csrftoken'),\n+          _method: 'PATCH'\n+        }),\n+        headers: {\n+          'Content-Type': 'application/x-www-form-urlencoded'\n+        }\n+      }).\n+        success(function editToList(data) {\n+          tag.label = data.label;\n+          tag.keywords = data.keywords;\n+          tag.hours = data.hours;\n+        });\n+    };\n+\n+    this.cancel = function(tagId) {\n+      var tag = search(tagId, $scope.tags);\n+      tag.showEdit = false;\n+    };\n+\n+    this.deleteTag = function(tagId) {\n+      $http({\n+        method: 'POST',\n+        url: tagUrl + tagId,\n+        data: $.param({\n+          csrfmiddlewaretoken: getCookie('csrftoken'),\n+          _method: 'DELETE'\n+        }),\n+        headers: {\n+          'Content-Type': 'application/x-www-form-urlencoded'\n+        }\n+      }).\n+        success(function removeTagFromList(data) {\n+          $scope.tags = $scope.tags.filter(function(tag) {\n+            return tag.id !== tagId;\n+          });\n+        });\n+    };\n+\n+    function search(id, tags){","path":"cal/cal/static/js/app.js","position":107,"original_position":107,"commit_id":"6ece03194176ed44256bc492b946792219f507cd","original_commit_id":"0795162e9d653c52c9b2a2b56aef2dc24de71d2c","user":{"login":"tiffanyqi","id":6607768,"avatar_url":"https://avatars.githubusercontent.com/u/6607768?v=3","gravatar_id":"","url":"https://api.github.com/users/tiffanyqi","html_url":"https://github.com/tiffanyqi","followers_url":"https://api.github.com/users/tiffanyqi/followers","following_url":"https://api.github.com/users/tiffanyqi/following{/other_user}","gists_url":"https://api.github.com/users/tiffanyqi/gists{/gist_id}","starred_url":"https://api.github.com/users/tiffanyqi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tiffanyqi/subscriptions","organizations_url":"https://api.github.com/users/tiffanyqi/orgs","repos_url":"https://api.github.com/users/tiffanyqi/repos","events_url":"https://api.github.com/users/tiffanyqi/events{/privacy}","received_events_url":"https://api.github.com/users/tiffanyqi/received_events","type":"User","site_admin":false},"body":"@MaxFangX `var tag = $scope.tags.find(function(tag, index, array) { return tag.id == id; });` to me seems like copying and pasting every time when we can just use one function that does call this called `search`. wouldn't this still be constant time since we're still using the `find` library function?","created_at":"2016-10-22T17:33:58Z","updated_at":"2016-10-22T17:33:58Z","html_url":"https://github.com/MaxFangX/calendar-analytics/pull/43#discussion_r84581447","pull_request_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/pulls/43","_links":{"self":{"href":"https://api.github.com/repos/MaxFangX/calendar-analytics/pulls/comments/84581447"},"html":{"href":"https://github.com/MaxFangX/calendar-analytics/pull/43#discussion_r84581447"},"pull_request":{"href":"https://api.github.com/repos/MaxFangX/calendar-analytics/pulls/43"}}},"pull_request":{"url":"https://api.github.com/repos/MaxFangX/calendar-analytics/pulls/43","id":89543392,"html_url":"https://github.com/MaxFangX/calendar-analytics/pull/43","diff_url":"https://github.com/MaxFangX/calendar-analytics/pull/43.diff","patch_url":"https://github.com/MaxFangX/calendar-analytics/pull/43.patch","issue_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/issues/43","number":43,"state":"open","locked":false,"title":"Add tags","user":{"login":"tiffanyqi","id":6607768,"avatar_url":"https://avatars.githubusercontent.com/u/6607768?v=3","gravatar_id":"","url":"https://api.github.com/users/tiffanyqi","html_url":"https://github.com/tiffanyqi","followers_url":"https://api.github.com/users/tiffanyqi/followers","following_url":"https://api.github.com/users/tiffanyqi/following{/other_user}","gists_url":"https://api.github.com/users/tiffanyqi/gists{/gist_id}","starred_url":"https://api.github.com/users/tiffanyqi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tiffanyqi/subscriptions","organizations_url":"https://api.github.com/users/tiffanyqi/orgs","repos_url":"https://api.github.com/users/tiffanyqi/repos","events_url":"https://api.github.com/users/tiffanyqi/events{/privacy}","received_events_url":"https://api.github.com/users/tiffanyqi/received_events","type":"User","site_admin":false},"body":"- Allow users to add, edit, and remove tags in AJAX.\r\n- Better tag display\r\n\r\nNote: \r\n- Also deleted some spaces in models.py\r\n- Not sure how to remove static/.DS_Store from this PR. Thoughts?","created_at":"2016-10-16T22:52:49Z","updated_at":"2016-10-22T17:33:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"19c708bdec38a1f1f3335002479cf36ac3cf8ac3","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/pulls/43/commits","review_comments_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/pulls/43/comments","review_comment_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/pulls/comments{/number}","comments_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/issues/43/comments","statuses_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/statuses/6ece03194176ed44256bc492b946792219f507cd","head":{"label":"MaxFangX:add-tags","ref":"add-tags","sha":"6ece03194176ed44256bc492b946792219f507cd","user":{"login":"MaxFangX","id":7884003,"avatar_url":"https://avatars.githubusercontent.com/u/7884003?v=3","gravatar_id":"","url":"https://api.github.com/users/MaxFangX","html_url":"https://github.com/MaxFangX","followers_url":"https://api.github.com/users/MaxFangX/followers","following_url":"https://api.github.com/users/MaxFangX/following{/other_user}","gists_url":"https://api.github.com/users/MaxFangX/gists{/gist_id}","starred_url":"https://api.github.com/users/MaxFangX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaxFangX/subscriptions","organizations_url":"https://api.github.com/users/MaxFangX/orgs","repos_url":"https://api.github.com/users/MaxFangX/repos","events_url":"https://api.github.com/users/MaxFangX/events{/privacy}","received_events_url":"https://api.github.com/users/MaxFangX/received_events","type":"User","site_admin":false},"repo":{"id":41992038,"name":"calendar-analytics","full_name":"MaxFangX/calendar-analytics","owner":{"login":"MaxFangX","id":7884003,"avatar_url":"https://avatars.githubusercontent.com/u/7884003?v=3","gravatar_id":"","url":"https://api.github.com/users/MaxFangX","html_url":"https://github.com/MaxFangX","followers_url":"https://api.github.com/users/MaxFangX/followers","following_url":"https://api.github.com/users/MaxFangX/following{/other_user}","gists_url":"https://api.github.com/users/MaxFangX/gists{/gist_id}","starred_url":"https://api.github.com/users/MaxFangX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaxFangX/subscriptions","organizations_url":"https://api.github.com/users/MaxFangX/orgs","repos_url":"https://api.github.com/users/MaxFangX/repos","events_url":"https://api.github.com/users/MaxFangX/events{/privacy}","received_events_url":"https://api.github.com/users/MaxFangX/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MaxFangX/calendar-analytics","description":"The calendar stats app for efficiency whores, curious users, and people obsessed with logging","fork":false,"url":"https://api.github.com/repos/MaxFangX/calendar-analytics","forks_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/forks","keys_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/teams","hooks_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/hooks","issue_events_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/issues/events{/number}","events_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/events","assignees_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/assignees{/user}","branches_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/branches{/branch}","tags_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/tags","blobs_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/git/refs{/sha}","trees_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/statuses/{sha}","languages_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/languages","stargazers_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/stargazers","contributors_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/contributors","subscribers_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/subscribers","subscription_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/subscription","commits_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/commits{/sha}","git_commits_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/git/commits{/sha}","comments_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/comments{/number}","issue_comment_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/issues/comments{/number}","contents_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/contents/{+path}","compare_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/merges","archive_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/downloads","issues_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/issues{/number}","pulls_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/pulls{/number}","milestones_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/milestones{/number}","notifications_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/labels{/name}","releases_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/releases{/id}","deployments_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/deployments","created_at":"2015-09-06T06:53:53Z","updated_at":"2016-07-29T10:59:18Z","pushed_at":"2016-10-21T06:30:01Z","git_url":"git://github.com/MaxFangX/calendar-analytics.git","ssh_url":"git@github.com:MaxFangX/calendar-analytics.git","clone_url":"https://github.com/MaxFangX/calendar-analytics.git","svn_url":"https://github.com/MaxFangX/calendar-analytics","homepage":"","size":1546,"stargazers_count":8,"watchers_count":8,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":23,"forks":0,"open_issues":23,"watchers":8,"default_branch":"master"}},"base":{"label":"MaxFangX:master","ref":"master","sha":"cd5386c4d296930a0328dc19f6fc0de268091485","user":{"login":"MaxFangX","id":7884003,"avatar_url":"https://avatars.githubusercontent.com/u/7884003?v=3","gravatar_id":"","url":"https://api.github.com/users/MaxFangX","html_url":"https://github.com/MaxFangX","followers_url":"https://api.github.com/users/MaxFangX/followers","following_url":"https://api.github.com/users/MaxFangX/following{/other_user}","gists_url":"https://api.github.com/users/MaxFangX/gists{/gist_id}","starred_url":"https://api.github.com/users/MaxFangX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaxFangX/subscriptions","organizations_url":"https://api.github.com/users/MaxFangX/orgs","repos_url":"https://api.github.com/users/MaxFangX/repos","events_url":"https://api.github.com/users/MaxFangX/events{/privacy}","received_events_url":"https://api.github.com/users/MaxFangX/received_events","type":"User","site_admin":false},"repo":{"id":41992038,"name":"calendar-analytics","full_name":"MaxFangX/calendar-analytics","owner":{"login":"MaxFangX","id":7884003,"avatar_url":"https://avatars.githubusercontent.com/u/7884003?v=3","gravatar_id":"","url":"https://api.github.com/users/MaxFangX","html_url":"https://github.com/MaxFangX","followers_url":"https://api.github.com/users/MaxFangX/followers","following_url":"https://api.github.com/users/MaxFangX/following{/other_user}","gists_url":"https://api.github.com/users/MaxFangX/gists{/gist_id}","starred_url":"https://api.github.com/users/MaxFangX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaxFangX/subscriptions","organizations_url":"https://api.github.com/users/MaxFangX/orgs","repos_url":"https://api.github.com/users/MaxFangX/repos","events_url":"https://api.github.com/users/MaxFangX/events{/privacy}","received_events_url":"https://api.github.com/users/MaxFangX/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MaxFangX/calendar-analytics","description":"The calendar stats app for efficiency whores, curious users, and people obsessed with logging","fork":false,"url":"https://api.github.com/repos/MaxFangX/calendar-analytics","forks_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/forks","keys_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/teams","hooks_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/hooks","issue_events_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/issues/events{/number}","events_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/events","assignees_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/assignees{/user}","branches_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/branches{/branch}","tags_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/tags","blobs_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/git/refs{/sha}","trees_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/statuses/{sha}","languages_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/languages","stargazers_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/stargazers","contributors_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/contributors","subscribers_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/subscribers","subscription_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/subscription","commits_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/commits{/sha}","git_commits_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/git/commits{/sha}","comments_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/comments{/number}","issue_comment_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/issues/comments{/number}","contents_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/contents/{+path}","compare_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/merges","archive_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/downloads","issues_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/issues{/number}","pulls_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/pulls{/number}","milestones_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/milestones{/number}","notifications_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/labels{/name}","releases_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/releases{/id}","deployments_url":"https://api.github.com/repos/MaxFangX/calendar-analytics/deployments","created_at":"2015-09-06T06:53:53Z","updated_at":"2016-07-29T10:59:18Z","pushed_at":"2016-10-21T06:30:01Z","git_url":"git://github.com/MaxFangX/calendar-analytics.git","ssh_url":"git@github.com:MaxFangX/calendar-analytics.git","clone_url":"https://github.com/MaxFangX/calendar-analytics.git","svn_url":"https://github.com/MaxFangX/calendar-analytics","homepage":"","size":1546,"stargazers_count":8,"watchers_count":8,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":23,"forks":0,"open_issues":23,"watchers":8,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/MaxFangX/calendar-analytics/pulls/43"},"html":{"href":"https://github.com/MaxFangX/calendar-analytics/pull/43"},"issue":{"href":"https://api.github.com/repos/MaxFangX/calendar-analytics/issues/43"},"comments":{"href":"https://api.github.com/repos/MaxFangX/calendar-analytics/issues/43/comments"},"review_comments":{"href":"https://api.github.com/repos/MaxFangX/calendar-analytics/pulls/43/comments"},"review_comment":{"href":"https://api.github.com/repos/MaxFangX/calendar-analytics/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/MaxFangX/calendar-analytics/pulls/43/commits"},"statuses":{"href":"https://api.github.com/repos/MaxFangX/calendar-analytics/statuses/6ece03194176ed44256bc492b946792219f507cd"}}}}
{"actor":{"display_login":"tiffanyqi"}}