Module: CollectionObjectsHelper

Defined in:
app/helpers/collection_objects_helper.rb

Instance Method Summary collapse

Instance Method Details

#collection_object_autocomplete_tag(collection_object) ⇒ Object



41
42
43
44
45
46
# File 'app/helpers/collection_objects_helper.rb', line 41

def collection_object_autocomplete_tag(collection_object)
  return nil if collection_object.nil?
  [collection_object_identifier_tag(collection_object),
   collection_object_taxon_determination_tag(collection_object)
  ].join(' ').html_safe
end

#collection_object_browse_next_by_identifier(collection_object) ⇒ link_to

Returns this may not work for all identifier types, i.e. those with identifiers like `123.34` or `3434.33X` may not increment correctly.

Returns:

  • (link_to)

    this may not work for all identifier types, i.e. those with identifiers like `123.34` or `3434.33X` may not increment correctly



152
153
154
155
156
157
158
159
160
161
# File 'app/helpers/collection_objects_helper.rb', line 152

def collection_object_browse_next_by_identifier(collection_object)
  return nil if collection_object.nil?
  o = collection_object.next_by_identifier
  return (:div, 'None', 'class' => 'navigation-item disable') if o.nil?
  link_text = (:span, 'Next by id', 'class' => 'small-icon icon-right', 'data-icon' => 'arrow-right')
  link_to(link_text, browse_collection_objects_task_path(collection_object_id: o.id),
          data: {arrow: :next,
                 'no-turbolinks' => 'false',
                 help: 'Sorts by identifier type, namespace, then an conversion of identifier into integer.  Will not work for all identifier types.'}, class:'navigation-item')
end

#collection_object_browse_previous_by_identifier(collection_object) ⇒ link_to

Returns this may not work for all identifier types, i.e. those with identifiers like `123.34` or `3434.33X` may not increment correctly.

Returns:

  • (link_to)

    this may not work for all identifier types, i.e. those with identifiers like `123.34` or `3434.33X` may not increment correctly



138
139
140
141
142
143
144
145
146
147
148
# File 'app/helpers/collection_objects_helper.rb', line 138

def collection_object_browse_previous_by_identifier(collection_object)
  return nil if collection_object.nil?
  o = collection_object.previous_by_identifier
  return (:div, 'None', 'class' => 'navigation-item disable') if o.nil?
  link_text = (:span, 'Previous by id', 'class' => 'small-icon icon-left', 'data-icon' => 'arrow-left')
  link_to(link_text, browse_collection_objects_task_path(collection_object_id: o.id), data: {
    arrow: :previous,
    'no-turbolinks' => 'true',
    help: 'Sorts by identifier type, namespace, then an conversion of identifier into integer.  Will not work for all identifier types.'},
    class: 'navigation-item')
end

#collection_object_deaccession_tag(collection_object) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'app/helpers/collection_objects_helper.rb', line 69

def collection_object_deaccession_tag(collection_object)
  return nil if collection_object.nil? || (collection_object.deaccession_reason.blank? && collection_object.deaccessioned_at.nil?)
  msg = ['DEACCESSIONED"', collection_object.deaccession_reason, collection_object.deaccessioned_at&.year].compact.join(' - ')
  (:span, msg, class: [
    :feedback,
    'feedback-thin',
    'feedback-danger'
  ]).html_safe
end

#collection_object_identifier_tag(collection_object) ⇒ Object



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

def collection_object_identifier_tag(collection_object)
  return nil if collection_object.nil?
  t, i = collection_object_visualized_identifier(collection_object)

  return (:span, i, class: [
    :feedback,
    'feedback-thin',
    (t == :collection_object ? 'feedback-primary' : 'feedback-warning')
  ]) if i
  (:span, 'no identifier assigned', class: [:feedback, 'feedback-thin', 'feedback-warning'])
end


26
27
28
29
# File 'app/helpers/collection_objects_helper.rb', line 26

def collection_object_link(collection_object)
  return nil if collection_object.nil?
  link_to(collection_object_tag(collection_object).html_safe, collection_object.metamorphosize)
end

#collection_object_metadata_badge(collection_object) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'app/helpers/collection_objects_helper.rb', line 163

def (collection_object)
  return nil if collection_object.nil?
  o = collection_object

  layout = Waxy::Geometry::Layout.new(
    Waxy::Geometry::Orientation::LAYOUT_POINTY,
    Waxy::Geometry::Point.new(14,14), # size
    Waxy::Geometry::Point.new(14,14), # start
    0 # padding
  )

  s = [
    (o.identifiers.any? ? 1 : 0),
    (o.taxon_determinations.any? ? 1 : 0),
    (o.collecting_event&.map_center.nil? ? 0 : 1),
    (o.collecting_event_id ? 1 : 0),
    (o.buffered_determinations.blank? ? 0 : 1),
    (o.buffered_collecting_event.blank? ? 0 : 1),
  ]

  a = Waxy::Meta.new
  a.size = s
  a.stroke = 'grey'
  a.link_title = "#{o.id.to_s} created #{time_ago_in_words(o.created_at)} ago by #{user_tag(o.creator)}"

  c = Waxy::Render::Svg::Canvas.new(28, 28)
  c.body << Waxy::Render::Svg.rectangle(layout, [a], 0)
  c.to_svg
