Module: TaxonNamesHelper

Defined in:
app/helpers/taxon_names_helper.rb

Instance Method Summary collapse

Instance Method Details



242
243
244
245
246
247
248
249
250
251
# File 'app/helpers/taxon_names_helper.rb', line 242

def ancestor_browse_taxon_name_link(taxon_name, path = :browse_nomenclature_task_path)
  text = 'Up'
  if taxon_name.ancestors.any?
    a = taxon_name.ancestors.first.metamorphosize
    text = object_tag(a)
    link_to((:span, text, data: {icon: 'arrow-up'}, class: 'small-icon'), send(path, taxon_name_id: a.id), class: 'navigation-item', data: {arrow: 'ancestor'})
  else
    (:div, (:span, text, class: 'small-icon', data: {icon: 'arrow-up'}), class: 'navigation-item disable')
  end
end

#cached_classified_as_tag(taxon_name) ⇒ Object



149
150
151
# File 'app/helpers/taxon_names_helper.rb', line 149

def cached_classified_as_tag(taxon_name)
  taxon_name.cached_classified_as ? taxon_name.cached_classified_as.strip.html_safe : ''
end

#current_author_year(taxon_name) ⇒ String

Returns:

  • (String)


100
101
102
103
# File 'app/helpers/taxon_names_helper.rb', line 100

def current_author_year(taxon_name)
  return nil if taxon_name.nil? || taxon_name.cached_author_year.nil?
  taxon_name.cached_author_year
end


253
254
255
256
257
258
259
260
261
262
# File 'app/helpers/taxon_names_helper.rb', line 253

def descendant_browse_taxon_name_link(taxon_name, path = :browse_nomenclature_task_path)
  text = 'Down'
  if taxon_name.descendants.any?
    a = taxon_name.descendants.first.metamorphosize
    text = taxon_name_tag(a)
    link_to((:span, text, data: {icon: 'arrow-down'}, class: 'small-icon'), send(path, taxon_name_id: a.id), class: 'navigation-item', data: {arrow: 'descendant'})
  else
    (:div, (:span, text, class: 'small-icon', data: {icon: 'arrow-down'}), class: 'navigation-item disable')
  end
end


191
192
193
# File 'app/helpers/taxon_names_helper.rb', line 191

def edit_original_combination_task_link(taxon_name)
  link_to('Edit original combination', edit_protonym_original_combination_task_path(taxon_name)) if GENUS_AND_SPECIES_RANK_NAMES.include?(taxon_name.rank_string)
end


206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'app/helpers/taxon_names_helper.rb', line 206

def edit_taxon_name_link(taxon_name, target: nil)
  i = {'Combination': :combination, 'Protonym': :taxon_name}[taxon_name.type.to_sym]
  t = taxon_name.metamorphosize
  case target
  when :edit_task
    path = case i
           when :taxon_name
             new_taxon_name_task_path(taxon_name_id: t.id)
           when :combination
             new_combination_task_path(taxon_name_id: t.id, literal: URI.escape(t.cached))
           end
    link_to(
      (
        :span, 'Edit (task)',
        'data-icon' => 'edit',
        class: 'small-icon'
      ),
      path, class: 'navigation-item', 'data-task' => 'new_taxon_name')
  else
    link_to((:span, 'Edit', 'data-icon' => 'edit', 'class' => 'small-icon'), send("edit_#{i}_path}", taxon_name.metamorphosize), 'class' => 'navigation-item')
  end
end

#edit_taxon_name_path_string(taxon_name) ⇒ Object

See #edit_object_path_string in navigation_helper.rb



196
197
198
199
200
201
202
203
204
# File 'app/helpers/taxon_names_helper.rb', line 196

def edit_taxon_name_path_string(taxon_name)
  if taxon_name.type == 'Protonym'
    'edit_taxon_name_path'
  elsif taxon_name.type == 'Combination'
    'edit_combination_path'
  else
    nil
  end
end

#full_original_taxon_name_string(taxon_name) ⇒ String

Returns the name in original combination, with author year, with HTML.

Returns:

  • (String)

    the name in original combination, with author year, with HTML



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

