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

rubocop:todo Metrics/MethodLength


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/helpers/submissions_helper.rb', line 71

def asset_group_select(asset_groups) # rubocop:todo Metrics/MethodLength
  prompt =
    case asset_groups.size
    when 0
      '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


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

def field_input_tag(field_info, values: {}, name_format: '%s', enforce_required: true)
  case field_info.kind
  when 'Selection'
    field_selection_tag(values, field_info, name_format, enforce_required)
  when 'Text'
    field_text_tag(values, field_info, name_format, enforce_required)
  when 'Numeric'
    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
# 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

rubocop:enable Metrics/AbcSize, Metrics/MethodLength


128
129
130
# File 'app/helpers/submissions_helper.rb', line 128

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

#projects_select(form, projects) ⇒ Object

rubocop:todo Metrics/MethodLength


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/helpers/submissions_helper.rb', line 52

def projects_select(form, projects) # rubocop:todo Metrics/MethodLength
  prompt =
    case projects.count
    when 0
      '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


132
133
134
135
136
137
138
# File 'app/helpers/submissions_helper.rb', line 132

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$/)

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

#studies_select(form, studies) ⇒ Object

rubocop:todo Metrics/MethodLength


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

def studies_select(form, studies) # rubocop:todo Metrics/MethodLength
  prompt =
    case studies.count
    when 0
      '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

140
141
142
143
# File 'app/helpers/submissions_helper.rb', line 140

def submission_link(submission, options)
  link_text = tag.strong(submission.name) << ' ' << badge(submission.state, type: 'submission-state')
  link_to(link_text, submission_path(submission), options)
end

#submission_status_message(submission) ⇒ Object

rubocop:todo Metrics/MethodLength, Metrics/AbcSize


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/helpers/submissions_helper.rb', line 93

def submission_status_message(submission) # rubocop:todo Metrics/CyclomaticComplexity
  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.') +
      tag.p(
        # rubocop:todo Layout/LineLength
        'It should be processed approximately 10 minutes after you have submitted it, however sometimes this may take longer.'
        # rubocop:enable Layout/LineLength
      )
  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(
        # rubocop:todo Layout/LineLength
        "<h3>Your submission has failed:</h3><p> #{h((submission.message || 'No failure reason recorded').lines.first)} </p>"
        # rubocop:enable Layout/LineLength
      )
    )
  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