Skip to content

Commit

Permalink
Merge pull request #19 from jcoyne/master
Browse files Browse the repository at this point in the history
Added 'show'  parameter to add_facet_field and Fixed paths to folder_control and bookmark_control partials
  • Loading branch information
cbeer committed Feb 14, 2012
2 parents a29da79 + d6bcf88 commit 2132247
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ Gemfile.lock
tmp/test_app
.rvmrc
pkg/*
*.swp
8 changes: 4 additions & 4 deletions app/helpers/blacklight/blacklight_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def render_document_list_partial options={}
# renders next to title. Includes just 'Folder' by default.
def render_index_doc_actions(document, options={})
content = []
content << render(:partial => 'bookmark_control', :locals => {:document=> document}.merge(options)) if has_user_authentication_provider? and current_user
content << render(:partial => 'folder_control', :locals => {:document=> document}.merge(options))
content << render(:partial => 'catalog/bookmark_control', :locals => {:document=> document}.merge(options)) if has_user_authentication_provider? and current_user
content << render(:partial => 'catalog/folder_control', :locals => {:document=> document}.merge(options))

content_tag("div", content.join("\n").html_safe, :class=>"documentFunctions")
end
Expand All @@ -86,8 +86,8 @@ def render_index_doc_actions(document, options={})
# renders next to title. By default includes 'Folder' and 'Bookmarks'
def render_show_doc_actions(document=@document, options={})
content = []
content << render(:partial => 'bookmark_control', :locals => {:document=> document}.merge(options)) if has_user_authentication_provider? and current_user
content << render(:partial => 'folder_control', :locals => {:document=> document}.merge(options))
content << render(:partial => 'catalog/bookmark_control', :locals => {:document=> document}.merge(options)) if has_user_authentication_provider? and current_user
content << render(:partial => 'catalog/folder_control', :locals => {:document=> document}.merge(options))

content_tag("div", content.join("\n").html_safe, :class=>"documentFunctions")
end
Expand Down
4 changes: 3 additions & 1 deletion app/helpers/blacklight/facets_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def render_facet_limit(display_facet, options = {})
# By default, only render facets with items.
# @param [RSolr::Ext::Response::Facets::FacetField] display_facet
def should_render_facet? display_facet
return !display_facet.items.blank?
# display when show is nil or true
display = facet_configuration_for_field(display_facet.name).show != false
return display && display_facet.items.present?
end

# the name of the partial to use to render a facet field. Can be over-ridden for custom
Expand Down
6 changes: 6 additions & 0 deletions lib/generators/blacklight/templates/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class CatalogController < ApplicationController
# on the solr side in the request handler itself. Request handler defaults
# sniffing requires solr requests to be made with "echoParams=all", for
# app code to actually have it echo'd back to see it.
#
# :show may be set to false if you don't want the facet to be drawn in the
# facet bar
config.add_facet_field 'format', :label => 'Format'
config.add_facet_field 'pub_date', :label => 'Publication Year'
config.add_facet_field 'subject_topic_facet', :label => 'Topic', :limit => 20
Expand All @@ -48,6 +51,9 @@ class CatalogController < ApplicationController
# previously. Simply remove these lines if you'd rather use Solr request
# handler defaults, or have no facets.
config.default_solr_params[:'facet.field'] = config.facet_fields.keys
#use this instead if you don't want to query facets marked :show=>false
#config.default_solr_params[:'facet.field'] = config.facet_fields.select{ |k, v| v[:show] != false}.keys


# solr fields to be displayed in the index (search results) view
# The ordering of the field names is the order of the display
Expand Down
34 changes: 33 additions & 1 deletion test_support/spec/helpers/blacklight_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,39 @@ def export_as_weird_dup ; "weird_dup" ; end
response = render_link_rel_alternates(@document)
response.html_safe?.should == true
end

end

describe "with a config" do
before do
@config = Blacklight::Configuration.new.configure do |config|
config.show.html_title = "title_display"
config.show.heading = "title_display"
config.show.display_type = 'format'

config.index.show_link = 'title_display'
config.index.record_display_type = 'format'
end

@document = SolrDocument.new('title_display' => "A Fake Document", 'id'=>'8')
helper.stub(:blacklight_config).and_return(@config)
helper.stub(:has_user_authentication_provider?).and_return(true)
helper.stub(:current_user).and_return(User.new)
end
describe "render_index_doc_actions" do
it "should render partials" do
response = helper.render_index_doc_actions(@document)
response.should have_selector(".bookmark_toggle")
response.should have_selector(".folder_toggle")
end
end
describe "render_show_doc_actions" do
it "should render partials" do
response = helper.render_show_doc_actions(@document)
response.should have_selector(".bookmark_toggle")
response.should have_selector(".folder_toggle")
end
end
end


end
17 changes: 15 additions & 2 deletions test_support/spec/helpers/facets_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,27 @@
describe FacetsHelper do

describe "should_render_facet?" do
before do
@config = Blacklight::Configuration.new do |config|
config.add_facet_field 'basic_field'
config.add_facet_field 'no_show', :show=>false
end

helper.stub(:blacklight_config => @config)
end
it "should render facets with items" do
a = mock(:items => [1,2])
a = mock(:items => [1,2], :name=>'basic_field')
helper.should_render_facet?(a).should == true
end
it "should not render facets without items" do
empty = mock(:items => [])
empty = mock(:items => [], :name=>'basic_field')
helper.should_render_facet?(empty).should == false
end

it "should not render facets where show is set to false" do
a = mock(:items => [1,2], :name=>'no_show')
helper.should_render_facet?(a).should == false
end
end

describe "facet_by_field_name" do
Expand Down
6 changes: 6 additions & 0 deletions test_support/spec/lib/blacklight_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@

@config.facet_fields["publication_date"].label.should == "Publication Date"
end

it "should allow you to not show the facet in the facet bar" do
@config.add_facet_field("publication_date", :show=>false)

@config.facet_fields["publication_date"]['show'].should be_false
end

it "should raise on nil solr field name" do
lambda { @config.add_facet_field(nil) }.should raise_error ArgumentError
Expand Down

0 comments on commit 2132247

Please sign in to comment.