def full_original_taxon_name_string(taxon_name)
  return nil if taxon_name.nil? || taxon_name.cached_original_combination.nil?
  [ taxon_name.cached_original_combination,
    taxon_name.cached_author_year
  ].compact.join(' ')
end

#full_original_taxon_name_tag(taxon_name) ⇒ String

Returns the name in original combination, with author year, with HTML.

Returns:

  • (String)

    the name in original combination, with author year, with HTML



69
70
71
72
73
74
# File 'app/helpers/taxon_names_helper.rb', line 69

def full_original_taxon_name_tag(taxon_name)
  return nil if taxon_name.nil?
  [ original_taxon_name_tag(taxon_name),
    history_author_year_tag(taxon_name)
  ].compact.join(' ').html_safe
end

#full_taxon_name_tag(taxon_name) ⇒ String

Returns the current name/combination with author year, with HTML.

Returns:

  • (String)

    the current name/combination with author year, with HTML



62
63
64
65
# File 'app/helpers/taxon_names_helper.rb', line 62

def full_taxon_name_tag(taxon_name)
  return nil if taxon_name.nil?
  [taxon_name_tag(taxon_name), taxon_name.cached_author_year].compact.join(' ').html_safe
end

#label_for_taxon_name(taxon_name) ⇒ Object



11
12
13
14
# File 'app/helpers/taxon_names_helper.rb', line 11

def label_for_taxon_name(taxon_name)
  return nil if taxon_name.nil?
  [taxon_name.cached, taxon_name.cached_author_year].compact.join(' ')
end


264
265
266
267
268
269
270
271
272
# File 'app/helpers/taxon_names_helper.rb', line 264

def next_sibling_browse_taxon_name_link(taxon_name, path = :browse_nomenclature_task_path)
  text = 'Next'
  link_object = taxon_name.next_sibling
  if link_object.nil?
    (:div, (:span, text), class:  'navigation-item disable')
  else
    link_to(text, send(path, taxon_name_id: link_object.id), title: taxon_name_tag(link_object), class: 'navigation-item', data: { button: 'next' })
  end
end

#original_author_year(taxon_name) ⇒ String

Returns removes parens.

Returns:

  • (String)

    removes parens



94
95
96
97
# File 'app/helpers/taxon_names_helper.rb', line 94

def original_author_year(taxon_name)
  return nil if taxon_name.nil? || taxon_name.cached_author_year.nil?
  taxon_name.original_author_year || ''
end


168
169
170
171
# File 'app/helpers/taxon_names_helper.rb', line 168

def original_taxon_name_link(taxon_name)
  return nil if taxon_name.nil?
  link_to(original_taxon_name_tag(taxon_name).html_safe, browse_nomenclature_task_path(taxon_name_id: taxon_name.id))
end

#original_taxon_name_tag(taxon_name) ⇒ String

Returns the taxon name in original combination, without author year, with HTML.

Returns:

  • (String)

    the taxon name in original combination, without author year, with HTML



51
52
53
54
55
56
57
58
# File 'app/helpers/taxon_names_helper.rb', line 51

def original_taxon_name_tag(taxon_name)
  return nil if taxon_name.nil?
  if taxon_name.cached_original_combination_html.nil?
    taxon_name_tag(taxon_name)
  else
    taxon_name.cached_original_combination_html.html_safe
  end
end

#parent_taxon_name_for_select(taxon_name) ⇒ Object

@taxon_name.parent.andand.display_name(:type => :for_select_list)



178
179
180
# File 'app/helpers/taxon_names_helper.rb', line 178

def parent_taxon_name_for_select(taxon_name)
  taxon_name.parent ? taxon_name_for_select(taxon_name.parent) : nil
end


274
275
276
277
278
279
280
281
282
283
# File 'app/helpers/taxon_names_helper.rb', line 274

def previous_sibling_browse_taxon_name_link(taxon_name, path = :browse_nomenclature_task_path)
  text = 'Previous'
  link_object = taxon_name.previous_sibling

  if link_object.nil?
    (:div, (:span, text), class: 'navigation-item disable')
  else
    link_to(text, send(path, taxon_name_id: link_object.id), class: 'navigation-item', data: { button: 'back' })
  end
