<commit_before>class TreeBuilderReportReports < TreeBuilderReportReportsClass
  private

  def initialize(name, type, sandbox, build = true)
    @rpt_menu  = sandbox[:rpt_menu]
    @grp_title = sandbox[:grp_title]
    super(name, type, sandbox, build = true)
  end

  def tree_init_options(tree_name)
    {
      :leaf     => 'full_ids',
      :full_ids => true
    }
  end

  def set_locals_for_render
    locals = super
    locals.merge!(:autoload => true)
  end

  def root_options
    {
      :title   => t = _("All Reports"),
      :tooltip => t
    }
  end

  # Get root nodes count/array for explorer tree
  def x_get_tree_roots(count_only, options)
    objects = []
    @rpt_menu.each_with_index do |r, i|
      objects.push(
        :id    => i.to_s,
        :text  => r[0],
        :icon  => "pficon #{@grp_title == r[0] ? 'pficon-folder-close-blue' : 'pficon-folder-close'}",
        :tip   => r[0]
      )
      # load next level of folders when building the tree
      @tree_state.x_tree(options[:tree])[:open_nodes].push("xx-#{i}")
    end
    count_only_or_objects(count_only, objects)
  end

  def x_get_tree_custom_kids(object, count_only, _options)
    objects = []
    nodes = object[:full_id] ? object[:full_id].split('-') : object[:id].to_s.split('-')
    if nodes.length == 1 && @rpt_menu[nodes.last.to_i][1].kind_of?(Array)
      @rpt_menu[nodes.last.to_i][1].each_with_index do |r, i|
        objects.push(
          :id    => "#{nodes.last.split('-').last}-#{i}",
          :text  => r[0],
          :icon  => "pficon #{@grp_title == @rpt_menu[nodes.last.to_i][0] ? 'pficon-folder-close-blue' : 'pficon-folder-close'}",
          :tip   => r[0]
        )
      end
    elsif nodes.length >= 2 # || (object[:full_id] && object[:full_id].split('_').length == 2)
      el1 = nodes.length == 2 ? nodes[0].split('_').first.to_i : nodes[1].split('_').first.to_i
      @rpt_menu[el1][1][nodes.last.to_i][1].each_with_index do |r|
        objects.push(MiqReport.find_by_name(r))
        # break after adding 1 report for a count_only,
        # don't need to go thru them all to determine if node has children
        break if count_only
      end
    end
    count_only_or_objects(count_only, objects)
  end
end
<commit_msg>TreeBuilderReportReports no db counts<commit_after>class TreeBuilderReportReports < TreeBuilderReportReportsClass
  private

  def initialize(name, type, sandbox, build = true)
    @rpt_menu  = sandbox[:rpt_menu]
    @grp_title = sandbox[:grp_title]
    super(name, type, sandbox, build = true)
  end

  def tree_init_options(tree_name)
    {
      :leaf     => 'full_ids',
      :full_ids => true
    }
  end

  def set_locals_for_render
    locals = super
    locals.merge!(:autoload => true)
  end

  def root_options
    {
      :title   => t = _("All Reports"),
      :tooltip => t
    }
  end

  # Get root nodes count/array for explorer tree
  def x_get_tree_roots(count_only, options)
    objects = @rpt_menu.each_with_index.map do |r, i|
      # load next level of folders when building the tree
      @tree_state.x_tree(options[:tree])[:open_nodes].push("xx-#{i}")
      folder_hash(i.to_s, r[0], @grp_title == r[0])
    end
    count_only_or_objects(count_only, objects)
  end

  def x_get_tree_custom_kids(object, count_only, _options)
    nodes = object[:full_id] ? object[:full_id].split('-') : object[:id].to_s.split('-')
    node_id = nodes.last.to_i
    if nodes.length == 1 && @rpt_menu[node_id][1].kind_of?(Array)
      child_names = @rpt_menu[node_id][1]
      return child_names.size if count_only
      child_names.each_with_index.map do |r, i|
        folder_hash("#{node_id}-#{i}", r[0], @grp_title == @rpt_menu[node_id][0])
      end
    elsif nodes.length >= 2
      el1 = nodes.length == 2 ? nodes[0].split('_').first.to_i : nodes[1].split('_').first.to_i
      child_names = @rpt_menu[el1][1][node_id][1]
      return child_names.size if count_only
      MiqReport.where(:name => child_names)
    end
  end

  def folder_hash(id, text, blue)
    {
      :id    => id,
      :text  => text,
      :icon  => "pficon #{blue ? 'pficon-folder-close-blue' : 'pficon-folder-close'}",
      :tip   => text
    }
  end
end

{'fraction_non_alphanumeric': 0.14579349904397707, 'fraction_numerical': 0.008126195028680689, 'mean_word_length': 2.907563025210084, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, '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': '1360409', 'n_tokens_mistral': 1544, 'n_tokens_neox': 1530, 'n_words': 304}