Module: TaxonNamesHelper
- Defined in:
- app/helpers/taxon_names_helper.rb
Instance Method Summary collapse
- #ancestor_browse_taxon_name_link(taxon_name, path = :browse_nomenclature_task_path) ⇒ Object
- #cached_classified_as_tag(taxon_name) ⇒ Object
- #current_author_year(taxon_name) ⇒ String
-
#defined_full_original_taxon_name_tag(taxon_name) ⇒ String?
!! This is used in taxon_name attributes now! TODO: Refactor our logic for display contexts and value contexts to better reflect presence of data vs.
- #descendant_browse_taxon_name_link(taxon_name, path = :browse_nomenclature_task_path) ⇒ Object
- #document_names_per_year(names) ⇒ Object
- #edit_original_combination_task_link(taxon_name) ⇒ Object
- #edit_taxon_name_link(taxon_name, target: nil) ⇒ Object
-
#edit_taxon_name_path_string(taxon_name) ⇒ Object
See #edit_object_path_string in navigation_helper.rb.
-
#full_original_taxon_name_label(taxon_name) ⇒ String
The name in original combination, with author year, without HTML.
-
#full_original_taxon_name_tag(taxon_name) ⇒ String
The name in original combination, with author year, with HTML.
-
#full_taxon_name_tag(taxon_name) ⇒ String
The current name/combination with author year, with HTML.
-
#label_for_taxon_name(taxon_name) ⇒ String
!! Unified deprecated taxon_name_name_string() here.
- #next_sibling_browse_taxon_name_link(taxon_name, path = :browse_nomenclature_task_path) ⇒ Object
-
#original_author_year(taxon_name) ⇒ String
Removes parens.
- #original_taxon_name_link(taxon_name) ⇒ Object
-
#original_taxon_name_tag(taxon_name) ⇒ String
The taxon name in original combination, without author year, with HTML.
-
#parent_taxon_name_for_select(taxon_name) ⇒ Object
@taxon_name.parent.andand.display_name(:type => :for_select_list).
- #previous_sibling_browse_taxon_name_link(taxon_name, path = :browse_nomenclature_task_path) ⇒ Object
- #rank_tag(taxon_name) ⇒ Object
-
#simple_hierarchy_tag(names, selected_names = nil) ⇒ String
!! Does not try to sort names, works best in combination with ‘ancestrify: true` in ::Queries::TaxonNames::Filter TODO: there is some missalignment on the name matching, you’ll see some names that likely matched not linked.
-
#taxon_name_autocomplete_selected_tag(taxon_name) ⇒ String
No HTML inside <input>.
- #taxon_name_autocomplete_tag(taxon_name, term) ⇒ Object
- #taxon_name_browse_link(taxon_name) ⇒ Object
- #taxon_name_for_select(taxon_name) ⇒ Object
- #taxon_name_gender_sentence_tag(taxon_name) ⇒ Object
- #taxon_name_inferred_combination_tag(taxon_name) ⇒ Object
- #taxon_name_inventory_stats(taxon_name) ⇒ Object
- #taxon_name_latinization_tag(taxon_name) ⇒ Object
- #taxon_name_link(taxon_name) ⇒ Object
- #taxon_name_link_path(taxon_name, path) ⇒ Object protected
- #taxon_name_original_combination_tag(taxon_name, css_class = [:feedback, 'feedback-notice', 'feedback-thin']) ⇒ Object
- #taxon_name_otus_links(taxon_name) ⇒ Object
- #taxon_name_parent_navigator_item_link(taxon_name, target = :taxon_name_path) ⇒ Object
- #taxon_name_parent_tag(taxon_name, css_class = [:feedback, 'feedback-secondary', 'feedback-thin']) ⇒ Object
-
#taxon_name_rank_select_tag(taxon_name: TaxonName.new, code: nil) ⇒ Object
TODO: Scope to code.
- #taxon_name_rank_tag(taxon_name, css_class = [:feedback, 'feedback-info', 'feedback-thin']) ⇒ Object
- #taxon_name_short_status(taxon_name) ⇒ Object
- #taxon_name_short_status_label(taxon_name) ⇒ Object
- #taxon_name_status_label(taxon_name) ⇒ Object
-
#taxon_name_tag(taxon_name) ⇒ String
The taxon name without author year, with HTML.
- #taxon_name_type_short_tag(taxon_name) ⇒ Object
- #taxon_name_year_data_table(data, *attributes) ⇒ Object
- #taxon_names_by_year_count(names) ⇒ Object
-
#taxon_names_count_by_validity_and_year(scope = nil) ⇒ Object
Perhaps a /lib/catalog method.
-
#taxon_names_cumulative_count_by_validity_and_year(scope = nil) ⇒ Object
Perhaps a /lib/catalog method.
- #taxon_names_per_year(totals) ⇒ Object
- #taxon_names_search_form ⇒ Object
Instance Method Details
#ancestor_browse_taxon_name_link(taxon_name, path = :browse_nomenclature_task_path) ⇒ Object
312 313 314 315 316 317 318 319 320 321 |
# File 'app/helpers/taxon_names_helper.rb', line 312 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. text = object_tag(a) link_to(content_tag(:span, text, data: {icon: 'arrow-up'}, class: 'small-icon'), taxon_name_link_path(a, path), class: 'navigation-item', data: {arrow: 'ancestor'}) else content_tag(:div, content_tag(:span, text, class: 'small-icon', data: {icon: 'arrow-up'}), class: 'navigation-item disable') end end |
#cached_classified_as_tag(taxon_name) ⇒ Object
207 208 209 |
# File 'app/helpers/taxon_names_helper.rb', line 207 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
107 108 109 110 |
# File 'app/helpers/taxon_names_helper.rb', line 107 def (taxon_name) return nil if taxon_name.nil? || taxon_name..nil? taxon_name. end |
#defined_full_original_taxon_name_tag(taxon_name) ⇒ String?
!! This is used in taxon_name attributes now! TODO: Refactor our logic for display contexts and value contexts to better reflect presence of data vs. utility of report.
85 86 87 88 |
# File 'app/helpers/taxon_names_helper.rb', line 85 def defined_full_original_taxon_name_tag(taxon_name) return nil if taxon_name.nil? || taxon_name.cached_original_combination_html.blank? full_original_taxon_name_tag(taxon_name) end |
#descendant_browse_taxon_name_link(taxon_name, path = :browse_nomenclature_task_path) ⇒ Object
323 324 325 326 327 328 329 330 331 332 |
# File 'app/helpers/taxon_names_helper.rb', line 323 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. text = taxon_name_tag(a) link_to(content_tag(:span, text, data: {icon: 'arrow-down'}, class: 'small-icon'), taxon_name_link_path(a, path), class: 'navigation-item', data: {arrow: 'descendant'}) else content_tag(:div, content_tag(:span, text, class: 'small-icon', data: {icon: 'arrow-down'}), class: 'navigation-item disable') end end |
#document_names_per_year(names) ⇒ Object
521 522 523 524 525 |
# File 'app/helpers/taxon_names_helper.rb', line 521 def document_names_per_year(names) taxon_names_per_year( taxon_names_by_year_count(names) ) end |
#edit_original_combination_task_link(taxon_name) ⇒ Object
261 262 263 |
# File 'app/helpers/taxon_names_helper.rb', line 261 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 |
#edit_taxon_name_link(taxon_name, target: nil) ⇒ Object
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'app/helpers/taxon_names_helper.rb', line 276 def edit_taxon_name_link(taxon_name, target: nil) i = {'Combination': :combination, 'Protonym': :taxon_name}[taxon_name.type.to_sym] t = taxon_name. 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.encode_www_form_component(t.cached)) # only spaces should be an issue end link_to( content_tag( :span, 'Edit (task)', 'data-icon' => 'edit', class: 'small-icon' ), path, class: 'navigation-item', 'data-task' => 'new_taxon_name') else link_to(content_tag(:span, 'Edit', 'data-icon' => 'edit', 'class' => 'small-icon'), send("edit_#{i}_path}", taxon_name.), 'class' => 'navigation-item') end end |
#edit_taxon_name_path_string(taxon_name) ⇒ Object
See #edit_object_path_string in navigation_helper.rb
266 267 268 269 270 271 272 273 274 |
# File 'app/helpers/taxon_names_helper.rb', line 266 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_label(taxon_name) ⇒ String
Returns the name in original combination, with author year, without HTML.
92 93 94 95 96 97 |
# File 'app/helpers/taxon_names_helper.rb', line 92 def full_original_taxon_name_label(taxon_name) return nil if taxon_name.nil? || taxon_name.cached_original_combination.nil? [ taxon_name.cached_original_combination, taxon_name. ].compact.join(' ') end |
#full_original_taxon_name_tag(taxon_name) ⇒ String
Returns the name in original combination, with author year, with HTML.
73 74 75 76 77 78 |
# File 'app/helpers/taxon_names_helper.rb', line 73 def full_original_taxon_name_tag(taxon_name) return nil if taxon_name.nil? [ original_taxon_name_tag(taxon_name), (taxon_name) ].compact.join(' ').html_safe end |
#full_taxon_name_tag(taxon_name) ⇒ String
Returns the current name/combination with author year, with HTML.
66 67 68 69 |
# File 'app/helpers/taxon_names_helper.rb', line 66 def full_taxon_name_tag(taxon_name) return nil if taxon_name.nil? [taxon_name_tag(taxon_name), taxon_name.].compact.join(' ').html_safe end |
#label_for_taxon_name(taxon_name) ⇒ String
!! Unified deprecated taxon_name_name_string() here
14 15 16 17 |
# File 'app/helpers/taxon_names_helper.rb', line 14 def label_for_taxon_name(taxon_name) return nil if taxon_name.nil? [taxon_name.cached, taxon_name.].compact.join(' ') end |
#next_sibling_browse_taxon_name_link(taxon_name, path = :browse_nomenclature_task_path) ⇒ Object
334 335 336 337 338 339 340 341 342 |
# File 'app/helpers/taxon_names_helper.rb', line 334 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? content_tag(:div, content_tag(:span, text), class: 'navigation-item disable') else link_to(text, taxon_name_link_path(link_object, path), title: taxon_name_tag(link_object), class: 'navigation-item', data: { button: 'next' }) end end |
#original_author_year(taxon_name) ⇒ String
Returns removes parens.
101 102 103 104 |
# File 'app/helpers/taxon_names_helper.rb', line 101 def (taxon_name) return nil if taxon_name.nil? || taxon_name..nil? taxon_name. || '' end |
#original_taxon_name_link(taxon_name) ⇒ Object
238 239 240 241 |
# File 'app/helpers/taxon_names_helper.rb', line 238 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)).html_safe, taxon_name.].compact.join(' ').html_safe end |
#original_taxon_name_tag(taxon_name) ⇒ String
Returns the taxon name in original combination, without author year, with HTML.
55 56 57 58 59 60 61 62 |
# File 'app/helpers/taxon_names_helper.rb', line 55 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)
248 249 250 |
# File 'app/helpers/taxon_names_helper.rb', line 248 def parent_taxon_name_for_select(taxon_name) taxon_name.parent ? taxon_name_for_select(taxon_name.parent) : nil end |
#previous_sibling_browse_taxon_name_link(taxon_name, path = :browse_nomenclature_task_path) ⇒ Object
344 345 346 347 348 349 350 351 352 353 |
# File 'app/helpers/taxon_names_helper.rb', line 344 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? content_tag(:div, content_tag(:span, text), class: 'navigation-item disable') else link_to(text, taxon_name_link_path(link_object, path), class: 'navigation-item', data: { button: 'back' }) end end |
#rank_tag(taxon_name) ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'app/helpers/taxon_names_helper.rb', line 299 def rank_tag(taxon_name) case taxon_name.type when 'Protonym' if taxon_name.rank_class taxon_name.rank.downcase else content_tag(:em, 'ERROR') end when 'Combination' content_tag(:em, 'Combination') end end |
#simple_hierarchy_tag(names, selected_names = nil) ⇒ String
!! Does not try to sort names, works best in combination with ‘ancestrify: true` in ::Queries::TaxonNames::Filter TODO: there is some missalignment on the name matching, you’ll see some names that likely matched not linked.
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
# File 'app/helpers/taxon_names_helper.rb', line 532 def simple_hierarchy_tag(names, selected_names = nil) match = [] if selected_names match = selected_names.select("CASE WHEN taxon_names.type = 'Protonym' THEN taxon_names.id ELSE taxon_names.cached_valid_taxon_name_id END as id").pluck(:id) end # taxon_names.cached as alias, \ objects = names.left_joins(:valid_taxon_name) .select("CASE WHEN taxon_names.type = 'Protonym' THEN taxon_names.id ELSE taxon_names.cached_valid_taxon_name_id END as id, \ CASE WHEN taxon_names.type = 'Protonym' THEN taxon_names.parent_id ELSE valid_taxon_names_taxon_names.parent_id END as parent_id, \ COALESCE(taxon_names.name, valid_taxon_names_taxon_names.name, valid_taxon_names_taxon_names.name, valid_taxon_Names_taxon_names.cached) as label") .order('parent_id, label') .distinct d = Utilities::Hierarchy.new(objects:, match:).to_a rows = [] d.each do |r| s = ' ' * r[3] * 10 # space a = (r[2] ? " [#{r[2]}]" : '') # alias if r[4] # matched rows.push s + link_to( tag.b(r[1] + a), browse_nomenclature_task_path(taxon_name_id: r[0])) else # unmatched rows.push s + r[1] + a end end rows.join('<br>').html_safe end |
#taxon_name_autocomplete_selected_tag(taxon_name) ⇒ String
Returns no HTML inside <input>.
34 35 36 |
# File 'app/helpers/taxon_names_helper.rb', line 34 def taxon_name_autocomplete_selected_tag(taxon_name) label_for_taxon_name(taxon_name) end |
#taxon_name_autocomplete_tag(taxon_name, term) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/taxon_names_helper.rb', line 19 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 = [ content_tag(:span, mark_tag(taxon_name., term), class: :klass), taxon_name_rank_tag(taxon_name), taxon_name_parent_tag(taxon_name), taxon_name_original_combination_tag(taxon_name), taxon_name_type_short_tag(taxon_name) # " [#{taxon_name.sml_t}]" ].compact.join(' ').html_safe end |
#taxon_name_browse_link(taxon_name) ⇒ Object
221 222 223 224 |
# File 'app/helpers/taxon_names_helper.rb', line 221 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.].compact.join(' ').html_safe end |
#taxon_name_for_select(taxon_name) ⇒ Object
243 244 245 |
# File 'app/helpers/taxon_names_helper.rb', line 243 def taxon_name_for_select(taxon_name) taxon_name.name if taxon_name end |
#taxon_name_gender_sentence_tag(taxon_name) ⇒ Object
202 203 204 205 |
# File 'app/helpers/taxon_names_helper.rb', line 202 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_inferred_combination_tag(taxon_name) ⇒ Object
193 194 195 196 197 198 199 200 |
# File 'app/helpers/taxon_names_helper.rb', line 193 def taxon_name_inferred_combination_tag(taxon_name) return nil if taxon_name.nil? || taxon_name.is_combination? || taxon_name.is_valid? if taxon_name.is_protonym? return nil if taxon_name.cached_primary_homonym == taxon_name.cached_secondary_homonym end tag.span(tag.em('inferred combination'), class: :subtle) end |
#taxon_name_inventory_stats(taxon_name) ⇒ Object
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'app/helpers/taxon_names_helper.rb', line 368 def taxon_name_inventory_stats(taxon_name) d = [] i = { rank: nil, taxa: {}, names: {} } # !! descendants: false is [self and desecendants] ::Queries::TaxonName::Filter.new(synonymify: true, descendants: false, taxon_name_id: taxon_name.id).all .where(type: 'Protonym') .select(:rank_klass).distinct.pluck(:rank_class).compact.sort{|a,b| RANKS.index(a) <=> RANKS.index(b)}.each do |r| n = r.safe_constantize.rank_name.to_sym j = i.deep_dup j[:rank] = n j[:names][:valid] = ::Queries::TaxonName::Filter.new(validity: true, descendants: false, taxon_name_id: taxon_name.id, rank: r, taxon_name_type: 'Protonym' ).all.count j[:names][:invalid] = ::Queries::TaxonName::Filter.new(descendants: false, synonymify: true, taxon_name_id: taxon_name.id, rank: r, taxon_name_type: 'Protonym' ).all.that_is_invalid.count # This is the number of OTUs behind the ranks at this concept, i.e. a measure of how partitioned the data are beyond valid/invalid categories. j[:taxa] = ::Queries::Otu::Filter.new(coordinatify: true, taxon_name_query: {descendants: false, taxon_name_id: taxon_name.id, rank: r} ).all.count d.push j end d end |
#taxon_name_latinization_tag(taxon_name) ⇒ Object
211 212 213 214 |
# File 'app/helpers/taxon_names_helper.rb', line 211 def taxon_name_latinization_tag(taxon_name) list = taxon_name.taxon_name_classifications.with_type_array(LATINIZED_TAXON_NAME_CLASSIFICATION_NAMES).map(&:classification_label) content_tag(:span, "The word \"#{taxon_name.name}\" has the following Latin-based classifications: #{list.to_sentence}.", class: 'history__latinized_classifications') if list.any? end |
#taxon_name_link(taxon_name) ⇒ Object
216 217 218 219 |
# File 'app/helpers/taxon_names_helper.rb', line 216 def taxon_name_link(taxon_name) return nil if taxon_name.nil? link_to(taxon_name_tag(taxon_name), taxon_name.).html_safe end |
#taxon_name_link_path(taxon_name, path) ⇒ Object (protected)
567 568 569 570 571 572 573 |
# File 'app/helpers/taxon_names_helper.rb', line 567 def taxon_name_link_path(taxon_name, path) if path == :taxon_name_path send(path, taxon_name) else send(path, taxon_name_id: taxon_name.id) end end |
#taxon_name_original_combination_tag(taxon_name, css_class = [:feedback, 'feedback-notice', 'feedback-thin']) ⇒ Object
48 49 50 51 |
# File 'app/helpers/taxon_names_helper.rb', line 48 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? content_tag(:span, taxon_name.cached_original_combination, class: css_class) end |
#taxon_name_otus_links(taxon_name) ⇒ Object
355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'app/helpers/taxon_names_helper.rb', line 355 def taxon_name_otus_links(taxon_name) if taxon_name.otus.load.any? ('The following Otus are linked to this name: ' + content_tag(:ul, class: 'no_bullets') do taxon_name.otus.each do |o| concat(content_tag(:li, otu_link(o) )) end end.html_safe).html_safe else content_tag(:em, 'There are no Otus linked to this name.') end end |
#taxon_name_parent_navigator_item_link(taxon_name, target = :taxon_name_path) ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 |
# File 'app/helpers/taxon_names_helper.rb', line 226 def taxon_name_parent_navigator_item_link(taxon_name, target = :taxon_name_path) return nil if taxon_name.nil? || target.nil? if target case target.to_sym when :taxon_name_path link_to(taxon_name_tag(taxon_name), taxon_name.) else link_to(taxon_name_tag(taxon_name), send(target, {taxon_name_id: taxon_name.id})) end end end |
#taxon_name_parent_tag(taxon_name, css_class = [:feedback, 'feedback-secondary', 'feedback-thin']) ⇒ Object
43 44 45 46 |
# File 'app/helpers/taxon_names_helper.rb', line 43 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? content_tag(: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
253 254 255 |
# File 'app/helpers/taxon_names_helper.rb', line 253 def taxon_name_rank_select_tag(taxon_name: TaxonName.new, code: nil) select(:taxon_name, :rank_class, (RANKS_SELECT_OPTIONS, selected: taxon_name.rank_string) ) end |
#taxon_name_rank_tag(taxon_name, css_class = [:feedback, 'feedback-info', 'feedback-thin']) ⇒ Object
38 39 40 41 |
# File 'app/helpers/taxon_names_helper.rb', line 38 def taxon_name_rank_tag(taxon_name, css_class = [:feedback, 'feedback-info', 'feedback-thin'] ) return nil if taxon_name.nil? content_tag(:span, taxon_name.rank || 'Combination', class: css_class) end |
#taxon_name_short_status(taxon_name) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'app/helpers/taxon_names_helper.rb', line 121 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)), (n), ] else v = n.valid_taxon_name s += [ original_taxon_name_tag(n), (n), 'whose valid/accepted name is', link_to(taxon_name_tag(v), browse_nomenclature_task_path(taxon_name_id: v.id) ), v. ] end (s.join(' ') + '.').html_safe else if taxon_name.is_valid? # taxon_name.unavailable_or_invalid? content_tag(:span, 'This name is valid/accepted.', class: :brief_status, data: {icon: :ok, status: :valid }) else if taxon_name.is_ambiguously_invalid? tag.span('This name is not valid/accepted.'.html_safe, class: :brief_status, data: {icon: :attention, status: :invalid}) else tag.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}) end end end end |
#taxon_name_short_status_label(taxon_name) ⇒ Object
159 160 161 162 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/taxon_names_helper.rb', line 159 def taxon_name_short_status_label(taxon_name) if taxon_name.is_combination? n = taxon_name.finest_protonym s = ['This name is subsequent combination of'] if n.is_valid? s += [ original_taxon_name_tag(n), (n), ] else v = n.valid_taxon_name s += [ original_taxon_name_tag(n), (n), 'whose valid/accepted name is', taxon_name_tag(v), v. ] end (s.join(' ') + '.') else if taxon_name.is_valid? # taxon_name.unavailable_or_invalid? 'This name is valid/accepted.' else if taxon_name.is_ambiguously_invalid? 'This name is not valid/accepted.' else "This name is not valid/accepted. The valid name is #{taxon_name.valid_taxon_name.cached}." end end end end |
#taxon_name_status_label(taxon_name) ⇒ Object
155 156 157 |
# File 'app/helpers/taxon_names_helper.rb', line 155 def taxon_name_status_label(taxon_name) taxon_name.combined_statuses.collect{|s| s}.join('; ') end |
#taxon_name_tag(taxon_name) ⇒ String
Returns 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
112 113 114 115 116 117 118 119 |
# File 'app/helpers/taxon_names_helper.rb', line 112 def taxon_name_type_short_tag(taxon_name) return nil if taxon_name.nil? if taxon_name.is_valid? '✓'.html_safe # checkmark else taxon_name.type == 'Combination' ? '[c]' : '❌'.html_safe # c or X end end |
#taxon_name_year_data_table(data, *attributes) ⇒ Object
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'app/helpers/taxon_names_helper.rb', line 433 def taxon_name_year_data_table(data, *attributes) a = data[:data].first b = data[:data].second content_tag(:table, safe_join([ tag.thead( tag.tr( safe_join [tag.th('Year'), tag.th(a[:name]), tag.th(b[:name])] ) ), safe_join((data[:metadata][:min_year]..data[:metadata][:max_year]).collect{|y| tag.tr( safe_join([ tag.td(y), tag.td(a[:data][y]), tag.td(b[:data][y]) ]) ) }) ]), *attributes ) end |
#taxon_names_by_year_count(names) ⇒ Object
516 517 518 519 |
# File 'app/helpers/taxon_names_helper.rb', line 516 def taxon_names_by_year_count(names) t = names.select('EXTRACT(YEAR FROM taxon_names.cached_nomenclature_date) AS year, COUNT(*) AS count').group('year').inject({}){|hsh, r| hsh[r.year.to_i] = r.count; hsh} t end |
#taxon_names_count_by_validity_and_year(scope = nil) ⇒ Object
Perhaps a /lib/catalog method
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'app/helpers/taxon_names_helper.rb', line 402 def taxon_names_count_by_validity_and_year(scope = nil) return {} if scope.nil? invalid = taxon_names_by_year_count(scope.that_is_invalid) valid = taxon_names_by_year_count(scope.that_is_valid) min = [invalid.keys.sort.first, invalid.keys.sort.first].compact.sort.first || 0 max = [valid.keys.sort.last, valid.keys.sort.last].compact.sort.first || 0 min = 1759 if min < 1759 max = Time.current.year if max > Time.current.year invalid_data = {} valid_data = {} (min..max).each do |y| invalid_data[y] = invalid[y].present? ? invalid[y].to_i : 0 valid_data[y] = valid[y].present? ? valid[y].to_i : 0 end return { metadata: { max_year: max, min_year: min, }, data: [ { name: 'Valid', data: valid_data}, { name: 'Invalid', data: invalid_data} ] } end |
#taxon_names_cumulative_count_by_validity_and_year(scope = nil) ⇒ Object
Perhaps a /lib/catalog method
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'app/helpers/taxon_names_helper.rb', line 459 def taxon_names_cumulative_count_by_validity_and_year(scope = nil) return {} if scope.nil? invalid = taxon_names_by_year_count(scope.that_is_invalid) valid = taxon_names_by_year_count(scope.that_is_valid) min = [invalid.keys.sort.first, invalid.keys.sort.first].compact.sort.first || 0 max = [valid.keys.sort.last, valid.keys.sort.last].compact.sort.first || 0 min = 1759 if min < 1759 max = Time.current.year if max > Time.current.year invalid_data = {} valid_data = {} invalid_total = 0 valid_total = 0 (min..max).each do |y| i = ( invalid[y].present? ? invalid[y].to_i : 0 ) v = ( valid[y].present? ? valid[y].to_i : 0 ) invalid_total += i valid_total += v invalid_data[y] = invalid_total valid_data[y] = valid_total end return { metadata: { max_year: max, min_year: min, }, data: [ { name: 'Valid', data: valid_data}, { name: 'Invalid', data: invalid_data} ] } end |
#taxon_names_per_year(totals) ⇒ Object
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'app/helpers/taxon_names_helper.rb', line 500 def taxon_names_per_year(totals) min = totals.keys.sort.first || 0 max = totals.keys.sort.last || 0 min = 1759 if min < 1759 max = Time.current.year if max > Time.current.year data = {} (min..max).each do |y| data[y] = totals[y].present? ? totals[y].to_i : 0 end data end |
#taxon_names_search_form ⇒ Object
257 258 259 |
# File 'app/helpers/taxon_names_helper.rb', line 257 def taxon_names_search_form render '/taxon_names/quick_search_form' end |