blacklight 5.0.0.pre4 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,13 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Blacklight::CatalogHelperBehavior
3
3
 
4
+ ##
4
5
  # Override the Kaminari page_entries_info helper with our own, blacklight-aware
5
- # implementation
6
+ # implementation.
7
+ # Displays the "showing X through Y of N" message.
6
8
  #
7
- # Pass in an RSolr::Response. Displays the "showing X through Y of N" message.
9
+ # @param [RSolr::Resource] (or other Kaminari-compatible objects)
10
+ # @return [String]
8
11
  def page_entries_info(collection, options = {})
9
12
  entry_name = if options[:entry_name]
10
13
  options[:entry_name]
@@ -40,68 +43,122 @@ module Blacklight::CatalogHelperBehavior
40
43
  end
41
44
  end
42
45
 
46
+ ##
47
+ # Get the offset counter for a document
48
+ #
49
+ # @param [Integer] document index
50
+ # @return [Integer]
43
51
  def document_counter_with_offset idx
44
52
  unless render_grouped_response?
45
53
  idx + 1 + @response.params[:start].to_i
46
54
  end
47
55
  end
48
56
 
49
- # Like #page_entries_info above, but for an individual
50
- # item show page. Displays "showing X of Y items" message. Actually takes
51
- # data from session though (not a great design).
52
- # Code should call this method rather than interrogating session directly,
53
- # because implementation of where this data is stored/retrieved may change.
57
+ ##
58
+ # Like #page_entries_info above, but for an individual
59
+ # item show page. Displays "showing X of Y items" message.
60
+ #
61
+ # @see #page_entries_info
62
+ # @return [String]
54
63
  def item_page_entry_info
55
64
  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
56
65
  end
57
66
 
67
+ ##
58
68
  # Look up search field user-displayable label
59
69
  # based on params[:qt] and blacklight_configuration.
60
70
  def search_field_label(params)
61
71
  h( label_for_search_field(params[:search_field]) )
62
72
  end
63
73
 
74
+ ##
75
+ # Look up the current sort field, or provide the default if none is set
76
+ #
77
+ # @return [Blacklight::Configuration::SortField]
64
78
  def current_sort_field
65
- blacklight_config.sort_fields[params[:sort]] || (blacklight_config.sort_fields.first ? blacklight_config.sort_fields.first.last : nil )
79
+ blacklight_config.sort_fields[params[:sort]] || default_sort_field
66
80
  end
67
81
 
82
+ ##
83
+ # Look up the current per page value, or the default if none if set
84
+ #
85
+ # @return [Integer]
68
86
  def current_per_page
69
- (@response.rows if @response and @response.rows > 0) || params.fetch(:per_page, (blacklight_config.per_page.first unless blacklight_config.per_page.blank?)).to_i
87
+ (@response.rows if @response and @response.rows > 0) || params.fetch(:per_page, default_per_page).to_i
70
88
  end
71
89
 
72
- # Export to Refworks URL, called in _show_tools
90
+ ##
91
+ # Export to Refworks URL
92
+ #
93
+ # @param [SolrDocument]
94
+ # @return [String]
73
95
  def refworks_export_url(document = @document)
74
96
  "http://www.refworks.com/express/expressimport.asp?vendor=#{CGI.escape(application_name)}&filter=MARC%20Format&encoding=65001&url=#{CGI.escape(polymorphic_path(document, :format => 'refworks_marc_txt', :only_path => false))}"
75
97
  end
76
98
 
99
+ ##
100
+ # Get the classes to add to a document's div
101
+ #
102
+ # @return [String]
77
103
  def render_document_class(document = @document)
78
104
  'blacklight-' + document.get(blacklight_config.view_config(document_index_view_type_field).display_type_field).parameterize rescue nil
79
105
  end
80
106
 
107
+ ##
108
+ # Render the sidebar partial for a document
109
+ #
110
+ # @param [SolrDocument]
111
+ # @return [String]
81
112
  def render_document_sidebar_partial(document = @document)
82
113
  render :partial => 'show_sidebar'
83
114
  end
84
115
 
116
+ ##
117
+ # Check if any search parameters have been set
118
+ # @return [Boolean]
85
119
  def has_search_parameters?
86
120
  !params[:q].blank? or !params[:f].blank? or !params[:search_field].blank?
