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

  def index
    @tabform = nil
    @tabform ||= "tasks_1" if role_allows(:feature => "job_my_smartproxy")
    @tabform ||= "tasks_2" if role_allows(:feature => "miq_task_my_ui")
    @tabform ||= "tasks_3" if role_allows(:feature => "job_all_smartproxy")
    @tabform ||= "tasks_4" if role_allows(:feature => "miq_task_all_ui")
    jobs
    render :action => "jobs"
  end

  # New tab was pressed
  def change_tab
    @tabform = "tasks_#{params[:tab]}"
    jobs
    render :action => "jobs"
  end

  def build_jobs_tab
    @pp_choices = PPCHOICES2  # Get special pp choices for jobs/tasks lists
    @settings[:perpage][:job_task] ||= 50       # Default to 50 per page until changed
    @tasks_options = HashWithIndifferentAccess.new if @tasks_options.blank?
    @tasks_options[:zones] = Zone.all.collect { |z| z.name unless z.miq_servers.blank? }.compact
    tasks_set_default_options if @tasks_options[@tabform].blank?

    if role_allows(:feature => "job_my_smartproxy")
      @tabs ||= [["1", ""]]
      @tabs.push(["1", "My VM Analysis Tasks"])
    end
    if role_allows(:feature => "miq_task_my_ui")
      @tabs ||= [["2", ""]]
      @tabs.push(["2", "My Other UI Tasks"])
    end
    if role_allows(:feature => "job_all_smartproxy")
      @tabs ||= [["3", ""]]
      @tabs.push(["3", "All VM Analysis Tasks"])
    end
    if role_allows(:feature => "miq_task_all_ui")
      @tabs ||= [["4", ""]]
      @tabs.push(["4", "All Other Tasks"])
    end

    case @tabform
    when "tasks_1"
      @tabs[0][0] = "1"
    when "tasks_2"
      @tabs[0][0] = "2"
    when "tasks_3"
      @tabs[0][0] = "3"
    when "tasks_4"
      @tabs[0][0] = "4"
    end
  end

  # Show job list for the current user
  def jobs
    build_jobs_tab
    @title = "Tasks for #{current_user.name}"
    @breadcrumbs = []
    @lastaction = "jobs"

    @edit = {}
    @edit[:opts] = {}
    @edit[:opts] = copy_hash(@tasks_options[@tabform])   # Backup current settings

    if params[:action] != "button" && (params[:ppsetting] || params[:searchtag] ||
                                       params[:entry] || params[:sort_choice] || params[:user_choice])
      get_jobs(tasks_condition(@tasks_options[@tabform]))
      render :update do |page|
        page.replace_html("gtl_div", :partial => "layouts/gtl", :locals => {:action_url => @lastaction})
        page.replace("pc_div_1", :partial => '/layouts/pagingcontrols', :locals => {:pages => @pages, :action_url => @lastaction, :db => @view.db, :headers => @view.headers})
        page << "miqSparkle(false);"  # Need to turn off sparkle in case original ajax element gets replaced
      end
    else                      # Came in from non-ajax, just get the jobs
      get_jobs(tasks_condition(@tasks_options[@tabform]))
    end
  end

  def get_jobs(conditions)
    if @tabform == "tasks_1"
      @layout = "my_tasks"
      @lastaction = "jobs"
      @view, @pages = get_view(Job, :conditions => conditions)  # Get the records (into a view) and the paginator
      drop_breadcrumb(:name => "My VM Analysis Tasks", :url => "/miq_task/index?jobs_tab=tasks")

    elsif @tabform == "tasks_2"
      # My UI Tasks
      @layout = "my_ui_tasks"
      @lastaction = "ui_jobs"
      @view, @pages = get_view(MiqTask, :conditions => conditions)  # Get the records (into a view) and the paginator
      drop_breadcrumb(:name => "My Other UI Tasks", :url => "/miq_task/index?jobs_tab=tasks")

    elsif @tabform == "tasks_3" || @tabform == "alltasks_1"
      @layout = "all_tasks"
      @lastaction = "all_jobs"
      @view, @pages = get_view(Job, :conditions => conditions)  # Get the records (into a view) and the paginator
      drop_breadcrumb(:name => "All VM Analysis Tasks", :url => "/miq_task/index?jobs_tab=alltasks")
      @user_names = Job.distinct("userid").pluck("userid").delete_if(&:blank?)

    elsif @tabform == "tasks_4" || @tabform == "alltasks_2"
      # All UI Tasks
      @layout = "all_ui_tasks"
      @lastaction = "all_ui_jobs"
      @view, @pages = get_view(MiqTask, :conditions => conditions)  # Get the records (into a view) and the paginator
      drop_breadcrumb(:name => "All Other Tasks", :url => "/miq_task/index?jobs_tab=alltasks")
      @user_names = MiqTask.distinct("userid").pluck("userid").delete_if(&:blank?)
    end
  end

  # Cancel a single selected job
  def canceljobs
    assert_privileges("miq_task_canceljob")<commit_msg>MiqTaskController - fix @lastaction to "jobs"<commit_after>class MiqTaskController < ApplicationController
  before_action :check_privileges
  before_action :get_session_data
  after_action :cleanup_action
  after_action :set_session_data

  def index
    @tabform = nil
    @tabform ||= "tasks_1" if role_allows(:feature => "job_my_smartproxy")
    @tabform ||= "tasks_2" if role_allows(:feature => "miq_task_my_ui")
    @tabform ||= "tasks_3" if role_allows(:feature => "job_all_smartproxy")
    @tabform ||= "tasks_4" if role_allows(:feature => "miq_task_all_ui")
    jobs
    render :action => "jobs"
  end

  # New tab was pressed
  def change_tab
    @tabform = "tasks_#{params[:tab]}"
    jobs
    render :action => "jobs"
  end

  def build_jobs_tab
    @pp_choices = PPCHOICES2  # Get special pp choices for jobs/tasks lists
    @settings[:perpage][:job_task] ||= 50       # Default to 50 per page until changed
    @tasks_options = HashWithIndifferentAccess.new if @tasks_options.blank?
    @tasks_options[:zones] = Zone.all.collect { |z| z.name unless z.miq_servers.blank? }.compact
    tasks_set_default_options if @tasks_options[@tabform].blank?

    if role_allows(:feature => "job_my_smartproxy")
      @tabs ||= [["1", ""]]
      @tabs.push(["1", "My VM Analysis Tasks"])
    end
    if role_allows(:feature => "miq_task_my_ui")
      @tabs ||= [["2", ""]]
      @tabs.push(["2", "My Other UI Tasks"])
    end
    if role_allows(:feature => "job_all_smartproxy")
      @tabs ||= [["3", ""]]
      @tabs.push(["3", "All VM Analysis Tasks"])
    end
    if role_allows(:feature => "miq_task_all_ui")
      @tabs ||= [["4", ""]]
      @tabs.push(["4", "All Other Tasks"])
    end

    case @tabform
    when "tasks_1"
      @tabs[0][0] = "1"
    when "tasks_2"
      @tabs[0][0] = "2"
    when "tasks_3"
      @tabs[0][0] = "3"
    when "tasks_4"
      @tabs[0][0] = "4"
    end
  end

  # Show job list for the current user
  def jobs
    build_jobs_tab
    @title = "Tasks for #{current_user.name}"
    @breadcrumbs = []
    @lastaction = "jobs"

    @edit = {}
    @edit[:opts] = {}
    @edit[:opts] = copy_hash(@tasks_options[@tabform])   # Backup current settings

    if params[:action] != "button" && (params[:ppsetting] || params[:searchtag] ||
                                       params[:entry] || params[:sort_choice] || params[:user_choice])
      get_jobs(tasks_condition(@tasks_options[@tabform]))
      render :update do |page|
        page.replace_html("gtl_div", :partial => "layouts/gtl", :locals => {:action_url => @lastaction})
        page.replace("pc_div_1", :partial => '/layouts/pagingcontrols', :locals => {:pages => @pages, :action_url => @lastaction, :db => @view.db, :headers => @view.headers})
        page << "miqSparkle(false);"  # Need to turn off sparkle in case original ajax element gets replaced
      end
    else                      # Came in from non-ajax, just get the jobs
      get_jobs(tasks_condition(@tasks_options[@tabform]))
    end
  end

  def get_jobs(conditions)
    @lastaction = "jobs"

    if @tabform == "tasks_1"
      @layout = "my_tasks"
      @view, @pages = get_view(Job, :conditions => conditions)  # Get the records (into a view) and the paginator
      drop_breadcrumb(:name => "My VM Analysis Tasks", :url => "/miq_task/index?jobs_tab=tasks")

    elsif @tabform == "tasks_2"
      # My UI Tasks
      @layout = "my_ui_tasks"
      @view, @pages = get_view(MiqTask, :conditions => conditions)  # Get the records (into a view) and the paginator
      drop_breadcrumb(:name => "My Other UI Tasks", :url => "/miq_task/index?jobs_tab=tasks")

    elsif @tabform == "tasks_3" || @tabform == "alltasks_1"
      @layout = "all_tasks"
      @view, @pages = get_view(Job, :conditions => conditions)  # Get the records (into a view) and the paginator
      drop_breadcrumb(:name => "All VM Analysis Tasks", :url => "/miq_task/index?jobs_tab=alltasks")
      @user_names = Job.distinct("userid").pluck("userid").delete_if(&:blank?)

    elsif @tabform == "tasks_4" || @tabform == "alltasks_2"
      # All UI Tasks
      @layout = "all_ui_tasks"
      @view, @pages = get_view(MiqTask, :conditions => conditions)  # Get the records (into a view) and the paginator
      drop_breadcrumb(:name => "All Other Tasks", :url => "/miq_task/index?jobs_tab=alltasks")
      @user_names = MiqTask.distinct("userid").pluck("userid").delete_if(&:blank?)
    end
  end

  # Cancel a single selected job
  def canceljobs
    assert_privileges("miq_task_canceljob")
{'fraction_non_alphanumeric': 0.15032967032967032, 'fraction_numerical': 0.008791208791208791, 'mean_word_length': 3.356629966491144, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '114991', 'n_tokens_mistral': 3183, 'n_tokens_neox': 3083, 'n_words': 735}