<commit_before>angular.module("doubtfire.tasks.task-comments-viewer", [])

#
# View's the comments for a specific task, and allows new
# comments to be made on a task
#
.directive('taskCommentsViewer', ->
  restrict: 'E'
  templateUrl: 'tasks/task-comments-viewer/task-comments-viewer.tpl.html'
  scope:
    task: '='
    comment: '=?'
    autofocus: '@?'
    refocusOnTaskChange: '@?'
  controller: ($scope, $modal, $state, $timeout, listenerService, currentUser, TaskFeedback, TaskComment, Task, Project, taskService, alertService, projectService, analyticsService) ->
    # Cleanup
    listeners = listenerService.listenTo($scope)

    # Initialise scope comment text
    unless _.isString $scope.comment?.text
      $scope.comment = { text: "" }

    # Watch for initial task
    listeners.push $scope.$watch 'task', (newTask) ->
      return unless newTask?.project? # Must have project for task to be mapped
      $scope.project = newTask.project()
      # Once project is loaded fetch task comments
      TaskComment.query {
        project_id: $scope.project.project_id,
        task_definition_id: $scope.task.task_definition_id
      }, (response) ->
        $scope.task.comments = _.map(response, taskService.mapComment)
        $scope.task.num_new_comments = 0
        scrollDown()
        $scope.focus?() if $scope.refocusOnTaskChange

    # Automatically scroll the inner div to the bottom of comments
    scrollDown = ->
      $timeout ->
        objDiv = document.querySelector("task-comments-viewer .panel-body")
        wrappedResult = angular.element(objDiv)
        wrappedResult[0].scrollTop = wrappedResult[0].scrollHeight

    # Checks for enter keydown
    $scope.enterDown = (editor) ->

      return CodeMirror.Pass

    # Submits a new comment
    $scope.addComment = ->
      $scope.comment.text = $scope.comment.text.trim()
      taskService.addComment $scope.task, $scope.comment.text,
        (success) ->
          $scope.comment.text = ""
          analyticsService.event "View Task Comments", "Added new comment"
          scrollDown()
        (response) ->
          alertService.add("danger", response.data.error, 2000)

    # Deletes existing comment
    $scope.deleteComment = (id) ->
      TaskComment.delete { project_id: $scope.project.project_id, task_definition_id: $scope.task.task_definition_id, id: id },
        (response) ->
          $scope.task.comments = $scope.task.comments.filter (e) -> e.id isnt id
          analyticsService.event "View Task Comments", "Deleted existing comment"
        (response) ->
          alertService.add("danger", response.data.error, 2000)
)
<commit_msg>FIX: Fix comments from not being submitted<commit_after>angular.module("doubtfire.tasks.task-comments-viewer", [])

#
# View's the comments for a specific task, and allows new
# comments to be made on a task
#
.directive('taskCommentsViewer', ->
  restrict: 'E'
  templateUrl: 'tasks/task-comments-viewer/task-comments-viewer.tpl.html'
  scope:
    task: '='
    comment: '=?'
    autofocus: '@?'
    refocusOnTaskChange: '@?'
  controller: ($scope, $modal, $state, $timeout, listenerService, currentUser, TaskFeedback, TaskComment, Task, Project, taskService, alertService, projectService, analyticsService) ->
    # Cleanup
    listeners = listenerService.listenTo($scope)

    # Initialise scope comment text
    unless _.isString $scope.comment?.text
      $scope.comment = { text: "" }

    # Watch for initial task
    listeners.push $scope.$watch 'task', (newTask) ->
      return unless newTask?.project? # Must have project for task to be mapped
      $scope.project = newTask.project()
      # Once project is loaded fetch task comments
      TaskComment.query {
        project_id: $scope.project.project_id,
        task_definition_id: $scope.task.task_definition_id
      }, (response) ->
        $scope.task.comments = _.map(response, taskService.mapComment)
        $scope.task.num_new_comments = 0
        scrollDown()
        $scope.focus?() if $scope.refocusOnTaskChange

    # Automatically scroll the inner div to the bottom of comments
    scrollDown = ->
      $timeout ->
        objDiv = document.querySelector("task-comments-viewer .panel-body")
        wrappedResult = angular.element(objDiv)
        wrappedResult[0].scrollTop = wrappedResult[0].scrollHeight

    # Checks for enter keydown
    $scope.enterDown = (editor) ->
      $scope.addComment()
      return CodeMirror.Pass

    # Submits a new comment
    $scope.addComment = ->
      $scope.comment.text = $scope.comment.text.trim()
      taskService.addComment $scope.task, $scope.comment.text,
        (success) ->
          $scope.comment.text = ""
          analyticsService.event "View Task Comments", "Added new comment"
          scrollDown()
        (response) ->
          alertService.add("danger", response.data.error, 2000)

    # Deletes existing comment
    $scope.deleteComment = (id) ->
      TaskComment.delete { project_id: $scope.project.project_id, task_definition_id: $scope.task.task_definition_id, id: id },
        (response) ->
          $scope.task.comments = $scope.task.comments.filter (e) -> e.id isnt id
          analyticsService.event "View Task Comments", "Deleted existing comment"
        (response) ->
          alertService.add("danger", response.data.error, 2000)
)

{'fraction_non_alphanumeric': 0.12035298535486294, 'fraction_numerical': 0.004130679684566279, 'mean_word_length': 3.017345399698341, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2559843', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1529, 'n_words': 365}