Class: CommandProposal::TasksController

Inherits:
EngineController
  • Object
show all
Includes:
ParamsHelper, PermissionsHelper
Defined in:
app/controllers/command_proposal/tasks_controller.rb

Instance Method Summary collapse

Methods included from PermissionsHelper

#approval_required?, #can_approve?, #can_command?, #cmd_config, #command_user, #current_is_author?, #has_approval?, #permitted_to_use?

Methods included from ParamsHelper

#command_paginate, #current_params, #current_path, #div, #humanized_duration, #sort_order, #toggled_param, #toggled_sort_order, #true_param?, #truthy?

Methods included from ApplicationHelper

#cmd_path, #cmd_url, #engine, #runner_path, #runner_url, #string_path

Instance Method Details

#createObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/command_proposal/tasks_controller.rb', line 53

def create
  @task = ::CommandProposal::Task.new(task_params.except(:code))
  @task.user = command_user
  @task.skip_approval = true unless approval_required?(@task.session_type)

  # Cannot create the iteration until the task is created, so save then update
  if @task.save && @task.update(task_params)
    if @task.console?
      @task.code = nil # Creates a blank iteration to track approval
      redirect_to cmd_path(@task)
    else
      redirect_to cmd_path(:edit, @task)
    end
  else
    # TODO: Display errors
    render "form"
  end
end

#editObject



47
48
49
50
51
# File 'app/controllers/command_proposal/tasks_controller.rb', line 47

def edit
  @task = ::CommandProposal::Task.find_by!(friendly_id: params[:id])

  render "form"
end

#indexObject



16
17
18
19
20
21
22
# File 'app/controllers/command_proposal/tasks_controller.rb', line 16

def index
  @tasks = ::CommandProposal::Task.includes(:iterations)
  @tasks = @tasks.order(Arel.sql("COALESCE(command_proposal_tasks.last_executed_at, command_proposal_tasks.created_at) DESC"))
  @tasks = @tasks.search(params[:search]) if params[:search].present?
  @tasks = @tasks.by_session(params[:filter])
  @tasks = @tasks.cmd_page(params[:page])
end

#newObject



40
41
42
43
44
45
# File 'app/controllers/command_proposal/tasks_controller.rb', line 40

def new
  @task = ::CommandProposal::Task.new
  @task.session_type = params[:session_type] if params[:session_type].in?(::CommandProposal::Task.session_types)

  render "form"
end

#searchObject



12
13
14
# File 'app/controllers/command_proposal/tasks_controller.rb', line 12

def search
  redirect_to cmd_path(:tasks, current_params)
end

#showObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/command_proposal/tasks_controller.rb', line 24

def show
  @task = ::CommandProposal::Task.find_by!(friendly_id: params[:id])
  if @task.console?
    @lines = @task.lines
    @iteration = @task.first_iteration

    return # Don't execute the rest of the function
  end

  if params.key?(:iteration)
    @iteration = @task.iterations.find(params[:iteration])
  else
    @iteration = @task.current_iteration
  end
end

#updateObject



72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/command_proposal/tasks_controller.rb', line 72

def update
  @task = ::CommandProposal::Task.find_by!(friendly_id: params[:id])
  @task.user = command_user
  @task.skip_approval = true unless approval_required?(@task.session_type)

  if @task.update(task_params)
    redirect_to cmd_path(@task)
  else
    # TODO: Display errors
    render "form"
  end
end