<commit_before>module = angular.module('impac.components.widgets.hr-payroll-taxes',[])

module.controller('WidgetHrPayrollTaxesCtrl', ($scope, $q, ChartFormatterSvc, $filter, $translate) ->

  w = $scope.widget

  # Define settings
  # --------------------------------------
  $scope.orgDeferred = $q.defer()
  $scope.timePeriodDeferred = $q.defer()
  $scope.histModeDeferred = $q.defer()
  $scope.chartDeferred = $q.defer()

  settingsPromises = [
    $scope.orgDeferred.promise
    $scope.timePeriodDeferred.promise
    $scope.histModeDeferred.promise
    $scope.chartDeferred.promise
  ]


  # Widget specific methods
  # --------------------------------------
  w.initContext = ->
    $scope.isDataFound = w.content? && !_.isEmpty(w.content.total_tax) && !_.isEmpty(w.content.dates)

  $scope.getCurrentPrice = ->
    return _.last w.content.total_tax if $scope.isDataFound

  $scope.getCurrency = ->
    return w.content.currency || "USD" if $scope.isDataFound

  $scope.getPeriod = ->
    if $scope.isDataFound && w.metadata && w.metadata.hist_parameters
      period_param = w.metadata.hist_parameters.period || "MONTHLY"
      period = "day"
      period = period_param.substr(0,period_param.length-2).toLowerCase() if period_param != "DAILY"
      return "(current #{period})"


  # Chart formating function
  # --------------------------------------
  $scope.drawTrigger = $q.defer()
  w.format = ->
    if $scope.isDataFound

      period = null
      period = w.metadata.hist_parameters.period if w.metadata? && w.metadata.hist_parameters?
      dates = _.map w.content.dates, (date) ->
        $filter('mnoDate')(date, period)

      inputData = {title: "Payroll Taxes", labels: dates, values: w.content.total_tax}
      all_values_are_positive = true
      angular.forEach(w.content.total_tax, (value) ->
        all_values_are_positive &&= value >= 0
      )

      options = {
        scaleBeginAtZero: all_values_are_positive,
        showXLabels: false,
      }
      # translate
      $translate('impac.widget.hr_payroll_taxes.payroll_taxes').then((result) ->
        inputData.title = result

        chartData = ChartFormatterSvc.lineChart([inputData],options)

        # calls chart.draw()
        $scope.drawTrigger.notify(chartData)
      )

  # Widget is ready: can trigger the "wait for settigns to be ready"
  # --------------------------------------
  $scope.widgetDeferred.resolve(settingsPromises)
)

module.directive('widgetHrPayrollTaxes', ->
  return {
    restrict: 'A',
    controller: 'WidgetHrPayrollTaxesCtrl',
  }
)
<commit_msg>use an instant translation instead promise callback<commit_after>module = angular.module('impac.components.widgets.hr-payroll-taxes',[])

module.controller('WidgetHrPayrollTaxesCtrl', ($scope, $q, ChartFormatterSvc, $filter, $translate) ->

  w = $scope.widget

  # Define settings
  # --------------------------------------
  $scope.orgDeferred = $q.defer()
  $scope.timePeriodDeferred = $q.defer()
  $scope.histModeDeferred = $q.defer()
  $scope.chartDeferred = $q.defer()

  settingsPromises = [
    $scope.orgDeferred.promise
    $scope.timePeriodDeferred.promise
    $scope.histModeDeferred.promise
    $scope.chartDeferred.promise
  ]


  # Widget specific methods
  # --------------------------------------
  w.initContext = ->
    $scope.isDataFound = w.content? && !_.isEmpty(w.content.total_tax) && !_.isEmpty(w.content.dates)

  $scope.getCurrentPrice = ->
    return _.last w.content.total_tax if $scope.isDataFound

  $scope.getCurrency = ->
    return w.content.currency || "USD" if $scope.isDataFound

  $scope.getPeriod = ->
    if $scope.isDataFound && w.metadata && w.metadata.hist_parameters
      period_param = w.metadata.hist_parameters.period || "MONTHLY"
      period = "day"
      period = period_param.substr(0,period_param.length-2).toLowerCase() if period_param != "DAILY"
      return "(current #{period})"


  # Chart formating function
  # --------------------------------------
  $scope.drawTrigger = $q.defer()
  w.format = ->
    if $scope.isDataFound

      period = null
      period = w.metadata.hist_parameters.period if w.metadata? && w.metadata.hist_parameters?
      dates = _.map w.content.dates, (date) ->
        $filter('mnoDate')(date, period)

      inputData = {title: $translate.instant('impac.widget.hr_payroll_taxes.payroll_taxes'), labels: dates, values: w.content.total_tax}
      all_values_are_positive = true
      angular.forEach(w.content.total_tax, (value) ->
        all_values_are_positive &&= value >= 0
      )

      options = {
        scaleBeginAtZero: all_values_are_positive,
        showXLabels: false,
      }
      chartData = ChartFormatterSvc.lineChart([inputData],options)

      # calls chart.draw()
      $scope.drawTrigger.notify(chartData)

  # Widget is ready: can trigger the "wait for settigns to be ready"
  # --------------------------------------
  $scope.widgetDeferred.resolve(settingsPromises)
)

module.directive('widgetHrPayrollTaxes', ->
  return {
    restrict: 'A',
    controller: 'WidgetHrPayrollTaxesCtrl',
  }
)

{'fraction_non_alphanumeric': 0.18384236453201971, 'fraction_numerical': 0.0011822660098522167, 'mean_word_length': 2.633500357909807, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, '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': '2145624', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1556, 'n_words': 265}