<commit_before>module EmsCommon
  extend ActiveSupport::Concern

  def gtl_url
    restful? ? '/' : '/show'
  end

  def show_download
    get_tagdata(@ems)
    drop_breadcrumb(:name => @ems.name + _(" (Summary)"), :url => show_link(@ems))
    @showtype = "main"
    set_summary_pdf_data
  end

  def show_main
    get_tagdata(@ems)
    drop_breadcrumb(:name => @ems.name + _(" (Summary)"), :url => show_link(@ems))
    @showtype = "main"
  end

  def show_props
    drop_breadcrumb(:name => @ems.name + _(" (Properties)"), :url => show_link(@ems, :display  =>  "props"))
  end

  def show_ems_folders
    if params[:vat]
      drop_breadcrumb(:name => @ems.name + _(" (VMs & Templates)"),
                      :url  => show_link(@ems, :display => "ems_folder", :vat => "true"))
    else
      drop_breadcrumb(:name => @ems.name + _(" (Hosts & Clusters)"),
                      :url  => show_link(@ems, :display => "ems_folders"))
    end
    @showtype = "config"

    cluster = @record
    @datacenter_tree = TreeBuilderVat.new(:vat_tree, :vat, @sb, true, cluster, !!params[:vat])
    self.x_active_tree = :vat_tree
  end

  def show_timeline
    @showtype = "timeline"
    session[:tl_record_id] = params[:id] if params[:id]
    @record = find_by_id_filtered(model, session[:tl_record_id])
    @timeline = @timeline_filter = true
    @lastaction = "show_timeline"
    tl_build_timeline # Create the timeline report
    drop_breadcrumb(:name => _("Timelines"), :url => show_link(@record, :refresh => "n", :display => "timeline"))
  end

  def show_dashboard
    @showtype = "dashboard"
    @lastaction = "show_dashboard"
    drop_breadcrumb(:name => @ems.name + _(" (Dashboard)"), :url => show_link(@ems))
  end

  def show_ad_hoc_metrics
    @showtype = "ad_hoc_metrics"
    @lastaction = "show_ad_hoc_metrics"
    drop_breadcrumb(:name => @ems.name + _(" (Ad hoc Metrics)"), :url => show_link(@ems))
  end

  def show_topology
    @showtype = "topology"
    @lastaction = "show_topology"
    drop_breadcrumb(:name => @ems.name + _(" (Topology)"), :url => show_link(@ems))
  end

  def show_performance
    @showtype = "performance"
    drop_breadcrumb(:name => _("%{name} Capacity & Utilization") % {:name => @record.name},
                    :url  => "/#{@table_name}/show/#{@record.id}?display=#{@display}&refresh=n")
    perf_gen_init_options # Initialize perf chart options, charts will be generated async
  end

  def view_setup_params
    {
      "instances"                     => [ManageIQ::Providers::CloudManager::Vm, _("Instances")],
      "images"                        => [ManageIQ::Providers::CloudManager::Template, _("Images")],
      "block_storage_managers"        => [ManageIQ::Providers::StorageManager,
                                          _("Block Storage Managers"),
                                          :block_storage_managers],
      "object_storage_managers"       => [ManageIQ::Providers::StorageManager,
                                          _("Object Storage Managers"),
                                          :object_storage_managers],
      "storage_managers"              => [ManageIQ::Providers::StorageManager,
                                          _("Storage Managers"),
                                          :storage_managers],
      "miq_templates"                 => [MiqTemplate,            _("Templates")],
      "vms"                           => [Vm,                     _("VMs")],
      "orchestration_stacks"          => [OrchestrationStack,     _("Stacks")],
      # "configuration_jobs"            => [ConfigurationJob, _("Configuration Jobs")],
      "cloud_object_store_containers" => [CloudObjectStoreContainer, _('Cloud Object Store Containers')],
      'containers'                    => [Container,              _('Containers')],
      'container_replicators'         => [ContainerReplicator,    _('Container Replicators')],
      'container_nodes'               => [ContainerNode,          _('Container Nodes')],
      'container_groups'              => [ContainerGroup,         _('Pods')],
      'container_services'            => [ContainerService,       _('Container Services')],
      'container_images'              => [ContainerImage,         _('Container Images')],
      'container_routes'              => [ContainerRoute,         _('Container Routes')],
      'container_builds'              => [ContainerBuild,         _('Container Builds')],
      'container_projects'            => [ContainerProject,       _('Container Projects')],
      'container_image_registries'    => [ContainerImageRegistry, _('Container Image Registries')],
      'container_templates'           => [ContainerTemplate,      _('Container Templates')],
      'availability_zones'            => [AvailabilityZone,       _('Availability Zones')],
      'host_aggregates'               => [HostAggregate,          _('Host Aggregates')],
      'middleware_servers'            => [MiddlewareServer,       _('Middleware Servers')],
      'middleware_deployments'        => [MiddlewareDeployment,   _('Middleware Deployments')],
      'middleware_datasources'        => [MiddlewareDatasource,   _('Middleware Datasources')],
      'middleware_domains'            => [MiddlewareDomain,       _('Middleware Domains')],
      'middleware_server_groups'      => [MiddlewareServerGroup,  _('Middleware Server Groups')],
      'middleware_messagings'         => [MiddlewareMessaging,    _('Middleware Messagings')],
      'cloud_tenants'                 => [CloudTenant,            _('Cloud Tenants')],
      'cloud_volumes'                 => [CloudVolume,            _('Cloud Volumes')],
      'flavors'                       => [Flavor,                 _('Flavors')],
      'security_groups'               => [SecurityGroup,          _('Security Groups')],
      'floating_ips'                  => [FloatingIp,             _('Floating IPs')],
      'network_routers'               => [NetworkRouter,          _('Network Routers')],
      'network_ports'                 => [NetworkPort,            _('Network Ports')],
      'cloud_subnets'                 => [CloudSubnet,            _('Cloud Subnets')],
      'cloud_networks'                => [CloudNetwork,           _('Cloud Networks')],
      'load_balancers'                => [LoadBalancer,           _('Load Balancers')],
      'storages'                      => [Storage,                _('Managed Datastores')],
      'ems_clusters'                  => [EmsCluster,             title_for_clusters],
      'persistent_volumes'            => [PersistentVolume,       _('Volumes'), :persistent_volumes],
      'hosts'                         => [Host,                   _("Managed Hosts")],
    }
  end

  def show_entities(display)
    view_setup_helper(display, *view_setup_params[display])
  end

  def show
    @display = params[:display] || "main" unless control_selected?

    session[:vm_summary_cool] = (settings(:views, :vm_summary_cool).to_s == "summary")
    @summary_view = session[:vm_summary_cool]
    @ems = @record = identify_record(params[:id])
    return if record_no_longer_exists?(@ems)

    @gtl_url = gtl_url
    @showtype = "config"
    drop_breadcrumb({:name => ui_lookup(:tables => @table_name), :url => "/#{@table_name}/show_list?page=#{@current_page}&refresh=y"}, true)

    case params[:display]
    when 'main'                          then show_main
    when 'download_pdf', 'summary_only'  then show_download
    when 'props'                         then show_props
    when 'ems_folders'                   then show_ems_folders
    when 'timeline'                      then show_timeline
    when 'dashboard'                     then show_dashboard
    when 'ad_hoc_metrics'                then show_ad_hoc_metrics
    when 'topology'                      then show_topology
    when 'performance'                   then show_performance
    when nil
      if control_selected? # pagination controls
        show_entities(@display) # display loaded from session
      else                 # or default display
        show_main
      end
    else show_entities(params[:display])
    end

    @lastaction = "show"
    session[:tl_record_id] = @record.id

    # Came in from outside show_list partial
    if params[:ppsetting] || params[:searchtag] || params[:entry] || params[:sort_choice]
      replace_gtl_main_div
    end

    render :template => "shared/views/ems_common/show" if params[:action] == 'show' && !performed?
  end

  def view_setup_helper(display, kls, title, parent_method = nil)
    drop_breadcrumb(:name => @ems.name + _(" (All %{title})") % {:title => title},
                    :url  => show_link(@ems, :display => display))
    opts = {:parent => @ems}
    opts[:parent_method] = parent_method if parent_method
    @view, @pages = get_view(kls, **opts)

    # display need's to be set so that it's stored in the session
    @showtype = @display = display
  end

  # Show the main MS list view
  def show_list
    process_show_list
  end

  def new
    @doc_url = provider_documentation_url
    assert_privileges("#{permission_prefix}_new")
    @ems = model.new
    set_form_vars
    @in_a_form = true
    session[:changed] = nil
    drop_breadcrumb(:name => _("Add New %{table}") % {:table => ui_lookup(:table => @table_name)},<commit_msg>EmsCommon: use GenericShow mixin.<commit_after>module EmsCommon
  extend ActiveSupport::Concern

  def show_props
    drop_breadcrumb(:name => @ems.name + _(" (Properties)"), :url => show_link(@ems, :display  =>  "props"))
  end

  def show_ems_folders
    if params[:vat]
      drop_breadcrumb(:name => @ems.name + _(" (VMs & Templates)"),
                      :url  => show_link(@ems, :display => "ems_folder", :vat => "true"))
    else
      drop_breadcrumb(:name => @ems.name + _(" (Hosts & Clusters)"),
                      :url  => show_link(@ems, :display => "ems_folders"))
    end
    @showtype = "config"

    cluster = @record
    @datacenter_tree = TreeBuilderVat.new(:vat_tree, :vat, @sb, true, cluster, !!params[:vat])
    self.x_active_tree = :vat_tree
  end

  def show_timeline
    @showtype = "timeline"
    session[:tl_record_id] = params[:id] if params[:id]
    @record = find_by_id_filtered(model, session[:tl_record_id])
    @timeline = @timeline_filter = true
    @lastaction = "show_timeline"
    tl_build_timeline # Create the timeline report
    drop_breadcrumb(:name => _("Timelines"), :url => show_link(@record, :refresh => "n", :display => "timeline"))
  end

  def show_dashboard
    @showtype = "dashboard"
    @lastaction = "show_dashboard"
    drop_breadcrumb(:name => @ems.name + _(" (Dashboard)"), :url => show_link(@ems))
  end

  def show_ad_hoc_metrics
    @showtype = "ad_hoc_metrics"
    @lastaction = "show_ad_hoc_metrics"
    drop_breadcrumb(:name => @ems.name + _(" (Ad hoc Metrics)"), :url => show_link(@ems))
  end

  def show_topology
    @showtype = "topology"
    @lastaction = "show_topology"
    drop_breadcrumb(:name => @ems.name + _(" (Topology)"), :url => show_link(@ems))
  end

  def show_performance
    @showtype = "performance"
    drop_breadcrumb(:name => _("%{name} Capacity & Utilization") % {:name => @record.name},
                    :url  => "/#{@table_name}/show/#{@record.id}?display=#{@display}&refresh=n")
    perf_gen_init_options # Initialize perf chart options, charts will be generated async
  end

  def view_setup_params
    {
      "instances"                     => [ManageIQ::Providers::CloudManager::Vm, _("Instances")],
      "images"                        => [ManageIQ::Providers::CloudManager::Template, _("Images")],
      "block_storage_managers"        => [ManageIQ::Providers::StorageManager,
                                          _("Block Storage Managers"),
                                          :block_storage_managers],
      "object_storage_managers"       => [ManageIQ::Providers::StorageManager,
                                          _("Object Storage Managers"),
                                          :object_storage_managers],
      "storage_managers"              => [ManageIQ::Providers::StorageManager,
                                          _("Storage Managers"),
                                          :storage_managers],
      "miq_templates"                 => [MiqTemplate,            _("Templates")],
      "vms"                           => [Vm,                     _("VMs")],
      "orchestration_stacks"          => [OrchestrationStack,     _("Stacks")],
      # "configuration_jobs"            => [ConfigurationJob, _("Configuration Jobs")],
      "cloud_object_store_containers" => [CloudObjectStoreContainer, _('Cloud Object Store Containers')],
      'containers'                    => [Container,              _('Containers')],
      'container_replicators'         => [ContainerReplicator,    _('Container Replicators')],
      'container_nodes'               => [ContainerNode,          _('Container Nodes')],
      'container_groups'              => [ContainerGroup,         _('Pods')],
      'container_services'            => [ContainerService,       _('Container Services')],
      'container_images'              => [ContainerImage,         _('Container Images')],
      'container_routes'              => [ContainerRoute,         _('Container Routes')],
      'container_builds'              => [ContainerBuild,         _('Container Builds')],
      'container_projects'            => [ContainerProject,       _('Container Projects')],
      'container_image_registries'    => [ContainerImageRegistry, _('Container Image Registries')],
      'container_templates'           => [ContainerTemplate,      _('Container Templates')],
      'availability_zones'            => [AvailabilityZone,       _('Availability Zones')],
      'host_aggregates'               => [HostAggregate,          _('Host Aggregates')],
      'middleware_servers'            => [MiddlewareServer,       _('Middleware Servers')],
      'middleware_deployments'        => [MiddlewareDeployment,   _('Middleware Deployments')],
      'middleware_datasources'        => [MiddlewareDatasource,   _('Middleware Datasources')],
      'middleware_domains'            => [MiddlewareDomain,       _('Middleware Domains')],
      'middleware_server_groups'      => [MiddlewareServerGroup,  _('Middleware Server Groups')],
      'middleware_messagings'         => [MiddlewareMessaging,    _('Middleware Messagings')],
      'cloud_tenants'                 => [CloudTenant,            _('Cloud Tenants')],
      'cloud_volumes'                 => [CloudVolume,            _('Cloud Volumes')],
      'flavors'                       => [Flavor,                 _('Flavors')],
      'security_groups'               => [SecurityGroup,          _('Security Groups')],
      'floating_ips'                  => [FloatingIp,             _('Floating IPs')],
      'network_routers'               => [NetworkRouter,          _('Network Routers')],
      'network_ports'                 => [NetworkPort,            _('Network Ports')],
      'cloud_subnets'                 => [CloudSubnet,            _('Cloud Subnets')],
      'cloud_networks'                => [CloudNetwork,           _('Cloud Networks')],
      'load_balancers'                => [LoadBalancer,           _('Load Balancers')],
      'storages'                      => [Storage,                _('Managed Datastores')],
      'ems_clusters'                  => [EmsCluster,             title_for_clusters],
      'persistent_volumes'            => [PersistentVolume,       _('Volumes'), :persistent_volumes],
      'hosts'                         => [Host,                   _("Managed Hosts")],
    }
  end

  def show_entities(display)
    view_setup_helper(display, *view_setup_params[display])
  end

  def show
    return unless init_show
    session[:vm_summary_cool] = (settings(:views, :vm_summary_cool).to_s == "summary")
    @summary_view = session[:vm_summary_cool]
    @ems = @record

    drop_breadcrumb({:name => ui_lookup(:tables => @table_name), :url => "/#{@table_name}/show_list?page=#{@current_page}&refresh=y"}, true)

    case params[:display]
    when 'main'                          then show_main
    when 'download_pdf', 'summary_only'  then show_download
    when 'props'                         then show_props
    when 'ems_folders'                   then show_ems_folders
    when 'timeline'                      then show_timeline
    when 'dashboard'                     then show_dashboard
    when 'ad_hoc_metrics'                then show_ad_hoc_metrics
    when 'topology'                      then show_topology
    when 'performance'                   then show_performance
    when nil
      if control_selected? # pagination controls
        show_entities(@display) # display loaded from session
      else                 # or default display
        show_main
      end
    else show_entities(params[:display])
    end

    @lastaction = "show"
    session[:tl_record_id] = @record.id

    replace_gtl_main_div if is_gtl_request?
    render :template => "shared/views/ems_common/show" if params[:action] == 'show' && !performed?
  end

  def view_setup_helper(display, kls, title, parent_method = nil)
    drop_breadcrumb(:name => @ems.name + _(" (All %{title})") % {:title => title},
                    :url  => show_link(@ems, :display => display))
    opts = {:parent => @ems}
    opts[:parent_method] = parent_method if parent_method
    @view, @pages = get_view(kls, **opts)

    # display need's to be set so that it's stored in the session
    @showtype = @display = display
  end

  # Show the main MS list view
  def show_list
    process_show_list
  end

  def new
    @doc_url = provider_documentation_url
    assert_privileges("#{permission_prefix}_new")
    @ems = model.new
    set_form_vars
    @in_a_form = true
    session[:changed] = nil
    drop_breadcrumb(:name => _("Add New %{table}") % {:table => ui_lookup(:table => @table_name)},
{'fraction_non_alphanumeric': 0.1299098698119506, 'fraction_numerical': 0.0, 'mean_word_length': 2.2528049221860296, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 163, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 31, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7293563', 'n_tokens_mistral': 5251, 'n_tokens_neox': 5103, 'n_words': 1026}