Module: IdentifiersHelper
- Defined in:
- app/helpers/identifiers_helper.rb
Instance Method Summary collapse
- #add_identifier_link(object: nil) ⇒ Object
- #identifier_annotation_tag(identifier) ⇒ String?
- #identifier_autocomplete_tag(identifier) ⇒ String?
-
#identifier_link(identifier) ⇒ String?
Link to GET identifiers/:id.
-
#identifier_list_labels(object) ⇒ String?
A list of identifiers without HTML.
-
#identifier_list_tag(object) ⇒ String
Assumes the display context is on the object in question.
-
#identifier_recent_objects_partial ⇒ True
Indicates a custom partial should be used, see list_helper.rb.
- #identifier_short_tag(identifier) ⇒ String?
- #identifier_tag(identifier) ⇒ String?
- #identifier_type_select_options ⇒ Object
- #identifier_type_tag(identifier) ⇒ String?
-
#identifiers_partial ⇒ True
Indicates a custom partial should be used, see list_helper.rb.
- #identifiers_search_form ⇒ Object
-
#identifiers_tag(object) ⇒ String?
Identifiers for object with HTML.
- #label_for_identifier(identifier) ⇒ Object
-
#simple_identifier_list_tag(object) ⇒ String?
A list of identifiers with HTML.
- #visible_identifiers(object) ⇒ Object private
Instance Method Details
#add_identifier_link(object: nil) ⇒ Object
97 98 99 100 101 102 |
# File 'app/helpers/identifiers_helper.rb', line 97 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?
33 34 35 36 |
# File 'app/helpers/identifiers_helper.rb', line 33 def identifier_annotation_tag(identifier) return nil if identifier.nil? content_tag(:span, identifier.cached, class: [:annotation__identifier]) end |
#identifier_autocomplete_tag(identifier) ⇒ String?
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? content_tag(:span, class: :annotation__identifier) do [ object_tag(identifier.annotated_object.), content_tag(:span, identifier.identifier_object_type, class: [:feedback, 'feedback-thin', 'feedback-primary']), content_tag(:span, identifier.type, class: [:feedback, 'feedback-thin', 'feedback-secondary']), ].join(' ').html_safe end end |
#identifier_link(identifier) ⇒ String?
Returns 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.) end |
#identifier_list_labels(object) ⇒ String?
Returns a list of identifiers without HTML.
83 84 85 86 87 |
# File 'app/helpers/identifiers_helper.rb', line 83 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.
64 65 66 67 68 69 70 71 |
# File 'app/helpers/identifiers_helper.rb', line 64 def identifier_list_tag(object) ids = visible_identifiers(object).load return nil unless ids.any? content_tag(:h3, 'Identifiers') + content_tag(:ul, class: 'annotations_identifier_list') do ids.collect{|a| content_tag(:li, identifier_annotation_tag(a)) }.join.html_safe end end |
#identifier_recent_objects_partial ⇒ True
Returns indicates a custom partial should be used, see list_helper.rb.
116 117 118 |
# File 'app/helpers/identifiers_helper.rb', line 116 def identifier_recent_objects_partial true end |
#identifier_short_tag(identifier) ⇒ String?
57 58 59 60 |
# File 'app/helpers/identifiers_helper.rb', line 57 def identifier_short_tag(identifier) return nil if identifier.nil? content_tag(:span, identifier.cached, class: [:feedback, 'feedback-thin', 'feedback-primary']) end |
#identifier_tag(identifier) ⇒ String?
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_options ⇒ Object
120 121 122 123 124 125 126 |
# File 'app/helpers/identifiers_helper.rb', line 120 def 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?
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_partial ⇒ True
Returns indicates a custom partial should be used, see list_helper.rb.
110 111 112 |
# File 'app/helpers/identifiers_helper.rb', line 110 def identifiers_partial true end |
#identifiers_search_form ⇒ Object
104 105 106 |
# File 'app/helpers/identifiers_helper.rb', line 104 def identifiers_search_form render('/identifiers/quick_search_form') end |
#identifiers_tag(object) ⇒ String?
Returns identifiers for object with HTML.
91 92 93 94 95 |
# File 'app/helpers/identifiers_helper.rb', line 91 def identifiers_tag(object) ids = visible_identifiers(object) return nil unless ids.any? return ids.collect{|a| content_tag(: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.
75 76 77 78 79 |
# File 'app/helpers/identifiers_helper.rb', line 75 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)
130 131 132 133 134 135 136 |
# File 'app/helpers/identifiers_helper.rb', line 130 def visible_identifiers(object) if object.has_identifiers? object.identifiers.visible(Current.project_id) else ::Identifier.none end end |