Module: DescriptorsHelper
- Defined in:
- app/helpers/descriptors_helper.rb
Instance Method Summary collapse
- #descriptor_link(descriptor) ⇒ Object
-
#descriptor_matrix_character_states_label(descriptor) ⇒ String?
State labels formatted for matrix export.
- #descriptor_matrix_column_link(descriptor) ⇒ Object
-
#descriptor_matrix_label(descriptor) ⇒ String
The column/descriptor name presented in the exported matrix.
-
#descriptor_matrix_label_csv(descriptor, quote = '"') ⇒ String
The column/descriptor name modified for comma separated quote delimited CSV export.
- #descriptor_tag(descriptor) ⇒ Object
- #descriptors_autocomplete_tag(descriptor, term = nil) ⇒ Object
- #descriptors_search_form ⇒ Object
- #label_for_descriptor(descriptor) ⇒ Object
Instance Method Details
#descriptor_link(descriptor) ⇒ Object
17 18 19 20 |
# File 'app/helpers/descriptors_helper.rb', line 17 def descriptor_link(descriptor) return nil if descriptor.nil? link_to(descriptor_tag(descriptor).html_safe, descriptor.) end |
#descriptor_matrix_character_states_label(descriptor) ⇒ String?
Returns state labels formatted for matrix export.
74 75 76 77 78 79 80 |
# File 'app/helpers/descriptors_helper.rb', line 74 def descriptor_matrix_character_states_label(descriptor) if descriptor.qualitative? descriptor.character_states.map{|state| state.name.gsub(/[\W]/ , "_")}.join(" ") else nil end end |
#descriptor_matrix_column_link(descriptor) ⇒ Object
54 55 56 57 |
# File 'app/helpers/descriptors_helper.rb', line 54 def descriptor_matrix_column_link(descriptor) z = [descriptor.short_name, descriptor.name].compact.first link_to(z, new_descriptor_task_path(descriptor.), data: {help: descriptor.name}) end |
#descriptor_matrix_label(descriptor) ⇒ String
Returns the column/descriptor name presented in the exported matrix.
61 62 63 |
# File 'app/helpers/descriptors_helper.rb', line 61 def descriptor_matrix_label(descriptor) descriptor.name.gsub(/[\W]/ , "_") end |
#descriptor_matrix_label_csv(descriptor, quote = '"') ⇒ String
Returns the column/descriptor name modified for comma separated
quote delimited CSV export.
68 69 70 |
# File 'app/helpers/descriptors_helper.rb', line 68 def descriptor_matrix_label_csv(descriptor, quote = '"') quote + descriptor.name.gsub('"', "'") + quote end |
#descriptor_tag(descriptor) ⇒ Object
3 4 5 6 |
# File 'app/helpers/descriptors_helper.rb', line 3 def descriptor_tag(descriptor) return nil if descriptor.nil? descriptor.name end |
#descriptors_autocomplete_tag(descriptor, term = nil) ⇒ Object
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 52 |
# File 'app/helpers/descriptors_helper.rb', line 22 def descriptors_autocomplete_tag(descriptor, term = nil) return nil if descriptor.nil? if term s = descriptor.name.gsub(/#{Regexp.escape(term)}/i, "<mark>#{term}</mark>") else s = descriptor.name end s += ' ' + content_tag(:span, descriptor.type.split('::').last, class: [:feedback, 'feedback-secondary', 'feedback-thin']) c = descriptor.observations.count if c > 0 s += ' ' + content_tag(:span, "#{c.to_s} #{'observation'.pluralize(c)}".html_safe, class: [:feedback, 'feedback-info', 'feedback-thin']) end d = Observation.joins(:depictions).where(descriptor_id: descriptor.id).count if d > 0 s += ' ' + content_tag(:span, "#{d.to_s} #{'observation depiction'.pluralize(d)}".html_safe, class: [:feedback, 'feedback-secondary', 'feedback-thin']) end e = descriptor.observation_matrices.count s += ' ' if e > 0 s += content_tag(:span, "#{e.to_s} #{'matrix'.pluralize(e)}".html_safe, class: [:feedback, 'feedback-secondary', 'feedback-thin']) else s += content_tag(:span, "No matrix".html_safe, class: [:feedback, 'feedback-warning', 'feedback-thin']) end s.html_safe end |
#descriptors_search_form ⇒ Object
13 14 15 |
# File 'app/helpers/descriptors_helper.rb', line 13 def descriptors_search_form render('/descriptors/quick_search_form') end |
#label_for_descriptor(descriptor) ⇒ Object
8 9 10 11 |
# File 'app/helpers/descriptors_helper.rb', line 8 def label_for_descriptor(descriptor) return nil if descriptor.nil? descriptor.name end |