Module: ApplicationHelper

Includes:
Informatics::Globals
Defined in:
app/helpers/application_helper.rb,
lib/informatics/lib/informatics/controller_helper.rb

Instance Method Summary collapse

Methods included from Informatics::Globals

#application, #application=, #defaults, #defaults=, #global_searchable_classes, #search_options

Instance Method Details

#about(title = '') ⇒ Object

From Pipelines


126
127
128
# File 'app/helpers/application_helper.rb', line 126

def about(title = '')
  add :about, title
end

#add(type, link, options = nil) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/informatics/lib/informatics/controller_helper.rb', line 10

def add(type, link, options = nil)
  o = Informatics::Support::Options.collect(options)
  l = Informatics::Support::Options.collect(link)
  case type
  when :menu
    @menu ||= Informatics::View::Menu::List.new
    @menu = add_link(@menu, l, o, options)
  when :back_menu
    @back_menu ||= Informatics::View::Menu::List.new
    @back_menu.add_item text: l.first_key, link: l.first_value
  when :about, :title # Replaces :title
    @about = link
  when :lab_option
    @lab_menu = add_link(@lab_menu, l, o, options)
  when :lab_manager_option
    @lab_manager_menu = add_link(@lab_manager_menu, l, o, options)
  when :admin_option
    @admin_menu = add_link(@admin_menu, l, o, options)
  when :manager_option
    @manager_menu = add_link(@manager_menu, l, o, options)
  when :legend_option
    @legend = add_link(@legend, l, o, options)
  when :tab
    @tabs = Informatics::View::Tabs::List.new unless @tabs
    @tabs.add_item text: l.first_key, link: l.first_value
  end
end

#api_dataObject


34
35
36
# File 'app/helpers/application_helper.rb', line 34

def api_data
  { api_version: RELEASE.api_version }
end

#custom_text(identifier, differential = nil) ⇒ Object

Should return either the custom text or a blank string


3
4
5
6
7
8
9
10
11
12
# File 'app/helpers/application_helper.rb', line 3

def custom_text(identifier, differential = nil)
  Rails.cache.fetch("#{identifier}-#{differential}") do
    custom_text = CustomText.find_by(
      identifier: identifier,
      differential: differential
    )

    custom_text.try(:content) || ''
  end
end

#display_boolean_results(result) ⇒ Object


207
208
209
210
211
212
213
214
# File 'app/helpers/application_helper.rb', line 207

def display_boolean_results(result)
  return 'NA' if (!result || result.empty?)
  if result == 'pass' || result == '1' || result == 'true'
    return icon('far', 'check-circle', title: result)
  else
    return icon('fas', 'exclamation-circle', class: 'text-danger', title: result)
  end
end

#display_complex_content(hash_content) ⇒ Object


178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'app/helpers/application_helper.rb', line 178

def display_complex_content(hash_content)
  hash_content.each do |key, value|
    case key
    when 'criterion'
      output = ''
      value.each do |v|
        output = output + (:span, "<strong>#{v.inspect}</strong>")
        output = output + (:br)
      end
      return output
    when 'link'
      return link_to(value['label'], value['href'])
    end
  end
end

#display_empty_table(display_text, link = nil) ⇒ Object


116
117
118
119
120
121
122
# File 'app/helpers/application_helper.rb', line 116

def display_empty_table(display_text, link = nil)
  if link.nil?
    (:div, display_text, class: 'empty_table', id: 'empty_table')
  else
    (:div, link_to(display_text, link), class: 'empty_table', id: 'empty_table')
  end
end

#display_follow(item, user, msg) ⇒ Object


100
101
102
103
104
105
106
# File 'app/helpers/application_helper.rb', line 100

def display_follow(item, user, msg)
  if user.following?(item)
    'Unfollow ' + msg
  else
    'Follow ' + msg
  end
end

#display_hash_value(hash, key, sub_key) ⇒ Object


223
224
225
# File 'app/helpers/application_helper.rb', line 223

def display_hash_value(hash, key, sub_key)
  hash.fetch(key, {}).fetch(sub_key, '')
end

#display_ready_for_manual_qc(v) ⇒ Object


194
195
196
197
198
199
200
# File 'app/helpers/application_helper.rb', line 194

