Module: TaxonNames::JsonCatalogHelper

Defined in:
app/helpers/taxon_names/json_catalog_helper.rb

Overview

Helpers for rendering a JSON version of a catalog.

See also the paper catalog version.

Constant Summary collapse

OPTIONS =
{ }.freeze

Instance Method Summary collapse

Instance Method Details

#json_catalog_entry_item(catalog_entry_item: nil, catalog_object: nil) ⇒ Object



53
54
55
56
57
58
# File 'app/helpers/taxon_names/json_catalog_helper.rb', line 53

def json_catalog_entry_item(catalog_entry_item: nil, catalog_object: nil)
  e = {
    label: paper_catalog_li_tag(catalog_entry_item, catalog_object, :browse_nomenclature_task_path),
    year: catalog_entry_item.nomenclature_date&.year,
  }
end

#recursive_catalog_json(taxon_name: nil, target_depth: 0, depth: 0, data: { timeline: [], sources: [], repositories: []}) ⇒ Hash

Returns timeline: [] sources: [] respositories: [] distribution: String.

Returns:

  • (Hash)

    timeline: [] sources: [] respositories: [] distribution: String



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/taxon_names/json_catalog_helper.rb', line 16

def recursive_catalog_json(taxon_name: nil, target_depth: 0, depth: 0, data: { timeline: [], sources: [], repositories: []} )
  return data if taxon_name.nil?

  cat = ::Catalog::Nomenclature::Entry.new(taxon_name)
  data[:sources] += [cat.sources].flatten

  if target_depth == depth
    # distribution is only calculated for species level here!!
    d = paper_distribution_entry(taxon_name)
    if d && d.items.any?
      data[:distribution] = d.to_s
      # data[:supplementary_distribution].items += d.items
    end
  end

  cat.ordered_by_nomenclature_date.each do |c|
    i = json_catalog_entry_item(catalog_entry_item: c, catalog_object: cat.object)

    if t = paper_history_type_material(c)
      i[:type_label] = t
      if r = paper_repositories(c)
        data[:repositories].push r
      end
    end

    data[:timeline].push i
  end

  if depth < target_depth
    taxon_name.children.that_is_valid.order(:cached).each do |t|
      recursive_catalog_json(taxon_name: t, depth: depth + 1, target_depth: nil, data: nil)
    end
  end

  data
end