87
121
  end
88
122
 
123
+ ##
124
+ # Should we display the sort and per page widget?
125
+ #
126
+ # @param [Blacklight::SolrResponse]
127
+ # @return [Boolean]
89
128
  def show_sort_and_per_page? response = nil
90
129
  response ||= @response
91
130
  !response.empty?
92
131
  end
93
132
 
133
+ ##
134
+ # If no search parameters have been given, we should
135
+ # auto-focus the user's cursor into the searchbox
136
+ #
137
+ # @return [Boolean]
94
138
  def should_autofocus_on_search_box?
95
139
  controller.is_a? Blacklight::Catalog and
96
140
  action_name == "index" and
97
141
  !has_search_parameters?
98
142
  end
99
143
 
144
+ ##
145
+ # Does the document have a thumbnail to render?
146
+ #
147
+ # @param [SolrDocument]
148
+ # @return [Boolean]
100
149
  def has_thumbnail? document
101
150
  blacklight_config.view_config(document_index_view_type).thumbnail_method or
102
151
  blacklight_config.view_config(document_index_view_type).thumbnail_field && document.has?(blacklight_config.view_config(document_index_view_type).thumbnail_field)
103
152
  end
104
153
 
154
+ ##
155
+ # Render the thumbnail, if available, for a document and
156
+ # link it to the document record.
157
+ #
158
+ # @param [SolrDocument]
159
+ # @param [Hash] options to pass to the image tag
160
+ # @param [Hash] url options to pass to #link_to_document
161
+ # @return [String]
105
162
  def render_thumbnail_tag document, image_options = {}, url_options = {}
106
163
  value = if blacklight_config.view_config(document_index_view_type).thumbnail_method
107
164
  send(blacklight_config.view_config(document_index_view_type).thumbnail_method, document, image_options)
@@ -114,24 +171,40 @@ module Blacklight::CatalogHelperBehavior
114
171
  end
115
172
  end
116
173
 
174
+ ##
175
+ # Get the URL to a document's thumbnail image
176
+ #
177
+ # @param [SolrDocument]
178
+ # @return [String]
117
179
  def thumbnail_url document
118
180
  if document.has? blacklight_config.view_config(document_index_view_type).thumbnail_field
119
181
  document.first(blacklight_config.view_config(document_index_view_type).thumbnail_field)
120
182
  end
121
183
  end
122
184
 
185
+ ##
186
+ # Get url parameters to a search within a grouped result set
187
+ #
188
+ # @param [Blacklight::SolrResponse::Group]
189
+ # @return [Hash]
123
190
  def add_group_facet_params_and_redirect group
124
191
  add_facet_params_and_redirect(group.field, group.key)
125
192
  end
126
193
 
127
- def has_alternative_views?
128
- blacklight_config.view.keys.length > 1
129
- end
130
-
194
+ ##
195
+ # Render the view type icon for the results view picker
196
+ #
197
+ # @param [String]
198
+ # @return [String]
131
199
  def render_view_type_group_icon view
132
200
  content_tag :span, '', class: "glyphicon #{blacklight_config.view[view].icon_class || default_view_type_group_icon_classes(view) }"
133
201
  end
134
202
 
203
+ ##
204
+ # Get the default view type classes for a view in the results view picker
205
+ #
206
+ # @param [String]
207
+ # @return [String]
135
208
  def default_view_type_group_icon_classes view
136
209
  "glyphicon-#{view.to_s.parameterize } view-icon-#{view.to_s.parameterize}"
137
210
  end
