Class: PlanMyStuff::ProjectsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/plan_my_stuff/projects_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /projects



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/plan_my_stuff/projects_controller.rb', line 24

def create
  @project = PMS::Project.create!(
    title: project_params[:title],
    readme: project_params[:readme] || '',
    description: project_params[:description],
    user: pms_current_user,
  )

  flash[:success] = 'Project was successfully created.'
  redirect_to(plan_my_stuff.project_path(@project.number))
rescue PMS::ValidationError => e
  @project = PMS::Project.new(
    title: project_params[:title],
    readme: project_params[:readme],
    description: project_params[:description],
  )
  flash.now[:error] = e.message
  render(:new, status: PMS.unprocessable_status)
end

#editObject

GET /projects/:id/edit



53
54
55
# File 'app/controllers/plan_my_stuff/projects_controller.rb', line 53

def edit
  @project = PMS::Project.find(params[:id].to_i)
end

#indexObject

GET /projects



6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/plan_my_stuff/projects_controller.rb', line 6

def index
  all_projects = PMS::BaseProject.list.reject(&:closed)
  @filter = params[:filter].presence_in(%w[testing all]) || 'regular'
  @projects =
    case @filter
    when 'testing' then all_projects.select { |p| p.is_a?(PMS::TestingProject) }
    when 'regular' then all_projects.reject { |p| p.is_a?(PMS::TestingProject) }
    else all_projects
    end
  @support_user = support_user?
end

#newObject

GET /projects/new



19
20
21
# File 'app/controllers/plan_my_stuff/projects_controller.rb', line 19

def new
  @project = PMS::Project.new
end

#showObject

GET /projects/:id



45
46
47
48
49
50
# File 'app/controllers/plan_my_stuff/projects_controller.rb', line 45

def show
  @project = PMS::Project.find(params[:id].to_i)
  @statuses = @project.statuses.pluck(:name)
  @items_by_status = @project.items.group_by(&:status)
  @support_user = support_user?
end

#updateObject

PATCH/PUT /projects/:id



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/plan_my_stuff/projects_controller.rb', line 58

def update
  @project = PMS::Project.find(params[:id].to_i)

  @project.update!(
    title: project_params[:title],
    readme: project_params[:readme],
    description: project_params[:description],
  )

  flash[:success] = 'Project was successfully updated.'
  redirect_to(plan_my_stuff.project_path(@project.number))
rescue PMS::StaleObjectError
  flash.now[:error] = 'Project was modified by someone else. Please review the latest changes and try again.'
  render(:edit, status: PMS.unprocessable_status)
end