blacklight 8.0.0.beta4 → 8.0.0.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop_todo.yml +3 -1
- data/Gemfile +0 -4
- data/README.md +1 -1
- data/Rakefile +18 -0
- data/VERSION +1 -1
- data/app/assets/config/blacklight/manifest.js +3 -0
- data/app/assets/stylesheets/blacklight/_facets.scss +32 -5
- data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +1 -1
- data/app/components/blacklight/document_component.rb +44 -18
- data/app/components/blacklight/document_metadata_component.html.erb +4 -2
- data/app/components/blacklight/document_metadata_component.rb +8 -2
- data/app/components/blacklight/metadata_field_layout_component.rb +7 -4
- data/app/components/blacklight/metadata_field_plain_text_layout_component.rb +17 -0
- data/app/components/blacklight/response/facet_group_component.html.erb +2 -1
- data/app/components/blacklight/response/sort_component.rb +1 -1
- data/app/components/blacklight/response/spellcheck_component.rb +1 -1
- data/app/components/blacklight/response/view_type_button_component.rb +1 -1
- data/app/components/blacklight/response/view_type_component.rb +1 -1
- data/app/components/blacklight/search_context/server_applied_params_component.html.erb +4 -0
- data/app/components/blacklight/search_context/server_applied_params_component.rb +13 -0
- data/app/components/blacklight/{search_context_component.html.erb → search_context/server_item_pagination_component.html.erb} +0 -0
- data/app/components/blacklight/search_context/server_item_pagination_component.rb +71 -0
- data/app/components/blacklight/system/dropdown_component.rb +1 -1
- data/app/components/blacklight/system/flash_message_component.rb +1 -1
- data/app/components/blacklight/system/modal_component.rb +1 -1
- data/app/controllers/concerns/blacklight/bookmarks.rb +1 -1
- data/app/controllers/concerns/blacklight/search_context.rb +46 -6
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +0 -101
- data/app/helpers/blacklight/catalog_helper_behavior.rb +27 -54
- data/app/helpers/blacklight/component_helper_behavior.rb +0 -11
- data/app/helpers/blacklight/document_helper_behavior.rb +76 -0
- data/app/helpers/blacklight/layout_helper_behavior.rb +59 -0
- data/app/helpers/blacklight/url_helper_behavior.rb +11 -3
- data/app/javascript/blacklight/bookmark_toggle.js +8 -15
- data/app/javascript/blacklight/button_focus.js +10 -10
- data/app/javascript/blacklight/index.js +5 -5
- data/app/javascript/blacklight/modal.js +11 -16
- data/app/javascript/blacklight/search_context.js +51 -57
- data/app/models/concerns/blacklight/document.rb +11 -0
- data/app/models/record_mailer.rb +19 -15
- data/app/presenters/blacklight/document_presenter.rb +13 -11
- data/app/presenters/blacklight/index_presenter.rb +1 -1
- data/app/presenters/blacklight/rendering/abstract_step.rb +4 -0
- data/app/presenters/blacklight/rendering/join.rb +7 -1
- data/app/presenters/blacklight/rendering/link_to_facet.rb +1 -1
- data/app/presenters/blacklight/rendering/microdata.rb +1 -1
- data/app/services/blacklight/search_service.rb +2 -1
- data/app/views/catalog/_document.atom.builder +1 -1
- data/app/views/catalog/_document.html.erb +3 -8
- data/app/views/catalog/_document_list.html.erb +2 -1
- data/app/views/catalog/_show_main_content.html.erb +3 -9
- data/app/views/catalog/index.html.erb +3 -0
- data/app/views/catalog/show.html.erb +1 -6
- data/app/views/layouts/blacklight/base.html.erb +4 -4
- data/app/views/record_mailer/email_record.text.erb +4 -3
- data/app/views/record_mailer/sms_record.text.erb +4 -4
- data/blacklight.gemspec +1 -1
- data/config/importmap.rb +1 -1
- data/config/locales/blacklight.ar.yml +209 -232
- data/config/locales/blacklight.ca.yml +0 -6
- data/config/locales/blacklight.de.yml +197 -215
- data/config/locales/blacklight.en.yml +2 -6
- data/config/locales/blacklight.es.yml +196 -215
- data/config/locales/blacklight.fr.yml +196 -219
- data/config/locales/blacklight.hu.yml +193 -212
- data/config/locales/blacklight.it.yml +197 -215
- data/config/locales/blacklight.nl.yml +193 -212
- data/config/locales/blacklight.pt-BR.yml +195 -215
- data/config/locales/blacklight.sq.yml +193 -212
- data/config/locales/blacklight.zh.yml +194 -213
- data/lib/blacklight/configuration/session_tracking_config.rb +45 -0
- data/lib/blacklight/configuration/view_config.rb +0 -4
- data/lib/blacklight/configuration.rb +8 -4
- data/lib/blacklight/engine.rb +6 -7
- data/lib/blacklight/routes/searchable.rb +1 -0
- data/lib/generators/blacklight/assets/importmap_generator.rb +9 -2
- data/lib/generators/blacklight/assets/propshaft_generator.rb +11 -2
- data/lib/generators/blacklight/assets/sprockets_generator.rb +2 -0
- data/lib/generators/blacklight/templates/solr_document.rb +0 -6
- data/package.json +7 -4
- data/rollup.config.js +11 -1
- data/spec/components/blacklight/document_component_spec.rb +9 -4
- data/spec/components/blacklight/search_context/server_applied_params_component_spec.rb +29 -0
- data/spec/components/blacklight/{search_context_component_spec.rb → search_context/server_item_pagination_component_spec.rb} +15 -4
- data/spec/controllers/bookmarks_controller_spec.rb +1 -1
- data/spec/controllers/catalog_controller_spec.rb +17 -5
- data/spec/features/component_template_override_spec.rb +8 -0
- data/spec/features/modal_spec.rb +12 -0
- data/spec/features/sitelinks_search_box_spec.rb +13 -0
- data/spec/helpers/blacklight/url_helper_behavior_spec.rb +1 -1
- data/spec/helpers/blacklight_helper_spec.rb +0 -56
- data/spec/helpers/catalog_helper_spec.rb +56 -0
- data/spec/lib/blacklight/configuration/session_tracking_config_spec.rb +38 -0
- data/spec/models/blacklight/icon_spec.rb +0 -2
- data/spec/models/record_mailer_spec.rb +36 -23
- data/spec/presenters/blacklight/document_presenter_spec.rb +1 -0
- data/spec/presenters/blacklight/field_presenter_spec.rb +2 -2
- data/spec/presenters/blacklight/index_presenter_spec.rb +1 -0
- data/spec/presenters/blacklight/show_presenter_spec.rb +1 -0
- data/spec/presenters/pipeline_spec.rb +13 -2
- data/spec/routing/catalog_routing_spec.rb +4 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/view_component_test_helpers.rb +21 -0
- data/spec/test_app_templates/Gemfile.extra +4 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +8 -0
- data/spec/views/catalog/_document.html.erb_spec.rb +22 -1
- data/spec/views/catalog/_document_list.html.erb_spec.rb +7 -2
- data/tasks/blacklight.rake +1 -1
- metadata +24 -20
- data/app/assets/javascripts/blacklight/blacklight.esm.js +0 -390
- data/app/assets/javascripts/blacklight/blacklight.esm.js.map +0 -1
- data/app/assets/javascripts/blacklight/blacklight.js +0 -398
- data/app/assets/javascripts/blacklight/blacklight.js.map +0 -1
- data/app/components/blacklight/search_context_component.rb +0 -68
- data/app/models/concerns/blacklight/document/email.rb +0 -27
- data/app/models/concerns/blacklight/document/sms.rb +0 -25
- data/spec/features/sitelinks_search_box.rb +0 -13
- data/spec/models/blacklight/document/email_spec.rb +0 -57
- data/spec/models/blacklight/document/sms_spec.rb +0 -58
- data/spec/support/view_component_capybara_test_helpers.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccd45650da142937ce72464e061e05ed63793c553e0d0676d139010dd218cb44
|
4
|
+
data.tar.gz: 5221c9746cf8c4168444c57ca18062be9a6cb95743a58ea53040056ccf8bdee9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dc2e36331089bcd0404a3a34c3a8bf71d6fa103c19a65f7e94620e14ac41a5f8ccfe8c1b750a305bbb7db051c323a7410b693a137579073f776e65debd76c5b
|
7
|
+
data.tar.gz: fb238384ea2c98c6e442b6706c473766118e83e860d3d4509e45b4cd50e993e22da8f67b29d61b4f4a40e6a9502cb8b07f822129ff9f3348f6c5c40cd210ee66
|
data/.gitignore
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -371,7 +371,9 @@ Rails/HelperInstanceVariable:
|
|
371
371
|
Exclude:
|
372
372
|
- 'app/helpers/blacklight/blacklight_helper_behavior.rb'
|
373
373
|
- 'app/helpers/blacklight/catalog_helper_behavior.rb'
|
374
|
+
- 'app/helpers/blacklight/document_helper_behavior.rb'
|
374
375
|
- 'app/helpers/blacklight/component_helper_behavior.rb'
|
376
|
+
- 'app/helpers/blacklight/layout_helper_behavior.rb'
|
375
377
|
- 'app/helpers/blacklight/render_partials_helper_behavior.rb'
|
376
378
|
|
377
379
|
# Offense count: 2
|
@@ -384,7 +386,7 @@ Rails/I18nLocaleAssignment:
|
|
384
386
|
# Offense count: 10
|
385
387
|
Rails/OutputSafety:
|
386
388
|
Exclude:
|
387
|
-
- 'app/components/blacklight/
|
389
|
+
- 'app/components/blacklight/search_context/server_item_pagination_component.rb'
|
388
390
|
- 'app/helpers/blacklight/catalog_helper_behavior.rb'
|
389
391
|
- 'app/helpers/blacklight/configuration_helper_behavior.rb'
|
390
392
|
- 'app/presenters/blacklight/rendering/join.rb'
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -60,7 +60,7 @@ components in the gem are changed, this bundle should be rebuild with the
|
|
60
60
|
following steps:
|
61
61
|
1. [Install npm](https://www.npmjs.com/get-npm)
|
62
62
|
1. run `npm install` to download dependencies
|
63
|
-
1. run `npm run
|
63
|
+
1. run `npm run prepare` to build the bundle
|
64
64
|
1. run `npm publish` to push the javascript package to https://npmjs.org/package/blacklight-frontend
|
65
65
|
|
66
66
|
## Using the javascript
|
data/Rakefile
CHANGED
@@ -10,6 +10,24 @@ end
|
|
10
10
|
|
11
11
|
Bundler::GemHelper.install_tasks
|
12
12
|
|
13
|
+
# Hook up our NPM tasks to the standard uild and release tasks
|
14
|
+
Rake::Task['build'].enhance(['build:npm'])
|
15
|
+
Rake::Task['release'].enhance(['release:npm'])
|
16
|
+
|
17
|
+
# rubocop:disable Rails/RakeEnvironment
|
18
|
+
desc 'build javascript assets'
|
19
|
+
task 'build:npm' do
|
20
|
+
sh 'npm install'
|
21
|
+
sh 'npm run prepare'
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Publish javascript assets to npm\n" \
|
25
|
+
"To prevent publishing in NPM use e.g. `npm_push=no rake release`"
|
26
|
+
task 'release:npm' do
|
27
|
+
sh 'npm publish' unless %w[n no nil false off 0].include?(ENV["npm_push"].to_s.downcase)
|
28
|
+
end
|
29
|
+
# rubocop:enable Rails/RakeEnvironment
|
30
|
+
|
13
31
|
load "tasks/blacklight.rake"
|
14
32
|
load "lib/railties/blacklight.rake"
|
15
33
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
8.0.0.
|
1
|
+
8.0.0.beta6
|
@@ -1,16 +1,36 @@
|
|
1
1
|
.sidenav {
|
2
|
+
--bl-facets-smallish-padding: .25rem;
|
3
|
+
--bl-facets-smallish-border: var(--bs-border-width) solid var(--bs-border-color);
|
4
|
+
--bl-facets-smallish-margin-bottom: #{$spacer};
|
5
|
+
--bl-facets-smallish-border-radius: #{$border-radius};
|
6
|
+
|
2
7
|
.navbar-toggler {
|
3
|
-
|
8
|
+
--bs-navbar-toggler-padding-x: #{$navbar-toggler-padding-x};
|
9
|
+
--bs-navbar-toggler-padding-y: #{$navbar-toggler-padding-y};
|
10
|
+
--bs-navbar-toggler-border-color: #{$navbar-light-toggler-border-color};
|
11
|
+
--bs-navbar-toggler-border-radius: #{$navbar-toggler-border-radius};
|
4
12
|
color: $navbar-light-active-color;
|
5
13
|
|
6
14
|
&:hover,
|
7
15
|
&:focus {
|
8
16
|
color: $navbar-light-active-color;
|
9
17
|
}
|
10
|
-
}
|
11
18
|
|
12
|
-
|
13
|
-
|
19
|
+
[data-hide-label] {
|
20
|
+
display: inline;
|
21
|
+
}
|
22
|
+
[data-show-label] {
|
23
|
+
display: none;
|
24
|
+
}
|
25
|
+
|
26
|
+
&[aria-expanded="false"] {
|
27
|
+
[data-hide-label] {
|
28
|
+
display: none;
|
29
|
+
}
|
30
|
+
[data-show-label] {
|
31
|
+
display: inline;
|
32
|
+
}
|
33
|
+
}
|
14
34
|
}
|
15
35
|
}
|
16
36
|
|
@@ -19,9 +39,16 @@
|
|
19
39
|
$next: breakpoint-next($breakpoint, $grid-breakpoints);
|
20
40
|
$infix: breakpoint-infix($breakpoint, $grid-breakpoints);
|
21
41
|
|
42
|
+
|
22
43
|
&#{$infix} {
|
23
|
-
@include media-breakpoint-
|
44
|
+
@include media-breakpoint-down($next) {
|
45
|
+
border: var(--bl-facets-smallish-border);
|
46
|
+
padding: var(--bl-facets-smallish-padding);
|
47
|
+
margin-bottom: var(--bl-facets-smallish-margin-bottom);
|
48
|
+
border-radius: var(--bl-facets-smallish-border-radius);
|
24
49
|
|
50
|
+
}
|
51
|
+
@include media-breakpoint-up($next) {
|
25
52
|
// scss-lint:disable ImportantRule
|
26
53
|
.facets-collapse {
|
27
54
|
display: block !important;
|
@@ -1,7 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'view_component/version'
|
4
|
+
|
3
5
|
module Blacklight
|
6
|
+
##
|
7
|
+
# A component for rendering a single document
|
8
|
+
#
|
9
|
+
# @note when subclassing this component, you must explicitly specify the collection parameter
|
10
|
+
# as `document` and handle the `document` parameter in your initializer.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# class MyDocumentComponent < Blacklight::DocumentComponent
|
14
|
+
# with_collection_parameter :document
|
15
|
+
#
|
16
|
+
# def initialize(document:, **kwargs)
|
17
|
+
# super(document: document, **kwargs)
|
18
|
+
# end
|
19
|
+
# end
|
4
20
|
class DocumentComponent < Blacklight::Component
|
21
|
+
with_collection_parameter :document
|
22
|
+
|
23
|
+
# ViewComponent 3 changes iteration counters to begin at 0 rather than 1
|
24
|
+
COLLECTION_INDEX_OFFSET = ViewComponent::VERSION::MAJOR < 3 ? 0 : 1
|
25
|
+
|
5
26
|
# Content appearing before the document
|
6
27
|
renders_one :header
|
7
28
|
|
@@ -56,38 +77,36 @@ module Blacklight
|
|
56
77
|
# Backwards compatibility
|
57
78
|
renders_one :actions
|
58
79
|
|
59
|
-
with_collection_parameter :document
|
60
|
-
|
61
80
|
# rubocop:disable Metrics/ParameterLists
|
62
|
-
# @param document [Blacklight::
|
63
|
-
# @param presenter [Blacklight::DocumentPresenter]
|
81
|
+
# @param document [Blacklight::DocumentPresenter]
|
82
|
+
# @param presenter [Blacklight::DocumentPresenter] alias for document
|
83
|
+
# @param partials [Array, nil] view partial names that should be used to provide content for the `partials` slot
|
64
84
|
# @param id [String] HTML id for the root element
|
65
85
|
# @param classes [Array, String] additional HTML classes for the root element
|
66
86
|
# @param component [Symbol, String] HTML tag type to use for the root element
|
67
87
|
# @param title_component [Symbol, String] HTML tag type to use for the title element
|
68
88
|
# @param counter [Number, nil] a pre-computed counter for the position of this document in a search result set
|
69
|
-
# @param document_counter [Number, nil]
|
70
|
-
# @param counter_offset [Number]
|
89
|
+
# @param document_counter [Number, nil] provided by ViewComponent collection iteration
|
90
|
+
# @param counter_offset [Number] the offset of the start of the collection counter parameter for the component to the overall result set
|
71
91
|
# @param show [Boolean] are we showing only a single document (vs a list of search results); used for backwards-compatibility
|
72
|
-
def initialize(document: nil, presenter: nil,
|
92
|
+
def initialize(document: nil, presenter: nil, partials: nil,
|
73
93
|
id: nil, classes: [], component: :article, title_component: nil,
|
74
94
|
counter: nil, document_counter: nil, counter_offset: 0,
|
75
|
-
show: false)
|
76
|
-
|
77
|
-
raise ArgumentError, 'missing keyword: :document or :presenter'
|
78
|
-
end
|
95
|
+
show: false, **args)
|
96
|
+
Blacklight.deprecation.warn('the `presenter` argument to DocumentComponent#initialize is deprecated; pass the `presenter` in as document instead') if presenter
|
79
97
|
|
80
|
-
@
|
81
|
-
@
|
98
|
+
@presenter = presenter || document || args[self.class.collection_parameter]
|
99
|
+
@document = @presenter.document
|
100
|
+
@view_partials = partials || []
|
82
101
|
|
83
102
|
@component = component
|
84
103
|
@title_component = title_component
|
85
104
|
@id = id || ('document' if show)
|
86
105
|
@classes = classes
|
87
106
|
|
88
|
-
@document_counter = document_counter
|
89
107
|
@counter = counter
|
90
|
-
@
|
108
|
+
@document_counter = document_counter || args.fetch(self.class.collection_counter_parameter, nil)
|
109
|
+
@counter ||= @document_counter + COLLECTION_INDEX_OFFSET + counter_offset if @document_counter.present?
|
91
110
|
|
92
111
|
@show = show
|
93
112
|
end
|
@@ -108,13 +127,20 @@ module Blacklight
|
|
108
127
|
set_slot(:thumbnail, nil) unless thumbnail || show?
|
109
128
|
set_slot(:metadata, nil, fields: presenter.field_presenters) unless metadata
|
110
129
|
set_slot(:embed, nil) unless embed
|
130
|
+
if view_partials.present?
|
131
|
+
view_partials.each do |view_partial|
|
132
|
+
with_partial(view_partial) do
|
133
|
+
helpers.render_document_partial @document, view_partial, component: self, document_counter: @counter
|
134
|
+
end
|
135
|
+
end
|
136
|
+
else
|
137
|
+
set_slot(:partials, nil)
|
138
|
+
end
|
111
139
|
end
|
112
140
|
|
113
141
|
private
|
114
142
|
|
115
|
-
|
116
|
-
@presenter ||= helpers.document_presenter(@document)
|
117
|
-
end
|
143
|
+
attr_reader :document_counter, :presenter, :view_partials
|
118
144
|
|
119
145
|
def show?
|
120
146
|
@show
|
@@ -8,17 +8,23 @@ module Blacklight
|
|
8
8
|
with_collection_parameter :fields
|
9
9
|
|
10
10
|
# @param fields [Enumerable<Blacklight::FieldPresenter>] Document field presenters
|
11
|
-
|
11
|
+
# rubocop:disable Metrics/ParameterLists
|
12
|
+
def initialize(fields: [], tag: 'dl', classes: %w[document-metadata dl-invert row], show: false, view_type: nil, field_layout: nil, **component_args)
|
12
13
|
@fields = fields
|
14
|
+
@tag = tag
|
15
|
+
@classes = classes
|
13
16
|
@show = show
|
14
17
|
@view_type = view_type
|
18
|
+
@field_layout = field_layout
|
19
|
+
@component_args = component_args
|
15
20
|
end
|
21
|
+
# rubocop:enable Metrics/ParameterLists
|
16
22
|
|
17
23
|
def before_render
|
18
24
|
return unless fields
|
19
25
|
|
20
26
|
@fields.each do |field|
|
21
|
-
with_field(component: field.component, field: field, show: @show, view_type: @view_type)
|
27
|
+
with_field(component: field.component, field: field, show: @show, view_type: @view_type, layout: @field_layout)
|
22
28
|
end
|
23
29
|
end
|
24
30
|
|
@@ -5,18 +5,21 @@ module Blacklight
|
|
5
5
|
with_collection_parameter :field
|
6
6
|
renders_one :label
|
7
7
|
renders_many :values, (lambda do |value: nil, &block|
|
8
|
-
if
|
9
|
-
|
8
|
+
if @value_tag.nil?
|
9
|
+
block&.call || value
|
10
|
+
elsif block
|
11
|
+
content_tag @value_tag, class: "#{@value_class} blacklight-#{@key}", &block
|
10
12
|
else
|
11
|
-
content_tag
|
13
|
+
content_tag @value_tag, value, class: "#{@value_class} blacklight-#{@key}"
|
12
14
|
end
|
13
15
|
end)
|
14
16
|
|
15
17
|
# @param field [Blacklight::FieldPresenter]
|
16
|
-
def initialize(field:, label_class: 'col-md-3', value_class: 'col-md-9')
|
18
|
+
def initialize(field:, value_tag: 'dd', label_class: 'col-md-3', value_class: 'col-md-9')
|
17
19
|
@field = field
|
18
20
|
@key = @field.key.parameterize
|
19
21
|
@label_class = label_class
|
22
|
+
@value_tag = value_tag
|
20
23
|
@value_class = value_class
|
21
24
|
end
|
22
25
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Blacklight
|
4
|
+
class MetadataFieldPlainTextLayoutComponent < Blacklight::MetadataFieldLayoutComponent
|
5
|
+
with_collection_parameter :field
|
6
|
+
|
7
|
+
def initialize(field:, **kwargs)
|
8
|
+
super(field: field, **kwargs, value_tag: nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
# rubocop:disable Rails/OutputSafety
|
12
|
+
def call
|
13
|
+
[label.to_s.strip, helpers.strip_tags(CGI.unescape_html(safe_join(values, "\n")).strip)].compact.join(' ').html_safe
|
14
|
+
end
|
15
|
+
# rubocop:enable Rails/OutputSafety
|
16
|
+
end
|
17
|
+
end
|
@@ -17,7 +17,8 @@
|
|
17
17
|
expanded: 'false',
|
18
18
|
label: t('blacklight.search.facets.group.toggle'),
|
19
19
|
} do %>
|
20
|
-
<span
|
20
|
+
<span data-show-label><%= t('blacklight.search.facets.group.open') %></span>
|
21
|
+
<span data-hide-label><%= t('blacklight.search.facets.group.close') %></span>
|
21
22
|
<% end %>
|
22
23
|
</div>
|
23
24
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Blacklight
|
4
4
|
module Response
|
5
|
-
class SortComponent <
|
5
|
+
class SortComponent < Blacklight::Component
|
6
6
|
def initialize(search_state:, param: 'sort', choices: {}, id: 'sort-dropdown', classes: [], selected: nil)
|
7
7
|
@param = param
|
8
8
|
@choices = choices
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Blacklight
|
4
4
|
module Response
|
5
5
|
# Render spellcheck results for a search query
|
6
|
-
class SpellcheckComponent <
|
6
|
+
class SpellcheckComponent < Blacklight::Component
|
7
7
|
# @param [Blacklight::Response] response
|
8
8
|
# @param [Array<String>] options explicit spellcheck options to render
|
9
9
|
def initialize(response:, options: nil)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Blacklight
|
4
4
|
module Response
|
5
5
|
# Render spellcheck results for a search query
|
6
|
-
class ViewTypeButtonComponent <
|
6
|
+
class ViewTypeButtonComponent < Blacklight::Component
|
7
7
|
with_collection_parameter :view
|
8
8
|
# @param [Blacklight::Configuration::View] view
|
9
9
|
def initialize(view:, key: nil, selected: false, search_state: nil, classes: 'btn btn-outline-secondary btn-icon')
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Blacklight
|
4
4
|
module Response
|
5
5
|
# Render spellcheck results for a search query
|
6
|
-
class ViewTypeComponent <
|
6
|
+
class ViewTypeComponent < Blacklight::Component
|
7
7
|
renders_many :views, 'Blacklight::Response::ViewTypeButtonComponent'
|
8
8
|
|
9
9
|
# @param [Blacklight::Response] response
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Blacklight
|
4
|
+
module SearchContext
|
5
|
+
class ServerAppliedParamsComponent < Blacklight::Component
|
6
|
+
delegate :current_search_session, :link_back_to_catalog, to: :helpers
|
7
|
+
|
8
|
+
def render?
|
9
|
+
current_search_session
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
File without changes
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Blacklight
|
4
|
+
module SearchContext
|
5
|
+
class ServerItemPaginationComponent < Blacklight::Component
|
6
|
+
with_collection_parameter :search_context
|
7
|
+
|
8
|
+
def initialize(search_context:, search_session:, current_document:)
|
9
|
+
@search_context = search_context
|
10
|
+
@search_session = search_session
|
11
|
+
@current_document_id = current_document.id
|
12
|
+
end
|
13
|
+
|
14
|
+
def render?
|
15
|
+
@search_context.present? && (@search_context[:prev] || @search_context[:next]) && (@search_session['document_id'] == @current_document_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Displays "showing X of Y items" message.
|
20
|
+
#
|
21
|
+
# @return [String]
|
22
|
+
def item_page_entry_info
|
23
|
+
t('blacklight.search.entry_pagination_info.other', current: number_with_delimiter(count),
|
24
|
+
total: number_with_delimiter(total),
|
25
|
+
count: total).html_safe
|
26
|
+
end
|
27
|
+
|
28
|
+
def link_to_previous_document(previous_document = nil, classes: 'previous', **link_opts)
|
29
|
+
previous_document ||= @search_context[:prev]
|
30
|
+
link_opts = session_tracking_params(previous_document, count - 1, per_page: per_page, search_id: search_id).merge(class: classes, rel: 'prev').merge(link_opts)
|
31
|
+
link_to_unless previous_document.nil?, raw(t('views.pagination.previous')), url_for_document(previous_document), link_opts do
|
32
|
+
tag.span raw(t('views.pagination.previous')), class: 'previous'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def link_to_next_document(next_document = nil, classes: 'next', **link_opts)
|
37
|
+
next_document ||= @search_context[:next]
|
38
|
+
link_opts = session_tracking_params(next_document, count + 1, per_page: per_page, search_id: search_id).merge(class: classes, rel: 'next').merge(link_opts)
|
39
|
+
link_to_unless next_document.nil?, raw(t('views.pagination.next')), url_for_document(next_document), link_opts do
|
40
|
+
tag.span raw(t('views.pagination.next')), class: 'next'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def count
|
47
|
+
@search_session['counter'].to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
def per_page
|
51
|
+
@search_session['per_page']
|
52
|
+
end
|
53
|
+
|
54
|
+
def total
|
55
|
+
@search_session['total'].to_i
|
56
|
+
end
|
57
|
+
|
58
|
+
def search_id
|
59
|
+
@search_session['id'] || helpers.current_search_session&.id
|
60
|
+
end
|
61
|
+
|
62
|
+
def session_tracking_params(...)
|
63
|
+
helpers.session_tracking_params(...)
|
64
|
+
end
|
65
|
+
|
66
|
+
def url_for_document(...)
|
67
|
+
helpers.search_state.url_for_document(...)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Blacklight
|
4
4
|
module System
|
5
|
-
class DropdownComponent <
|
5
|
+
class DropdownComponent < Blacklight::Component
|
6
6
|
renders_one :button, (lambda do |classes:, label:|
|
7
7
|
button_tag class: classes, aria: { expanded: false }, data: { toggle: 'dropdown', 'bs-toggle': 'dropdown' } do
|
8
8
|
safe_join([label, content_tag(:span, '', class: 'caret')])
|
@@ -15,7 +15,7 @@ module Blacklight::Bookmarks
|
|
15
15
|
|
16
16
|
before_action :verify_user
|
17
17
|
|
18
|
-
blacklight_config.track_search_session = false
|
18
|
+
blacklight_config.track_search_session.storage = false
|
19
19
|
blacklight_config.http_method = Blacklight::Engine.config.blacklight.bookmarks_http_method
|
20
20
|
blacklight_config.add_results_collection_tool(:clear_bookmarks_widget)
|
21
21
|
|
@@ -28,6 +28,28 @@ module Blacklight::SearchContext
|
|
28
28
|
session[:history].blank? ? ::Search.none : ::Search.where(id: session[:history]).order("updated_at desc")
|
29
29
|
end
|
30
30
|
|
31
|
+
# GET previous and next document json for the document specified by
|
32
|
+
# the counter param in current search
|
33
|
+
def page_links
|
34
|
+
counter_param = params.delete(:counter)
|
35
|
+
@page_link_data = {}
|
36
|
+
if counter_param
|
37
|
+
index = counter_param.to_i - 1
|
38
|
+
response, documents = search_service.previous_and_next_documents_for_search index, search_state.reset_search
|
39
|
+
if documents.detect(&:present?)
|
40
|
+
@page_link_data[:prev] = page_links_document_path(documents.first, index)
|
41
|
+
@page_link_data[:next] = page_links_document_path(documents.last, index + 2)
|
42
|
+
end
|
43
|
+
if response&.total && response.total.positive?
|
44
|
+
@page_link_data[:counterRaw] = counter_param
|
45
|
+
@page_link_data[:counterDelimited] = helpers.number_with_delimiter(counter_param.to_i)
|
46
|
+
@page_link_data[:totalRaw] = response.total
|
47
|
+
@page_link_data[:totalDelimited] = helpers.number_with_delimiter(response.total)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
render json: @page_link_data
|
51
|
+
end
|
52
|
+
|
31
53
|
private
|
32
54
|
|
33
55
|
# sets up the session[:search] hash if it doesn't already exist
|
@@ -85,6 +107,8 @@ module Blacklight::SearchContext
|
|
85
107
|
end
|
86
108
|
|
87
109
|
def find_or_initialize_search_session_from_params params
|
110
|
+
return unless blacklight_config.track_search_session.storage == 'server'
|
111
|
+
|
88
112
|
params_copy = params.reject { |k, v| nonpersisted_search_session_params.include?(k.to_sym) || v.blank? }
|
89
113
|
|
90
114
|
return if params_copy.reject { |k, _v| [:action, :controller].include? k.to_sym }.blank?
|
@@ -127,15 +151,31 @@ module Blacklight::SearchContext
|
|
127
151
|
# calls setup_previous_document then setup_next_document.
|
128
152
|
# used in the show action for single view pagination.
|
129
153
|
def setup_next_and_previous_documents
|
130
|
-
|
131
|
-
|
132
|
-
response, documents = search_service.previous_and_next_documents_for_search index, search_state.reset(current_search_session.query_params)
|
154
|
+
return { counter: params[:counter] } if setup_next_and_previous_on_client?
|
155
|
+
return nil unless setup_next_and_previous_on_server?
|
133
156
|
|
134
|
-
|
135
|
-
|
136
|
-
|
157
|
+
index = search_session['counter'].to_i - 1
|
158
|
+
response, documents = search_service.previous_and_next_documents_for_search index, search_state.reset(current_search_session.query_params)
|
159
|
+
|
160
|
+
search_session['total'] = response.total
|
161
|
+
{ prev: documents.first, next: documents.last }
|
137
162
|
rescue Blacklight::Exceptions::InvalidRequest => e
|
138
163
|
logger&.warn "Unable to setup next and previous documents: #{e}"
|
139
164
|
nil
|
140
165
|
end
|
166
|
+
|
167
|
+
def setup_next_and_previous_on_server?
|
168
|
+
search_session['counter'] && current_search_session && blacklight_config.track_search_session.storage == 'server'
|
169
|
+
end
|
170
|
+
|
171
|
+
def setup_next_and_previous_on_client?
|
172
|
+
params[:counter] && blacklight_config.track_search_session.storage == 'client'
|
173
|
+
end
|
174
|
+
|
175
|
+
def page_links_document_path(document, counter)
|
176
|
+
return nil unless document
|
177
|
+
return search_state.url_for_document(document, counter: counter) if blacklight_config.view_config(:show).route
|
178
|
+
|
179
|
+
solr_document_path(document, counter: counter)
|
180
|
+
end
|
141
181
|
end
|