@@ -0,0 +1,61 @@
1
+ module Blacklight::ConfigurationHelperBehavior
2
+
3
+ ##
4
+ # Index fields to display for a type of document
5
+ #
6
+ # @param [SolrDocument] document
7
+ # @return [Array<Blacklight::Solr::Configuration::SolrField>]
8
+ def index_fields document=nil
9
+ blacklight_config.index_fields
10
+ end
11
+
12
+ # Used in the document_list partial (search view) for building a select element
13
+ def sort_fields
14
+ blacklight_config.sort_fields.map { |key, x| [x.label, x.key] }
15
+ end
16
+
17
+ # Used in the search form partial for building a select tag
18
+ def search_fields
19
+ search_field_options_for_select
20
+ end
21
+
22
+ # used in the catalog/_show/_default partial
23
+ def document_show_fields document=nil
24
+ blacklight_config.show_fields
25
+ end
26
+
27
+ ##
28
+ # Get the default index view type
29
+ def default_document_index_view_type
30
+ blacklight_config.view.keys.first
31
+ end
32
+
33
+ ##
34
+ # Check if there are alternative views configuration
35
+ def has_alternative_views?
36
+ blacklight_config.view.keys.length > 1
37
+ end
38
+
39
+ ##
40
+ # Maximum number of results for spell checking
41
+ def spell_check_max
42
+ blacklight_config.spell_max
43
+ end
44
+
45
+ # Used in the document list partial (search view) for creating a link to the document show action
46
+ def document_show_link_field document=nil
47
+ blacklight_config.view_config(document_index_view_type).title_field.to_sym
48
+ end
49
+
50
+ ##
51
+ # Default sort field
52
+ def default_sort_field
53
+ blacklight_config.sort_fields.first.last if blacklight_config.sort_fields.first
54
+ end
55
+
56
+ ##
57
+ # The default value for search results per page
58
+ def default_per_page
59
+ blacklight_config.per_page.first unless blacklight_config.per_page.blank?
60
+ end
61
+ end
@@ -2,11 +2,23 @@ module Blacklight::FacetsHelperBehavior
2
2
 
3
3
  include Blacklight::Facet
4
4
 
5
+ ##
6
+ # Check if any of the given fields have values
7
+ #
8
+ # @param [Array<String>]
9
+ # @param [Hash] options
10
+ # @return [Boolean]
5
11
  def has_facet_values? fields = facet_field_names, options = {}
6
12
  facets_from_request(fields).any? { |display_facet| !display_facet.items.empty? }
7
13
  end
8
14
 
9
- # Render a collection of facet fields
15
+ ##
16
+ # Render a collection of facet fields.
17
+ # @see #render_facet_limit
18
+ #
19
+ # @param [Array<String>]
20
+ # @param [Hash] options
21
+ # @return String
10
22
  def render_facet_partials fields = facet_field_names, options = {}
