blacklight-spotlight 0.14.0 → 0.14.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5a848d17a782a172979d2f5f1474be224e5aa50
4
- data.tar.gz: aaf3bb7c7c594a324f31bacc68a854576bcadfa3
3
+ metadata.gz: b0aefec4ae05cfb0ff575bc3f774e69f8e949757
4
+ data.tar.gz: 2bf34ba4683b051d523cb98e461e96fa2cad2149
5
5
  SHA512:
6
- metadata.gz: fa6893ca19f7e9607d5398f2920af9954b9edee98a4e0cd59e120057ed1aed8c0b901bbe2933efdd9aef2140a6c04708b442472b8a55133055db960be35e9190
7
- data.tar.gz: 41d04adaad2035a0ee4693b41ed794fe5b8d4d627f1b638cc6d07967385919424c4789e0ef4e1ff13a14b3a57cb950bd333f02120fe522a5fd1cd102b9e5b468
6
+ metadata.gz: e6e7e9d9b16f7267bb1862edc08be110799329d727cdf4d6e208e70af90442c665733aaa3d750dd26c26215a456dc04c9a22e53d711e2c9358cc385194fef93f
7
+ data.tar.gz: 44143ac2594a25f1b191c8117bd986b90d593bb7d95c36d6fe0b04f20d8e89665551ac3ce8373115c2cf1e957fb8b5ff015e34de1bbd6f6de51dcc29592c4381
@@ -36,7 +36,6 @@
36
36
  background-color: $masthead-bg;
37
37
  border-bottom: 1px solid $navbar-default-border;
38
38
  margin-bottom: $padding-large-vertical * 2.5;
39
- overflow: hidden;
40
39
  padding: 0;
41
40
  position: relative;
42
41
  // allow dropdowns in the top nav to stack above the masthead
@@ -126,7 +125,7 @@
126
125
  -webkit-filter: blur($masthead-image-blur);
127
126
  filter: blur($masthead-image-blur);
128
127
 
129
- height: $masthead-height;
128
+ height: 100%;
130
129
 
131
130
  // Shift image slightly to hide blurred edge of image
132
131
  margin-left: -$masthead-image-blur;
@@ -145,7 +144,7 @@
145
144
  rgba(0, 0, 0, 0.5)
146
145
  );
147
146
 
148
- height: $masthead-height;
147
+ height: 100%;
149
148
  }
150
149
  }
151
150
 
@@ -21,7 +21,7 @@ module Spotlight
21
21
  add_breadcrumb t(:'spotlight.configuration.sidebar.header'), exhibit_dashboard_path(@exhibit)
22
22
  add_breadcrumb t(:'spotlight.configuration.sidebar.search_configuration'), edit_exhibit_search_configuration_path(@exhibit)
23
23
 
24
- @field_metadata = Spotlight::FieldMetadata.new(repository, @blacklight_configuration.blacklight_config)
24
+ @field_metadata = Spotlight::FieldMetadata.new(current_exhibit, repository, @blacklight_configuration.blacklight_config)
25
25
  end
26
26
 
27
27
  def update
@@ -107,8 +107,8 @@ module Spotlight
107
107
  class: 'btn btn-default btn-xs metadata-select',
108
108
  data: {
109
109
  behavior: 'metadata-select',
110
- 'deselect-text': t(:".deselect_all"),
111
- 'select-text': t(:".select_all")
110
+ 'deselect-text' => t(:".deselect_all"),
111
+ 'select-text' => t(:".select_all")
112
112
  }
113
113
  )
114
114
  end
@@ -37,11 +37,11 @@ module Spotlight
37
37
  def nestable_data_attributes_hash(type)
38
38
  case type
39
39
  when 'feature_pages'
40
- { "data-max-depth": '2',
41
- "data-expand-btn-HTML": '',
42
- "data-collapse-btn-HTML": '' }
40
+ { 'data-max-depth' => '2',
41
+ 'data-expand-btn-HTML' => '',
42
+ 'data-collapse-btn-HTML' => '' }
43
43
  when 'about_pages'
44
- { "data-max-depth": '1' }
44
+ { 'data-max-depth' => '1' }
45
45
  else
46
46
  {}
47
47
  end
@@ -2,8 +2,12 @@ module Spotlight
2
2
  ##
3
3
  # Expose Solr index metadata about fields
4
4
  class FieldMetadata
5
- attr_reader :repository, :blacklight_config
6
- def initialize(repository, blacklight_config)
5
+ FACET_LIMIT = 20
6
+
7
+ attr_reader :exhibit, :repository, :blacklight_config
8
+
9
+ def initialize(exhibit, repository, blacklight_config)
10
+ @exhibit = exhibit
7
11
  @repository = repository
