<commit_before>class HostController < ApplicationController
  before_action :check_privileges
  before_action :get_session_data
  after_action :cleanup_action
  after_action :set_session_data

  include Mixins::GenericListMixin
  include Mixins::MoreShowActions

  def show_association(action, display_name, listicon, method, klass, association = nil, conditions = nil)
    set_config(identify_record(params[:id]))
    super
  end

  def download_summary_pdf
    super do
      set_config(@record)
    end
  end

  def show
    return if perfmenu_click?

    @lastaction = "show"
    @showtype = "config"

    @display = params[:display] || "main" unless pagination_or_gtl_request?

    @host = @record = identify_record(params[:id])
    return if record_no_longer_exists?(@host, 'Host')

    @gtl_url = "/show"
    @showtype = "config"
    case @display
    when "main", "summary_only"
      get_tagdata(@host)
      drop_breadcrumb({:name => _("Hosts"), :url => "/host/show_list?page=#{@current_page}&refresh=y"}, true)
      drop_breadcrumb(:name => _("%{name} (Summary)") % {:name => @host.name }, :url => "/host/show/#{@host.id}")
      @showtype = "main"
      set_summary_pdf_data if @display == "summary_only"

    when "devices"
      drop_breadcrumb(:name => _("%{name} (Devices)") % {:name => @host.name},
                      :url  => "/host/show/#{@host.id}?display=devices")

    when "os_info"
      drop_breadcrumb(:name => _("%{name} (OS Information)") % {:name => @host.name},
                      :url  => "/host/show/#{@host.id}?display=os_info")

    when "hv_info"
      drop_breadcrumb(:name => _("%{name} (VM Monitor Information)") % {:name => @host.name},
                      :url  => "/host/show/#{@host.id}?display=hv_info")

    when "network"
      drop_breadcrumb(:name => _("%{name} (Network)") % {:name => @host.name},
                      :url  => "/host/show/#{@host.id}?display=network")

      @network_tree = TreeBuilderNetwork.new(:network_tree, :network, @sb, true, @host)
      self.x_active_tree = :network_tree

    when "performance"
      show_performance

    when "timeline"
      show_timeline

    when "compliance_history"
      show_compliance_history

    when "storage_adapters"
      drop_breadcrumb(:name => _("%{name} (Storage Adapters)") % {:name => @host.name},
                      :url  => "/host/show/#{@host.id}?display=storage_adapters")
      @sa_tree = TreeBuilderStorageAdapters.new(:sa_tree, :sa, @sb, true, @host)
      self.x_active_tree = :sa_tree

    when "miq_templates", "vms"
      title = @display == "vms" ? _("VMs") : _("Templates")
      kls = @display == "vms" ? Vm : MiqTemplate
      drop_breadcrumb(:name => _("%{name} (All %{title})") % {:name => @host.name, :title => title},
                      :url  => "/host/show/#{@host.id}?display=#{@display}")
      @view, @pages = get_view(kls, :parent => @host) # Get the records (into a view) and the paginator
      @showtype = @display

    when "cloud_tenants"
      drop_breadcrumb(:name => _("%{name} (All cloud tenants present on this host)") % {:name => @host.name},
                      :url  => "/host/show/#{@host.id}?display=cloud_tenants")
      @view, @pages = get_view(CloudTenant, :parent => @host) # Get the records (into a view) and the paginator
      @showtype = "cloud_tenants"

    when "resource_pools"
      drop_breadcrumb(:name => _("%{name} (All Resource Pools)") % {:name => @host.name},
                      :url  => "/host/show/#{@host.id}?display=resource_pools")
      @view, @pages = get_view(ResourcePool, :parent => @host)  # Get the records (into a view) and the paginator
      @showtype = "resource_pools"

    when "storages"
      drop_breadcrumb(:name => _("%{name} (All %{tables})") % {:name   => @host.name,
                                                               :tables => ui_lookup(:tables => "storages")},
                      :url  => "/host/show/#{@host.id}?display=storages")
      @view, @pages = get_view(Storage, :parent => @host) # Get the records (into a view) and the paginator
      @showtype = "storages"
    end
    @lastaction = "show"
    session[:tl_record_id] = @record.id

    replace_gtl_main_div if pagination_request?
  end

  def filesystems_subsets
    condition = nil
    label     = _('Files')

    host_service_group = HostServiceGroup.where(:id => params['host_service_group']).first
    if host_service_group
      condition = host_service_group.host_service_group_filesystems_condition
      label     = _("Configuration files of nova service")
    end

    # HACK: UI get_view can't do arel relations, so I need to expose conditions
    condition = condition.to_sql if condition

    return label, condition
  end

  def set_config_local
    set_config(identify_record(params[:id]))
    super
  end
  alias_method :set_config_local, :drift_history
  alias_method :set_config_local, :groups
  alias_method :set_config_local, :patches
  alias_method :set_config_local, :users

  def filesystems
    label, condition = filesystems_subsets
    show_association('filesystems', label, 'filesystems', :filesystems, Filesystem, nil, condition)
  end