11
23
  safe_join(facets_from_request(fields).map do |display_facet|
12
24
  render_facet_limit(display_facet, options)
@@ -14,14 +26,17 @@ module Blacklight::FacetsHelperBehavior
14
26
  end
15
27
 
16
28
 
17
- # used in the catalog/_facets partial and elsewhere
29
+ ##
18
30
  # Renders a single section for facet limit with a specified
19
31
  # solr field used for faceting. Can be over-ridden for custom
20
32
  # display on a per-facet basis.
21
33
  #
22
34
  # @param [Blacklight::SolrResponse::Facets::FacetField] display_facet
23
35
  # @param [Hash] options parameters to use for rendering the facet limit partial
24
- #
36
+ # @option options [String] :partial partial to render
37
+ # @option options [String] :layout partial layout to render
38
+ # @option options [Hash] :locals locals to pass to the partial
39
+ # @return [String]
25
40
  def render_facet_limit(display_facet, options = {})
26
41
  return if not should_render_facet?(display_facet)
27
42
  options = options.dup
@@ -39,7 +54,9 @@ module Blacklight::FacetsHelperBehavior
39
54
  # Determine if Blacklight should render the display_facet or not
40
55
  #
41
56
  # By default, only render facets with items.
42
- # @param [Blacklight::SolrResponse::Facets::FacetField] display_facet
57
+ #
58
+ # @param [Blacklight::SolrResponse::Facets::FacetField] display_facet
59
+ # @return [Boolean]
43
60
  def should_render_facet? display_facet
44
61
  # display when show is nil or true
45
62
  facet_config = facet_configuration_for_field(display_facet.name)
@@ -63,15 +80,21 @@ module Blacklight::FacetsHelperBehavior
63
80
  end
64
81
 
65
82
  ##
66
- # if the facet is 'active', don't collapse
67
- # if the facet is configured to collapse (the default), collapse
68
- # if the facet is configured not to collapse, don't collapse
83
+ # Determine whether a facet should be rendered as collapsed or not.
84
+ # - if the facet is 'active', don't collapse
85
+ # - if the facet is configured to collapse (the default), collapse
86
+ # - if the facet is configured not to collapse, don't collapse
87
+ #
88
+ # @param [Blacklight::Configuration::FacetField]
89
+ # @return [Boolean]
69
90
  def should_collapse_facet? facet_field
70
91
  !facet_field_in_params?(facet_field.field) && facet_field.collapse
71
92
  end
72
93
 
73
- # the name of the partial to use to render a facet field. Can be over-ridden for custom
74
- # display on a per-facet basis.
94
+ ##
95
+ # the name of the partial to use to render a facet field.
96
+ #
97
+ # @return [String]
75
98
  def facet_partial_name(display_facet = nil)
76
99
  config = facet_configuration_for_field(display_facet.name)
77
100
  name = config.try(:partial)
@@ -79,17 +102,17 @@ module Blacklight::FacetsHelperBehavior
79
102
  name ||= "facet_limit"
80
103
  end
81
104
 
82
- #
83
- # facet param helpers ->
84
- #
85
-
105
+ ##
86
106
  # Standard display of a facet value in a list. Used in both _facets sidebar
87
107
  # partial and catalog/facet expanded list. Will output facet value name as
88
- # a link to add that to your restrictions, with count in parens.
89
- # first arg item is a facet value item from rsolr-ext.
90
- # options consist of:
91
- # :suppress_link => true # do not make it a link
92
- # :route_set => my_engine # call link_to on engine routes.
108
+ # a link to add that to your restrictions, with count in parens.
109
+ #
110
+ # @param [Blacklight::SolrResponse::Facets::FacetField]
111
+ # @param [String] facet item
112
+ # @param [Hash] options
113
+ # @option options [Boolean] :suppress_link display the facet, but don't link to it
114
+ # @option options [Rails::Engine] :route_set route set to use to render the link
115
+ # @return [String]
93
116
  def render_facet_value(facet_solr_field, item, options ={})
94
117
  scope = options.delete(:route_set) || self
95
118
  path = scope.url_for(add_facet_params_and_redirect(facet_solr_field, item).merge(only_path: true))
@@ -98,8 +121,9 @@ module Blacklight::FacetsHelperBehavior
98
121
  end + render_facet_count(item.hits)
99
122
  end
100
123
 
101
- # Standard display of a SELECTED facet value, no link, special span
102
- # with class, and 'remove' button.
124
+ ##
125
+ # Standard display of a SELECTED facet value (e.g. without a link and with a remove button)
126
+ # @params (see #render_facet_value)
103
127
  def render_selected_facet_value(facet_solr_field, item)
104
128
  content_tag(:span, :class => "facet-label") do
105
129
  content_tag(:span, facet_display_value(facet_solr_field, item), :class => "selected") +
@@ -108,20 +132,35 @@ module Blacklight::FacetsHelperBehavior
108
132
  end + render_facet_count(item.hits, :classes => ["selected"])
109
133
  end
110
134
 
135
+ ##
111
136
  # Renders a count value for facet limits. Can be over-ridden locally
112
137
  # to change style. And can be called by plugins to get consistent display.
113
138
  #
114
- # option :class takes an array of classes to add to count span.
139
+ # @param [Integer] number of facet results
140
+ # @param [Hash] options
141
+ # @option options [Array<String>] an array of classes to add to count span.
142
+ # @return [String]
115
143
  def render_facet_count(num, options = {})
116
144
  classes = (options[:classes] || []) << "facet-count"
117
145
  content_tag("span", t('blacklight.search.facets.count', :number => num), :class => classes)
118
146
  end
119
147
 
148
+ ##
149
+ # Are any facet restrictions for a field in the query parameters?
150
+ #
151
+ # @param [String] facet field
152
+ # @return [Boolean]
120
153
  def facet_field_in_params? field
121
154
  params[:f] and params[:f][field]
122
155
  end
123
156
 
124
- # true or false, depending on whether the field and value is in params[:f]
157
+ ##
158
+ # Check if the query parameters have the given facet field with the
159
+ # given value.
160
+ #
161
+ # @param [Object] facet field
162
+ # @param [Object] facet value
163
+ # @return [Boolean]
125
164
  def facet_in_params?(field, item)
126
165
  if item and item.respond_to? :field
127
166
  field = item.field
@@ -132,6 +171,12 @@ module Blacklight::FacetsHelperBehavior
132
171
  facet_field_in_params?(field) and params[:f][field].include?(value)
133
172
  end
134
173
 
174
+ ##
175
+ # Get the displayable version of a facet's value
176
+ #
177
+ # @param [Object] field
178
+ # @param [String] item value
179
+ # @return [String]
135
180
  def facet_display_value field, item
136
181
  facet_config = facet_configuration_for_field(field)
137
182
 
@@ -11,9 +11,12 @@
11
11
  # to form fields used for sort and change per-page
12
12
  module Blacklight::HashAsHiddenFieldsHelperBehavior
13
13
 
14
+ ##
14
15
  # Writes out zero or more <input type="hidden"> elements, completely
15
16
  # representing a hash passed in using Rails-style request parameters
16
- # for hashes nested with arrays and other hashes.
17
+ # for hashes nested with arrays and other hashes.
18
+ # @param [Hash]
19
+ # @return [String]
17
20
  def render_hash_as_hidden_fields(hash)
18
21
 
19
22
  hidden_fields = []
@@ -7,16 +7,30 @@
7
7
  # search results page (render_constraints(_*))
8
8
  module Blacklight::RenderConstraintsHelperBehavior
9
9
 
10
+ ##
11
+ # Check if the query has any constraints defined (a query, facet, etc)
12
+ #
13
+ # @param [Hash] query parameters
14
+ # @return [Boolean]
10
15
  def query_has_constraints?(localized_params = params)
11
16
  !(localized_params[:q].blank? and localized_params[:f].blank?)
12
17
  end
13
18
 
14
- # Render actual constraints, not including header or footer
19
+ ##
20
+ # Render the actual constraints, not including header or footer
15
21
  # info.
22
+ #
23
+ # @param [Hash] query parameters
24
+ # @return [String]
16
25
  def render_constraints(localized_params = params)
17
26
  render_constraints_query(localized_params) + render_constraints_filters(localized_params)
18
27
  end
19
28
 
29
+ ##
30
+ # Render the query constraints
31
+ #
32
+ # @param [Hash] query parameters
33
+ # @return [String]
20
34
  def render_constraints_query(localized_params = params)
21
35
  # So simple don't need a view template, we can just do it here.
22
36
  if (!localized_params[:q].blank?)
@@ -36,6 +50,11 @@ module Blacklight::RenderConstraintsHelperBehavior
36
50
  end
37
51
  end
38
52
 
53
+ ##
54
+ # Render the facet constraints
55
+ #
56
+ # @param [Hash] query parameters
57
+ # @return [String]
39
58
  def render_constraints_filters(localized_params = params)
40
59
  return "".html_safe unless localized_params[:f]
41
60
  content = []
@@ -46,6 +65,13 @@ module Blacklight::RenderConstraintsHelperBehavior
46
65
  safe_join(content.flatten, "\n")
47
66
  end
48
67
 
68
+ ##
69
+ # Render a single facet's constraint
70
+ #
71
+ # @param [String] facet field
72
+ # @param [Array<String>] selected facet values
73
+ # @param [Hash] query parameters
74
+ # @return [String]
49
75
  def render_filter_element(facet, values, localized_params)
50
76
  facet_config = facet_configuration_for_field(facet)
51
77
 
@@ -66,15 +92,12 @@ module Blacklight::RenderConstraintsHelperBehavior
66
92
  #
67
93
  # Can pass in nil label if desired.
68
94
  #
69
- # options:
70
- # [:remove]
71
- # url to execute for a 'remove' action
72
- # [:classes]
73
- # can be an array of classes to add to container span for constraint.
74
- # [:escape_label]
75
- # default true, HTML escape.
76
- # [:escape_value]
77
- # default true, HTML escape.
95
+ # @param [String] label to display
96
+ # @param [String] value to display
97
+ # @param [Hash] options
98
+ # @option options [String] :remove url to execute for a 'remove' action
99
+ # @option options [Array<String>] :classes an array of classes to add to container span for constraint.
100
+ # @return [String]
78
101
  def render_constraint_element(label, value, options = {})
79
102
  render(:partial => "catalog/constraints_element", :locals => {:label => label, :value => value, :options => options})
80
103
  end