blacklight 7.15.2 → 7.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/VERSION +1 -1
  4. data/app/components/blacklight/advanced_search_form_component.html.erb +9 -3
  5. data/app/components/blacklight/advanced_search_form_component.rb +48 -35
  6. data/app/components/blacklight/constraints_component.html.erb +19 -3
  7. data/app/components/blacklight/constraints_component.rb +5 -1
  8. data/app/components/blacklight/content_areas_shim.rb +12 -0
  9. data/app/components/blacklight/document/action_component.html.erb +1 -1
  10. data/app/components/blacklight/document/action_component.rb +6 -1
  11. data/app/components/blacklight/document/actions_component.html.erb +3 -5
  12. data/app/components/blacklight/document/actions_component.rb +16 -2
  13. data/app/components/blacklight/document/thumbnail_component.html.erb +3 -3
  14. data/app/components/blacklight/document/thumbnail_component.rb +11 -3
  15. data/app/components/blacklight/document_component.html.erb +4 -7
  16. data/app/components/blacklight/document_component.rb +73 -73
  17. data/app/components/blacklight/document_metadata_component.html.erb +2 -2
  18. data/app/components/blacklight/document_metadata_component.rb +13 -2
  19. data/app/components/blacklight/document_title_component.html.erb +17 -0
  20. data/app/components/blacklight/document_title_component.rb +59 -0
  21. data/app/components/blacklight/facet_field_checkboxes_component.html.erb +2 -2
  22. data/app/components/blacklight/facet_field_component.rb +4 -1
  23. data/app/components/blacklight/facet_field_list_component.html.erb +2 -2
  24. data/app/components/blacklight/facet_field_no_layout_component.rb +4 -1
  25. data/app/components/blacklight/metadata_field_component.html.erb +2 -2
  26. data/app/components/blacklight/metadata_field_layout_component.html.erb +3 -1
  27. data/app/components/blacklight/metadata_field_layout_component.rb +26 -1
  28. data/app/components/blacklight/response/view_type_button_component.html.erb +4 -0
  29. data/app/components/blacklight/response/view_type_button_component.rb +38 -0
  30. data/app/components/blacklight/response/view_type_component.html.erb +2 -5
  31. data/app/components/blacklight/response/view_type_component.rb +9 -13
  32. data/app/components/blacklight/search_bar_component.rb +9 -2
  33. data/app/components/blacklight/system/dropdown_component.html.erb +4 -7
  34. data/app/components/blacklight/system/dropdown_component.rb +24 -0
  35. data/app/components/blacklight/system/flash_message_component.html.erb +1 -1
  36. data/app/components/blacklight/system/flash_message_component.rb +7 -1
  37. data/app/components/blacklight/system/modal_component.rb +7 -1
  38. data/app/controllers/concerns/blacklight/catalog.rb +1 -1
  39. data/app/helpers/blacklight/blacklight_helper_behavior.rb +3 -4
  40. data/app/helpers/blacklight/catalog_helper_behavior.rb +2 -0
  41. data/app/helpers/blacklight/component_helper_behavior.rb +2 -2
  42. data/app/helpers/blacklight/configuration_helper_behavior.rb +2 -2
  43. data/app/presenters/blacklight/document_presenter.rb +8 -4
  44. data/app/services/blacklight/search_service.rb +1 -1
  45. data/app/views/bookmarks/_tools.html.erb +1 -1
  46. data/app/views/catalog/_citation.html.erb +1 -1
  47. data/app/views/catalog/_document.html.erb +2 -2
  48. data/app/views/catalog/_facet_layout.html.erb +2 -2
  49. data/app/views/catalog/_show_main_content.html.erb +3 -3
  50. data/app/views/catalog/email.html.erb +2 -2
  51. data/app/views/catalog/email_success.html.erb +1 -1
  52. data/app/views/catalog/facet.html.erb +3 -3
  53. data/app/views/catalog/sms.html.erb +2 -2
  54. data/app/views/catalog/sms_success.html.erb +1 -1
  55. data/blacklight.gemspec +1 -1
  56. data/config/locales/blacklight.de.yml +2 -2
  57. data/lib/blacklight/configuration.rb +50 -5
  58. data/lib/blacklight/configuration/view_config.rb +18 -5
  59. data/lib/blacklight/engine.rb +3 -1
  60. data/lib/blacklight/nested_open_struct_with_hash_access.rb +23 -7
  61. data/lib/blacklight/open_struct_with_hash_access.rb +4 -0
  62. data/lib/blacklight/search_builder.rb +1 -0
  63. data/lib/blacklight/search_state.rb +2 -2
  64. data/lib/blacklight/solr/facet_paginator.rb +2 -0
  65. data/lib/blacklight/solr/request.rb +31 -0
  66. data/lib/blacklight/solr/response.rb +2 -16
  67. data/lib/blacklight/solr/response/facets.rb +76 -22
  68. data/lib/blacklight/solr/response/params.rb +104 -0
  69. data/lib/blacklight/solr/search_builder_behavior.rb +64 -28
  70. data/lib/generators/blacklight/assets_generator.rb +6 -2
  71. data/lib/generators/blacklight/user_generator.rb +1 -1
  72. data/spec/components/blacklight/document_component_spec.rb +3 -3
  73. data/spec/helpers/blacklight/configuration_helper_behavior_spec.rb +6 -7
  74. data/spec/helpers/blacklight_helper_spec.rb +2 -2
  75. data/spec/helpers/catalog_helper_spec.rb +1 -1
  76. data/spec/lib/blacklight/configuration/view_config_spec.rb +1 -1
  77. data/spec/lib/blacklight/open_struct_with_hash_access_spec.rb +12 -0
  78. data/spec/models/blacklight/configuration_spec.rb +64 -0
  79. data/spec/models/blacklight/solr/facet_paginator_spec.rb +4 -0
  80. data/spec/models/blacklight/solr/request_spec.rb +62 -29
  81. data/spec/models/blacklight/solr/response/facets_spec.rb +109 -0
  82. data/spec/models/blacklight/solr/response_spec.rb +10 -0
  83. data/spec/models/blacklight/solr/search_builder_spec.rb +58 -0
  84. data/spec/services/blacklight/search_service_spec.rb +1 -1
  85. data/spec/views/catalog/_constraints.html.erb_spec.rb +1 -1
  86. data/spec/views/catalog/_view_type_group.html.erb_spec.rb +8 -9
  87. data/spec/views/catalog/index.atom.builder_spec.rb +1 -1
  88. metadata +10 -4
