Class: CoPlan::PlansController

Inherits:
ApplicationController show all
Defined in:
app/controllers/coplan/plans_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

controller_path

Instance Method Details

#editObject



16
17
18
# File 'app/controllers/coplan/plans_controller.rb', line 16

def edit
  authorize!(@plan, :update?)
end

#indexObject



5
6
7
8
9
# File 'app/controllers/coplan/plans_controller.rb', line 5

def index
  @plans = Plan.order(updated_at: :desc)
  @plans = @plans.where(status: params[:status]) if params[:status].present?
  @plans = @plans.where(created_by_user: current_user) if params[:scope] == "mine"
end

#showObject



11
12
13
14
# File 'app/controllers/coplan/plans_controller.rb', line 11

def show
  authorize!(@plan, :show?)
  @threads = @plan.comment_threads.includes(:comments, :created_by_user).order(:created_at)
end

#updateObject



20
21
22
23
24
25
# File 'app/controllers/coplan/plans_controller.rb', line 20

def update
  authorize!(@plan, :update?)
  @plan.update!(title: params[:plan][:title])
  broadcast_plan_update(@plan)
  redirect_to plan_path(@plan), notice: "Plan updated."
end

#update_statusObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/coplan/plans_controller.rb', line 27

def update_status
  authorize!(@plan, :update_status?)
  new_status = params[:status]
  if Plan::STATUSES.include?(new_status) && @plan.update(status: new_status)
    broadcast_plan_update(@plan)
    if @plan.saved_change_to_status?
      Plans::TriggerAutomatedReviews.call(plan: @plan, new_status: new_status, triggered_by: current_user)
    end
    redirect_to plan_path(@plan), notice: "Status updated to #{new_status}."
  else
    redirect_to plan_path(@plan), alert: "Invalid status."
  end
end