Module: IdentifiersHelper

Defined in:
app/helpers/identifiers_helper.rb

Instance Method Summary collapse

Instance Method Details



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

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



91
92
93
94
95
# File 'app/helpers/identifiers_helper.rb', line 91

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



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

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



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

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.identifier, 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



128
129
130
131
132
133
134
# File 'app/helpers/identifiers_helper.rb', line 128

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

#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



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

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



118
119
120
# File 'app/helpers/identifiers_helper.rb', line 118

def identifiers_partial
  true
end

#identifiers_search_formObject



112
113
114
# File 'app/helpers/identifiers_helper.rb', line 112

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



99
100
101
102
103
# File 'app/helpers/identifiers_helper.rb', line 99

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



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



83
84
85
86
87
# File 'app/helpers/identifiers_helper.rb', line 83

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)



138
139
140
141
142
143
144
145
146
147
148
149
# File 'app/helpers/identifiers_helper.rb', line 138

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