@@ -120,6 +120,16 @@ RSpec.describe Blacklight::Solr::Response, api: true do
120
120
  expect(r.params['test']).to eq :test
121
121
  end
122
122
 
123
+ it 'extracts json params' do
124
+ raw_response = eval(mock_query_response)
125
+ raw_response['responseHeader']['params']['test'] = 'from query'
126
+ raw_response['responseHeader']['params'].delete('rows')
127
+ raw_response['responseHeader']['params']['json'] = { limit: 5, params: { test: 'from json params' } }.to_json
128
+ r = described_class.new(raw_response, raw_response['params'])
129
+ expect(r.params['test']).to eq 'from query'
130
+ expect(r.rows).to eq 5
131
+ end
132
+
123
133
  it 'provides the solr-returned params and "rows" should be 11' do
124
134
  raw_response = eval(mock_query_response)
125
135
  r = described_class.new(raw_response, {})
@@ -259,6 +259,23 @@ RSpec.describe Blacklight::Solr::SearchBuilderBehavior, api: true do
259
259
  end
260
260
  end
261
261
 
262
+ describe 'with a json facet' do
263
+ let(:user_params) { { f: { json_facet: ['value'] } }.with_indifferent_access }
264
+
265
+ before do
266
+ blacklight_config.add_facet_field 'json_facet', field: 'foo', json: { bar: 'baz' }
267
+ end
268
+
269
+ it "has proper solr parameters" do
270
+ expect(subject[:fq]).to include('{!term f=foo}value')
271
+ expect(subject.dig(:json, :facet, 'json_facet')).to include(
272
+ field: 'foo',
273
+ type: 'terms',
274
+ bar: 'baz'
275
+ )
276
+ end
277
+ end
278
+
262
279
  describe 'with multi-valued facets' do
263
280
  let(:user_params) { { f_inclusive: { format: %w[Book Movie CD] } } }
264
281
 
