Skip to content

Commit

Permalink
provide support to configure a view by default to show the title only (
Browse files Browse the repository at this point in the history
  • Loading branch information
Darren Hardy authored and camillevilla committed Dec 12, 2017
1 parent edb76a7 commit 1c4921a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/models/spotlight/blacklight_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,14 @@ def set_index_field_defaults(field)
return unless index_fields.blank?

views = default_blacklight_config.view.keys | [:show, :enabled]
field.merge! Hash[views.map { |v| [v, true] }]
field.merge! Hash[views.map { |v| [v, !title_only_by_default?(v)] }]
end

# Check to see whether config.view.foobar.title_only_by_default is available
def title_only_by_default?(view)
return false if [:show, :enabled].include?(view)
title_only = default_blacklight_config.view.send(:[], view).try(:title_only_by_default)
title_only.nil? ? false : title_only
end

def set_show_field_defaults(field)
Expand Down
3 changes: 3 additions & 0 deletions lib/generators/spotlight/templates/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ class CatalogController < ApplicationController
config.add_sort_field 'relevance', sort: 'score desc', label: 'Relevance'

config.add_field_configuration_to_solr_request!

# Set which views by default only have the title displayed, e.g.,
# config.view.gallery.title_only_by_default = true
end
end
13 changes: 13 additions & 0 deletions spec/models/spotlight/blacklight_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,19 @@

expect(subject.blacklight_config.show_fields.keys).to eq %w(c a b)
end

context 'title only configuration' do
before do
blacklight_config.configure do |config|
config.view.gallery.title_only_by_default = true
config.add_index_field 'a'
end
end
it 'only shows titles (i.e., no metadata) for gallery view' do
expect(subject.blacklight_config.index_fields['a'][:list]).to eq true
expect(subject.blacklight_config.index_fields['a'][:gallery]).to eq false
end
end
end

describe 'a newly created instance' do
Expand Down

0 comments on commit 1c4921a

Please sign in to comment.