Module: SubmissionsHelper

Defined in:
app/helpers/submissions_helper.rb

Overview

Helper methods for presenting submission related information

Instance Method Summary collapse

Instance Method Details

#asset_group_select(asset_groups) ⇒ Object


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/helpers/submissions_helper.rb', line 59

def asset_group_select(asset_groups)
  prompt = case asset_groups.size
           when 0 then 'There are no Asset Groups associcated with this Study'
           else 'Please select an asset group for this order.'
           end

  collection_select(
    :submission,
    :asset_group_id,
    asset_groups, :id, :name,
    { prompt: prompt },
    class: 'submission_asset_group_id required form-control',
    disabled: asset_groups.empty?
  )
end

#field_input_tag(field_info, values: {}, name_format: '%s', enforce_required: true) ⇒ Object


22
23
24
25
26
27
28
29
30
# File 'app/helpers/submissions_helper.rb', line 22

def field_input_tag(field_info, values: {}, name_format: '%s', enforce_required: true)
  case field_info.kind
  when 'Selection' then field_selection_tag(values, field_info, name_format, enforce_required)
  when 'Text'      then field_text_tag(values, field_info, name_format, enforce_required)
  when 'Numeric'   then field_number_tag(values, field_info, name_format, enforce_required)
  # Fall back to a text field
  else field_text_tag(values, field_info, name_format, enforce_required)
  end
end

#order_input_label(field_info) ⇒ Object

<label for=“submission_order_params_field_info_key”>field_info.display_name/label>


6
7
8
# File 'app/helpers/submissions_helper.rb', line 6

def order_input_label(field_info)
  label('submission[order_params]', field_info.key, field_info.display_name, class: 'form-label')
end

#order_input_tag(order, field_info) ⇒ Object

Returns a either a text input or a selection tag based on the 'kind' of the order parameter passed in. field_info is expected to be FieldInfo [sic]


13
14
15
16
17
18
19
20
# File 'app/helpers/submissions_helper.rb', line 13

def order_input_tag(order, field_info)
  request_options = order&.request_options || {}
  field_input_tag(
    field_info,
    values: request_options,
    name_format: 'submission[order_params][%s]'
  )
end

#order_sample_names(order) ⇒ Object


98
99
100
# File 'app/helpers/submissions_helper.rb', line 98

def order_sample_names(order)
  order.assets.map(&:aliquots).flatten.map(&:sample).map(&:name).join(', ')
end

#projects_select(form, projects) ⇒ Object


46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/submissions_helper.rb', line 46

def projects_select(form, projects)
  prompt = case projects.count
           when 0 then 'There are no valid projects available'
           else 'Please select a Project for this Submission...'
           end
  form.collection_select(
    :project_name,
    projects, :name, :name,
    { prompt: prompt },
    disabled: true, class: 'submission_project_name custom-select'
  )
end

#request_description(presenter, request_type) ⇒ Object


102
103
104
105
106
107
108
# File 'app/helpers/submissions_helper.rb', line 102

def request_description(presenter, request_type)
  request_type_name = request_type.name.titleize

  return request_type_name unless request_type.request_class_name.match?(/SequencingRequest$/)

  (:em, pluralize(presenter.lanes_of_sequencing, 'Lane') + ' of ') + request_type_name
end

#studies_select(form, studies) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/submissions_helper.rb', line 32

def studies_select(form, studies)
  prompt = case studies.count
           when 0 then 'You are not managing any Studies at this time'
           else 'Please select a Study for this Submission...'
           end

  form.collection_select(
    :study_id,
    studies, :id, :name,
    { prompt: prompt },
    disabled: true, class: 'study_id custom-select'
  )
end

110
111
112
113
114
# File 'app/helpers/submissions_helper.rb', line 110

def submission_link(submission, options)
  link_text = (:strong, submission.name) << ' ' <<
              (:span, submission.state, class: "batch-state badge badge-#{submission.state}")
  link_to(link_text, submission_path(submission), options)
end

#submission_status_message(submission) ⇒ Object


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/helpers/submissions_helper.rb', line 75

def submission_status_message(submission)
  case submission.state
  when 'building'
    display_user_guide(
      'This submission is still open for editing, further orders can still be added...',
      edit_submission_path(submission)
    ) + button_to('Edit Submission', edit_submission_path(submission), method: :get, class: 'button')
  when 'pending'
    display_user_guide('Your submission is currently pending.') +
      (:p, 'It should be processed approximately 10 minutes after you have submitted it, however sometimes this may take longer.')
  when 'processing'
    display_user_guide('Your submission is currently being processed.  This should take no longer than five minutes.')
  when 'failed'
    display_user_error(raw("<h3>Your submission has failed:</h3><p> #{h((submission.message || 'No failure reason recorded').lines.first)} </p>"))
  when 'ready'
    alert(:success) { raw('Your submission has been <strong>processed</strong>.') }
  when 'cancelled'
    alert(:info) { raw('Your submission has been <strong>cancelled</strong>.') }
  else
    alert(:danger) { 'Your submission is in an unknown state (contact support).' }
  end
end