<commit_before>timeTracker.controller('TimerCtrl', ['$scope', 'timer', '$account', '$redmine', '$ticket', '$message', ($scope, timer, $account, $redmine, $ticket, $message) ->

  # ONE_MINUTE = 1000 * 60
  ONE_MINUTE = 1000 * 5 # for develop
  COMMENT_MAX = 255

  hours = 0
  start = null

  $scope.isTracking = false
  $scope.comment = ""
  $scope.commentMaxLength = COMMENT_MAX
  $scope.commentRemain = COMMENT_MAX
  $scope.clickSubmitButton = ->


  ###
   get data from sync Storage, then init.
  ###
  init = ->
    $account.getAccounts (accounts) ->
      if not accounts? or not accounts?[0]? then return
      url    = accounts[0].url
      apiKey = accounts[0].apiKey
      userId = accounts[0].userId
      $scope.clickSubmitButton = -> onClickSubmit(url, apiKey, userId)
      $redmine(url, apiKey).issues.getOnUser(userId, successGetIssues)


  ###
   merge ticket on strage, and update view
  ###
  successGetIssues = (data, status, headers, config) ->
    if not data?.issues? then return
    $ticket.addArray data.issues
    $scope.tickets = $ticket.getSelectable()
    $scope.selectedTicket = $ticket.getSelected()
    $ticket.sync()


  ###
   Start or End Time tracking
  ###
  onClickSubmit = (url, apiKey, userId) ->
    if $scope.isTracking
      $scope.isTracking = false
      timer.stop()
    else
      $scope.isTracking = true
      timer.start()


  ###
   on timer stopped, send time entry.
  ###
  $scope.$on 'timer-stopped', (e, millisec) ->
    if millisec > ONE_MINUTE
      hours = millisec / 1000 / 60 / 60
      $redmine(url, apiKey).issues.submitTime(userId, $scope.comment, hours, submitSuccess, submitError)
      $message.toast "Submitting #{$scope.selectedTicket[0].subject}: #{hours} hr"
    else
      $message.toast 'Too short time entry.'

<commit_msg>use timer<commit_after>timeTracker.controller('TimerCtrl', ['$scope', '$account', '$redmine', '$ticket', '$message', ($scope, $account, $redmine, $ticket, $message) ->

  # ONE_MINUTE = 1
  ONE_MINUTE = 0 # for develop
  COMMENT_MAX = 255

  $scope.isTracking = false
  $scope.comment = ""
  $scope.commentMaxLength = COMMENT_MAX
  $scope.commentRemain = COMMENT_MAX

  _redmine = null

  ###
   get data from sync Storage, then init.
  ###
  init = ->
    $account.getAccounts (accounts) ->
      if not accounts? or not accounts?[0]? then return
      url    = accounts[0].url
      apiKey = accounts[0].apiKey
      userId = accounts[0].userId
      _redmine = $redmine(url, apiKey, userId)
      _redmine.issues.getOnUser(successGetIssues)


  ###
   merge ticket on strage, and update view
  ###
  successGetIssues = (data, status, headers, config) ->
    if not data?.issues? then return
    $ticket.addArray data.issues
    $scope.tickets = $ticket.getSelectable()
    $scope.selectedTicket = $ticket.getSelected()
    $ticket.sync()


  ###
   Start or End Time tracking
  ###
  $scope.clickSubmitButton = () ->
    if $scope.isTracking
      $scope.isTracking = false
      $scope.$broadcast 'timer-stop'
    else
      $scope.isTracking = true
      $scope.$broadcast 'timer-start'


  ###
   on timer stopped, send time entry.
  ###
  $scope.$on 'timer-stopped', (e, time) ->
    if _redmine? and time.minutes >= ONE_MINUTE
      hours = time.minutes / 60
      _redmine.issues.submitTime($scope.comment, hours, submitSuccess, submitError)
      $message.toast "Submitting #{$scope.selectedTicket[0].subject}: #{hours} hr"
    else
      $message.toast 'Too short time entry.'


{'fraction_non_alphanumeric': 0.13970166379804935, 'fraction_numerical': 0.011474469305794608, 'mean_word_length': 3.126627218934911, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '5412702', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1126, 'n_words': 275}