def display_ready_for_manual_qc(v)
  if v
    icon('far', 'check-circle')
  else
    icon('fas', 'exclamation-circle', class: 'text-danger')
  end
end

#display_request_information(request, rit, batch = nil) ⇒ Object


202
203
204
205
# File 'app/helpers/application_helper.rb', line 202

def display_request_information(request, rit, batch = nil)
  r = request.value_for(rit.name, batch)
  (!r || r.empty?) ? 'NA' : r
end

#display_status(status) ⇒ Object


50
51
52
53
54
# File 'app/helpers/application_helper.rb', line 50

def display_status(status)
  return if status.blank?

  (:span, status, class: "request-state badge badge-#{status}")
end

#display_user_error(display_text, link = nil) ⇒ Object


44
45
46
47
48
# File 'app/helpers/application_helper.rb', line 44

def display_user_error(display_text, link = nil)
  alert(:danger) do
    link.present? ? link_to(display_text, link) : display_text
  end
end

#display_user_guide(display_text, link = nil) ⇒ Object


38
39
40
41
42
# File 'app/helpers/application_helper.rb', line 38

def display_user_guide(display_text, link = nil)
  alert(:user_guide) do
    concat link.present? ? link_to(display_text, link) : display_text
  end
end

56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/helpers/application_helper.rb', line 56

def dynamic_link_to(summary_item)
  object = summary_item.object
  if object.instance_of?(Submission)
    return link_to("Submission #{object.id}", study_information_submission_path(object.study, object))
  elsif object.instance_of?(Asset)
    return link_to("#{object.label.capitalize} #{object.name}", asset_path(object))
  elsif object.instance_of?(Request)
    return link_to("Request #{object.id}", request_path(object))
  else
    return 'No link available'
  end
end

The admin email address should be stored in config.yml for the current environment


243
244
245
246
# File 'app/helpers/application_helper.rb', line 243

def help_email_link
  admin_address = configatron.admin_email || '[email protected]'
  link_to admin_address.to_s, "mailto:#{admin_address}"
end

236
237
238
239
240
# File 'app/helpers/application_helper.rb', line 236

def help_link(text, entry = '', options = {})
  url = "#{configatron.help_link_base_url}/#{entry}"
  options[:class] = "#{options[:class]} external_help"
  link_to text, url, options
end

#help_text(&block) ⇒ Object


232
233
234
# File 'app/helpers/application_helper.rb', line 232

def help_text(&block)
  (:small, class: 'form-text text-muted col', &block)
end

#hidden_label_tag_for_testing(name, text = nil, options = {}) ⇒ Object

Creates a label that is hidden from the view so that testing is easier


228
229
230
# File 'app/helpers/application_helper.rb', line 228

def hidden_label_tag_for_testing(name, text = nil, options = {})
  label_tag(name, text, options.merge(style: 'display:none;'))
end

#item_status(item) ⇒ Object


170
171
172
173
174
175
176
# File 'app/helpers/application_helper.rb', line 170

def item_status(item)
  if item.failures.empty?
    ''
  else
    '<span style="color:red;">FAILED</span>'
  end
end

#loggerObject


38
39
40
# File 'lib/informatics/lib/informatics/controller_helper.rb', line 38

def logger
  Rails.logger
end

#remote_error(identifier = 'remote_error') ⇒ Object


14
15
16
17
18
# File 'app/helpers/application_helper.rb', line 14

def remote_error(identifier = 'remote_error')
  ('div', id: identifier, class: 'error', style: 'display:none;') do
    'An error has occurred and the results can not be shown at the moment'
  end
end

#render_flashesObject


24
25
26
27
28
29
30
31
32
# File 'app/helpers/application_helper.rb', line 24

def render_flashes
  output = String.new.html_safe
  flash.each do |key, message|
    output << alert(key, id: "message_#{key}") do
      Array(message).reduce(String.new.html_safe) { |buffer, m| buffer << (:div, m) }
    end
  end
  output
end

69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/application_helper.rb', line 69