end

#rank_tag(taxon_name) ⇒ Object



229
230
231
232
233
234
235
236
237
238
239
240
# File 'app/helpers/taxon_names_helper.rb', line 229

def rank_tag(taxon_name)
  case taxon_name.type
  when 'Protonym'
    if taxon_name.rank_class
      taxon_name.rank.downcase
    else
      (:em, 'ERROR')
    end
  when 'Combination'
    (:em, 'Combination')
  end
end

#taxon_name_autocomplete_selected_tag(taxon_name) ⇒ String

Returns no HTML inside <input>.

Returns:

  • (String)

    no HTML inside <input>



29
30
31
32
# File 'app/helpers/taxon_names_helper.rb', line 29

def taxon_name_autocomplete_selected_tag(taxon_name)
  return nil if taxon_name.nil?
  [taxon_name.cached, taxon_name.cached_author_year].compact.join(' ')
end

#taxon_name_autocomplete_tag(taxon_name, term) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/taxon_names_helper.rb', line 16

def taxon_name_autocomplete_tag(taxon_name, term)
  return nil if taxon_name.nil?
  klass = taxon_name.rank_class ? taxon_name.rank_class.nomenclatural_code : nil
  a = [
    (:span, mark_tag(taxon_name.cached_html_name_and_author_year, term),  class: :klass),
    taxon_name_rank_tag(taxon_name),
    taxon_name_parent_tag(taxon_name),
    taxon_name_original_combination_tag(taxon_name)
  ].compact.join('&nbsp;').html_safe
end


163
164
165
166
# File 'app/helpers/taxon_names_helper.rb', line 163

def taxon_name_browse_link(taxon_name)
  return nil if taxon_name.nil?
  [ link_to(taxon_name_tag(taxon_name), browse_nomenclature_task_path(taxon_name_id: taxon_name.id)).html_safe,  taxon_name.cached_author_year].compact.join(' ').html_safe
end

#taxon_name_for_select(taxon_name) ⇒ Object



173
174
175
# File 'app/helpers/taxon_names_helper.rb', line 173

def taxon_name_for_select(taxon_name)
  taxon_name.name if taxon_name
end

#taxon_name_gender_sentence_tag(taxon_name) ⇒ Object



144
145
146
147
# File 'app/helpers/taxon_names_helper.rb', line 144

def taxon_name_gender_sentence_tag(taxon_name)
  return nil if taxon_name.nil?
  "The name is #{taxon_name.gender_name}." if taxon_name.gender_name
end

#taxon_name_latinization_tag(taxon_name) ⇒ Object



153
154
155
156
# File 'app/helpers/taxon_names_helper.rb', line 153

def taxon_name_latinization_tag(taxon_name)
  list = taxon_name.taxon_name_classifications.with_type_array(LATINIZED_TAXON_NAME_CLASSIFICATION_NAMES).map(&:classification_label)
  (:span,  "The word \"#{taxon_name.name}\" has the following Latin-based classifications: #{list.to_sentence}.", class: 'history__latinized_classifications') if list.any?
end


158
159
160
161
# File 'app/helpers/taxon_names_helper.rb', line 158

def taxon_name_link(taxon_name)
  return nil if taxon_name.nil?
  link_to(taxon_name_tag(taxon_name), taxon_name.metamorphosize).html_safe
end

#taxon_name_name_string(taxon_name) ⇒ String

Returns the current name/combination with author year, without HTML.

Returns:

  • (String)

    the current name/combination with author year, without HTML



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

def taxon_name_name_string(taxon_name)
  return nil if taxon_name.nil?
  [ taxon_name.cached, taxon_name.cached_author_year].compact.join(' ')
end

#taxon_name_original_combination_tag(taxon_name, css_class = [:feedback, 'feedback-notice', 'feedback-thin']) ⇒ Object



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

def taxon_name_original_combination_tag(taxon_name, css_class = [:feedback, 'feedback-notice', 'feedback-thin'] )
  return nil if taxon_name.nil? || taxon_name.cached_original_combination.blank?
  (:span, taxon_name.cached_original_combination, class: css_class)
end


