<commit_before># View Service

angular.module('bp.services').service 'bpViewService', deps [
  '$rootScope'
  '$state'
  ], (
  $rootScope
  $state
  ) ->
  direction = 'normal'
  transition = ''

  @to = (state, stateParams = {}) ->
    $state.transitionTo state, stateParams

  # Flexible API paramaters scope.getDirection parameters...
  # 1) fromURL, toURL
  # 2) fromStateName, toStateName
  # 3) options = {from, to}
  @getDirection = (from, to) ->
    dir = 'normal'
    from = '/' if from is '^'
    {to, from} = from if angular.isObject from

    if from
      fromURL = if from.charAt(0) is '/' then from else $state.href from
    else
      fromURL = $state.current.url
    toURL = if to.charAt(0) is '/' then to else $state.href to

    fromURL = fromURL.split '/'
    toURL = toURL.split '/'
    if toURL.length is fromURL.length-1 and
        fromURL.slice(0,fromURL.length-1).join('') is toURL.join('')
      dir = 'reverse'
    dir

  @getFullTransition = -> "#{transition}-#{direction}"

  $rootScope.$on '$stateChangeStart', (
    event
    toState
    toParams
    fromState
    fromParams
    ) =>

    if toParams.direction
      {direction} = toParams
    else
      direction = @getDirection fromState.url, toState.url

    transition =<commit_msg>fix(viewService): detect direction for URL with trailing slash<commit_after># View Service

angular.module('bp.services').service 'bpViewService', deps [
  '$rootScope'
  '$state'
  ], (
  $rootScope
  $state
  ) ->
  direction = 'normal'
  transition = ''

  @to = (state, stateParams = {}) ->
    $state.transitionTo state, stateParams

  # returns array of url segments for url or state (name)
  @_getURISegmentsFrom = (urlOrState) ->
    url =
      if angular.isString urlOrState
        if urlOrState.charAt(0) is '/'
          urlOrState
        else
          $state.href urlOrState
      else if angular.isObject urlOrState and urlOrState.url?
        urlOrState.url

    # remove trailing slashes
    url = url.replace /\/$/, ''

    url.split('/')

  # Flexible API paramaters scope.getDirection parameters...
  # 1) fromURL, toURL
  # 2) fromStateName, toStateName
  # 3) options = {from, to}
  @getDirection = (from, to) ->
    dir = 'normal'
    {to, from} = from if angular.isObject from
    from =  $state.current.url unless from

    return 'none' if from is '^'

    fromURI = @_getURISegmentsFrom from
    toURI = @_getURISegmentsFrom to

    if toURI.length is fromURI.length-1 and
        fromURI.slice(0,fromURI.length-1).join('') is toURI.join('')
      dir = 'reverse'
    else if toURI.length is fromURI.length
      dir = 'none'
    dir

  @getFullTransition = -> "#{transition}-#{direction}"

  $rootScope.$on '$stateChangeStart', (
    event
    toState
    toParams
    fromState
    fromParams
    ) =>

    if toParams.direction
      {direction} = toParams
    else
      direction = @getDirection fromState.url, toState.url

    transition =
{'fraction_non_alphanumeric': 0.12631578947368421, 'fraction_numerical': 0.0050933786078098476, 'mean_word_length': 2.6641791044776117, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '6626857', 'n_tokens_mistral': 975, 'n_tokens_neox': 949, 'n_words': 246}