Module: AssetsHelper

Defined in:
app/helpers/assets_helper.rb

Instance Method Summary collapse

Instance Method Details

#current_user_can_make_additional_requests_on?(_asset, study) ⇒ Boolean

Returns:

  • (Boolean)

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

def current_user_can_make_additional_requests_on?(_asset, study)
  return false unless study.present?              # Study must be specified ...
  return true if current_user.is_administrator?   # ... user could be an administrator ...

  current_user.is_manager?(study)                 # ... or the manager of the specified study
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)

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

def current_user_can_request_additional_library_on?(asset)
  asset.is_a?(SampleTube) && current_user.is_administrator?
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)

59
60
61
62
63
# File 'app/helpers/assets_helper.rb', line 59

def current_user_can_request_additional_sequencing_on?(asset)
  asset.sequenceable? && # Asset must be sequenceable ...
    (current_user.is_administrator? || # ... user could be an administrator ...
      current_user.is_manager?) # ... or a manager
end

#current_user_studies_from(_asset) ⇒ Object


77
78
79
80
81
# File 'app/helpers/assets_helper.rb', line 77

def current_user_studies_from(_asset)
  return Study if current_user.is_administrator?

  Study.managed_by(current_user)
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.


40
41
42
43
44
# File 'app/helpers/assets_helper.rb', line 40

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


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

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

#labware_types_for_selectObject


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

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


30
31
32
33
34
# File 'app/helpers/assets_helper.rb', line 30

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

#select_field_sorted_by_name(field, select_options_source, selected, 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.


48
49
50
51
52
53
54
55
56
# File 'app/helpers/assets_helper.rb', line 48

def select_field_sorted_by_name(field, select_options_source, selected, options = {})
  (: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: (selected.present? and not current_user.is_administrator?), class: 'form-control select2')
    )
  end
end

#well_color(plate_layout, row, column) ⇒ Object


19
20
21
22
23
24
25
26
27
# File 'app/helpers/assets_helper.rb', line 19

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


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

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

#well_information(plate_layout, row, column) ⇒ Object


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

def well_information(plate_layout, row, column)
  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