Module: DescriptorsHelper

Defined in:
app/helpers/descriptors_helper.rb

Instance Method Summary collapse

Instance Method Details



12
13
14
15
# File 'app/helpers/descriptors_helper.rb', line 12

def descriptor_link(descriptor)
  return nil if descriptor.nil?
  link_to(descriptor_tag(descriptor).html_safe, descriptor.metamorphosize)
end

#descriptor_matrix_character_states_label(descriptor) ⇒ String?

Returns state labels formatted for matrix export.

Returns:

  • (String, nil)

    state labels formatted for matrix export



62
63
64
65
66
67
68
# File 'app/helpers/descriptors_helper.rb', line 62

def descriptor_matrix_character_states_label(descriptor)
  if descriptor.qualitative?
    descriptor.character_states.map{|state| state.name.gsub(/[\W]/ , "_")}.join(" ")
  else 
    nil
  end
end


49
50
51
52
# File 'app/helpers/descriptors_helper.rb', line 49

def descriptor_matrix_column_link(descriptor)
  z = [descriptor.short_name, descriptor.name].compact.first
  link_to(z, new_descriptor_task_path(descriptor.metamorphosize), data: {help: descriptor.name})
end

#descriptor_matrix_label(descriptor) ⇒ String

Returns the column/descriptor name presented in the exported matrix.

Returns:

  • (String)

    the column/descriptor name presented in the exported matrix



56
57
58
# File 'app/helpers/descriptors_helper.rb', line 56

def descriptor_matrix_label(descriptor)
  descriptor.name.gsub(/[\W]/ , "_")
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



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
# File 'app/helpers/descriptors_helper.rb', line 17

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 += ' ' + (:span, descriptor.type.split('::').last, class: [:feedback, 'feedback-secondary', 'feedback-thin'])

  c = descriptor.observations.count
  if c > 0
    s += ' ' + (:span, "#{c.to_s}&nbsp;#{'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 += ' ' + (:span, "#{d.to_s}&nbsp;#{'observation depiction'.pluralize(d)}".html_safe, class: [:feedback, 'feedback-secondary', 'feedback-thin'])
  end

  e =  descriptor.observation_matrices.count
  s += ' '
  if e > 0
    s +=  (:span, "#{e.to_s}&nbsp;#{'matrix'.pluralize(e)}".html_safe, class: [:feedback, 'feedback-secondary', 'feedback-thin'])
  else
    s += (:span, "No matrix".html_safe, class: [:feedback, 'feedback-warning', 'feedback-thin'])
  end

  s.html_safe
end

#descriptors_search_formObject



8
9
10
# File 'app/helpers/descriptors_helper.rb', line 8

def descriptors_search_form
  render('/descriptors/quick_search_form')
end