Class: ForemanTasks::TasksController

Inherits:
ApplicationController
  • Object
show all
Includes:
Foreman::Controller::AutoCompleteSearch, Foreman::Controller::CsvResponder, FindTasksCommon
Defined in:
app/controllers/foreman_tasks/tasks_controller.rb

Instance Method Summary collapse

Methods included from FindTasksCommon

#current_taxonomy_search, #search_query

Instance Method Details

#abortObject



52
53
54
55
56
57
58
59
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 52

def abort
  if @dynflow_task.abort
    flash[:info] = _('Trying to abort the task')
  else
    flash[:warning] = _('The task cannot be aborted at the moment.')
  end
  redirect_back(:fallback_location => foreman_tasks_task_path(@dynflow_task))
end

#cancelObject



44
45
46
47
48
49
50
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 44

def cancel
  if @dynflow_task.cancel
    render json: { statusText: 'OK' }
  else
    render json: {}, status: :bad_request
  end
end

#cancel_stepObject



35
36
37
38
39
40
41
42
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 35

def cancel_step
  result = ForemanTasks.dynflow.world.event(@dynflow_task.external_id, params[:step_id].to_i, ::Dynflow::Action::Cancellable::Cancel).wait
  if result.rejected?
    render json: { error: result.reason }, status: :bad_request
  else
    render json: { statusText: 'OK' }
  end
end

#controller_nameObject

we need do this to make the Foreman helpers working properly



90
91
92
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 90

def controller_name
  'foreman_tasks_tasks'
end

#force_unlockObject



79
80
81
82
83
84
85
86
87
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 79

def force_unlock
  if @dynflow_task.pending?
    @dynflow_task.halt
    render json: { statusText: 'OK' }
  else
    # Cannot halt an already stopped task
    render json: {}, status: :bad_request
  end
end

#indexObject



14
15
16
17
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 14

def index
  params[:order] ||= 'started_at DESC'
  respond_with_tasks resource_base
end

#resource_classObject



94
95
96
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 94

def resource_class
  ForemanTasks::Task
end

#resumeObject



61
62
63
64
65
66
67
68
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 61

def resume
  if @dynflow_task.resumable?
    ForemanTasks.dynflow.world.execute(@dynflow_task.execution_plan.id)
    render json: { statusText: 'OK' }
  else
    render json: {}, status: :bad_request
  end
end

#showObject



9
10
11
12
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 9

def show
  @task = resource_base.find(params[:id])
  render :layout => !request.xhr?
end

#sub_tasksObject



29
30
31
32
33
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 29

def sub_tasks
  # @task is used when rendering breadcrumbs
  @task = resource_base.find(params[:id])
  respond_with_tasks @task.sub_tasks
end

#summaryObject



19
20
21
22
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 19

def summary
  scope = resource_base.search_for(current_taxonomy_search).select(:id)
  render json: Task::Summarizer.new(Task.where(:id => scope), params[:recent_timeframe].to_i).summary
end

#summary_sub_tasksObject



24
25
26
27
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 24

def summary_sub_tasks
  filtered_scope = resource_base.find(params[:id]).sub_tasks
  render :json => Task::Summarizer.new(filtered_scope, params[:recent_timeframe].to_i).summary
end

#unlockObject



70
71
72
73
74
75
76
77
# File 'app/controllers/foreman_tasks/tasks_controller.rb', line 70

def unlock
  if @dynflow_task.paused?
    @dynflow_task.halt
    render json: { statusText: 'OK' }
  else
    render json: {}, status: :bad_request
  end
end