Module: ConfidencesHelper

Defined in:
app/helpers/confidences_helper.rb

Instance Method Summary collapse

Instance Method Details



58
59
60
61
62
63
# File 'app/helpers/confidences_helper.rb', line 58

def add_confidence_link(object: nil)
  link_to('Add confidence', new_confidence_path(
    confidence_object_type: object.class.base_class.name,
    confidence_object_id: object.id
  )) if object.has_confidences?
end

#confidence_annotation_confidence(confidence) ⇒ Object



23
24
25
26
# File 'app/helpers/confidences_helper.rb', line 23

def confidence_annotation_confidence(confidence)
  return nil if confidence.nil?
  (:span, controlled_vocabulary_term_tag(confidence.confidence_level), class: [:annotation__confidence])
end

#confidence_default_icon(object) ⇒ Object



40
41
42
43
44
45
46
# File 'app/helpers/confidences_helper.rb', line 40

def confidence_default_icon(object)
  (:div, '', data: {
    'confidence-default' => 'true',
    'confidence-object-global-id' => object.to_global_id.to_s,
    'default-confidenced-id' => is_default_confidenced?(object), 
    'inserted-confidence-level-count' => inserted_confidence_level_count  })
end


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

def confidence_link(confidence)
  return nil if confidence.nil?
  link_to(confidence_tag(confidence), confidence.confidence_object.metamorphosize)
end

#confidence_list_tag(object) ⇒ String (html)?

Returns a ul/li of tags for the object.

Returns:

  • (String (html), nil)

    a ul/li of tags for the object



15
16
17
18
19
20
21
# File 'app/helpers/confidences_helper.rb', line 15

def confidence_list_tag(object)
  return nil unless object.has_confidences? && object.confidences.any?
  (:h3, 'Confidences') +
    (:ul, class: 'annotations__confidences_list') do
    object.confidences.collect { |a| (:li, confidence_tag(a)) }.join.html_safe
  end
end

#confidence_tag(confidence) ⇒ Object



3
4
5
6
# File 'app/helpers/confidences_helper.rb', line 3

def confidence_tag(confidence)
  return nil if confidence.nil?
  controlled_vocabulary_term_tag(confidence.confidence_level)
end

#confidences_search_formObject



28
29
30
# File 'app/helpers/confidences_helper.rb', line 28

def confidences_search_form
  render('/confidences/quick_search_form')
end

#inserted_confidence_levelObject



36
37
38
# File 'app/helpers/confidences_helper.rb', line 36

def inserted_confidence_level
  inserted_pinboard_item_object_for_klass('ConfidenceLevel')
end

#inserted_confidence_level_countObject



32
33
34
# File 'app/helpers/confidences_helper.rb', line 32

def inserted_confidence_level_count
  inserted_confidence_level.try(:confidences).try(:count)
end

#is_default_confidenced?(object) ⇒ Integer, false

Returns true if the object has the confidence level, and is annotated with the confidence level presently defaulted on the pinboard.

Returns:

  • (Integer, false)

    true if the object has the confidence level, and is annotated with the confidence level presently defaulted on the pinboard



50
51
52
53
54
55
56
# File 'app/helpers/confidences_helper.rb', line 50

def is_default_confidenced?(object)
  return false if object.blank?
  confidence_level = inserted_confidence_level
  return false if confidence_level.blank?
  t = Confidence.where(confidence_object: object, confidence_level: confidence_level).first.try(:id)
  t ? t : false
end