Module: IdentifiersHelper

Defined in:
app/helpers/identifiers_helper.rb

Instance Method Summary collapse

Instance Method Details



95
96
97
98
99
100
# File 'app/helpers/identifiers_helper.rb', line 95

def add_identifier_link(object: nil)
  link_to('Add identifier', new_identifier_path(
    identifier: {
      identifier_object_type: object.class.base_class.name,
      identifier_object_id: object.id})) if object.has_identifiers?
end

#identifier_annotation_tag(identifier) ⇒ String?

Returns:

  • (String, nil)


33
34
35
36
# File 'app/helpers/identifiers_helper.rb', line 33

def identifier_annotation_tag(identifier)
  return nil if identifier.nil?
  (:span, identifier.cached, class: [:annotation__identifier])
end

#identifier_autocomplete_tag(identifier) ⇒ String?

Returns:

  • (String, nil)


39
40
41
42
43
44
45
46
47
48
# File 'app/helpers/identifiers_helper.rb', line 39

def identifier_autocomplete_tag(identifier)
  return nil if identifier.nil?
  (:span, class: :annotation__identifier) do
    [
      object_tag(identifier.annotated_object.metamorphosize),
      (:span, identifier.identifier_object_type, class: [:feedback, 'feedback-thin', 'feedback-primary']),
      (:span, identifier.type, class: [:feedback, 'feedback-thin', 'feedback-secondary']),
    ].join(' ').html_safe
  end
end

Returns link to GET identifiers/:id.

Returns:

  • (String, nil)

    link to GET identifiers/:id



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

def identifier_link(identifier)
  return nil if identifier.nil?
  link_to(identifier_tag(identifier).html_safe, identifier.identifier_object.metamorphosize)
end

#identifier_list_labels(object) ⇒ String?

Returns a list of identifiers without HTML.

Returns:

  • (String, nil)

    a list of identifiers without HTML



81
82
83
84
# File 'app/helpers/identifiers_helper.rb', line 81

def identifier_list_labels(object)
  return nil if !object.identifiers.any?
  object.identifiers.collect{|a| a.cached }.join(', ')
end

#identifier_list_tag(object) ⇒ String

Returns assumes the display context is on the object in question.

Returns:

  • (String)

    assumes the display context is on the object in question



64
65
66
67
68
69
70
# File 'app/helpers/identifiers_helper.rb', line 64

def identifier_list_tag(object)
  return nil unless object.has_identifiers? && object.identifiers.any?
  (:h3, 'Identifiers') +
    (:ul, class: 'annotations_identifier_list') do
    object.identifiers.collect{|a| (:li, identifier_annotation_tag(a)) }.join.html_safe
  end
end

#identifier_recent_objects_partialTrue

Returns indicates a custom partial should be used, see list_helper.rb.

Returns:

  • (True)

    indicates a custom partial should be used, see list_helper.rb



114
115
116
# File 'app/helpers/identifiers_helper.rb', line 114

def identifier_recent_objects_partial
  true
end

#identifier_short_tag(identifier) ⇒ String?

Returns:

  • (String, nil)


57
58
59
60
# File 'app/helpers/identifiers_helper.rb', line 57

def identifier_short_tag(identifier)
  return nil if identifier.nil?
  (:span, identifier.cached, class: [:feedback, 'feedback-thin', 'feedback-primary'])
end

#identifier_tag(identifier) ⇒ String?

Returns:

  • (String, nil)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/identifiers_helper.rb', line 4

def identifier_tag(identifier)
  return nil if identifier.nil? || identifier.new_record?
  if identifier.is_local?
    if identifier.namespace.is_virtual?
      [
        tag.span(identifier.namespace.short_name, class: [:feedback, 'feedback-thin', 'feedback-light']),
        tag.span(identifier.cached, title: identifier.type.demodulize.titleize.humanize)
      ].join(' ').html_safe
    else
      tag.span(identifier.cached, title: identifier.type.demodulize.titleize.humanize)
    end
  else
    tag.span(identifier.cached, title: identifier.type.demodulize.titleize.humanize)
  end
end

#identifier_type_select_optionsObject



118
119
120
121
122
123
124
# File 'app/helpers/identifiers_helper.rb', line 118

def identifier_type_select_options
  a = []
  %I{global local unknown}.each do |t|
    a += IDENTIFIERS_JSON[t][:all].collect{|b,c| [c[:label], b]}
  end
  a
end

#identifier_type_tag(identifier) ⇒ String?

Returns:

  • (String, nil)


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

def identifier_type_tag(identifier)
  return nil if identifier.nil?
  identifier.class.name.demodulize.underscore.humanize.downcase
end

#identifiers_partialTrue

Returns indicates a custom partial should be used, see list_helper.rb.

Returns:

  • (True)

    indicates a custom partial should be used, see list_helper.rb



108
109
110
# File 'app/helpers/identifiers_helper.rb', line 108

def identifiers_partial
  true
end

#identifiers_search_formObject



102
103
104
# File 'app/helpers/identifiers_helper.rb', line 102

def identifiers_search_form
  render('/identifiers/quick_search_form')
end

#identifiers_tag(object) ⇒ String?

Returns identifiers for object with HTML.

Returns:

  • (String, nil)

    identifiers for object with HTML



88
89
90
91
92
93
# File 'app/helpers/identifiers_helper.rb', line 88

def identifiers_tag(object)
  if object.identifiers.any?
    return object.identifiers.collect{|a| (:span, identifier_tag(a))}.join('; ').html_safe
  end
  nil
end

#label_for_identifier(identifier) ⇒ Object



20
21
22
23
# File 'app/helpers/identifiers_helper.rb', line 20

def label_for_identifier(identifier)
  return nil if identifier.nil?
  identifier.cached
end

#simple_identifier_list_tag(object) ⇒ String?

Returns a list of identifiers with HTML.

Returns:

  • (String, nil)

    a list of identifiers with HTML



74
75
76
77
# File 'app/helpers/identifiers_helper.rb', line 74

def simple_identifier_list_tag(object)
  return nil if !object.identifiers.any?
  object.identifiers.collect{|a| tag.span(identifier_annotation_tag(a)) }.join.html_safe
end