Module: CollectingEventsHelper

Defined in:
app/helpers/collecting_events_helper.rb

Instance Method Summary collapse

Instance Method Details

#collecting_event_autocomplete_tag(collecting_event, join_string = '<br>', term: nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/collecting_events_helper.rb', line 19

def collecting_event_autocomplete_tag(collecting_event, join_string = '<br>', term: nil)
  return nil if collecting_event.nil?
  s = [ collecting_event_identifiers_tag(collecting_event),
    collecting_event_geographic_names_tag(collecting_event),
    collecting_event_verbatim_locality_tag(collecting_event),
    collecting_event_dates_tag(collecting_event),
    collecting_event_collectors_tag(collecting_event),
    collecting_event_verbatim_coordinates_tag(collecting_event),
    # collecting_event_coordinates_tag(collecting_event), # this is very slow
    collecting_event_method_habitat_tag(collecting_event),
    collecting_event_uses_tag(collecting_event)
  ].compact.join(join_string)
  mark_tag(s, term)
end

#collecting_event_browse_next_by_identifier(collecting_event) ⇒ 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



184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'app/helpers/collecting_events_helper.rb', line 184

def collecting_event_browse_next_by_identifier(collecting_event)
  return nil if collecting_event.nil?
  o = collecting_event.next_by_identifier
  return (:div, 'None', 'class' => 'navigation-item disable') if o.nil?
  link_text = safe_join(['Next by id', (:span, '', class: 'small-icon margin-small-left', data: { icon: 'arrow-right' })], '')
  link_to(
    link_text, browse_collecting_events_task_path(collecting_event_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

#collecting_event_browse_previous_by_identifier(collecting_event) ⇒ 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



168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'app/helpers/collecting_events_helper.rb', line 168

def collecting_event_browse_previous_by_identifier(collecting_event)
  return nil if collecting_event.nil?
  o = collecting_event.previous_by_identifier
  return (:div, 'None', 'class' => 'navigation-item disable') if o.nil?
  link_text = safe_join([(:span, '', class: 'small-icon', data: { icon: 'arrow-left' }), 'Previous by id'], '')
  link_to(
    link_text, browse_collecting_events_task_path(collecting_event_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

#collecting_event_collectors_tag(collecting_event) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'app/helpers/collecting_events_helper.rb', line 72

def collecting_event_collectors_tag(collecting_event)
  return nil if collecting_event.nil? || (collecting_event.verbatim_collectors.blank? && !collecting_event.collectors.load.any?)
  a = ''

  a << (
    :span, Utilities::Strings.authorship_sentence(collecting_event.collectors.collect{|a| a.cached})
  ) if collecting_event.collectors.any?

  a << '&nbsp;'.html_safe + (:span,  collecting_event.verbatim_collectors, class: [:feedback, 'feedback-thin','feedback-secondary']) if collecting_event.verbatim_collectors
  a.html_safe
end

#collecting_event_coordinates_tag(collecting_event) ⇒ Object

Slow, but accurate



85
86
87
88
89
# File 'app/helpers/collecting_events_helper.rb', line 85

def collecting_event_coordinates_tag(collecting_event)
  return nil if collecting_event.nil? || collecting_event.map_center_method.nil?
  c = collecting_event.map_center
  (:span, [c.x.round(4), c.y.round(4)].join('&nbsp;&#8212;&nbsp;').html_safe)
end

#collecting_event_dates_tag(collecting_event) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
# File 'app/helpers/collecting_events_helper.rb', line 97

def collecting_event_dates_tag(collecting_event)
  return nil if collecting_event.nil? || !collecting_event.has_some_date?
  s = collecting_event.date_range.uniq.join('&nbsp;&#8212;&nbsp;').html_safe
  a = ''
  a = tag.span(s) if s.present?

  if collecting_event.verbatim_date
    a << '&nbsp;'.html_safe + tag.span(collecting_event.verbatim_date, class: [
      :feedback, 'feedback-thin', 'feedback-secondary'])
  end
  a.html_safe
end

#collecting_event_geographic_names_tag(collecting_event) ⇒ Object



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

def collecting_event_geographic_names_tag(collecting_event)
  return nil if collecting_event.nil?

  a = [collecting_event.cached_level0_geographic_name,
       collecting_event.cached_level1_geographic_name,
       collecting_event.cached_level2_geographic_name
  ].compact
  return nil if a.empty?

  (:span, a.join(': '))
end

#collecting_event_georeference_points(collecting_events) ⇒ Object



256
257
258
259
260
261
# File 'app/helpers/collecting_events_helper.rb', line 256

def collecting_event_georeference_points(collecting_events)
  GeographicItem.joins(:collecting_events_through_georeferences)
    .where(georeferences: {collecting_event: collecting_events})
    .select(GeographicItem.lat_long_sql(:latitude), GeographicItem.lat_long_sql(:longitude) )
    .collect{|g| [g.longitude, g.latitude]}.uniq
end

#collecting_event_identifiers_tag(collecting_event) ⇒ Object

TODO: unify



44
45
46
47
48
49
50
51
52
53
# File 'app/helpers/collecting_events_helper.rb', line 44

def collecting_event_identifiers_tag(collecting_event)
  return nil if collecting_event.nil?
  if i = collecting_event.identifiers.load.first
    collecting_event.identifiers.limit(10).collect{|j|
      (:span, j.cached, class: [ :feedback, 'feedback-thin', 'feedback-secondary' ])
    }.join + ( collecting_event.identifiers.size > 10 ? ' ... and more!' : '')
  else
    nil
  end
end

#collecting_event_label_tag(label_text) ⇒ HTML

TODO: remove

Returns:

  • (HTML)

    a pre tag formatting a label



160
161
162
# File 'app/helpers/collecting_events_helper.rb', line 160

def collecting_event_label_tag(label_text)
  (:pre, label_text, class: [:large_type, :word_break] ) # large_type needs to be larger
end


115
116
117
118
# File 'app/helpers/collecting_events_helper.rb', line 115

def collecting_event_link(collecting_event)
  return nil if collecting_event.nil?
  link_to(collecting_event_tag(collecting_event).html_safe, collecting_event)
end

#collecting_event_method_habitat_tag(collecting_event) ⇒ Object



67
68
69
70
# File 'app/helpers/collecting_events_helper.rb', line 67

def collecting_event_method_habitat_tag(collecting_event)
  return nil if collecting_event.nil? || (collecting_event.verbatim_method.blank? && collecting_event.verbatim_habitat.blank?)
  (:span, [collecting_event.verbatim_method, collecting_event.verbatim_habitat].compact.join('; '))
end

#collecting_event_namespace_select_tagString

Returns short string of use in autocomplete selects.

Returns:

  • (String)

    short string of use in autocomplete selects



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

def collecting_event_namespace_select_tag
  select_tag(:ce_namespace, options_for_select(Namespace.pluck(:short_name).uniq), prompt: 'Select a namespace')
end

#collecting_event_tag(collecting_event) ⇒ Object



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

def collecting_event_tag(collecting_event)
  return nil if collecting_event.nil?
  if a = [ collecting_event.verbatim_label,
      collecting_event.print_label,
      collecting_event.document_label ].compact.first
    [ collecting_event_identifiers_tag(collecting_event), a].compact.join('&nbsp;').html_safe
  else
    collecting_event_autocomplete_tag(collecting_event, '; ').html_safe
  end
end

#collecting_event_to_geo_json_feature(collecting_event, skip_geometry: false) ⇒ GeoJSON::Feature

Returns the first geographic item of the first georeference on this collecting event.

Returns:

  • (GeoJSON::Feature)

    the first geographic item of the first georeference on this collecting event



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'app/helpers/collecting_events_helper.rb', line 200

def collecting_event_to_geo_json_feature(collecting_event, skip_geometry: false)
  return nil if collecting_event.nil?

  if skip_geometry
    shape_type, shape_id = collecting_event.geo_json_shape_key
    return nil if shape_type.nil?
    geometry = nil
  else
    geometry, shape_type, shape_id = collecting_event.geo_json_data
    return nil if geometry.nil?
  end

  l = label_for_collecting_event(collecting_event)

  return {
    'type' => 'Feature',
    'geometry' => geometry,
    'properties' => {
      'target' => {
        'type' => 'CollectingEvent',
        'id' => collecting_event.id,
        'label' => l
      },
      'base' => {
        'type' => 'CollectingEvent',
        'id' => collecting_event.id,
        'label' => l
      },
      'shape' => {
        'type' => shape_type,
        'id' => shape_id }
    }
  }
end

#collecting_event_to_simple_json_feature(collecting_event) ⇒ Object

TODO: deprecate TODO: parametrize to include gazetteer i.e. geographic_areas_geographic_items.where( gaz = 'some string') !! avoid loading the whole GeographicItem, just grab the bits we need.



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/helpers/collecting_events_helper.rb', line 239

def collecting_event_to_simple_json_feature(collecting_event)
  base = {
    'type' => 'Feature',
    'properties' => {
      'target' => {
        'type' => 'CollectingEvent',
        'id' => collecting_event.id },
        'label' => label_for_collecting_event(collecting_event) }
  }

  if collecting_event.geographic_items.any?
    geo_item_id = collecting_event.geographic_items.select(:id).first.id
    base['geometry'] = GeographicItem.find(geo_item_id).to_geo_json
  end
  base
end

#collecting_event_uses_tag(collecting_event) ⇒ Object



34
35
36
37
38
39
40
41
# File 'app/helpers/collecting_events_helper.rb', line 34

def collecting_event_uses_tag(collecting_event)
  return nil if collecting_event.nil?
  if collecting_event.collection_objects.any?
    (:span, 'Uses: ' + collecting_event.collection_objects.count.to_s, class: [ :feedback, 'feedback-thin', 'feedback-secondary' ])
  else
    nil
  end
end

#collecting_event_verbatim_coordinates_tag(collecting_event) ⇒ Object

Fast, but limited



92
93
94
95
# File 'app/helpers/collecting_events_helper.rb', line 92

def collecting_event_verbatim_coordinates_tag(collecting_event)
  return nil if collecting_event.nil? || collecting_event.latitude.blank?
  (:span, [collecting_event.latitude, collecting_event.longitude].join(',&nbsp;').html_safe)
end

#collecting_event_verbatim_locality_tag(collecting_event) ⇒ Object



110
111
112
113
# File 'app/helpers/collecting_events_helper.rb', line 110

def collecting_event_verbatim_locality_tag(collecting_event)
  return nil unless collecting_event&.verbatim_locality&.present?
  (:span, collecting_event.verbatim_locality)
end

#collecting_events_search_formObject



120
121
122
# File 'app/helpers/collecting_events_helper.rb', line 120

def collecting_events_search_form
  render('/collecting_events/quick_search_form')
end

#date_range_tag(collecting_event) ⇒ String?

Returns summary of date data.

Returns:

  • (String, nil)

    summary of date data



142
143
144
145
# File 'app/helpers/collecting_events_helper.rb', line 142

def date_range_tag(collecting_event)
  return if collecting_event.nil?
  [collecting_event.start_date_string, collecting_event.end_date_string].compact.join(' - ')
end

#elevation_tag(collecting_event) ⇒ String?

Returns summary of elevation data.

Returns:

  • (String, nil)

    summary of elevation data



132
133
134
135
136
137
138
# File 'app/helpers/collecting_events_helper.rb', line 132

def elevation_tag(collecting_event)
  return nil if collecting_event.nil?
  [
    Utilities::Strings.nil_wrap(nil, [collecting_event.minimum_elevation, collecting_event.maximum_elevation].compact.join('-'), 'm')&.html_safe,
    Utilities::Strings.nil_wrap(' +/-', collecting_event.elevation_precision, nil)&.html_safe
  ].compact.join.html_safe
end

#label_for_collecting_event(collecting_event) ⇒ Object



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

def label_for_collecting_event(collecting_event)
  return nil if collecting_event.nil?
  collecting_event.cached
end

#verbatim_gis_tag(collecting_event) ⇒ String?

Returns summary of verbatim gis related data.

Returns:

  • (String, nil)

    summary of verbatim gis related data



149
150
151
152
153
154
155
156
# File 'app/helpers/collecting_events_helper.rb', line 149

def verbatim_gis_tag(collecting_event)
  return if collecting_event.nil?
  [collecting_event.verbatim_latitude,
   collecting_event.verbatim_longitude,
   Utilities::Strings.nil_wrap(' (+/-', collecting_event.verbatim_geolocation_uncertainty, ')')&.html_safe,
   Utilities::Strings.nil_wrap(' [via ', collecting_event.verbatim_datum, ']')&.html_safe,
  ].compact.join(', ')
end