Module: AssetsHelper

Defined in:
app/helpers/assets_helper.rb

Overview

rubocop:todo Style/Documentation

Instance Method Summary collapse

Instance Method Details

#current_user_can_make_additional_requests_on?(_asset, study) ⇒ Boolean

Returns:

  • (Boolean)

74
75
76
77
78
# File 'app/helpers/assets_helper.rb', line 74

def current_user_can_make_additional_requests_on?(_asset, study)
  return false if study.blank? # Study must be specified ...

  can?(:create_additional, Request)
end

#current_user_can_request_additional_library_on?(asset) ⇒ Boolean

Returns true if the current user can request an additional library on the asset, otherwise false

Returns:

  • (Boolean)

70
71
72
# File 'app/helpers/assets_helper.rb', line 70

def current_user_can_request_additional_library_on?(asset)
  asset.is_a?(SampleTube) && can?(:create_additional, Request)
end

#current_user_can_request_additional_sequencing_on?(asset) ⇒ Boolean

Returns true if the current user can request additional sequencing on the given asset, otherwise false

Returns:

  • (Boolean)

65
66
67
# File 'app/helpers/assets_helper.rb', line 65

def current_user_can_request_additional_sequencing_on?(asset)
  asset.sequenceable? && can?(:create_additional, Request)
end

#current_user_studiesObject


80
81
82
# File 'app/helpers/assets_helper.rb', line 80

def current_user_studies
  Study.accessible_by(current_ability, :request_additional_with)
end

#instance_variable_or_id_param(name, &block) ⇒ Object

Given the core name of an instance variable or ID parameter this method yields the name of the ID parameter along with its current value, based either on the instance variable ID value or the ID parameter. For instance, if the 'name' is 'foo' then either the '@foo.id' value will be yielded, or the 'params' value if @foo is nil.


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

def instance_variable_or_id_param(name, &block)
  field_name, value = :"#{name}_id", instance_variable_get(:"@#{name}")
  value_id = value.nil? ? params[field_name] : value.id
  concat(capture(field_name, value_id, &block))
end

#labware_typesObject


84
85
86
# File 'app/helpers/assets_helper.rb', line 84

def labware_types
  ['All', *Labware.descendants.map(&:name)]
end

#labware_types_for_selectObject


88
89
90
# File 'app/helpers/assets_helper.rb', line 88

def labware_types_for_select
  labware_types.map { |at| [at.underscore.humanize, at] }
end

#new_request_receptacle_path_in_context(asset) ⇒ Object

Returns an appropriate path given the current parameters


34
35
36
37
38
# File 'app/helpers/assets_helper.rb', line 34

def new_request_receptacle_path_in_context(asset)
  path_options = asset.is_a?(Receptacle) ? { id: asset.id } : asset.receptacle.id
  path_options[:study_id] = params[:study_id] if params.key?(:study_id)
  new_request_receptacle_path(path_options)
end

#select_field_sorted_by_name(field, select_options_source, selected, can_edit, options = {}) ⇒ Object

Returns a select tag that has it's options ordered by name (assumes present of sorted_by_name function) and disabled if a value has been pre-selected.


52
53
54
55
56
57
58
59
60
61
62
# File 'app/helpers/assets_helper.rb', line 52

def select_field_sorted_by_name(field, select_options_source, selected, can_edit, options = {})
  disabled = selected.present? && !can_edit

  tag.div(class: 'col-md-5') do
    select_tag(
      field,
      options_for_select(select_options_source.sorted_by_name.pluck(:name, :id), selected.try(:to_i)),
      options.merge(disabled: disabled, class: 'form-control select2')
    )
  end
end

#well_color(plate_layout, row, column) ⇒ Object


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

def well_color(plate_layout, row, column)
  if plate_layout.empty_well_at?(row, column)
    'empty_cell'
  elsif plate_layout.good_well_at?(row, column)
    'good_cell'
  else
    'bad_cell'
  end
end

#well_identifier(plate_layout, row, column) ⇒ Object


3
4
5
# File 'app/helpers/assets_helper.rb', line 3

def well_identifier(plate_layout, row, column)
  plate_layout.cell_name_for_well_at(row, column)
end

#well_information(plate_layout, row, column) ⇒ Object

rubocop:todo Metrics/MethodLength


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/assets_helper.rb', line 7

def well_information(plate_layout, row, column) # rubocop:todo Metrics/MethodLength
  well = plate_layout.well_at(row, column)
  if plate_layout.empty_well_at?(row, column)
    ['Empty', '', '']
  elsif plate_layout.good_well_at?(row, column)
    ["Request ID: #{well[:request].id}", "Asset: #{well[:asset].name}", "Barcode: #{well[:asset].barcode}"]
  elsif plate_layout.bad_well_at?(row, column)
    ['Error', (well[:error]).to_s, '']
  else
    raise StandardError,
          "Unknown well status ((#{plate_layout.location_for_well_at(row, column)}) = #{
            plate_layout.well_at(row, column).inspect
          })"
  end
end