end

#collection_object_radial_tag(collection_object) ⇒ Object



31
32
33
# File 'app/helpers/collection_objects_helper.rb', line 31

def collection_object_radial_tag(collection_object)
  (:span, '', data: { 'global-id' => collection_object.to_global_id.to_s, 'collection-object-radial' => 'true'})
end

#collection_object_tag(collection_object) ⇒ Object

Return [String, nil]

a descriptor including the identifier and determination


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/collection_objects_helper.rb', line 5

def collection_object_tag(collection_object)
  return nil if collection_object.nil?
  a = [ 
    collection_object_deaccession_tag(collection_object),
    collection_object_identifier_tag(collection_object),
    taxon_determination_tag(collection_object.taxon_determinations.order(:position).first)
  ].compact

  if a.empty?
    a << [
      collection_object.buffered_collecting_event,
      collection_object.buffered_determinations,
      collection_object.buffered_other_labels
    ].compact
  end

  a << "[#{collection_object.type[(0..2)].capitalize}]"

  a.join('&nbsp;').html_safe
end

#collection_object_taxon_determination_tag(collection_object) ⇒ Object



90
91
92
93
94
95
# File 'app/helpers/collection_objects_helper.rb', line 90

def collection_object_taxon_determination_tag(collection_object)
  return nil if collection_object.nil?
  i = taxon_determination_tag(collection_object.taxon_determinations.order(:position).first)
  return (:span, i, class: [:feedback, 'feedback-thin', 'feedback-secondary']) if i
  nil
end

#collection_object_visualized_identifier(collection_object) ⇒ Array [Identifier, String (type)]?

Returns also checks virtual container for identifier by proxy.

Returns:

  • (Array [Identifier, String (type)], nil)

    also checks virtual container for identifier by proxy



81
82
83
84
85
86
87
88
# File 'app/helpers/collection_objects_helper.rb', line 81

def collection_object_visualized_identifier(collection_object)
  return nil if collection_object.nil?
  i = collection_object.identifiers&.first
  return  [:collection_object, identifier_tag(i)] if i
  j = collection_object&.container&.identifiers&.first
  return [:container, identifier_tag(j)] if j
  nil
end

#collection_objects_search_formObject



48
49
50
# File 'app/helpers/collection_objects_helper.rb', line 48

def collection_objects_search_form
  render('/collection_objects/quick_search_form')
end

#dwc_occurrence_table_body_tag(collection_objects) ⇒ Object



103
104
105
106
107
# File 'app/helpers/collection_objects_helper.rb', line 103

def dwc_occurrence_table_body_tag(collection_objects)
  collection_objects.collect do |c|
    dwc_occurrence_table_row_stub(c).html_safe
  end.join.html_safe
end

#dwc_occurrence_table_header_tagObject

TODO: Isolate into own helper TODO: syncronize with class methods



99
100
101
# File 'app/helpers/collection_objects_helper.rb', line 99

def dwc_occurrence_table_header_tag
  (:tr, CollectionObject::DwcExtensions::DWC_OCCURRENCE_MAP.keys.collect{|k| (:th, k)}.join.html_safe, class: [:error])
end

#dwc_occurrence_table_row_stub(collection_object) ⇒ Object



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

def dwc_occurrence_table_row_stub(collection_object)
  r = collection_object.dwc_occurrence
  if r
    dwc_occurrence_table_row_tag(r)
  else
    id = collection_object.to_param
    (:tr, nil, id: "dwc_row_stub_#{id}", data: {'collection-object-id': id}, class: 'dwc_row_stub' )
  end
end

#dwc_occurrence_table_row_tag(dwc_occurrence) ⇒ Object



126
127
128
129
130
131
132
133
134
# File 'app/helpers/collection_objects_helper.rb', line 126

def dwc_occurrence_table_row_tag(dwc_occurrence)
  o = metamorphosize_if(dwc_occurrence.dwc_occurrence_object)
  (:tr, class: [:contextMenuCells, :btn, 'btn-neutral']) do
    [CollectionObject::DwcExtensions::DWC_OCCURRENCE_MAP.keys.collect{|k| (:td, dwc_occurrence.send(k))}.join,
     fancy_show_tag(o),
     fancy_edit_tag(o)
    ].join.html_safe
  end
end

#dwc_table(collection_objects) ⇒ Object



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

def dwc_table(collection_objects)
  (:table) do
    dwc_occurrence_table_header_tag +
      dwc_occurrence_table_body_tag(collection_objects)
  end
end

#label_for_collection_object(collection_object) ⇒ Object



35
36
37
38
39
# File 'app/helpers/collection_objects_helper.rb', line 35

def label_for_collection_object(collection_object)
  return nil if collection_object.nil?
  [ 'CollectionObject ' + collection_object.id.to_s,
    collection_object.identifiers.first&.cached].compact.join(', ')
end


52
53
54
55
# File 'app/helpers/collection_objects_helper.rb', line 52

def verify_accessions_task_link(collection_object)
  priority = [collection_object.container, collection_object.identifiers.first, collection_object ].compact.first
  link_to('Verify', verify_accessions_task_path(by: priority.metamorphosize.class.name.tableize.singularize.to_sym, id: priority.to_param))
end