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



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

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


46
47
48
49
# File 'app/helpers/controlled_vocabulary_terms_helper.rb', line 46

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
13
# 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?
  # content_tag(:span, color_tag(controlled_vocabulary_term.css_color, controlled_vocabulary_term.name), title: controlled_vocabulary_term.definition, class: 'cvt-tag')
  (
    :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



51
52
53
# File 'app/helpers/controlled_vocabulary_terms_helper.rb', line 51

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

#controlled_vocabulary_term_use(controlled_vocabulary_term) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/controlled_vocabulary_terms_helper.rb', line 27

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
  else
    'n/a'
  end
end

#controlled_vocabulary_terms_search_formObject



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

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

#label_for_controlled_vocabulary_term(controlled_vocabulary_term) ⇒ Object



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

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



55
56
57
# File 'app/helpers/controlled_vocabulary_terms_helper.rb', line 55

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