Module: LeadsHelper
- Defined in:
- app/helpers/leads_helper.rb
Instance Method Summary collapse
-
#key_data(lead, metadata) ⇒ Object
An index of lead.id poisting to it’s content.
-
#key_metadata(lead, hsh: {}, depth: 1, couplet_number: 0) ⇒ Object
A depth-first traversal that numbers each entry.
-
#key_to_json(lead) ⇒ Object
Used to serve Keys to the API.
- #label_for_lead(lead) ⇒ Object
- #lead_autocomplete_tag(lead) ⇒ Object
- #lead_edges(lead) ⇒ Object
- #lead_id(lead) ⇒ Object
- #lead_link(lead) ⇒ Object
- #lead_no_text ⇒ Object
- #lead_tag(lead) ⇒ Object
- #lead_truncated_text(lead) ⇒ Object
-
#leads_recent_objects_partial ⇒ True
Indicates a custom partial should be used, see list_helper.rb.
- #leads_search_form ⇒ Object
- #print_key(lead) ⇒ Object
- #print_key_body(lead, metadata) ⇒ Object
- #print_key_markdown(lead) ⇒ Object
- #print_key_table(lead) ⇒ Object
- #print_key_table_body(lead, metadata) ⇒ Object
Instance Method Details
#key_data(lead, metadata) ⇒ Object
An index of lead.id poisting to it’s content
152 153 154 155 156 157 158 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 |
# File 'app/helpers/leads_helper.rb', line 152 def key_data(lead, ) data = {} lead.self_and_descendants.find_each do |l| d = { text: l.text, parent_id: l.parent_id, position: l.position, } if l.otu d.merge!( target_label: ( l.otu ? label_for_otu(l.otu) : nil ), target_id: l.otu&.id, target_type: '/api/v1/otus', # some concept of pointing to the ) elsif l.link_out_text d.merge!( target_label: l.link_out_text, target_type: :link_out, target_link: l.link_out ) else d.merge!( target_label: .dig(l.id, :couplet_number), target_type: :internal, ) end if l.depictions.load.any? d.merge!( figures: l.depictions.order(:position).collect{|d| depiction_to_json(d)} ) end data[l.id] = d end data end |
#key_metadata(lead, hsh: {}, depth: 1, couplet_number: 0) ⇒ Object
A depth-first traversal that numbers each entry. Renderers navigate this list in order to draw the key.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'app/helpers/leads_helper.rb', line 129 def (lead, hsh: {}, depth: 1, couplet_number: 0 ) @index ||= 0 if lead.children.any? @index += 1 hsh[lead.id] = { children: [], parent_id: lead.parent_id, position: lead.position, couplet_number: lead.origin_label || @index, # depth_vector: [depth, lead.parent_id, lead.position], depth: } end lead.children.order(:position).each_with_index do |l, i| hsh[l.parent_id][:children].push l.id (l, hsh:, depth: depth + 1 ) end hsh end |
#key_to_json(lead) ⇒ Object
Used to serve Keys to the API. Targeting a “standard” for exchanging keys to be used in the front end at github.com/SpeciesFileGroup/pinpoint
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'app/helpers/leads_helper.rb', line 192 def key_to_json(lead) m = (lead) d = key_data(lead, m) return { metadata: { server: root_url, key_version: '0.0.1', title: lead.text, origin_citation: lead.source&.cached, attribution: attribution_to_json(lead.attribution), taxonomic_scope: label_for_otu(lead.otu) # perhaps extend with identifiers, probably ultimately nested, with IDs }, data: { entries: m, leads: d } } end |
#label_for_lead(lead) ⇒ Object
37 38 39 |
# File 'app/helpers/leads_helper.rb', line 37 def label_for_lead(lead) lead_tag(lead) end |
#lead_autocomplete_tag(lead) ⇒ Object
33 34 35 |
# File 'app/helpers/leads_helper.rb', line 33 def lead_autocomplete_tag(lead) lead_tag(lead) end |
#lead_edges(lead) ⇒ Object
17 18 19 20 21 |
# File 'app/helpers/leads_helper.rb', line 17 def lead_edges(lead) edges = (lead.parent_id ? '↑' : '') + (lead.children.size > 0 ? '↓' : '') end |
#lead_id(lead) ⇒ Object
2 3 4 5 |
# File 'app/helpers/leads_helper.rb', line 2 def lead_id(lead) return nil if lead.nil? lead.origin_label ? "[#{lead.origin_label}]" : '' end |
#lead_link(lead) ⇒ Object
28 29 30 31 |
# File 'app/helpers/leads_helper.rb', line 28 def lead_link(lead) return nil if lead.nil? link_to(lead_tag(lead), lead) end |
#lead_no_text ⇒ Object
7 8 9 |
# File 'app/helpers/leads_helper.rb', line 7 def lead_no_text '(No text)' end |
#lead_tag(lead) ⇒ Object
23 24 25 26 |
# File 'app/helpers/leads_helper.rb', line 23 def lead_tag(lead) return nil if lead.nil? lead_edges(lead) + lead_id(lead) + ' ' + lead_truncated_text(lead) end |
#lead_truncated_text(lead) ⇒ Object
11 12 13 14 15 |
# File 'app/helpers/leads_helper.rb', line 11 def lead_truncated_text(lead) return nil if lead.nil? text = lead.text || lead_no_text text.slice(0..25) + (text.size > 25 ? '...' : '') end |
#leads_recent_objects_partial ⇒ True
Returns indicates a custom partial should be used, see list_helper.rb.
47 48 49 |
# File 'app/helpers/leads_helper.rb', line 47 def leads_recent_objects_partial true end |
#leads_search_form ⇒ Object
41 42 43 |
# File 'app/helpers/leads_helper.rb', line 41 def leads_search_form render('/leads/quick_search_form') end |
#print_key(lead) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'app/helpers/leads_helper.rb', line 51 def print_key(lead) @index = 0 # TODO: get this out of instance = (lead) t = tag.h1(lead.text) t << print_key_body(lead, ) t.html_safe end |
#print_key_body(lead, metadata) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'app/helpers/leads_helper.rb', line 102 def print_key_body(lead, ) data = key_data(lead, ) x = [] .keys.each do |k| [k][:children].each do |lid| a = data.dig(lid, :position) == 0 ? .dig(k, :couplet_number).to_s + '.' : '—' b = data.dig(lid, :text) if y = tag.b(data.dig(lid, :target_label)) c = y else c = .dig(lid, :couplet_number) end c = 'TODO: PROVIDE ENDPOINT' if c.blank? x.push [a,b, '…', c, '<br/>'] end x.push '<br/>' end x.flatten.join(' ').html_safe end |
#print_key_markdown(lead) ⇒ Object
211 212 |
# File 'app/helpers/leads_helper.rb', line 211 def print_key_markdown(lead) end |
#print_key_table(lead) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/helpers/leads_helper.rb', line 60 def print_key_table(lead) @index = 0 # TODO: get this out of instance = (lead) t = tag.h1(lead.text) t << tag.table( print_key_table_body(lead, ), id: 'key_table' ) t end |
#print_key_table_body(lead, metadata) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/helpers/leads_helper.rb', line 73 def print_key_table_body(lead, ) data = key_data(lead, ) x = [] .keys.each do |k| [k][:children].each do |lid| a = data.dig(lid, :position) == 0 ? .dig(k, :couplet_number).to_s : '—' b = data.dig(lid, :text) if y = tag.b(data.dig(lid, :target_label)) c = y else c = .dig(lid, :couplet_number) end c = 'TODO: PROVIDE ENDPOINT' if c.blank? x.push tag.tr( [ tag.td(a.html_safe), tag.td(b), tag.td(c) ].join.html_safe ) end end x.join.html_safe end |