8
12
  @blacklight_config = blacklight_config
9
13
  end
@@ -11,36 +15,52 @@ module Spotlight
11
15
  def field(field_name)
12
16
  {
13
17
  document_count: document_counts.fetch(field_name, 0),
14
- value_count: fields.fetch(field_name, {}).fetch('distinct', 0),
15
- terms: fields.fetch(field_name, {}).fetch('topTerms', [])
18
+ value_count: terms.fetch(field_name, []).length,
19
+ terms: terms.fetch(field_name, [])
16
20
  }
17
21
  end
18
22
 
23
+ def search_params
24
+ search_builder.merge(rows: 0, 'facet.limit' => FACET_LIMIT + 1)
25
+ end
26
+
19
27
  private
20
28
 
21
- def luke
22
- @luke ||= repository.send_and_receive('admin/luke', fl: '*', 'json.nl' => 'map')
29
+ def search_builder_class
30
+ blacklight_config.search_builder_class
31
+ end
32
+
33
+ def search_builder
34
+ search_builder_class.new(true, self)
23
35
  end
24
36
 
25
- def fields
26
- luke['fields']
37
+ def solr_response
38
+ @solr_response ||= repository.search(search_params.merge('facet.query' => facet_fields.map { |_key, fields| "#{fields.field}:[* TO *]" },
39
+ 'rows' => 0,
40
+ 'facet' => true))
27
41
  end
28
42
 
29
43
  # This gets the number of *documents* with a field
30
44
  def document_counts
31
45
  @document_count ||= begin
32
- solr_resp = repository.search('facet.query' => facet_fields.map { |_key, fields| "#{fields.field}:[* TO *]" },
33
- 'rows' => 0,
34
- 'facet' => true)
35
-
36
- solr_resp['facet_counts']['facet_queries'].each_with_object({}) do |(k, v), h|
46
+ solr_response.facet_queries.each_with_object({}) do |(k, v), h|
37
47
  h[k.split(/:/).first] = v
38
48
  end
39
49
  end
40
50
  end
41
51
 
52
+ def terms
53
+ @terms ||= begin
54
+ solr_response.aggregations.each_with_object({}) do |(facet_name, facet), h|
55
+ h[facet_name] = facet.items.map(&:label)
56
+ end
57
+ end
58
+ end
59
+
42
60
  def facet_fields
43
61
  blacklight_config.facet_fields.reject { |_k, v| v.pivot || v.query }
44
62
  end
63
+
64
+ alias_method :current_exhibit, :exhibit
45
65
  end
46
66
  end
@@ -2,7 +2,7 @@
2
2
  <td>
3
3
  <%= f.email_field :user_key, hide_label: true, disabled: f.object.persisted?, data: { behavior: 'check-user-existence' } %>
4
4
  <span style='display:none' class='help-block' data-behavior='no-user-note'>
5
- <%= t('.invite_html', link: link_to(t('.invite_link'), spotlight.invite_exhibit_roles_path(current_exhibit), data: { method: 'post', 'invite-url': spotlight.invite_exhibit_roles_path(current_exhibit) })) %>
5
+ <%= t('.invite_html', link: link_to(t('.invite_link'), spotlight.invite_exhibit_roles_path(current_exhibit), data: { method: 'post', 'invite-url' => spotlight.invite_exhibit_roles_path(current_exhibit) })) %>
6
6
  <span class='label label-warning pending-label'><%= t('.pending') %></span>
7
7
  </span>
8
8
  </td>
@@ -0,0 +1,12 @@
1
+ <%= content_tag :span, t(:'.document_count', count: metadata[:document_count]) %>
2
+ <% if metadata[:document_count] > 0 %>
3
+
4
+ <% if metadata[:value_count] > Spotlight::FieldMetadata::FACET_LIMIT %>
5
+ <%= content_tag :span, t(:'.too_many_values_count', count: Spotlight::FieldMetadata::FACET_LIMIT) %>
6
+ <% else %>
7
+ <%= content_tag :span, t(:'.value_count', count: metadata[:value_count]) %>
8
+ <% end %>
9
+ <% if metadata[:terms].any? %>
10
+ <%= tag("span", class: 'btn-with-tooltip glyphicon glyphicon-info-sign', data: {container: 'body', toggle: 'tooltip', placement: 'top', title: metadata[:terms].join(" • ")}) %>
11
+ <% end %>
12
+ <% end %>
@@ -19,13 +19,7 @@
19
19
  </h3>
