blacklight 4.0.0.pre7 → 4.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/VERSION +1 -1
- data/app/assets/stylesheets/blacklight/_catalog.css.scss +3 -3
- data/app/assets/stylesheets/blacklight/_dropdown.css.scss +0 -1
- data/app/assets/stylesheets/blacklight/_facets.css.scss +48 -43
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +13 -11
- data/app/helpers/blacklight/catalog_helper_behavior.rb +45 -29
- data/app/helpers/blacklight/facets_helper_behavior.rb +74 -14
- data/app/views/_user_util_links.html.erb +1 -1
- data/app/views/catalog/_facet_pivot.html.erb +16 -0
- data/app/views/catalog/_per_page_widget.html.erb +5 -3
- data/app/views/catalog/_sort_and_per_page.html.erb +1 -1
- data/app/views/catalog/_sort_widget.html.erb +3 -1
- data/app/views/catalog/index.html.erb +3 -4
- data/config/locales/blacklight.en.yml +3 -3
- data/lib/blacklight.rb +1 -0
- data/lib/blacklight/catalog.rb +1 -1
- data/lib/blacklight/configuration.rb +5 -4
- data/lib/blacklight/controller.rb +16 -72
- data/lib/blacklight/legacy_controller_methods.rb +69 -0
- data/lib/blacklight/solr_helper.rb +14 -8
- data/lib/blacklight/solr_response/facets.rb +24 -5
- data/lib/generators/blacklight/blacklight_generator.rb +2 -1
- data/lib/generators/blacklight/templates/catalog_controller.rb +1 -0
- data/test_support/spec/helpers/blacklight_helper_spec.rb +18 -1
- data/test_support/spec/helpers/facets_helper_spec.rb +63 -0
- data/test_support/spec/lib/blacklight_solr_response_spec.rb +35 -0
- data/test_support/spec/views/catalog/_facets.html.erb_spec.rb +2 -2
- metadata +5 -3
@@ -2,7 +2,7 @@
|
|
2
2
|
<% if has_user_authentication_provider? %>
|
3
3
|
<div class="util-links-login">
|
4
4
|
<% if current_user %>
|
5
|
-
<%= link_to t('blacklight.header_links.logout'), destroy_user_session_path %> <%= "[#{ link_to current_user, edit_user_registration_path }]" unless current_user.to_s.blank? %>
|
5
|
+
<%= link_to t('blacklight.header_links.logout'), destroy_user_session_path %> <%= "[#{ link_to current_user, edit_user_registration_path }]".html_safe unless current_user.to_s.blank? %>
|
6
6
|
<% else %>
|
7
7
|
<%= link_to t('blacklight.header_links.login'), new_user_session_path %>
|
8
8
|
<% end %>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<ul>
|
2
|
+
<% display_facet.items.each do |item| -%>
|
3
|
+
<li>
|
4
|
+
<% if facet_in_params?( solr_field, item ) %>
|
5
|
+
<%= render_selected_facet_value(solr_field, item) %>
|
6
|
+
<% else %>
|
7
|
+
<%= render_facet_value(solr_field, item) %>
|
8
|
+
<% end -%>
|
9
|
+
|
10
|
+
<% unless item.items.blank? %>
|
11
|
+
<%= render :partial => 'facet_pivot', :locals => { :display_facet => item, :solr_field => solr_field } %>
|
12
|
+
<% end %>
|
13
|
+
</li>
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
</ul>
|
@@ -1,13 +1,15 @@
|
|
1
|
+
<% if show_sort_and_per_page? and !blacklight_config.per_page.blank? %>
|
1
2
|
<div id="per_page-dropdown" class="dropdown pull-right hidden-phone">
|
2
3
|
<span class="hide-text"><%= t('blacklight.search.per_page.title') %></span>
|
3
4
|
<ul class="css-dropdown">
|
4
5
|
<li class="btn">
|
5
|
-
<%= link_to(
|
6
|
+
<%= link_to(t(:'blacklight.search.per_page.button_label', :count => current_per_page), "#") %> <span class="caret"></span>
|
6
7
|
<ul>
|
7
8
|
<%- blacklight_config.per_page.each do |count| %>
|
8
|
-
<li><%= link_to(
|
9
|
+
<li><%= link_to(t(:'blacklight.search.per_page.label', :count => count).html_safe, url_for(params_for_search.merge(:per_page => count))) %></li>
|
9
10
|
<%- end -%>
|
10
11
|
</ul>
|
11
12
|
</li>
|
12
13
|
</ul>
|
13
|
-
</div>
|
14
|
+
</div>
|
15
|
+
<% end %>
|
@@ -1,7 +1,8 @@
|
|
1
|
+
<% if show_sort_and_per_page? and !blacklight_config.sort_fields.blank? %>
|
1
2
|
<div id="sort-dropdown" class="dropdown pull-right hidden-phone">
|
2
3
|
<ul class="css-dropdown">
|
3
4
|
<li class="btn">
|
4
|
-
<%= link_to(
|
5
|
+
<%= link_to(t('blacklight.search.sort.label', :field =>current_sort_field.label), "#") %> <span class="caret"></span>
|
5
6
|
<ul>
|
6
7
|
<%- blacklight_config.sort_fields.each do |sort_key, field| %>
|
7
8
|
<li><%= link_to(field.label, url_for(params_for_search.merge(:sort => sort_key))) %></li>
|
@@ -10,3 +11,4 @@
|
|
10
11
|
</li>
|
11
12
|
</ul>
|
12
13
|
</div>
|
14
|
+
<% end %>
|
@@ -164,12 +164,12 @@ en:
|
|
164
164
|
request_error: "Sorry, I don't understand your search."
|
165
165
|
invalid_solr_id: "Sorry, you have requested a record that doesn't exist."
|
166
166
|
per_page:
|
167
|
-
|
168
|
-
|
167
|
+
label: '%{count}<span class="hide-text"> per page</span>'
|
168
|
+
button_label: '%{count} per page'
|
169
169
|
title: 'Number of results to display per page'
|
170
170
|
submit: 'Update'
|
171
171
|
sort:
|
172
|
-
label: 'Sort by'
|
172
|
+
label: 'Sort by %{field}'
|
173
173
|
submit: 'sort results'
|
174
174
|
form:
|
175
175
|
search_field:
|
data/lib/blacklight.rb
CHANGED
@@ -18,6 +18,7 @@ module Blacklight
|
|
18
18
|
autoload :User, 'blacklight/user'
|
19
19
|
|
20
20
|
autoload :Controller, 'blacklight/controller'
|
21
|
+
autoload :LegacyControllerMethods, 'blacklight/legacy_controller_methods'
|
21
22
|
autoload :Catalog, 'blacklight/catalog'
|
22
23
|
|
23
24
|
autoload :Routes, 'blacklight/routes'
|
data/lib/blacklight/catalog.rb
CHANGED
@@ -4,13 +4,13 @@ module Blacklight
|
|
4
4
|
# fields to display, facets to show, sort options, and search fields.
|
5
5
|
class Configuration < OpenStructWithHashAccess
|
6
6
|
|
7
|
-
# Set up Blacklight::Configuration.default_values to contain
|
7
|
+
# Set up Blacklight::Configuration.default_values to contain
|
8
8
|
# the basic, required Blacklight fields
|
9
9
|
class << self
|
10
10
|
def default_values
|
11
11
|
@default_values ||= begin
|
12
12
|
unique_key = ((SolrDocument.unique_key if defined?(SolrDocument)) || 'id')
|
13
|
-
|
13
|
+
|
14
14
|
{
|
15
15
|
:solr_path => 'select',
|
16
16
|
:qt => 'search',
|
@@ -22,6 +22,7 @@ module Blacklight
|
|
22
22
|
:spell_max => 5,
|
23
23
|
:max_per_page => 100,
|
24
24
|
:per_page => [10,20,50,100],
|
25
|
+
:document_index_view_types => ['list'],
|
25
26
|
:add_facet_fields_to_solr_request => false,
|
26
27
|
:add_field_configuration_to_solr_request => false
|
27
28
|
}
|
@@ -91,7 +92,7 @@ module Blacklight
|
|
91
92
|
end
|
92
93
|
|
93
94
|
def facet_fields_to_add_to_solr
|
94
|
-
return facet_fields.reject { |k,v| v[:query] }.map { |k,v| v.field } if self.add_facet_fields_to_solr_request
|
95
|
+
return facet_fields.reject { |k,v| v[:query] || v[:pivot] }.map { |k,v| v.field } if self.add_facet_fields_to_solr_request
|
95
96
|
|
96
97
|
[]
|
97
98
|
end
|
@@ -107,7 +108,7 @@ module Blacklight
|
|
107
108
|
|
108
109
|
##
|
109
110
|
# DSL helper
|
110
|
-
def configure
|
111
|
+
def configure
|
111
112
|
yield self if block_given?
|
112
113
|
self
|
113
114
|
end
|
@@ -4,35 +4,32 @@
|
|
4
4
|
# as this module is mixed-in to the application controller in the hosting app on installation.
|
5
5
|
module Blacklight::Controller
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
include Blacklight::LegacyControllerMethods
|
9
|
+
|
10
|
+
included do
|
11
|
+
include Blacklight::SearchFields
|
12
|
+
include ActiveSupport::Callbacks
|
10
13
|
|
11
|
-
base.send :before_filter, :default_html_head # add JS/stylesheet stuff
|
12
14
|
# now in application.rb file under config.filter_parameters
|
13
15
|
# filter_parameter_logging :password, :password_confirmation
|
14
|
-
|
15
|
-
|
16
|
+
helper_method :current_user_session, :current_user, :current_or_guest_user
|
17
|
+
after_filter :discard_flash_if_xhr
|
16
18
|
|
17
19
|
# handle basic authorization exception with #access_denied
|
18
|
-
|
20
|
+
rescue_from Blacklight::Exceptions::AccessDenied, :with => :access_denied
|
19
21
|
|
20
|
-
|
22
|
+
helper_method :request_is_for_user_resource?
|
21
23
|
|
22
|
-
base.send :layout, :choose_layout
|
23
|
-
|
24
24
|
# extra head content
|
25
|
-
|
26
|
-
|
27
|
-
base.send :helper_method, :javascript_includes
|
28
|
-
base.send :helper_method, :has_user_authentication_provider?
|
29
|
-
base.send :helper_method, :blacklight_config
|
25
|
+
helper_method :has_user_authentication_provider?
|
26
|
+
helper_method :blacklight_config
|
30
27
|
|
31
28
|
|
32
29
|
# This callback runs when a user first logs in
|
33
30
|
|
34
|
-
|
35
|
-
|
31
|
+
define_callbacks :logging_in_user
|
32
|
+
set_callback :logging_in_user, :before, :transfer_guest_user_actions_to_current_user
|
36
33
|
|
37
34
|
end
|
38
35
|
|
@@ -43,47 +40,7 @@ module Blacklight::Controller
|
|
43
40
|
def blacklight_config
|
44
41
|
default_catalog_controller.blacklight_config
|
45
42
|
end
|
46
|
-
|
47
|
-
# test for exception notifier plugin
|
48
|
-
def error
|
49
|
-
raise RuntimeError, "Generating a test error..."
|
50
|
-
end
|
51
|
-
|
52
|
-
#############
|
53
|
-
# Display-related methods.
|
54
|
-
#############
|
55
|
-
|
56
|
-
# before filter to set up our default html HEAD content. Sub-class
|
57
|
-
# controllers can over-ride this method, or instead turn off the before_filter
|
58
|
-
# if they like. See:
|
59
|
-
# http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html
|
60
|
-
# for how to turn off a filter in a sub-class and such.
|
61
|
-
def default_html_head
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
# An array of strings to be added to HTML HEAD section of view.
|
67
|
-
# See ApplicationHelper#render_head_content for details.
|
68
|
-
def extra_head_content
|
69
|
-
@extra_head_content ||= []
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
# Array, where each element is an array of arguments to
|
74
|
-
# Rails stylesheet_link_tag helper. See
|
75
|
-
# ApplicationHelper#render_head_content for details.
|
76
|
-
def stylesheet_links
|
77
|
-
@stylesheet_links ||= []
|
78
|
-
end
|
79
|
-
|
80
|
-
# Array, where each element is an array of arguments to
|
81
|
-
# Rails javascript_include_tag helper. See
|
82
|
-
# ApplicationHelper#render_head_content for details.
|
83
|
-
def javascript_includes
|
84
|
-
@javascript_includes ||= []
|
85
|
-
end
|
86
|
-
|
43
|
+
|
87
44
|
protected
|
88
45
|
|
89
46
|
# Returns a list of Searches from the ids in the user's history.
|
@@ -98,20 +55,7 @@ module Blacklight::Controller
|
|
98
55
|
request.env['PATH_INFO'] =~ /\/?users\/?/
|
99
56
|
end
|
100
57
|
|
101
|
-
|
102
|
-
# If a param[:no_layout] is set OR
|
103
|
-
# request.env['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest'
|
104
|
-
# don't use a layout, otherwise use the "application.html.erb" layout
|
105
|
-
#
|
106
|
-
def choose_layout
|
107
|
-
layout_name unless request.xml_http_request? || ! params[:no_layout].blank?
|
108
|
-
end
|
109
|
-
|
110
|
-
#over-ride this one locally to change what layout BL controllers use, usually
|
111
|
-
#by defining it in your own application_controller.rb
|
112
|
-
def layout_name
|
113
|
-
'blacklight'
|
114
|
-
end
|
58
|
+
|
115
59
|
|
116
60
|
# Should be provided by authentication provider
|
117
61
|
# def current_user
|
@@ -0,0 +1,69 @@
|
|
1
|
+
##
|
2
|
+
# These controller methods are mixed into the ApplicationController, and
|
3
|
+
# are likely things new Blacklight apps won't need (e.g. because of advancements in Rails)
|
4
|
+
# but are ideas that are firmly baked into existing application or plugins, so we're
|
5
|
+
# keeping around for now. There are probably better ways of doing some of the things
|
6
|
+
# in here, but you may find them useful.
|
7
|
+
module Blacklight
|
8
|
+
module LegacyControllerMethods
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
|
13
|
+
before_filter :default_html_head # add JS/stylesheet stuff
|
14
|
+
|
15
|
+
helper_method :extra_head_content, :stylesheet_links, :javascript_includes
|
16
|
+
end
|
17
|
+
|
18
|
+
#############
|
19
|
+
# Display-related methods.
|
20
|
+
#############
|
21
|
+
|
22
|
+
# before filter to set up our default html HEAD content. Sub-class
|
23
|
+
# controllers can over-ride this method, or instead turn off the before_filter
|
24
|
+
# if they like. See:
|
25
|
+
# http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html
|
26
|
+
# for how to turn off a filter in a sub-class and such.
|
27
|
+
def default_html_head
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# An array of strings to be added to HTML HEAD section of view.
|
33
|
+
# See ApplicationHelper#render_head_content for details.
|
34
|
+
def extra_head_content
|
35
|
+
@extra_head_content ||= []
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
# Array, where each element is an array of arguments to
|
40
|
+
# Rails stylesheet_link_tag helper. See
|
41
|
+
# ApplicationHelper#render_head_content for details.
|
42
|
+
def stylesheet_links
|
43
|
+
@stylesheet_links ||= []
|
44
|
+
end
|
45
|
+
|
46
|
+
# Array, where each element is an array of arguments to
|
47
|
+
# Rails javascript_include_tag helper. See
|
48
|
+
# ApplicationHelper#render_head_content for details.
|
49
|
+
def javascript_includes
|
50
|
+
@javascript_includes ||= []
|
51
|
+
end
|
52
|
+
|
53
|
+
protected
|
54
|
+
#
|
55
|
+
# If a param[:no_layout] is set OR
|
56
|
+
# request.env['HTTP_X_REQUESTED_WITH']=='XMLHttpRequest'
|
57
|
+
# don't use a layout, otherwise use the "application.html.erb" layout
|
58
|
+
#
|
59
|
+
def choose_layout
|
60
|
+
layout_name unless request.xml_http_request? || ! params[:no_layout].blank?
|
61
|
+
end
|
62
|
+
|
63
|
+
#over-ride this one locally to change what layout BL controllers use, usually
|
64
|
+
#by defining it in your own application_controller.rb
|
65
|
+
def layout_name
|
66
|
+
'blacklight'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -154,9 +154,9 @@ module Blacklight::SolrHelper
|
|
154
154
|
end
|
155
155
|
|
156
156
|
# Now any over-rides from current URL?
|
157
|
-
solr_params[:rows] = user_params[:per_page]
|
158
|
-
|
159
|
-
# Do we need to translate :page to Solr :start?
|
157
|
+
solr_params[:rows] = user_params[:per_page].to_i unless user_params[:per_page].blank?
|
158
|
+
|
159
|
+
# Do we need to translate :page to Solr :start?
|
160
160
|
unless user_params[:page].blank?
|
161
161
|
# already set solr_params["rows"] might not be the one we just set,
|
162
162
|
# could have been from app defaults too. But we need one.
|
@@ -166,13 +166,13 @@ module Blacklight::SolrHelper
|
|
166
166
|
if solr_params[:rows].blank?
|
167
167
|
raise Exception.new("To use pagination when no :per_page is supplied in the URL, :rows must be configured in blacklight_config default_solr_params")
|
168
168
|
end
|
169
|
-
|
170
|
-
solr_params[:page] = user_params[:page]
|
169
|
+
|
170
|
+
solr_params[:page] = user_params[:page].to_i
|
171
171
|
end
|
172
172
|
|
173
|
-
|
174
|
-
|
175
|
-
solr_params[:rows] = solr_params[:rows].to_i > blacklight_config.max_per_page
|
173
|
+
solr_params[:rows] ||= blacklight_config.per_page.first unless blacklight_config.per_page.blank?
|
174
|
+
|
175
|
+
solr_params[:rows] = blacklight_config.max_per_page if solr_params[:rows].to_i > blacklight_config.max_per_page
|
176
176
|
end
|
177
177
|
|
178
178
|
###
|
@@ -316,12 +316,18 @@ module Blacklight::SolrHelper
|
|
316
316
|
if blacklight_config.facet_fields.any? { |k,v| v[:query] }
|
317
317
|
solr_parameters[:'facet.query'] ||= []
|
318
318
|
end
|
319
|
+
|
320
|
+
if blacklight_config.facet_fields.any? { |k,v| v[:pivot] }
|
321
|
+
solr_parameters[:'facet.pivot'] ||= []
|
322
|
+
end
|
319
323
|
end
|
320
324
|
|
321
325
|
blacklight_config.facet_fields.each do |field_name, facet|
|
322
326
|
|
323
327
|
if blacklight_config.add_facet_fields_to_solr_request
|
324
328
|
case
|
329
|
+
when facet.pivot
|
330
|
+
solr_parameters[:'facet.pivot'] << facet.pivot.join(",")
|
325
331
|
when facet.query
|
326
332
|
solr_parameters[:'facet.query'] += facet.query.map { |k, x| x[:fq] }
|
327
333
|
|
@@ -1,10 +1,24 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
1
3
|
module Blacklight::SolrResponse::Facets
|
2
4
|
|
3
5
|
# represents a facet value; which is a field value and its hit count
|
4
|
-
class FacetItem
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
class FacetItem < OpenStruct
|
7
|
+
def initialize *args
|
8
|
+
options = args.extract_options!
|
9
|
+
|
10
|
+
# Backwards-compat method signature
|
11
|
+
value = args.shift
|
12
|
+
hits = args.shift
|
13
|
+
|
14
|
+
options[:value] = value if value
|
15
|
+
options[:hits] = hits if hits
|
16
|
+
|
17
|
+
super(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def label
|
21
|
+
super || value
|
8
22
|
end
|
9
23
|
end
|
10
24
|
|
@@ -26,7 +40,7 @@ module Blacklight::SolrResponse::Facets
|
|
26
40
|
facet_fields.map do |(facet_field_name,values_and_hits)|
|
27
41
|
items = []
|
28
42
|
values_and_hits.each_slice(2) do |k,v|
|
29
|
-
items << FacetItem.new(k, v)
|
43
|
+
items << FacetItem.new(:value => k, :hits => v)
|
30
44
|
end
|
31
45
|
FacetField.new(facet_field_name, items)
|
32
46
|
end
|
@@ -55,4 +69,9 @@ module Blacklight::SolrResponse::Facets
|
|
55
69
|
@facet_queries ||= facet_counts['facet_queries'] || {}
|
56
70
|
end
|
57
71
|
|
72
|
+
# Returns all of the facet queries
|
73
|
+
def facet_pivot
|
74
|
+
@facet_pivot ||= facet_counts['facet_pivot'] || {}
|
75
|
+
end
|
76
|
+
|
58
77
|
end # end Facets
|