<commit_before>'use strict';

angular.module('BB.Directives').directive 'bbDurations', () ->
  restrict: 'AE'
  replace: true
  scope : true
  controller : 'DurationList'


angular.module('BB.Controllers').controller 'DurationList', ($scope,  $rootScope, PageControllerService, $q, $attrs) ->
  $scope.controller = "public.controllers.DurationList"
  $scope.notLoaded $scope

  angular.extend(this, new PageControllerService($scope, $q))

  $rootScope.connection_started.then ->
    $scope.loadData()
  , (err) ->  $scope.setLoadedAndShowError($scope, err, 'Sorry, something went wrong')


  $scope.loadData = () =>
    id = $scope.bb.company_id
    service = $scope.bb.current_item.service
    if service && !$scope.durations
      $scope.durations =
        (for d in _.zip(service.durations, service.prices)
          {value: d[0], price: d[1]})
      
      initial_duration = $scope.$eval($attrs.bbInitialDuration)

      for duration in $scope.durations
        # does the current item already have a duration?
        if $scope.bb.current_item.duration && duration.value == $scope.bb.current_item.duration
          $scope.duration = duration
        else if initial_duration and initial_duration is duration.value
          $scope.duration = duration
          $scope.bb.current_item.setDuration(duration.value)

        if duration.value < 60
          duration.pretty = duration.value + " minutes"
        else if duration.value == 60
          duration.pretty = "1 hour"
        else
          duration.pretty = Math.floor(duration.value/60) + " hours"
          rem = duration.value % 60
          if rem != 0
            duration.pretty += " " + rem + " minutes"

      if $scope.durations.length == 1
        $scope.skipThisStep()
        $scope.selectDuration($scope.durations[0], $scope.nextRoute)

    $scope.setLoaded $scope


  $scope.selectDuration = (dur, route) =>
    $scope.bb.current_item.setDuration(dur.value)
    if $scope.$parent.$has_page_control
      return<commit_msg>Return closest to original form.<commit_after>'use strict';

angular.module('BB.Directives').directive 'bbDurations', () ->
  restrict: 'AE'
  replace: true
  scope : true
  controller : 'DurationList'


angular.module('BB.Controllers').controller 'DurationList', ($scope,  $rootScope, PageControllerService, $q, $attrs) ->
  $scope.controller = "public.controllers.DurationList"
  $scope.notLoaded $scope

  angular.extend(this, new PageControllerService($scope, $q))

  $rootScope.connection_started.then ->
    $scope.loadData()
  , (err) ->  $scope.setLoadedAndShowError($scope, err, 'Sorry, something went wrong')


  $scope.loadData = () =>
    id = $scope.bb.company_id
    service = $scope.bb.current_item.service
    if service && !$scope.durations
      $scope.durations =
        (for d in _.zip(service.durations, service.prices)
          {value: d[0], price: d[1]})
      
      initial_duration = $scope.$eval($attrs.bbInitialDuration)

      for duration in $scope.durations
        # does the current item already have a duration?
        if $scope.bb.current_item.duration && duration.value == $scope.bb.current_item.duration
          $scope.duration = duration
        else if initial_duration and initial_duration is duration.value
          $scope.duration = duration
          $scope.bb.current_item.setDuration(duration.value)

        if duration.value < 60
          duration.pretty = duration.value + " minutes"
        else if duration.value == 60
          duration.pretty = "1 hour"
        else
          duration.pretty = Math.floor(duration.value/60) + " hours"
          rem = duration.value % 60
          if rem != 0
            duration.pretty += " " + rem + " minutes"

      if $scope.durations.length == 1
        $scope.skipThisStep()
        $scope.selectDuration($scope.durations[0], $scope.nextRoute)

    $scope.setLoaded $scope


  $scope.selectDuration = (dur, route) =>
    $scope.duration = dur
    $scope.bb.current_item.setDuration(dur.value)
    if $scope.$parent.$has_page_control
      return
{'fraction_non_alphanumeric': 0.12700765999505806, 'fraction_numerical': 0.006918705213738572, 'mean_word_length': 2.8773946360153255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '2272341', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1182, 'n_words': 255}