<commit_before>faber.controller 'EditorController', ($rootScope, $scope, $controller, $log, contentService, componentsService, faberConfig) ->

  # extends BlockController
  $controller('BlockController', {$scope: $scope})

  $rootScope.$watch 'expanded', (newValue)->
    $rootScope.$broadcast if $rootScope.expanded then 'ExpandAll' else 'CollapseAll'

  # a flag to tell this is the top level block so it can have top level only components available
  $scope.isTopLevel = true

  $scope.block.blocks = contentService.getAll()

  # inherit from faberConfig if it is set when faber is initialised otherwise true by default
  $rootScope.expanded = if angular.isDefined faberConfig.expanded then faberConfig.expanded else true

  # initialise components service with the given components list
  componentsService.init(faberConfig.components or [])

  validateElementBlock = (block) ->
    if $scope.validateBlock block
      if block.blocks?.length > 0
        block.blocks = validateImported block.blocks
    return block

  validateGroupBlock = (block) ->
    if block.blocks?.length > 0
      for groupItem in block.blocks
        if groupItem.blocks?.length > 0
          groupItem.blocks = validateImported groupItem.blocks
    return block

  # validate the imported blocks at block level validation
  # at the block level validation, if the component set to the block is not found, the block will be removed trom the tree
  validateImported = (blocks) ->
    validated = []

    for block in blocks
      component = componentsService.findByTemplate block.component
      if component
        if component.type is 'element'
          validated.push validateElementBlock(block)
        if component.type is 'group'
          validated.push validateGroupBlock(block)
      else
        $log.warn 'cannot find a component of the given template': block.component
<commit_msg>Condition fix<commit_after>faber.controller 'EditorController', ($rootScope, $scope, $controller, $log, contentService, componentsService, faberConfig) ->

  # extends BlockController
  $controller('BlockController', {$scope: $scope})

  $rootScope.$watch 'expanded', (newValue)->
    $rootScope.$broadcast if $rootScope.expanded then 'ExpandAll' else 'CollapseAll'

  # a flag to tell this is the top level block so it can have top level only components available
  $scope.isTopLevel = true

  $scope.block.blocks = contentService.getAll()

  # inherit from faberConfig if it is set when faber is initialised otherwise true by default
  $rootScope.expanded = if angular.isDefined faberConfig.expanded then faberConfig.expanded else true

  # initialise components service with the given components list
  componentsService.init(faberConfig.components or [])

  validateElementBlock = (block) ->
    if $scope.validateBlock block and block.blocks?.length > 0
        block.blocks = validateImported block.blocks
    return block

  validateGroupBlock = (block) ->
    if block.blocks?.length > 0
      for groupItem in block.blocks
        if groupItem.blocks?.length > 0
          groupItem.blocks = validateImported groupItem.blocks
    return block

  # validate the imported blocks at block level validation
  # at the block level validation, if the component set to the block is not found, the block will be removed trom the tree
  validateImported = (blocks) ->
    validated = []

    for block in blocks
      component = componentsService.findByTemplate block.component
      if component
        if component.type is 'element'
          validated.push validateElementBlock(block)
        if component.type is 'group'
          validated.push validateGroupBlock(block)
      else
        $log.warn 'cannot find a component of the given template': block.component

{'fraction_non_alphanumeric': 0.07522005868231528, 'fraction_numerical': 0.0016004267804747934, 'mean_word_length': 3.6182266009852215, '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': '5444115', 'n_tokens_mistral': 982, 'n_tokens_neox': 951, 'n_words': 355}