20
20
  </div>
21
21
  <div class="facet-metadata col-sm-5">
22
- <%= content_tag :span, t(:'.document_count', count: metadata[:document_count]) %>
23
- <% if metadata[:document_count] > 0 %>
24
- • <%= content_tag :span, t(:'.value_count', count: metadata[:value_count]) %>
25
- <% if metadata[:terms].any? %>
26
- <%= tag("span", class: 'btn-with-tooltip glyphicon glyphicon-info-sign', data: {container: 'body', toggle: 'tooltip', placement: 'top', title: metadata[:terms].keys.map(&:to_s).join(" • ")}) %>
27
- <% end %>
28
- <% end %>
22
+ <%= render partial: 'facet_metadata', locals: { metadata: metadata } %>
29
23
  </div>
30
24
  <div class="col-sm-2 pull-right">
31
25
  <a class="btn btn-link collapse-toggle collapsed" role="button" data-toggle="collapse" href="#<%= key.parameterize %>_facet_options" aria-expanded="false" aria-controls="<%= key.parameterize %>_facet_options">
@@ -183,16 +183,18 @@ en:
183
183
  the facets shown in the sidebar to limit a search. You can select the facets
184
184
  that are available for searching below. Click a facet field name to edit its display label.
185
185
  Drag and drop facets to specify the order they are displayed in the sidebar.
186
+ sort_by:
187
+ label: "Sort by:"
188
+ count: Frequency
189
+ index: Value
190
+ facet_metadata:
186
191
  document_count:
187
192
  one: "%{count} item"
188
193
  other: "%{count} items"
194
+ too_many_values_count: "%{count}+ unique values"
189
195
  value_count:
190
196
  one: "%{count} unique value"
191
197
  other: "%{count} unique values"
192
- sort_by:
193
- label: "Sort by:"
194
- count: Frequency
195
- index: Value
196
198
  sort:
197
199
  header: "Sort fields"
198
200
  help: >
@@ -5,10 +5,10 @@ class ChangeRolesToSupportPolymorphicAssociations < ActiveRecord::Migration
5
5
 
6
6
  migrate_role_data_to_polymorphic_resource
7
7
 
8
+ remove_index :spotlight_roles, [:exhibit_id, :user_id]
8
9
  remove_column :spotlight_roles, :exhibit_id
9
10
 
10
11
  add_index :spotlight_roles, [:resource_type, :resource_id, :user_id], unique: true, name: 'index_spotlight_roles_on_resource_and_user_id'
11
- remove_index :spotlight_roles, [:exhibit_id, :user_id]
12
12
  end
13
13
 
14
14
  def down
@@ -20,12 +20,13 @@ class ChangeRolesToSupportPolymorphicAssociations < ActiveRecord::Migration
20
20
  Spotlight::Role.find_each do |e|
21
21
  e.update(exhibit_id: e.resource_id) if e.exhibit_id.nil? && e.resource_type == 'Spotlight::Exhibit'
22
22
  end
23
+
24
+ remove_index :spotlight_roles, name: 'index_spotlight_roles_on_resource_and_user_id'
23
25
 
24
26
  remove_column :spotlight_roles, :resource_id
25
27
  remove_column :spotlight_roles, :resource_type
26
28
 
27
29
  add_index :spotlight_roles, [:exhibit_id, :user_id], unique: true
28
- remove_index :spotlight_roles, name: 'index_spotlight_roles_on_resource_and_user_id'
29
30
  end
30
31
 
31
32
  private
@@ -4,8 +4,4 @@ require 'spotlight/engine'
4
4
  ##
5
5
  # Spotlight
6
6
  module Spotlight
7
- autoload :Config, 'spotlight/config'
8
- autoload :Base, 'spotlight/base'
9
- autoload :Controller, 'spotlight/controller'
10
- autoload :Catalog, 'spotlight/catalog'
11
7
  end
@@ -1,4 +1,4 @@
1
1
  #
2
2
  module Spotlight
3
- VERSION = '0.14.0'
3
+ VERSION = '0.14.1'
4
4
  end
@@ -82,12 +82,12 @@ module Spotlight
82
82
  end
83
83
  describe 'nestable data attributes hash' do
84
84
  it 'returns the appropriate hash for feature pages' do
85
- expect(helper.nestable_data_attributes_hash('feature_pages')).to eq "data-max-depth": '2',
86
- "data-expand-btn-HTML": '',
87
- "data-collapse-btn-HTML": ''
85
+ expect(helper.nestable_data_attributes_hash('feature_pages')).to eq('data-max-depth' => '2',
86
+ 'data-expand-btn-HTML' => '',
87
+ 'data-collapse-btn-HTML' => '')
88
88
  end
