<commit_before>module ApplicationController::TreeSupport
  extend ActiveSupport::Concern

  def squash_toggle
    @record = find_record
    item = "h_#{@record.name}"
    render :update do |page|
      page << javascript_prologue
      if session[:squash_open] == false
        page << "$('#squash_img i').attr('class','fa fa-angle-double-up fa-lg')"
        page << "$('#squash_img').prop('title', 'Collapse All')"
        page << "miqDynatreeToggleExpand('#{j_str(session[:tree_name])}', true)"
        session[:squash_open] = true
      else
        page << "$('#squash_img i').attr('class','fa fa-angle-double-down fa-lg')"
        page << "$('#squash_img').prop('title', 'Expand All')"
        page << "miqDynatreeToggleExpand('#{j_str(session[:tree_name])}', false);"
        page << "miqDynatreeActivateNodeSilently('#{j_str(session[:tree_name])}', '#{item}');"
        session[:squash_open] = false
      end
    end
  end

  def find_record
    if %w(container_image host).include? controller_name
      identify_record(params[:id], controller_name.classify)
    else
      identify_record(params[:id], VmOrTemplate)
    end
  end

  def tree_autoload_dynatree
    @edit ||= session[:edit]  # Remember any previous @edit
    klass_name = x_tree[:klass_name] if x_active_tree
    nodes = klass_name ? TreeBuilder.tree_add_child_nodes(@sb, klass_name, params[:id]) :
        tree_add_child_nodes(params[:id])
    render :json => nodes
  end

  def tree_autoload_quads
    # set temp list of hosts/vms to be shown on DC tree on mousein event
    build_vm_host_array if !@sb[:tree_hosts_hash].blank? || !@sb[:tree_vms_hash].blank?
    render :update do |page|
      page << javascript_prologue
      if !@sb[:tree_hosts_hash].blank? || !@sb[:tree_vms_hash].blank?
        page.replace("dc_tree_quads_div", :partial => "layouts/dc_tree_quads")
      end
      page << "miqSparkle(false);"
    end
  end

  private ############################

  # Build a compliance history tree
  def compliance_history_tree(rec, count)
    t_kids = []                          # Array to hold node children
    rec.compliances.order("timestamp DESC").limit(count).each do |c|
      c_node = TreeNodeBuilder.generic_tree_node(
        "c_#{c.id}",
        format_timezone(c.timestamp, Time.zone, 'gtl'),
        "#{c.compliant ? "check" : "x"}.png",
        nil,
        :style_class => "cfme-no-cursor-node"
      )
      c_node[:title] = "<b>" + __("Compliance Check on:") + "</b>" + c_node[:title].to_s
      c_kids = []
      temp_pol_id = nil
      p_node = {}
      p_kids = []
      c.compliance_details.order("miq_policy_desc, condition_desc").each do |d|
        if d.miq_policy_id != temp_pol_id<commit_msg>Fixed wrong gettext call introduced by internationalization<commit_after>module ApplicationController::TreeSupport
  extend ActiveSupport::Concern

  def squash_toggle
    @record = find_record
    item = "h_#{@record.name}"
    render :update do |page|
      page << javascript_prologue
      if session[:squash_open] == false
        page << "$('#squash_img i').attr('class','fa fa-angle-double-up fa-lg')"
        page << "$('#squash_img').prop('title', 'Collapse All')"
        page << "miqDynatreeToggleExpand('#{j_str(session[:tree_name])}', true)"
        session[:squash_open] = true
      else
        page << "$('#squash_img i').attr('class','fa fa-angle-double-down fa-lg')"
        page << "$('#squash_img').prop('title', 'Expand All')"
        page << "miqDynatreeToggleExpand('#{j_str(session[:tree_name])}', false);"
        page << "miqDynatreeActivateNodeSilently('#{j_str(session[:tree_name])}', '#{item}');"
        session[:squash_open] = false
      end
    end
  end

  def find_record
    if %w(container_image host).include? controller_name
      identify_record(params[:id], controller_name.classify)
    else
      identify_record(params[:id], VmOrTemplate)
    end
  end

  def tree_autoload_dynatree
    @edit ||= session[:edit]  # Remember any previous @edit
    klass_name = x_tree[:klass_name] if x_active_tree
    nodes = klass_name ? TreeBuilder.tree_add_child_nodes(@sb, klass_name, params[:id]) :
        tree_add_child_nodes(params[:id])
    render :json => nodes
  end

  def tree_autoload_quads
    # set temp list of hosts/vms to be shown on DC tree on mousein event
    build_vm_host_array if !@sb[:tree_hosts_hash].blank? || !@sb[:tree_vms_hash].blank?
    render :update do |page|
      page << javascript_prologue
      if !@sb[:tree_hosts_hash].blank? || !@sb[:tree_vms_hash].blank?
        page.replace("dc_tree_quads_div", :partial => "layouts/dc_tree_quads")
      end
      page << "miqSparkle(false);"
    end
  end

  private ############################

  # Build a compliance history tree
  def compliance_history_tree(rec, count)
    t_kids = []                          # Array to hold node children
    rec.compliances.order("timestamp DESC").limit(count).each do |c|
      c_node = TreeNodeBuilder.generic_tree_node(
        "c_#{c.id}",
        format_timezone(c.timestamp, Time.zone, 'gtl'),
        "#{c.compliant ? "check" : "x"}.png",
        nil,
        :style_class => "cfme-no-cursor-node"
      )
      c_node[:title] = "<b>" + _("Compliance Check on:") + "</b>" + c_node[:title].to_s
      c_kids = []
      temp_pol_id = nil
      p_node = {}
      p_kids = []
      c.compliance_details.order("miq_policy_desc, condition_desc").each do |d|
        if d.miq_policy_id != temp_pol_id
{'fraction_non_alphanumeric': 0.15429723291185632, 'fraction_numerical': 0.0, 'mean_word_length': 3.2875098193244305, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 13, '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': '5996229', 'n_tokens_mistral': 1869, 'n_tokens_neox': 1824, 'n_words': 357}