def request_count_link(study, asset, state, request_type)
  matching_requests   = asset.requests.select { |request| (request.request_type_id == request_type.id) and request.state == state }
  html_options, count = { title: "#{asset.try(:human_barcode) || asset.id} #{state}" }, matching_requests.size

  # 0 requests => no link, just '0'
  # 1 request  => request summary page
  # N requests => summary overview
  if count == 1
    url_path = request_path(matching_requests.first)
    link_to count, url_path, html_options
  elsif count > 1
    url_path = study_requests_path(study, state: state, request_type_id: request_type.id, asset_id: asset.id)
    link_to count, url_path, html_options
  end
end

85
86
87
# File 'app/helpers/application_helper.rb', line 85

def request_link(object, count, request_type, status = nil, options = {}, link_options = {})
  link_to_if((count != 0), count, request_list_path(object, request_type, status, options), link_options)
end

#request_list_path(object, request_type = nil, status = nil, options = {}) ⇒ Object


89
90
91
92
93
94
95
96
97
98
# File 'app/helpers/application_helper.rb', line 89

def request_list_path(object, request_type = nil, status = nil, options = {})
  options[:state] = status unless status.nil?
  options[:request_type_id] = request_type.id unless request_type.nil?

  if object.instance_of?(Asset)
    asset_path(object, options)
  elsif object.instance_of?(Study)
    study_requests_path(object, options)
  end
end

#required_markerObject


20
21
22
# File 'app/helpers/application_helper.rb', line 20

def required_marker
  (:span, '&raquo;'.html_safe, class: 'required')
end

#sorted_requests_for_search(requests) ⇒ Object


216
217
218
219
220
221
# File 'app/helpers/application_helper.rb', line 216

def sorted_requests_for_search(requests)
  sorted_requests = requests.select { |r| r.pipeline_id.nil? }
  new_requests = requests - sorted_requests
  new_requests.sort_by(&:pipeline_id)
  requests = requests + sorted_requests
end

#study_state(state) ⇒ Object


108
109
110
111
112
113
114
# File 'app/helpers/application_helper.rb', line 108

def study_state(state)
  if state == 'active'
    "<span style='color:green;'>#{state}</span>".html_safe
  else
    "<span style='color:red;'>#{state}</span>".html_safe
  end
end

#tab(name, target: nil, active: false, id: nil) ⇒ Object

<li class=“nav-item”>

<a class="nav-link <active>" id="name-tab" data-toggle="tab" href="#name"
 role="tab" aria-controls="name" aria-selected="true">name</a>

</li>


151
152
153
154
155
156
157
158
# File 'app/helpers/application_helper.rb', line 151

def tab(name, target: nil, active: false, id: nil)
  target ||= name.parameterize
  active_class = active ? 'active' : ''
  id ||= "#{name}-tab".parameterize
  (:li, class: 'nav-item') do
    link_to name, "##{target}", id: id, data: { toggle: 'tab' }, role: 'tab', aria_controls: target, class: ['nav-link', active_class]
  end
end

#tab_pane(name, id: nil, tab_id: nil, active: false, &block) ⇒ Object

<div class=“tab-pane fade show <active>” id=“pending” role=“tabpanel” aria-labelledby=“peding-tab”>

yield

</div>


163
164
165
166
167
168
# File 'app/helpers/application_helper.rb', line 163

def tab_pane(name, id: nil, tab_id: nil, active: false, &block)
  tab_id ||= "#{name}-tab".parameterize
  id ||= name.parameterize
  active_class = active ? 'active' : ''
  (:div, class: ['tab-pane', 'fade', 'show', active_class], id: id, role: 'tabpanel', aria_labelledby: tab_id, &block)
end

#tabulated_error_messages_for(*params) ⇒ Object


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'app/helpers/application_helper.rb', line 130

def tabulated_error_messages_for(*params)
  options = params.last.is_a?(Hash) ? params.pop.symbolize_keys : {}
  objects = params.collect { |object_name| instance_variable_get("@#{object_name}") }.compact
  count   = objects.inject(0) { |sum, object| sum + object.errors.count }
  if count.zero?
    ''
  else
    error_messages = objects.map { |object| object.errors.full_messages.map { |msg| (:div, msg) } }.join
    [(:td, class: 'error item') do
      "Your #{params.first} has not been created."
    end,
     (:td, class: 'error') do
       raw(error_messages)
     end].join.html_safe
  end
end