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?
-
#identifier_ul_list(object) ⇒ String
Assumes the display context is on the object in question.
-
#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
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?
36 37 38 39 |
# File 'app/helpers/identifiers_helper.rb', line 36 def identifier_annotation_tag(identifier) return nil if identifier.nil? content_tag(:span, identifier.cached, class: [:annotation__identifier]) end |
#identifier_autocomplete_tag(identifier) ⇒ String?
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? 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.
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.) end |
#identifier_list_labels(object) ⇒ String?
Returns 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.
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? content_tag(:h3, 'Identifiers') + identifier_ul_list(object) end |
#identifier_recent_objects_partial ⇒ True
Returns 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?
60 61 62 63 |
# File 'app/helpers/identifiers_helper.rb', line 60 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 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_options ⇒ Object
131 132 133 134 135 136 137 |
# File 'app/helpers/identifiers_helper.rb', line 131 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?
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.
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? content_tag(:ul, class: 'annotations_identifier_list') do ids.collect{|a| content_tag(:li, identifier_annotation_tag(a)) }.join.html_safe end end |
#identifiers_partial ⇒ True
Returns 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_form ⇒ Object
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.
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| content_tag(: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.
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 |