@@ -321,6 +338,38 @@ RSpec.describe Blacklight::Solr::SearchBuilderBehavior, api: true do
321
338
  end
322
339
  end
323
340
 
341
+ describe "solr json query parameters from the fielded search" do
342
+ let(:user_params) { subject_search_params }
343
+
344
+ before do
345
+ blacklight_config.search_fields['subject'].solr_parameters = {
346
+ some: :parameter
347
+ }
348
+
349
+ blacklight_config.search_fields['subject'].clause_params = {
350
+ edismax: {
351
+ another: :parameter
352
+ }
353
+ }
354
+ end
355
+
356
+ it 'sets solr parameters from the field' do
357
+ expect(subject[:some]).to eq :parameter
358
+ end
359
+
360
+ it 'does not set a q parameter' do
361
+ expect(subject).not_to have_key :q
362
+ end
363
+
364
+ it 'includes the user query in the JSON query DSL request' do
365
+ expect(subject.dig(:json, :query, :bool, :must, 0, :edismax)).to include query: 'wome'
366
+ end
367
+
368
+ it 'includes addtional clause parameters for the field' do
369
+ expect(subject.dig(:json, :query, :bool, :must, 0, :edismax)).to include another: :parameter
370
+ end
371
+ end
372
+
324
373
  describe "overriding of qt parameter" do
325
374
  let(:user_params) do
326
375
  { qt: 'overridden' }
@@ -751,4 +800,13 @@ RSpec.describe Blacklight::Solr::SearchBuilderBehavior, api: true do
751
800
  expect(subject.to_hash.with_indifferent_access.dig(:json, :query, :bool, :must, 1, :edismax, :qf)).to eq '${author_qf}'
752
801
  end
753
802
  end
803
+
804
+ describe '#where' do
805
+ let(:user_params) { {} }
806
+
807
+ it 'adds additional query filters on the search' do
808
+ subject.where(id: [1, 2, 3])
809
+ expect(subject.to_hash).to include q: '{!lucene}id:(1 OR 2 OR 3)'
810
+ end
811
+ end
754
812
  end
@@ -477,7 +477,7 @@ RSpec.describe Blacklight::SearchService, api: true do
477
477
  end
478
478
 
479
479
  before do
480
- blacklight_config.view.opensearch.title_field = :field
480
+ blacklight_config.view.opensearch(title_field: :field)
481
481
  allow(repository).to receive(:search).and_return(mock_response)
482
482
  end
483
483
 
@@ -3,7 +3,7 @@
3
3
  RSpec.describe "catalog/constraints" do
4
4
  let :blacklight_config do
5
5
  Blacklight::Configuration.new do |config|
6
- config.view.xyz
6
+ config.view.xyz({})
7
7
  end
8
8
  end
9
9
 
@@ -3,13 +3,9 @@
3
3
  RSpec.describe "catalog/_view_type_group" do
4
4
  let(:blacklight_config) { Blacklight::Configuration.new }
5
5
  let(:response) { instance_double(Blacklight::Solr::Response, empty?: false) }
6
- let(:icon_instance) { instance_double(Blacklight::Icon) }
7
6
 
8
7
  before do
9
8
  allow(view).to receive(:view_label), &:to_s
10
- allow(Blacklight::Icon).to receive(:new).and_return icon_instance
11
- allow(icon_instance).to receive(:svg).and_return '<svg></svg>'
12
- allow(icon_instance).to receive(:options).and_return({})
13
9
  allow(view).to receive_messages(how_sort_and_per_page?: true, blacklight_config: blacklight_config)
14
10
  controller.request.path_parameters[:action] = 'index'
15
11
  assign(:response, response)
@@ -24,13 +20,16 @@ RSpec.describe "catalog/_view_type_group" do
24
20
  it "displays the group" do
25
21
  blacklight_config.configure do |config|
26
22
  config.view.delete(:list)
27
- config.view.a
28
- config.view.b
29
- config.view.c
23
+ config.view.a(icon: :list)
24
+ config.view.b(icon: :list)
25
+ config.view.c(icon: :list)
30
26
  end
31
27
  render partial: 'catalog/view_type_group'
32
28
  expect(rendered).to have_selector('.btn-group.view-type-group')
33
29
  expect(rendered).to have_selector('.view-type-a', text: 'a')
