Module: ControlledVocabularyTermsHelper

Defined in:
app/helpers/controlled_vocabulary_terms_helper.rb

Instance Method Summary collapse

Instance Method Details

#controlled_vocabulary_term_autocomplete_tag(controlled_vocabulary_term) ⇒ Object



19
20
21
22
23
24
# File 'app/helpers/controlled_vocabulary_terms_helper.rb', line 19

def controlled_vocabulary_term_autocomplete_tag(controlled_vocabulary_term)
  [ controlled_vocabulary_term_tag(controlled_vocabulary_term),
    (:span, controlled_vocabulary_term.type, class: [:feedback, 'feedback-secondary', 'feedback-thin']),
    (:span, pluralize( controlled_vocabulary_term_use(controlled_vocabulary_term), 'use'), class: [:feedback, 'feedback-info', 'feedback-thin'])
  ].compact.join(' ')
end


59
60
61
62
# File 'app/helpers/controlled_vocabulary_terms_helper.rb', line 59

def controlled_vocabulary_term_link(controlled_vocabulary_term)
  return nil if controlled_vocabulary_term.nil?
  link_to(controlled_vocabulary_term_tag(controlled_vocabulary_term.metamorphosize).html_safe, controlled_vocabulary_term.metamorphosize)
end

#controlled_vocabulary_term_tag(controlled_vocabulary_term) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'app/helpers/controlled_vocabulary_terms_helper.rb', line 3

def controlled_vocabulary_term_tag(controlled_vocabulary_term)
  return nil if controlled_vocabulary_term.nil?
  (
    :span,
    (:span, controlled_vocabulary_term.name),
    title: controlled_vocabulary_term.definition,
    class: ['pill', controlled_vocabulary_term.type.tableize.singularize],
    style: ( controlled_vocabulary_term.css_color ? "background-color: #{ controlled_vocabulary_term.css_color}; color: #{ controlled_vocabulary_term.css_color}" : nil ),
    data: { 'global-id' => (controlled_vocabulary_term.persisted? ? controlled_vocabulary_term.metamorphosize.to_global_id.to_s : nil) } ) # need to preview CVTs that are not saved
end

#controlled_vocabulary_term_type_select_optionsObject



64
65
66
# File 'app/helpers/controlled_vocabulary_terms_helper.rb', line 64

def controlled_vocabulary_term_type_select_options
  %w[Keyword Topic Predicate BiologicalProperty BiocurationGroup BiocurationClass ConfidenceLevel]
end

#controlled_vocabulary_term_use(controlled_vocabulary_term) ⇒ Object



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
53
54
55
56
57
# File 'app/helpers/controlled_vocabulary_terms_helper.rb', line 26

def controlled_vocabulary_term_use(controlled_vocabulary_term)
  return nil if controlled_vocabulary_term.nil?

  a = { project_id: sessions_current_project_id }
  case controlled_vocabulary_term.type
  when 'Topic'
    CitationTopic.where(topic: controlled_vocabulary_term).where(a).count +
      Content.where(topic: controlled_vocabulary_term).where(a).count
  when 'Tag'
    Tag.where(keyword: controlled_vocabulary_term).where(a).count
  when 'BiologicalProperty'
    BiocurationClassification.where(biocuration_class: controlled_vocabulary_term).where(a).count
  when 'Predicate'
    InternalAttribute.where(predicate: controlled_vocabulary_term).where(a).count
  when 'ConfidenceLevel'
    Confidence.where(confidence_level: controlled_vocabulary_term).where(a).count
  when 'Keyword'
    Tag.where(keyword_id: controlled_vocabulary_term.id).where(a).count
  when 'BiocurationClass'
    BiocurationClassification
      .where(biocuration_class_id: controlled_vocabulary_term.id).where(a).count
  when 'BiocurationGroup'
    # Count of the uses of the group's classes.
    BiocurationClassification
      .joins(biocuration_class: :keywords)
      .where(keywords: { id: controlled_vocabulary_term.id })
      .where(a)
      .count
  else
    'n/a'
  end
end

#controlled_vocabulary_terms_across_projects_data(user) ⇒ Object



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
101
102
103
104
105
106
107
108
# File 'app/helpers/controlled_vocabulary_terms_helper.rb', line 76

def controlled_vocabulary_terms_across_projects_data(user)
  projects = user.projects

  terms, term_types = [], []
  data = projects.inject({}) {|hsh, i| hsh[i.id] = []; hsh }

  project_names = ['Term', 'Type']

  projects.joins(:controlled_vocabulary_terms).select('projects.*, COUNT(controlled_vocabulary_terms.*) c').group('projects.id').order(:c).each do |p|
    project_names.push(p.name)
    p.controlled_vocabulary_terms.order(:type, :name).each do |t|
      unless terms.index(t.name)
        terms.push t.name
        term_types.push t.type
      end

      data[p.id][terms.index(t.name)] = true
    end
  end

  # The columns
  y = data.values

  # Sort columns to place those with more values to the right
  y.sort!{|a,b| b.compact.count <=> a.compact.count}

  # Injdect the CVT type column
  y.unshift(term_types)

  z = terms.zip(*y)
  z.unshift project_names
  z
end

#controlled_vocabulary_terms_across_projects_table(data) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
# File 'app/helpers/controlled_vocabulary_terms_helper.rb', line 110

def controlled_vocabulary_terms_across_projects_table(data)
  t = '<table class="table table-striped tablesorter"><thead>'.html_safe
  t << tag.tr( data.shift.collect{|c| tag.th(c) }.join.html_safe )
  t << '</thead><tbody>'.html_safe

  data.each do |r|
    t << tag.tr( r.collect{|c| tag.td(c) }.join.html_safe )
  end

  t << '</tbody></table>'.html_safe
  t.html_safe
end

#controlled_vocabulary_terms_across_projects_tag(user) ⇒ Object



123
124
125
126
# File 'app/helpers/controlled_vocabulary_terms_helper.rb', line 123

def controlled_vocabulary_terms_across_projects_tag(user)
  d = controlled_vocabulary_terms_across_projects_data(user)
  controlled_vocabulary_terms_across_projects_table(d)
end

#controlled_vocabulary_terms_search_formObject



72
73
74
# File 'app/helpers/controlled_vocabulary_terms_helper.rb', line 72

def controlled_vocabulary_terms_search_form
  render('/controlled_vocabulary_terms/quick_search_form')
end

#label_for_controlled_vocabulary_term(controlled_vocabulary_term) ⇒ Object



14
15
16
17
# File 'app/helpers/controlled_vocabulary_terms_helper.rb', line 14

def label_for_controlled_vocabulary_term(controlled_vocabulary_term)
  return nil if controlled_vocabulary_term.nil?
  controlled_vocabulary_term.name
end

#term_and_definition_tag(controlled_vocabulary_term) ⇒ Object



68
69
70
# File 'app/helpers/controlled_vocabulary_terms_helper.rb', line 68

def term_and_definition_tag(controlled_vocabulary_term)
  (:span, controlled_vocabulary_term) + ': ' + (:span, controlled_vocabulary_term.definition)
end