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



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

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,
  )

  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

#editObject

GET /testing_projects/:id/edit



45
46
47
# File 'app/controllers/plan_my_stuff/testing_projects_controller.rb', line 45

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

#newObject

GET /testing_projects/new



6
7
8
9
# 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?
end

#showObject

GET /testing_projects/:id



38
39
40
41
42
# File 'app/controllers/plan_my_stuff/testing_projects_controller.rb', line 38

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

#updateObject

PATCH/PUT /testing_projects/:id



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/plan_my_stuff/testing_projects_controller.rb', line 50

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],
    },
  )

  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