Module: IdentifiersHelper

Defined in:
app/helpers/identifiers_helper.rb

Instance Method Summary collapse

Instance Method Details



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

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)


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

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)


42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/identifiers_helper.rb', line 42

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



30
31
32
33
# File 'app/helpers/identifiers_helper.rb', line 30

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



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

def identifier_list_labels(object)
  ids = visible_identifiers(object).pluck(:cached)
  return nil unless ids.any?
  ids.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



67
68
69
70
71
72
# File 'app/helpers/identifiers_helper.rb', line 67

def identifier_list_tag(object)
  ids = visible_identifiers(object).load
  return nil unless ids.any?
  (:h3, 'Identifiers') +
    identifier_ul_list(object)
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



127
128
129
# File 'app/helpers/identifiers_helper.rb', line 127

def identifier_recent_objects_partial
  true
end

#identifier_short_tag(identifier) ⇒ String?

Returns:

  • (String, nil)


60
61
62
63
# File 'app/helpers/identifiers_helper.rb', line 60

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
19
20
21
# File 'app/helpers/identifiers_helper.rb', line 4

def identifier_tag(identifier)
  return nil if identifier.nil? || identifier.new_record?
  title = identifier.type.demodulize.titleize.humanize
  if identifier.is_local?

    if identifier.is_virtual?
      [
        tag.span(identifier.namespace.short_name, class: [:feedback, 'feedback-thin', 'feedback-light']),
        tag.span(identifier.identifier, title:)
      ].join(' ').html_safe

    else
      tag.span(identifier.cached, title:)
    end
  else
    tag.span(identifier.cached, title:)
  end
end

#identifier_type_select_optionsObject



131
132
133
134
135
136
137
# File 'app/helpers/identifiers_helper.rb', line 131

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)


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

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

#identifier_ul_list(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



76
77
78
79
80
81
82
# File 'app/helpers/identifiers_helper.rb', line 76

def identifier_ul_list(object)
  ids = visible_identifiers(object).load
  return nil unless ids.any?
    (:ul, class: 'annotations_identifier_list') do
      ids.collect{|a| (:li, identifier_annotation_tag(a)) }.join.html_safe
    end
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



121
122
123
# File 'app/helpers/identifiers_helper.rb', line 121

def identifiers_partial
  true
end

#identifiers_search_formObject



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

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



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

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

#label_for_identifier(identifier) ⇒ Object



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

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



86
87
88
89
90
# File 'app/helpers/identifiers_helper.rb', line 86

def simple_identifier_list_tag(object)
  ids = visible_identifiers(object).load
  return nil unless ids.any?
  ids.collect{|a| tag.span(identifier_annotation_tag(a)) }.join(', ').html_safe
end

#visible_identifiers(object) ⇒ Object (private)



141
142
143
144
145
146
147
148
149
150
151
152
# File 'app/helpers/identifiers_helper.rb', line 141

def visible_identifiers(object)
  if object.has_identifiers?

    if controller
      object.identifiers.visible(sessions_current_project_id)
    else
      object.identifiers.visible(nil)
    end
  else
    ::Identifier.none
  end
end