<commit_msg>Remove all set_config calls from the HostController<commit_after>class HostController < ApplicationController
  before_action :check_privileges
  before_action :get_session_data
  after_action :cleanup_action
  after_action :set_session_data

  include Mixins::GenericListMixin
  include Mixins::MoreShowActions

  def show
    return if perfmenu_click?

    @lastaction = "show"
    @showtype = "config"

    @display = params[:display] || "main" unless pagination_or_gtl_request?

    @host = @record = identify_record(params[:id])
    return if record_no_longer_exists?(@host, 'Host')

    @gtl_url = "/show"
    @showtype = "config"
    case @display
    when "main", "summary_only"
      get_tagdata(@host)
      drop_breadcrumb({:name => _("Hosts"), :url => "/host/show_list?page=#{@current_page}&refresh=y"}, true)
      drop_breadcrumb(:name => _("%{name} (Summary)") % {:name => @host.name }, :url => "/host/show/#{@host.id}")
      @showtype = "main"
      set_summary_pdf_data if @display == "summary_only"

    when "devices"
      drop_breadcrumb(:name => _("%{name} (Devices)") % {:name => @host.name},
                      :url  => "/host/show/#{@host.id}?display=devices")

    when "os_info"
      drop_breadcrumb(:name => _("%{name} (OS Information)") % {:name => @host.name},
                      :url  => "/host/show/#{@host.id}?display=os_info")

    when "hv_info"
      drop_breadcrumb(:name => _("%{name} (VM Monitor Information)") % {:name => @host.name},
                      :url  => "/host/show/#{@host.id}?display=hv_info")

    when "network"
      drop_breadcrumb(:name => _("%{name} (Network)") % {:name => @host.name},
                      :url  => "/host/show/#{@host.id}?display=network")

      @network_tree = TreeBuilderNetwork.new(:network_tree, :network, @sb, true, @host)
      self.x_active_tree = :network_tree

    when "performance"
      show_performance

    when "timeline"
      show_timeline

    when "compliance_history"
      show_compliance_history

    when "storage_adapters"
      drop_breadcrumb(:name => _("%{name} (Storage Adapters)") % {:name => @host.name},
                      :url  => "/host/show/#{@host.id}?display=storage_adapters")
      @sa_tree = TreeBuilderStorageAdapters.new(:sa_tree, :sa, @sb, true, @host)
      self.x_active_tree = :sa_tree

    when "miq_templates", "vms"
      title = @display == "vms" ? _("VMs") : _("Templates")
      kls = @display == "vms" ? Vm : MiqTemplate
      drop_breadcrumb(:name => _("%{name} (All %{title})") % {:name => @host.name, :title => title},
                      :url  => "/host/show/#{@host.id}?display=#{@display}")
      @view, @pages = get_view(kls, :parent => @host) # Get the records (into a view) and the paginator
      @showtype = @display

    when "cloud_tenants"
      drop_breadcrumb(:name => _("%{name} (All cloud tenants present on this host)") % {:name => @host.name},
                      :url  => "/host/show/#{@host.id}?display=cloud_tenants")
      @view, @pages = get_view(CloudTenant, :parent => @host) # Get the records (into a view) and the paginator
      @showtype = "cloud_tenants"

    when "resource_pools"
      drop_breadcrumb(:name => _("%{name} (All Resource Pools)") % {:name => @host.name},
                      :url  => "/host/show/#{@host.id}?display=resource_pools")
      @view, @pages = get_view(ResourcePool, :parent => @host)  # Get the records (into a view) and the paginator
      @showtype = "resource_pools"

    when "storages"
      drop_breadcrumb(:name => _("%{name} (All %{tables})") % {:name   => @host.name,
                                                               :tables => ui_lookup(:tables => "storages")},
                      :url  => "/host/show/#{@host.id}?display=storages")
      @view, @pages = get_view(Storage, :parent => @host) # Get the records (into a view) and the paginator
      @showtype = "storages"
    end
    @lastaction = "show"
    session[:tl_record_id] = @record.id

    replace_gtl_main_div if pagination_request?
  end

  def filesystems_subsets
    condition = nil
    label     = _('Files')

    host_service_group = HostServiceGroup.where(:id => params['host_service_group']).first
    if host_service_group
      condition = host_service_group.host_service_group_filesystems_condition
      label     = _("Configuration files of nova service")
    end

    # HACK: UI get_view can't do arel relations, so I need to expose conditions
    condition = condition.to_sql if condition

    return label, condition
  end

  alias_method :set_config_local, :drift_history
  alias_method :set_config_local, :groups
  alias_method :set_config_local, :patches
  alias_method :set_config_local, :users

  def filesystems
    label, condition = filesystems_subsets
    show_association('filesystems', label, 'filesystems', :filesystems, Filesystem, nil, condition)
  end

{'fraction_non_alphanumeric': 0.14770240700218817, 'fraction_numerical': 0.0, 'mean_word_length': 3.1310599835661463, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1988770', 'n_tokens_mistral': 3331, 'n_tokens_neox': 3183, 'n_words': 709}