Module: ArclightHelper
- Defined in:
- app/helpers/arclight_helper.rb
Overview
Generic Helpers used in Arclight
Instance Method Summary collapse
- #aria_hidden_breadcrumb_separator ⇒ Object
- #collection_active? ⇒ Boolean
- #collection_active_class ⇒ Object
- #collection_count ⇒ Object
- #component_parents_to_links(document) ⇒ Object
- #component_top_level_parent_to_links(document) ⇒ Object
-
#config_field ⇒ Object
Defines custom helpers used for creating unique metadata blocks to render.
-
#custom_show_content_classes ⇒ Object
Classes used for customized show page in arclight.
-
#document_or_parent_icon(document) ⇒ Object
determine which icon to show in search results header these icon names will need to be updated when the icons are determined.
- #document_parents(document) ⇒ Object
- #ead_files(document) ⇒ Object
- #fields_have_content?(document, field_accessor) ⇒ Boolean
- #generic_context_navigation(document, original_parents: document.parent_ids, component_level: 1) ⇒ Object
-
#generic_document_fields(config_field) ⇒ Object
Calls the method for a configured field.
-
#generic_render_document_field_label(config_field, document, field: field_name) ⇒ Object
Calls the method for a configured field.
-
#generic_should_render_field?(config_field, document, field) ⇒ Boolean
Calls the method for a configured field.
- #grouped? ⇒ Boolean
- #hierarchy_component_context? ⇒ Boolean
- #normalize_id(id) ⇒ Object
- #on_repositories_index? ⇒ Boolean
- #on_repositories_show? ⇒ Boolean
- #online_contents_context? ⇒ Boolean
- #original_document?(document) ⇒ Boolean
- #parents_to_links(document) ⇒ Object
- #record_view? ⇒ Boolean
-
#regular_compact_breadcrumbs(document) ⇒ Object
For a non-grouped compact view, display the breadcrumbs with the following algorithm: - Display only the first two parts of the item breadcrumb: the repository and the collection.
- #render_grouped_documents(documents) ⇒ Object
-
#repositories_active_class ⇒ Object
the Repositories menu item is only active on the Repositories index page.
- #repository_collections_path(repository) ⇒ Object
-
#repository_faceted_on ⇒ Repository
If we have a facet on the repository, then return the Repository object for it.
- #results_view? ⇒ Boolean
-
#search_results_header_text ⇒ Object
Returns the i18n-ed string to be used as the h1 in search results.
- #search_with_group ⇒ Object
- #search_within_collection(collection_name, search) ⇒ Object
- #search_without_group ⇒ Object
- #show_expanded?(document) ⇒ Boolean
-
#within_collection_context? ⇒ Boolean
Determine if the user is currently under a collection context This is any record view (because it is either the collection or a component w/i a collection) or in a result view where a collection facet has been selected.
- #within_original_tree?(document) ⇒ Boolean
Instance Method Details
#aria_hidden_breadcrumb_separator ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/arclight_helper.rb', line 6 def safe_join( [ '<span aria-hidden="true">'.html_safe, t('arclight.breadcrumb_separator'), '</span>'.html_safe ] ) end |
#collection_active? ⇒ Boolean
119 120 121 |
# File 'app/helpers/arclight_helper.rb', line 119 def collection_active? try(:search_state) && search_state.params_for_search.try(:[], 'f').try(:[], 'level_sim') == ['Collection'] end |
#collection_active_class ⇒ Object
123 124 125 |
# File 'app/helpers/arclight_helper.rb', line 123 def collection_active_class 'active' if collection_active? end |
#collection_count ⇒ Object
127 128 129 |
# File 'app/helpers/arclight_helper.rb', line 127 def collection_count @response.response['numFound'] end |
#component_parents_to_links(document) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'app/helpers/arclight_helper.rb', line 56 def component_parents_to_links(document) parents = document_parents(document) return unless parents.length > 1 safe_join(parents.slice(1, 999).map do |parent| link_to parent.label, solr_document_path(parent.global_id) end, ) end |
#component_top_level_parent_to_links(document) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/helpers/arclight_helper.rb', line 67 def component_top_level_parent_to_links(document) parents = document_parents(document) return unless parents.length > 1 parent_link = link_to(parents[1].label, solr_document_path(parents[1].global_id)) return parent_link if parents.length == 2 safe_join( [ parent_link, , '…'.html_safe ] ) end |
#config_field ⇒ Object
Defines custom helpers used for creating unique metadata blocks to render
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'app/helpers/arclight_helper.rb', line 217 Arclight::Engine.config.catalog_controller_field_accessors.each do |config_field| ## # Mimics what document_show_fields from Blacklight does # https://github.com/projectblacklight/blacklight/blob/dee8d794125306ec8d4ab834a6a45bcf9671c791/app/helpers/blacklight/configuration_helper_behavior.rb#L35-L38 define_method(:"document_#{config_field}s") do |_document = nil| blacklight_config.send(:"#{config_field}s") end ## # Mimics what render_document_show_field_label from Blacklight does # https://github.com/projectblacklight/blacklight/blob/dee8d794125306ec8d4ab834a6a45bcf9671c791/app/helpers/blacklight/blacklight_helper_behavior.rb#L136-L156 define_method(:"render_document_#{config_field}_label") do |*args| = args. document = args.first field = [:field] t(:'blacklight.search.show.label', label: send(:"document_#{config_field}_label", document, field)) end ## # Mimics what document_show_field_label from Blacklight does # https://github.com/projectblacklight/blacklight/blob/dee8d794125306ec8d4ab834a6a45bcf9671c791/app/helpers/blacklight/configuration_helper_behavior.rb#L67-L74 define_method(:"document_#{config_field}_label") do |document, field| field_config = send(:"document_#{config_field}s", document)[field] field_config ||= Blacklight::Configuration::NullField.new(key: field) field_config.display_label('show') end ## # Mimics what should_render_show_field? from Blacklight does # https://github.com/projectblacklight/blacklight/blob/dee8d794125306ec8d4ab834a6a45bcf9671c791/app/helpers/blacklight/blacklight_helper_behavior.rb#L84-L92 define_method(:"should_render_#{config_field}?") do |document, field_config| should_render_field?(field_config, document) && document_has_value?(document, field_config) end end |
#custom_show_content_classes ⇒ Object
Classes used for customized show page in arclight
111 112 113 |
# File 'app/helpers/arclight_helper.rb', line 111 def custom_show_content_classes 'col-md-12 show-document' end |
#document_or_parent_icon(document) ⇒ Object
determine which icon to show in search results header these icon names will need to be updated when the icons are determined
187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'app/helpers/arclight_helper.rb', line 187 def document_or_parent_icon(document) case document.level&.downcase when 'collection' 'collection' when 'file' 'file' when 'series', 'subseries' 'folder' else 'container' end end |
#document_parents(document) ⇒ Object
85 86 87 |
# File 'app/helpers/arclight_helper.rb', line 85 def document_parents(document) Arclight::Parents.from_solr_document(document).as_parents end |
#ead_files(document) ⇒ Object
208 209 210 211 212 213 |
# File 'app/helpers/arclight_helper.rb', line 208 def ead_files(document) files = Arclight::DocumentDownloads.new(document, document.collection_unitid).files files.find do |file| file.type == 'ead' end end |
#fields_have_content?(document, field_accessor) ⇒ Boolean
160 161 162 163 164 |
# File 'app/helpers/arclight_helper.rb', line 160 def fields_have_content?(document, field_accessor) generic_document_fields(field_accessor).any? do |_, field| generic_should_render_field?(field_accessor, document, field) end end |
#generic_context_navigation(document, original_parents: document.parent_ids, component_level: 1) ⇒ Object
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'app/helpers/arclight_helper.rb', line 287 def (document, original_parents: document.parent_ids, component_level: 1) content_tag( :div, '', class: 'context-navigator', data: { collapse: I18n.t('arclight.views.show.collapse'), expand: I18n.t('arclight.views.show.expand'), arclight: { level: component_level, path: search_catalog_path(hierarchy_context: 'component'), name: document.collection_name, originalDocument: document.id, originalParents: original_parents, eadid: normalize_id(document.eadid) } } ) end |
#generic_document_fields(config_field) ⇒ Object
Calls the method for a configured field
257 258 259 |
# File 'app/helpers/arclight_helper.rb', line 257 def generic_document_fields(config_field) send(:"document_#{config_field}s") end |
#generic_render_document_field_label(config_field, document, field: field_name) ⇒ Object
Calls the method for a configured field
269 270 271 |
# File 'app/helpers/arclight_helper.rb', line 269 def generic_render_document_field_label(config_field, document, field: field_name) send(:"render_document_#{config_field}_label", document, field: field) end |
#generic_should_render_field?(config_field, document, field) ⇒ Boolean
Calls the method for a configured field
263 264 265 |
# File 'app/helpers/arclight_helper.rb', line 263 def generic_should_render_field?(config_field, document, field) send(:"should_render_#{config_field}?", document, field) end |
#grouped? ⇒ Boolean
131 132 133 |
# File 'app/helpers/arclight_helper.rb', line 131 def grouped? try(:search_state) && search_state.params_for_search.try(:[], 'group') == 'true' end |
#hierarchy_component_context? ⇒ Boolean
177 178 179 |
# File 'app/helpers/arclight_helper.rb', line 177 def hierarchy_component_context? params[:hierarchy_context] == 'component' end |
#normalize_id(id) ⇒ Object
115 116 117 |
# File 'app/helpers/arclight_helper.rb', line 115 def normalize_id(id) Arclight::NormalizedId.new(id).to_s end |
#on_repositories_index? ⇒ Boolean
151 152 153 |
# File 'app/helpers/arclight_helper.rb', line 151 def on_repositories_index? controller_name == 'repositories' && action_name == 'index' end |
#on_repositories_show? ⇒ Boolean
147 148 149 |
# File 'app/helpers/arclight_helper.rb', line 147 def on_repositories_show? controller_name == 'repositories' && action_name == 'show' end |
#online_contents_context? ⇒ Boolean
181 182 183 |
# File 'app/helpers/arclight_helper.rb', line 181 def online_contents_context? params[:view] == 'online_contents' end |
#original_document?(document) ⇒ Boolean
283 284 285 |
# File 'app/helpers/arclight_helper.rb', line 283 def original_document?(document) document.id == params['original_document'] end |
#parents_to_links(document) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/arclight_helper.rb', line 18 def parents_to_links(document) = [] << build_repository_link(document) << document_parents(document).map do |parent| link_to parent.label, solr_document_path(parent.global_id) end safe_join(, ) end |
#record_view? ⇒ Boolean
321 322 323 |
# File 'app/helpers/arclight_helper.rb', line 321 def record_view? controller_name == 'catalog' && action_name == 'show' end |
#regular_compact_breadcrumbs(document) ⇒ Object
For a non-grouped compact view, display the breadcrumbs with the following algorithm:
- Display only the first two parts of the item breadcrumb: the repository
and the collection.
- After the collection and the breadcrumb divider icon, show an ellipses as
shown in the mockup above. The repository and the collection parts are
linked as usual; the ellipses is not linked.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/arclight_helper.rb', line 38 def (document) = [build_repository_link(document)] parents = document_parents(document) << parents[0, 1].map do |parent| link_to parent.label, solr_document_path(parent.global_id) end << '…'.html_safe if parents.length > 1 safe_join( , ) end |
#render_grouped_documents(documents) ⇒ Object
200 201 202 203 204 205 206 |
# File 'app/helpers/arclight_helper.rb', line 200 def render_grouped_documents(documents) safe_join( documents.each_with_index.map do |document, i| render_document_partial(document, :arclight_index_group_document, document_counter: i) end ) end |
#repositories_active_class ⇒ Object
the Repositories menu item is only active on the Repositories index page
156 157 158 |
# File 'app/helpers/arclight_helper.rb', line 156 def repositories_active_class 'active' if on_repositories_index? end |
#repository_collections_path(repository) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'app/helpers/arclight_helper.rb', line 89 def repository_collections_path(repository) search_action_url( f: { repository_sim: [repository.name], level_sim: ['Collection'] } ) end |
#repository_faceted_on ⇒ Repository
If we have a facet on the repository, then return the Repository object for it
169 170 171 172 173 174 175 |
# File 'app/helpers/arclight_helper.rb', line 169 def repository_faceted_on return unless try(:search_state) && facet_field_in_params?('repository_sim') repos = Array(facet_params('repository_sim')) faceted = repos && repos.length == 1 && repos.first Arclight::Repository.find_by(name: repos.first) if faceted end |
#results_view? ⇒ Boolean
317 318 319 |
# File 'app/helpers/arclight_helper.rb', line 317 def results_view? controller_name == 'catalog' && action_name == 'index' end |
#search_results_header_text ⇒ Object
Returns the i18n-ed string to be used as the h1 in search results
99 100 101 102 103 104 105 106 107 |
# File 'app/helpers/arclight_helper.rb', line 99 def search_results_header_text if (repo = repository_faceted_on).present? t('arclight.search.repository_header', repository: repo.name) elsif collection_active? t('arclight.search.collections_header') else t('blacklight.search.header') end end |
#search_with_group ⇒ Object
135 136 137 |
# File 'app/helpers/arclight_helper.rb', line 135 def search_with_group search_state.params_for_search.merge('group' => 'true').except('page') end |
#search_within_collection(collection_name, search) ⇒ Object
143 144 145 |
# File 'app/helpers/arclight_helper.rb', line 143 def search_within_collection(collection_name, search) search.merge(f: { collection_sim: [collection_name] }) end |
#search_without_group ⇒ Object
139 140 141 |
# File 'app/helpers/arclight_helper.rb', line 139 def search_without_group search_state.params_for_search.except('group', 'page') end |
#show_expanded?(document) ⇒ Boolean
273 274 275 |
# File 'app/helpers/arclight_helper.rb', line 273 def (document) !original_document?(document) && within_original_tree?(document) end |
#within_collection_context? ⇒ Boolean
Determine if the user is currently under a collection context This is any record view (because it is either the collection or a component w/i a collection) or in a result view where a collection facet has been selected
311 312 313 314 315 |
# File 'app/helpers/arclight_helper.rb', line 311 def within_collection_context? return true if record_view? results_view? && params.dig(:f, 'collection_sim') end |
#within_original_tree?(document) ⇒ Boolean
277 278 279 280 281 |
# File 'app/helpers/arclight_helper.rb', line 277 def within_original_tree?(document) Array.wrap(params['original_parents']).map do |parent| Arclight::Parent.new(id: parent, eadid: document.parent_ids.first, level: nil, label: nil).global_id end.include?(document.id) end |