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



18
19
20
# File 'app/controllers/coplan/plans_controller.rb', line 18

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
15
16
# File 'app/controllers/coplan/plans_controller.rb', line 11

def show
  authorize!(@plan, :show?)
  threads = @plan.comment_threads.includes(:comments, :created_by_user, :plan_version).order(created_at: :asc)
  @active_threads = threads.active
  @archived_threads = threads.archived
end

#updateObject



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

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



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

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