89
89
  it 'returns the appropriate hash for about pages' do
90
- expect(helper.nestable_data_attributes_hash('about_pages')).to eq "data-max-depth": '1'
90
+ expect(helper.nestable_data_attributes_hash('about_pages')).to eq 'data-max-depth' => '1'
91
91
  end
92
92
  it 'returns an empty hash if the type is not valid' do
93
93
  expect(helper.nestable_data_attributes_hash('something_else')).to eq({})
@@ -18,7 +18,7 @@ describe SirTrevorRails::Blocks::Textable do
18
18
  end
19
19
  describe '#text_align' do
20
20
  it 'proxies the sir-trevor text-align attribute' do
21
- allow(subject).to receive_messages('text-align': 'text-align-value')
21
+ allow(subject).to receive_messages('text-align' => 'text-align-value')
22
22
  expect(subject.text_align).to eq 'text-align-value'
23
23
  end
24
24
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Spotlight::FieldMetadata do
4
+ let(:exhibit) { FactoryGirl.create(:exhibit) }
4
5
  let(:repository) { double }
5
6
  let(:blacklight_config) do
6
7
  Blacklight::Configuration.new do |config|
@@ -10,28 +11,15 @@ describe Spotlight::FieldMetadata do
10
11
  end
11
12
  end
12
13
 
13
- let(:luke_response) do
14
- {
15
- fields: {
16
- a: {
17
- distinct: 100,
18
- topTerms: %w(q w e)
19
- },
20
- b: {
21
- distinct: 50,
22
- topTerms: %w(r t y)
23
- },
24
- c: {
25
- distinct: 3,
26
- topTerms: [7, 8, 9]
27
- }
28
- }
29
- }.with_indifferent_access
30
- end
31
-
32
14
  let(:facet_response) do
