Class: SubmissionsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#block_api_access, #clean_params_from_check, #evil_parameter_hack!, #extract_header_info, #set_cache_disabled!

Instance Method Details

#cancelObject

Cancels the selected submission, and returns the user to the submission show page. Cancelled submissions in turn cancel all their requests. Only cancellable submissions can be cancelled. (There shouldn't be a link if they can't be cancelled) but it might be nice to add a bit more user friendly error handling here.


75
76
77
78
79
# File 'app/controllers/submissions_controller.rb', line 75

def cancel
  submission = Submission.find(params[:id])
  submission.cancel!
  redirect_to action: :show, id: params[:id]
end

#change_priorityObject


51
52
53
54
# File 'app/controllers/submissions_controller.rb', line 51

def change_priority
  Submission.find(params[:id]).update!(priority: params[:submission][:priority])
  redirect_to action: :show, id: params[:id]
end

#createObject

Triggered when someone clicks 'Save Order' in the submission creator New Order is just client side Creates an order, followed by a submission, and then assigns the order to the submission. On subsequent clicks of 'Save Order' we pass in the submission id from the original


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/submissions_controller.rb', line 20

def create
  @presenter = Submission::SubmissionCreator.new(current_user, params[:submission].to_unsafe_h)

  if @presenter.save
    render partial: 'saved_order',
           locals: {
             presenter: @presenter,
             order: @presenter.order,
             form: :dummy_form_symbol
           },
           layout: false
  else
    render partial: 'order_errors', layout: false, status: :unprocessable_entity
  end
end

#destroyObject

Submissions can only be destroyed when they are still building.


82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/submissions_controller.rb', line 82

def destroy
  ActiveRecord::Base.transaction do
    submission = Submission::SubmissionPresenter.new(current_user, id: params[:id])
    if submission.destroy
      flash[:notice] = 'Submission successfully deleted!'
    else
      flash[:error] = "This submission can't be deleted"
    end
    redirect_to action: :index
  end
end

#editObject


36
37
38
# File 'app/controllers/submissions_controller.rb', line 36

def edit
  @presenter = Submission::SubmissionCreator.new(current_user, id: params[:id])
end

#indexObject

Displays a list of submissions for the current user. building => Submissions which haven't yet been queued for building and may still be edited. Submissions begin in this state, and leave when the used clicks

'Build Submission'

pending => Submissions which the user has finished setting up, and has queued for processing by the delayed job ready => Submissions which the delayed job has finished processing. The final state of a submission.


62
63
64
65
66
67
68
69
# File 'app/controllers/submissions_controller.rb', line 62

def index
  # Disable cache of this page
  expires_now

  @building = Submission.building.order(created_at: :desc).where(user_id: current_user.id)
  @pending = Submission.pending.order(created_at: :desc).where(user_id: current_user.id)
  @ready = Submission.ready.order(created_at: :desc).limit(10).where(user_id: current_user.id)
end

#newObject

The main landing page for creating a new submission. Lots of ajax action!


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

def new
  expires_now
  @presenter = Submission::SubmissionCreator.new(current_user, study_id: params[:study_id])
end

#order_fieldsObject

AJAXY route for rendering the submission level options which appear upon selecting a submission template.


114
115
116
117
118
# File 'app/controllers/submissions_controller.rb', line 114

def order_fields
  @presenter = Submission::SubmissionCreator.new(current_user, params[:submission])

  render partial: 'order_fields', layout: false
end

#showObject

Show a submission. Read-only page, but provides a link to the edit page for submissions which haven't yet left state building


96
97
98
# File 'app/controllers/submissions_controller.rb', line 96

def show
  @presenter = Submission::SubmissionPresenter.new(current_user, id: params[:id])
end

#studyObject

An index page for study submissions. Bit unconventional URL eg: localhost:3000/submissions/study?id=23 Rather than localhost:3000/studies/23/submissions


104
105
106
107
# File 'app/controllers/submissions_controller.rb', line 104

def study
  @study       = Study.find(params[:id])
  @submissions = @study.submissions
end

#study_assetsObject

AJAXY route to populate study asset group dropdown


121
122
123
124
125
# File 'app/controllers/submissions_controller.rb', line 121

def study_assets
  @presenter = Submission::SubmissionCreator.new(current_user, params[:submission])

  render partial: 'study_assets', layout: false
end

#updateObject

This method will build a submission then redirect to the submission on completion


41
42
43
44
45
46
47
48
49
# File 'app/controllers/submissions_controller.rb', line 41

def update
  @presenter = Submission::SubmissionCreator.new(current_user, id: params[:id])

  @presenter.build_submission!

  flash[:error] = "The submission could not be built: #{@presenter.submission.errors.full_messages}" if @presenter.submission.errors.present?

  redirect_to @presenter.submission
end