Module: Blacklight::CatalogHelperBehavior
- Included in:
- CatalogHelper
- Defined in:
- app/helpers/blacklight/catalog_helper_behavior.rb
Instance Method Summary collapse
- #atom_feed_link_tag(options = {}) ⇒ Object
-
#bookmarked?(document) ⇒ Boolean
Check if the document is in the user's bookmarks.
- #current_bookmarks(response = nil) ⇒ Object
-
#current_per_page ⇒ Integer
Look up the current per page value, or the default if none if set.
-
#current_sort_field ⇒ Blacklight::Configuration::SortField
Look up the current sort field, or provide the default if none is set.
-
#default_view_type_group_icon_classes(view) ⇒ String
Get the default view type classes for a view in the results view picker.
- #document_class_prefix ⇒ Object
-
#document_counter_with_offset(idx, offset = nil) ⇒ Integer
Get the offset counter for a document.
-
#has_thumbnail?(document) ⇒ Boolean
Does the document have a thumbnail to render?.
-
#item_page_entry_info ⇒ String
Like #page_entries_info above, but for an individual item show page.
- #json_api_link_tag(options = {}) ⇒ Object
-
#page_entries_info(collection, options = {}) ⇒ String
Override the Kaminari page_entries_info helper with our own, blacklight-aware implementation.
-
#render_document_class(document = @document) ⇒ String
Get the classes to add to a document's div.
-
#render_document_main_content_partial(document = @document) ⇒ String
Render the main content partial for a document.
-
#render_document_sidebar_partial(document = @document) ⇒ String
Render the sidebar partial for a document.
- #render_search_to_page_title(params) ⇒ Object
- #render_search_to_page_title_filter(facet, values) ⇒ Object
-
#render_thumbnail_tag(document, image_options = {}, url_options = {}) ⇒ String
Render the thumbnail, if available, for a document and link it to the document record.
-
#render_view_type_group_icon(view) ⇒ String
Render the view type icon for the results view picker.
- #rss_feed_link_tag(options = {}) ⇒ Object
-
#search_field_label(params) ⇒ Object
Look up search field user-displayable label based on params and blacklight_configuration.
-
#should_autofocus_on_search_box? ⇒ Boolean
If no search parameters have been given, we should auto-focus the user's cursor into the searchbox.
-
#show_pagination?(response = nil) ⇒ Boolean
Should we display the pagination controls?.
-
#show_sort_and_per_page?(response = nil) ⇒ Boolean
Should we display the sort and per page widget?.
-
#thumbnail_url(document) ⇒ String
Get the URL to a document's thumbnail image.
Instance Method Details
#atom_feed_link_tag(options = {}) ⇒ Object
11 12 13 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 11 def atom_feed_link_tag( = {}) auto_discovery_link_tag(:atom, feed_link_url('atom', ), title: t('blacklight.search.atom_feed')) end |
#bookmarked?(document) ⇒ Boolean
Check if the document is in the user's bookmarks
265 266 267 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 265 def bookmarked? document current_bookmarks.any? { |x| x.document_id == document.id and x.document_type == document.class } end |
#current_bookmarks(response = nil) ⇒ Object
258 259 260 261 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 258 def current_bookmarks response = nil response ||= @response @current_bookmarks ||= current_or_guest_user.bookmarks_for_documents(response.documents).to_a end |
#current_per_page ⇒ Integer
Look up the current per page value, or the default if none if set
118 119 120 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 118 def current_per_page (@response.rows if @response and @response.rows > 0) || params.fetch(:per_page, default_per_page).to_i end |
#current_sort_field ⇒ Blacklight::Configuration::SortField
Look up the current sort field, or provide the default if none is set
110 111 112 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 110 def current_sort_field (blacklight_config.sort_fields.values.find {|f| f.sort == @response.sort} if @response and @response.sort.present?) || blacklight_config.sort_fields[params[:sort]] || default_sort_field end |
#default_view_type_group_icon_classes(view) ⇒ String
Get the default view type classes for a view in the results view picker
254 255 256 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 254 def default_view_type_group_icon_classes view "glyphicon-#{view.to_s.parameterize} view-icon-#{view.to_s.parameterize}" end |
#document_class_prefix ⇒ Object
136 137 138 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 136 def document_class_prefix 'blacklight-' end |
#document_counter_with_offset(idx, offset = nil) ⇒ Integer
Get the offset counter for a document
78 79 80 81 82 83 84 85 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 78 def document_counter_with_offset idx, offset = nil offset ||= @response.start if @response offset ||= 0 unless render_grouped_response? idx + 1 + offset end end |
#has_thumbnail?(document) ⇒ Boolean
Does the document have a thumbnail to render?
194 195 196 197 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 194 def has_thumbnail? document blacklight_config.view_config(document_index_view_type).thumbnail_method.present? or blacklight_config.view_config(document_index_view_type).thumbnail_field && document.has?(blacklight_config.view_config(document_index_view_type).thumbnail_field) end |
#item_page_entry_info ⇒ String
Like #page_entries_info above, but for an individual item show page. Displays “showing X of Y items” message.
93 94 95 96 97 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 93 def item_page_entry_info t('blacklight.search.entry_pagination_info.other', :current => number_with_delimiter(search_session['counter']), :total => number_with_delimiter(search_session['total']), :count => search_session['total'].to_i).html_safe end |
#json_api_link_tag(options = {}) ⇒ Object
17 18 19 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 17 def json_api_link_tag( = {}) auto_discovery_link_tag(:json, feed_link_url('json', ), type: 'application/json') end |
#page_entries_info(collection, options = {}) ⇒ String
Override the Kaminari page_entries_info helper with our own, blacklight-aware implementation. Displays the “showing X through Y of N” message.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 28 def page_entries_info(collection, = {}) return unless show_pagination? collection entry_name = if [:entry_name] [:entry_name] elsif collection.respond_to? :model # DataMapper collection.model.model_name.human.downcase elsif collection.respond_to? :model_name and !collection.model_name.nil? # AR, Blacklight::PaginationMethods collection.model_name.human.downcase else t('blacklight.entry_name.default') end entry_name = entry_name.pluralize unless collection.total_count == 1 # grouped response objects need special handling end_num = if collection.respond_to? :groups and render_grouped_response? collection collection.groups.length else collection.limit_value end end_num = if collection.offset_value + end_num <= collection.total_count collection.offset_value + end_num else collection.total_count end case collection.total_count when 0 t('blacklight.search.pagination_info.no_items_found', :entry_name => entry_name ).html_safe when 1 t('blacklight.search.pagination_info.single_item_found', :entry_name => entry_name).html_safe else t('blacklight.search.pagination_info.pages', :entry_name => entry_name, :current_page => collection.current_page, :num_pages => collection.total_pages, :start_num => number_with_delimiter(collection.offset_value + 1), :end_num => number_with_delimiter(end_num), :total_num => number_with_delimiter(collection.total_count), :count => collection.total_pages).html_safe end end |
#render_document_class(document = @document) ⇒ String
Get the classes to add to a document's div
126 127 128 129 130 131 132 133 134 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 126 def render_document_class(document = @document) types = document[blacklight_config.view_config(document_index_view_type).display_type_field] return if types.blank? Array(types).compact.map do |t| "#{document_class_prefix}#{t.try(:parameterize) || t}" end.join(' ') end |
#render_document_main_content_partial(document = @document) ⇒ String
Render the main content partial for a document
154 155 156 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 154 def render_document_main_content_partial(document = @document) render partial: 'show_main_content' end |
#render_document_sidebar_partial(document = @document) ⇒ String
Render the sidebar partial for a document
145 146 147 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 145 def (document = @document) render :partial => 'show_sidebar' end |
#render_search_to_page_title(params) ⇒ Object
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 280 def render_search_to_page_title(params) constraints = [] if params['q'].present? q_label = label_for_search_field(params[:search_field]) unless default_search_field && params[:search_field] == default_search_field[:key] constraints += if q_label.present? [t('blacklight.search.page_title.constraint', label: q_label, value: params['q'])] else [params['q']] end end if params['f'].present? constraints += params['f'].to_unsafe_h.collect { |key, value| render_search_to_page_title_filter(key, value) } end constraints.join(' / ') end |
#render_search_to_page_title_filter(facet, values) ⇒ Object
269 270 271 272 273 274 275 276 277 278 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 269 def render_search_to_page_title_filter(facet, values) facet_config = facet_configuration_for_field(facet) filter_label = facet_field_label(facet_config.key) filter_value = if values.size < 3 values.map {|value| facet_display_value(facet, value)}.to_sentence else t('blacklight.search.page_title.many_constraint_values', values: values.size) end t('blacklight.search.page_title.constraint', label: filter_label, value: filter_value) end |
#render_thumbnail_tag(document, image_options = {}, url_options = {}) ⇒ String
Render the thumbnail, if available, for a document and link it to the document record.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 207 def render_thumbnail_tag document, = {}, = {} value = if blacklight_config.view_config(document_index_view_type).thumbnail_method send(blacklight_config.view_config(document_index_view_type).thumbnail_method, document, ) elsif blacklight_config.view_config(document_index_view_type).thumbnail_field url = thumbnail_url(document) image_tag url, if url.present? end if value if == false Deprecation.warn(self, "passing false as the second argument to render_thumbnail_tag is deprecated. Use suppress_link: true instead. This behavior will be removed in Blacklight 7") = { suppress_link: true } end if [:suppress_link] value else link_to_document document, value, end end end |
#render_view_type_group_icon(view) ⇒ String
Render the view type icon for the results view picker
245 246 247 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 245 def render_view_type_group_icon view content_tag :span, '', class: "glyphicon #{blacklight_config.view[view].icon_class || default_view_type_group_icon_classes(view)}" end |
#rss_feed_link_tag(options = {}) ⇒ Object
5 6 7 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 5 def rss_feed_link_tag( = {}) auto_discovery_link_tag(:rss, feed_link_url('rss', ), title: t('blacklight.search.rss_feed')) end |
#search_field_label(params) ⇒ Object
Look up search field user-displayable label based on params and blacklight_configuration.
102 103 104 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 102 def search_field_label(params) h( label_for_search_field(params[:search_field]) ) end |
#should_autofocus_on_search_box? ⇒ Boolean
If no search parameters have been given, we should auto-focus the user's cursor into the searchbox
183 184 185 186 187 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 183 def should_autofocus_on_search_box? controller.is_a? Blacklight::Catalog and action_name == "index" and !has_search_parameters? end |
#show_pagination?(response = nil) ⇒ Boolean
Should we display the pagination controls?
173 174 175 176 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 173 def show_pagination? response = nil response ||= @response response.limit_value > 0 end |
#show_sort_and_per_page?(response = nil) ⇒ Boolean
Should we display the sort and per page widget?
163 164 165 166 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 163 def show_sort_and_per_page? response = nil response ||= @response !response.empty? end |
#thumbnail_url(document) ⇒ String
Get the URL to a document's thumbnail image
234 235 236 237 238 |
# File 'app/helpers/blacklight/catalog_helper_behavior.rb', line 234 def thumbnail_url document if document.has? blacklight_config.view_config(document_index_view_type).thumbnail_field document.first(blacklight_config.view_config(document_index_view_type).thumbnail_field) end end |