Class: Raif::Admin::TasksController

Inherits:
ApplicationController show all
Includes:
Pagy::Backend
Defined in:
app/controllers/raif/admin/tasks_controller.rb

Instance Method Summary collapse

Methods inherited from Raif::ApplicationController

#raif_current_user

Instance Method Details

#indexObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/raif/admin/tasks_controller.rb', line 8

def index
  @task_types = Raif::Task.distinct.pluck(:type)
  @selected_type = params[:task_types].present? ? params[:task_types] : "all"

  @task_statuses = [:all, :completed, :failed, :in_progress, :pending]
  @selected_statuses = params[:task_statuses].present? ? params[:task_statuses].to_sym : :all

  tasks = Raif::Task.order(created_at: :desc)
  tasks = tasks.where(type: @selected_type) if @selected_type.present? && @selected_type != "all"

  if @selected_statuses.present? && @selected_statuses != :all
    case @selected_statuses
    when :completed
      tasks = tasks.completed
    when :failed
      tasks = tasks.failed
    when :in_progress
      tasks = tasks.in_progress
    when :pending
      tasks = tasks.pending
    end
  end

  @pagy, @tasks = pagy(tasks)
end

#showObject



34
35
36
# File 'app/controllers/raif/admin/tasks_controller.rb', line 34

def show
  @task = Raif::Task.includes(:raif_model_completion).find(params[:id])
end