285
286
287
288
289
290
291
292
293
294
295
296
# File 'app/helpers/taxon_names_helper.rb', line 285

def taxon_name_otus_links(taxon_name)
  if taxon_name.otus.load.any?
    ('The following Otus are linked to this name: ' +
    (:ul, class: 'no_bullets') do
     taxon_name.otus.each do |o|
        concat((:li, otu_link(o) ))
      end
    end.html_safe).html_safe
  else
    (:em, 'There are no Otus linked to this name.')
  end
end

#taxon_name_parent_tag(taxon_name, css_class = [:feedback, 'feedback-secondary', 'feedback-thin']) ⇒ Object



39
40
41
42
# File 'app/helpers/taxon_names_helper.rb', line 39

def taxon_name_parent_tag(taxon_name, css_class = [:feedback, 'feedback-secondary', 'feedback-thin'] )
  return nil if taxon_name.nil? || taxon_name.parent_id.nil?
  (:span, taxon_name_tag(taxon_name.parent).html_safe, class: css_class)
end

#taxon_name_rank_select_tag(taxon_name: TaxonName.new, code: nil) ⇒ Object

TODO: Scope to code



183
184
185
# File 'app/helpers/taxon_names_helper.rb', line 183

def taxon_name_rank_select_tag(taxon_name: TaxonName.new, code:  nil)
  select(:taxon_name, :rank_class, options_for_select(RANKS_SELECT_OPTIONS, selected: taxon_name.rank_string) )
end

#taxon_name_rank_tag(taxon_name, css_class = [:feedback, 'feedback-info', 'feedback-thin']) ⇒ Object



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

def taxon_name_rank_tag(taxon_name, css_class = [:feedback, 'feedback-info', 'feedback-thin'] )
  return nil if taxon_name.nil?
  (:span, taxon_name.rank || 'Combination', class: css_class)
end

#taxon_name_short_status(taxon_name) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'app/helpers/taxon_names_helper.rb', line 114

def taxon_name_short_status(taxon_name)
  if taxon_name.is_combination?
    n = taxon_name.finest_protonym
    s = ["This name is subsequent combination of"]
    if n.is_valid?
      s += [
        link_to(original_taxon_name_tag(n), browse_nomenclature_task_path(taxon_name_id: n.id)),
        history_author_year_tag(n),
      ]
    else
      v = n.valid_taxon_name
      s += [
        original_taxon_name_tag(n),
        history_author_year_tag(n),
        "whose valid/accepted name is",
        link_to(taxon_name_tag(v), browse_nomenclature_task_path(taxon_name_id: v.id) ),
        v.cached_author_year
      ]
    end

    (s.join(' ') + '.').html_safe
  else
    if taxon_name.unavailable_or_invalid?
      (:span, "This name is not valid/accepted.<br>The valid name is #{taxon_name_browse_link(taxon_name.valid_taxon_name)}.".html_safe, class: :brief_status, data: {icon: :attention, status: :invalid})
    else
      (:span, 'This name is valid/accepted.', class: :brief_status, data: {icon: :ok, status: :valid })
    end
  end
end

#taxon_name_tag(taxon_name) ⇒ String

Returns the taxon name without author year, with HTML.

Returns:

  • (String)

    the taxon name without author year, with HTML



5
6
7
8
9
# File 'app/helpers/taxon_names_helper.rb', line 5

def taxon_name_tag(taxon_name)
  return nil if taxon_name.nil?
  return taxon_name.name if taxon_name.new_record?
  taxon_name.cached_html.try(:html_safe) || taxon_name.name
end

#taxon_name_type_short_tag(taxon_name) ⇒ Object



105
106
107
108
109
110
111
112
# File 'app/helpers/taxon_names_helper.rb', line 105

def taxon_name_type_short_tag(taxon_name)
  return nil if taxon_name.nil?
  if taxon_name.is_valid?
    '&#10003;'.html_safe # check
  else
    taxon_name.type == 'Combination' ? '[c]' : '&#10060;'.html_safe # c or X
  end
end

#taxon_names_search_formObject



187
188
189
# File 'app/helpers/taxon_names_helper.rb', line 187

def taxon_names_search_form
  render '/taxon_names/quick_search_form'
end