GitHub PullRequestReviewCommentEvent at 2014-04-25 15:01:58
Repository: related_tickets_app
Actor: pi3r
Payload: {"comment":{"url":"https://api.github.com/repos/zendesk/related_tickets_app/pulls/comments/12000287","id":12000287,"diff_hunk":"@@ -20,87 +11,77 @@\n     },\n \n     events: {\n-      'app.activated'             : 'init',\n-      'keydown #search-input'     : 'handleKeydown',\n-      'click .search-icon'        : 'handleClick',\n-      'requiredProperties.ready'  : 'handleRequiredProperties',\n-      'search.done'               : 'handleResults',\n-      'ticket.subject.changed'    : 'handleSubjecChanged'\n+      'app.created'             : 'onTicketSubjectChanged',\n+      'ticket.subject.changed'  : 'onTicketSubjectChanged',\n+      'keydown #search-input'   : 'onSearchKeyPressed',\n+      'click .search'           : 'onSearchClicked',\n+      'search.done'             : 'onSearchDone',\n+      'search.fail'             : 'onSearchFailed'\n     },\n \n-    init: function(data){\n-      if(!data.firstLoad){\n-        return;\n-      }\n-\n-      this.requiredProperties = [\n-        'ticket.subject'\n-      ];\n+    onTicketSubjectChanged: _.debounce(function() {\n+      if (_.isEmpty(this.ticket().subject())) { return; }\n \n-      this.allRequiredPropertiesExist();\n-    },\n-\n-    searchTickets: function(keywords){\n-      this.switchTo('searching');\n+      var keywords = this.extractKeywords(this.ticket().subject()).join(\" \");\n \n-      // parameters to search tickets that have been solved\n-      var params = keywords + \" type:ticket status>pending\";\n+      this.$('.search-input').val(keywords);\n \n-      this.ajax('search', params);\n-    },\n+      this.searchTickets(keywords);\n+    }, 400),\n \n-    handleKeydown: function(e) {\n+    onSearchKeyPressed: function(e) {\n       var query = this.$(e.target).val();\n \n-      if (e.which === 13) {\n-        if (query.length > 2) this.searchTickets(query);\n-        return false;\n-      }\n-    },\n-\n-    handleClick: function() {\n-      var query = this.$(\".search-wrapper\").find(\"#search-input\").val();\n+      if (e.which === 13 && !_.isEmpty(query)) {\n+        e.preventDefault();\n \n-      if (query.length > 2) this.searchTickets(query);\n+        this.searchTickets(query);\n+      }\n     },\n \n-    handleRequiredProperties: function() {\n-      var keywords = this.extractKeywords(this.ticket().subject()).join(\" \");\n+    onSearchClicked: function(e) {\n+      e.preventDefault();\n \n-      this.$('#search-input').val(keywords);\n+      var query = this.$('.search-input').val();\n \n-      this.searchTickets(keywords);\n+      if (!_.isEmpty(query)) {\n+        this.searchTickets(query);\n+      }\n     },\n \n-    handleResults: function(data) {\n-      var ticketId = this.ticket().id();\n+    onSearchDone: function(data) {\n+      var currentTicketId = this.ticket().id(),\n+          tickets = data.results.slice(0,10);\n \n-      if (ticketId) {\n+      if (currentTicketId) {\n         // remove current ticket from results\n-        this.relatedTickets.results = _.reject(data.results, function(result) {\n-          return result.id === ticketId;\n+        tickets = _.reject(tickets, function(ticket) {\n+          return ticket.id === currentTicketId;\n         });\n-      } else {\n-        this.relatedTickets.results = data.results;\n-      }\n-\n-      if (this.relatedTickets.results.length > 10) {\n-        this.relatedTickets.results = this.relatedTickets.results.slice(0,10);\n       }\n \n-      _.each(this.relatedTickets.results, function(result) {\n-        result.description = result.description.substr(0,300).concat(\"...\");\n+      _.each(tickets, function(ticket) {\n+        ticket.description = ticket.description.substr(0,300).concat(\"...\");","path":"app.js","position":120,"original_position":120,"commit_id":"a4fe19521107d92107dfa6845bc1e9f44561920c","original_commit_id":"a4fe19521107d92107dfa6845bc1e9f44561920c","user":{"login":"pi3r","id":330573,"avatar_url":"https://avatars.githubusercontent.com/u/330573?","gravatar_id":"3239561bdf46bfb395ddccb142db2213","url":"https://api.github.com/users/pi3r","html_url":"https://github.com/pi3r","followers_url":"https://api.github.com/users/pi3r/followers","following_url":"https://api.github.com/users/pi3r/following{/other_user}","gists_url":"https://api.github.com/users/pi3r/gists{/gist_id}","starred_url":"https://api.github.com/users/pi3r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pi3r/subscriptions","organizations_url":"https://api.github.com/users/pi3r/orgs","repos_url":"https://api.github.com/users/pi3r/repos","events_url":"https://api.github.com/users/pi3r/events{/privacy}","received_events_url":"https://api.github.com/users/pi3r/received_events","type":"User","site_admin":false},"body":"I think so, it's legacy code, I can change it if you want, maybe use css to concat instead of js.","created_at":"2014-04-25T15:01:58Z","updated_at":"2014-04-25T15:01:58Z","html_url":"https://github.com/zendesk/related_tickets_app/pull/8#discussion_r12000287","pull_request_url":"https://api.github.com/repos/zendesk/related_tickets_app/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/zendesk/related_tickets_app/pulls/comments/12000287"},"html":{"href":"https://github.com/zendesk/related_tickets_app/pull/8#discussion_r12000287"},"pull_request":{"href":"https://api.github.com/repos/zendesk/related_tickets_app/pulls/8"}}}}