33
15
  {
34
16
  facet_counts: {
17
+ facet_fields: {
18
+ a: { 'a' => 1, 'b' => 2, 'c' => 3 },
19
+ b: { 'b' => 1 },
20
+ c: { 7 => 1, 8 => 2, 9 => 3 }
21
+ },
22
+
35
23
  facet_queries: {
36
24
  'a:[* TO *]' => 5,
37
25
  'b:[* TO *]' => 10,
@@ -41,11 +29,10 @@ describe Spotlight::FieldMetadata do
41
29
  }.with_indifferent_access
42
30
  end
43
31
 
44
- subject { described_class.new(repository, blacklight_config) }
32
+ subject { described_class.new(exhibit, repository, blacklight_config) }
45
33
 
46
34
  before do
47
- allow(repository).to receive(:send_and_receive).with('admin/luke', hash_including(fl: '*')).and_return(luke_response)
48
- allow(repository).to receive(:search).with(hash_including('facet' => true)).and_return(facet_response)
35
+ allow(repository).to receive(:search).with(an_instance_of(SearchBuilder)).and_return(Blacklight::Solr::Response.new(facet_response, {}))
49
36
  end
50
37
 
51
38
  describe '#field' do
@@ -56,14 +43,14 @@ describe Spotlight::FieldMetadata do
56
43
  end
57
44
 
58
45
  it 'has a value count' do
59
- expect(subject.field('a')[:value_count]).to eq 100
60
- expect(subject.field('b')[:value_count]).to eq 50
46
+ expect(subject.field('a')[:value_count]).to eq 3
47
+ expect(subject.field('b')[:value_count]).to eq 1
61
48
  expect(subject.field('c')[:value_count]).to eq 3
62
49
  end
63
50
 
64
51
  it 'gets a list of top terms' do
65
- expect(subject.field('a')[:terms]).to match_array %w(q w e)
66
- expect(subject.field('b')[:terms]).to match_array %w(r t y)
52
+ expect(subject.field('a')[:terms]).to match_array %w(a b c)
53
+ expect(subject.field('b')[:terms]).to match_array %w(b)
67
54
  expect(subject.field('c')[:terms]).to match_array [7, 8, 9]
68
55
  end
69
56
 
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ module Spotlight
4
+ describe 'spotlight/search_configurations/_facet_metadata', type: :view do
5
+ before do
6
+ render partial: 'spotlight/search_configurations/facet_metadata', locals: { metadata: metadata }
7
+ end
8
+
9
+ context 'with a facet without any documents' do
10
+ let(:metadata) { { document_count: 0 } }
11
+
12
+ it 'shows there are no documents' do
13
+ expect(rendered).to have_content '0 items'
14
+ end
15
+ end
16
+
17
+ context 'with a facet with a small number of values' do
18
+ let(:metadata) { { document_count: 1, value_count: 3, terms: %w(a b c) } }
19
+
20
+ it 'shows the number of unique values' do
21
+ expect(rendered).to have_content '1 item'
22
+ expect(rendered).to have_content '3 unique values'
23
+ expect(rendered).to have_selector '.btn-with-tooltip'
24
+ end
25
+ end
26
+
27
+ context 'with a facet with a large number of values' do
28
+ let(:metadata) { { document_count: 1, value_count: 21, terms: %w() } }
29
+
30
+ it 'shows there are many unique values' do
31
+ expect(rendered).to have_content '20+ unique values'
32
+ end
33
+ end
34
+ end
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight-spotlight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-12-16 00:00:00.000000000 Z
14
+ date: 2015-12-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -793,6 +793,11 @@ files:
793
793
  - app/assets/stylesheets/spotlight/application.scss
794
794
  - app/assets/stylesheets/spotlight/typeahead.css
795
795
  - app/builders/spotlight/bootstrap_breadcrumbs_builder.rb
796
+ - app/controllers/concerns/spotlight/base.rb
797
+ - app/controllers/concerns/spotlight/catalog.rb
798
+ - app/controllers/concerns/spotlight/catalog/access_controls_enforcement.rb
799
+ - app/controllers/concerns/spotlight/config.rb
800
+ - app/controllers/concerns/spotlight/controller.rb
796
801
  - app/controllers/spotlight/about_pages_controller.rb
797
802
  - app/controllers/spotlight/appearances_controller.rb
798
803
  - app/controllers/spotlight/application_controller.rb
@@ -1021,6 +1026,7 @@ files:
1021
1026
  - app/views/spotlight/roles/index.html.erb
1022
1027
  - app/views/spotlight/search_configurations/_default_per_page.html.erb
1023
1028
  - app/views/spotlight/search_configurations/_document_index_view_types.html.erb
1029
+ - app/views/spotlight/search_configurations/_facet_metadata.html.erb
1024
1030
  - app/views/spotlight/search_configurations/_facets.html.erb
1025
1031
  - app/views/spotlight/search_configurations/_search_fields.html.erb
1026
1032
  - app/views/spotlight/search_configurations/_sort.html.erb
@@ -1115,11 +1121,6 @@ files:
1115
1121
  - lib/generators/spotlight/templates/spotlight.scss
1116
1122
  - lib/generators/spotlight/templates/spotlight_helper.rb
1117
1123
  - lib/spotlight.rb
1118
- - lib/spotlight/base.rb
1119
- - lib/spotlight/catalog.rb
1120
- - lib/spotlight/catalog/access_controls_enforcement.rb
1121
- - lib/spotlight/config.rb
1122
- - lib/spotlight/controller.rb
1123
1124
  - lib/spotlight/engine.rb
1124
1125
  - lib/spotlight/version.rb
1125
1126
  - lib/tasks/spotlight_tasks.rake
@@ -1311,6 +1312,7 @@ files:
1311
1312
  - spec/views/spotlight/pages/new.html.erb_spec.rb
1312
1313
  - spec/views/spotlight/pages/show.html.erb_spec.rb
1313
1314
  - spec/views/spotlight/roles/index.html.erb_spec.rb
1315
+ - spec/views/spotlight/search_configurations/_facet_metadata.html.erb_spec.rb
1314
1316
  - spec/views/spotlight/search_configurations/_search_fields.html.erb_spec.rb
1315
1317
  - spec/views/spotlight/search_configurations/_sort.html.erb_spec.rb
1316
1318
  - spec/views/spotlight/searches/_search.html.erb_spec.rb
@@ -1550,6 +1552,7 @@ test_files:
1550
1552
  - spec/views/spotlight/pages/new.html.erb_spec.rb
1551
1553
  - spec/views/spotlight/pages/show.html.erb_spec.rb
1552
1554
  - spec/views/spotlight/roles/index.html.erb_spec.rb
1555
+ - spec/views/spotlight/search_configurations/_facet_metadata.html.erb_spec.rb
1553
1556
  - spec/views/spotlight/search_configurations/_search_fields.html.erb_spec.rb
1554
1557
  - spec/views/spotlight/search_configurations/_sort.html.erb_spec.rb
1555
1558
  - spec/views/spotlight/searches/_search.html.erb_spec.rb