Module: LabelsHelper

Defined in:
app/helpers/labels_helper.rb

Instance Method Summary collapse

Instance Method Details

#label_code_128_tag(label) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'app/helpers/labels_helper.rb', line 128

def label_code_128_tag(label)
  begin
  c = Barby::Code128.new(label.text)

  (
    :span,

    (
      :span,
      c.to_svg(xmargin: 0, ymargin: 0).html_safe,
      class: :code128_barcode
    ) +
    (:span, label.text, class: 'code128_text'),
    class: :code128
  )

  rescue ArgumentError => e
    if e.message == "Data not valid"
      return tag.span('Label is set to Code128 but can not be encoded as such.')
    else
      raise e
    end
  end
end

#label_drawer_tag(label) ⇒ Object

Object is a Container TODO: Not done



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/helpers/labels_helper.rb', line 36

def label_drawer_tag(label)
  o = label.label_object
  tag.span(
    tag.span(
      tag.span(o.taxonomy['order']&.upcase, class: 'drawer_order') +
      tag.span(o.id, class: 'drawer_taxon_name_id'),
      class: 'drawer_top'
    ) +
    "\n" +
    tag.span(
      'stub', class: 'drawer_bottom'
    ), class: 'foo')
end


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

def label_link(label)
  return nil if label.nil?
  if label.label_object_id.blank?
    taxonworks_label_tag(label)
  else
    link_to((:span, label.text), print_labels_task_path(label_id: label.to_param))
  end
end

#label_slide_box_tag(label) ⇒ Object

Object is a Container TODO: Not done



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

def label_slide_box_tag(label)
  o = label.label_object
  tag.span(
    tag.span(
      tag.span(full_taxon_name_tag(o), class: 'unit_tray_header1_left') +
      tag.span(o.id, class: 'unit_tray_header1_right'),
      class: 'unit_tray_header1_top'
    ) +
    "\n" +
    tag.span(
      [o.taxonomy['order'], o.taxonomy['family']].compact.join(': '), class: 'unit_tray_header1_bottom'
    ), class: 'foo')
end

#label_svg_tag(label) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/helpers/labels_helper.rb', line 103

def label_svg_tag(label)
  c = ::RQRCode::QRCode.new(label.text)

  (
    :span,
    (:span, label.text, class: 'qrcode_text') +
    (
      :span,
      c.as_svg(
        offset: 0,
        color: '000',
        shape_rendering: 'crispEdges',
        module_size: 1,
        standalone: true,
        viewbox: true,
        svg_attributes: {
          class: :qrcode_svg
        }
      ).to_s.html_safe,
      class: :qrcode_barcode
    ),
    class: :qrcode
  )
end

#label_unit_tray_header1_tag(label) ⇒ Object

Object is a TaxonName



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/helpers/labels_helper.rb', line 67

def label_unit_tray_header1_tag(label)
  o = label.label_object
  tag.span(
    tag.span(
      tag.span(full_taxon_name_tag(o), class: 'unit_tray_header1_left') +
      tag.span(o.id, class: 'unit_tray_header1_right'),
      class: 'unit_tray_header1_top'
    ) +
    "\n" +
    tag.span(
      [o.taxonomy['order'], o.taxonomy['family']].compact.join(': '), class: 'unit_tray_header1_bottom'
    ) +
    tag.div('', class: 'unit_tray_header1_footer'),
    class: 'unit_tray_header1')
end

#label_vial_rack_horizontal_tag(label) ⇒ Object

Object is a Container TODO: Not done



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/helpers/labels_helper.rb', line 85

def label_vial_rack_horizontal_tag(label)
  o = label.label_object
  tag.span(
    tag.span(
      tag.span(o.taxonomy['order']&.upcase, class: 'vial_rack_order') +
      tag.span(o.taxonomy['family'], class: 'vial_rack_family'),
      class: 'vial_rack_top'
    ), class: 'foo')

  #  "\n" +
  #  tag.span( taxon_name_tag(o), class: 'vial_rack_species') # +
  # tag.span( o.cached_author_year, class: 'vial_rack_author_year') +
  # "\n" +
  # tag.span(
  #   tag.span(o.id, class: vial_rack_taxon_name_id) +
  #   tag.span('R', class: vial_rack_container_id)  # TODO: can we find this?
end

#taxonworks_label_tag(label) ⇒ Object

!! Note that ‘label_tag` is a Rails method, so we have to append and make exceptions



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/labels_helper.rb', line 9

def taxonworks_label_tag(label)
  return nil if label.nil?
  if label.is_generated?
    case label.type
    when 'Label::QrCode'
      return label_svg_tag(label)
    when 'Label::Code128'
      return label_code_128_tag(label)
    else
      return send('label_' + label.type.split('::').last.tableize.singularize + '_tag', label)
    end
  else
    (:span, label.text, style: label.style) # TODO: properly reference style
  end
end