Class: PlanMyStuff::TestingProjectsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /testing_projects



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/plan_my_stuff/testing_projects_controller.rb', line 14

def create
  @project = PlanMyStuff::TestingProject.create!(
    title: testing_project_params[:title],
    description: testing_project_params[:description],
    subject_urls: parse_subject_urls(testing_project_params[:subject_urls]),
    due_date: parse_due_date(testing_project_params[:due_date]),
    deadline_miss_reason: testing_project_params[:deadline_miss_reason],
    user: pms_current_user,
  )

  yield(@project) if block_given?
  return if performed?

  flash[:success] = 'Testing project was successfully created.'
  redirect_to(plan_my_stuff.testing_project_path(@project.number))
rescue PlanMyStuff::ValidationError => e
  pms_handle_rescue(e)
  @project = PlanMyStuff::TestingProject.new(
    title: testing_project_params[:title],
    description: testing_project_params[:description],
  )
  @project..subject_urls = parse_subject_urls(testing_project_params[:subject_urls])
  @project..due_date = safe_parse_due_date(testing_project_params[:due_date])
  @project..deadline_miss_reason = testing_project_params[:deadline_miss_reason]
  flash.now[:error] = e.message
  render(:new, status: PlanMyStuff.unprocessable_status)
end

#edit {|@project| ... } ⇒ Object

GET /testing_projects/:id/edit

Yields:

  • (@project)


52
53
54
55
56
# File 'app/controllers/plan_my_stuff/testing_projects_controller.rb', line 52

def edit
  @project = PlanMyStuff::TestingProject.find(params[:id].to_i)

  yield(@project) if block_given?
end

#new {|@project| ... } ⇒ Object

GET /testing_projects/new

Yields:

  • (@project)


6
7
8
9
10
11
# File 'app/controllers/plan_my_stuff/testing_projects_controller.rb', line 6

def new
  @project = PlanMyStuff::TestingProject.new
  @project..subject_urls = [params[:subject_url]] if params[:subject_url].present?

  yield(@project) if block_given?
end

#show {|@project| ... } ⇒ Object

GET /testing_projects/:id

Yields:

  • (@project)


43
44
45
46
47
48
49
# File 'app/controllers/plan_my_stuff/testing_projects_controller.rb', line 43

def show
  @project = PlanMyStuff::TestingProject.find(params[:id].to_i)
  @statuses = @project.statuses.pluck(:name)
  @items_by_status = @project.items.group_by(&:status)

  yield(@project) if block_given?
end

#updateObject

PATCH/PUT /testing_projects/:id



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/plan_my_stuff/testing_projects_controller.rb', line 59

def update
  @project = PlanMyStuff::TestingProject.find(params[:id].to_i)

  @project.update!(
    title: testing_project_params[:title],
    description: testing_project_params[:description],
    metadata: {
      subject_urls: parse_subject_urls(testing_project_params[:subject_urls]),
      due_date: parse_due_date(testing_project_params[:due_date]),
      deadline_miss_reason: testing_project_params[:deadline_miss_reason],
    },
  )

  yield(@project) if block_given?
  return if performed?

  flash[:success] = 'Testing project was successfully updated.'
  redirect_to(plan_my_stuff.testing_project_path(@project.number))
rescue PlanMyStuff::StaleObjectError => e
  pms_handle_rescue(e)
  flash.now[:error] =
    'Testing project was modified by someone else. Please review the latest changes and try again.'
  render(:edit, status: PlanMyStuff.unprocessable_status)
rescue PlanMyStuff::ValidationError => e
  pms_handle_rescue(e)
  flash.now[:error] = e.message
  render(:edit, status: PlanMyStuff.unprocessable_status)
end