30
+ within '.view-type-a' do
31
+ expect(rendered).to have_selector 'svg'
32
+ end
34
33
  expect(rendered).to have_selector('.view-type-b', text: 'b')
35
34
  expect(rendered).to have_selector('.view-type-c', text: 'c')
36
35
  end
@@ -38,8 +37,8 @@ RSpec.describe "catalog/_view_type_group" do
38
37
  it "sets the current view to 'active'" do
39
38
  blacklight_config.configure do |config|
40
39
  config.view.delete(:list)
41
- config.view.a
42
- config.view.b
40
+ config.view.a(icon: :list)
41
+ config.view.b(icon: :list)
43
42
  end
44
43
  render partial: 'catalog/view_type_group'
45
44
  expect(rendered).to have_selector('.active', text: 'a')
@@ -12,7 +12,7 @@ RSpec.describe "catalog/index" do
12
12
  end
13
13
  end
14
14
 
15
- let(:blacklight_config) { CatalogController.blacklight_config }
15
+ let(:blacklight_config) { CatalogController.blacklight_config.deep_copy }
16
16
 
17
17
  before do
18
18
  @response = Blacklight::Solr::Response.new({ response: { numFound: 30 } }, start: 10, rows: 10)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.15.2
4
+ version: 7.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
@@ -17,7 +17,7 @@ authors:
17
17
  autorequire:
18
18
  bindir: exe
19
19
  cert_chain: []
20
- date: 2021-03-02 00:00:00.000000000 Z
20
+ date: 2021-04-23 00:00:00.000000000 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: rails
@@ -129,14 +129,14 @@ dependencies:
129
129
  requirements:
130
130
  - - ">="
131
131
  - !ruby/object:Gem::Version
132
- version: 2.23.0
132
+ version: 2.28.0
133
133
  type: :runtime
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
- version: 2.23.0
139
+ version: 2.28.0
140
140
  - !ruby/object:Gem::Dependency
141
141
  name: rsolr
142
142
  requirement: !ruby/object:Gem::Requirement
@@ -402,6 +402,7 @@ files:
402
402
  - app/components/blacklight/constraint_layout_component.rb
403
403
  - app/components/blacklight/constraints_component.html.erb
404
404
  - app/components/blacklight/constraints_component.rb
405
+ - app/components/blacklight/content_areas_shim.rb
405
406
  - app/components/blacklight/document/action_component.html.erb
406
407
  - app/components/blacklight/document/action_component.rb
407
408
  - app/components/blacklight/document/actions_component.html.erb
@@ -420,6 +421,8 @@ files:
420
421
  - app/components/blacklight/document_component.rb
421
422
  - app/components/blacklight/document_metadata_component.html.erb
422
423
  - app/components/blacklight/document_metadata_component.rb
424
+ - app/components/blacklight/document_title_component.html.erb
425
+ - app/components/blacklight/document_title_component.rb
423
426
  - app/components/blacklight/facet_field_checkboxes_component.html.erb
424
427
  - app/components/blacklight/facet_field_checkboxes_component.rb
425
428
  - app/components/blacklight/facet_field_component.html.erb
@@ -448,6 +451,8 @@ files:
448
451
  - app/components/blacklight/response/sort_component.rb
449
452
  - app/components/blacklight/response/spellcheck_component.html.erb
450
453
  - app/components/blacklight/response/spellcheck_component.rb
454
+ - app/components/blacklight/response/view_type_button_component.html.erb
455
+ - app/components/blacklight/response/view_type_button_component.rb
451
456
  - app/components/blacklight/response/view_type_component.html.erb
452
457
  - app/components/blacklight/response/view_type_component.rb
453
458
  - app/components/blacklight/search_bar_component.html.erb
@@ -691,6 +696,7 @@ files:
691
696
  - lib/blacklight/solr/response/group_response.rb
692
697
  - lib/blacklight/solr/response/more_like_this.rb
693
698
  - lib/blacklight/solr/response/pagination_methods.rb
699
+ - lib/blacklight/solr/response/params.rb
694
700
  - lib/blacklight/solr/response/response.rb
695
701
  - lib/blacklight/solr/response/spelling.rb
696
702
  - lib/blacklight/solr/search_builder_behavior.rb