From 742456982ffe090d2b99f7178457ce939ddd27da Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Thu, 6 Feb 2014 15:51:02 -0800 Subject: [PATCH] Allow the spotlight default exhibit home page to live at the root_url, and add the search sidebar to the display --- .../spotlight/home_pages_controller.rb | 31 +++++++++++++++++++ app/helpers/spotlight/home_pages_helper.rb | 22 +++++++++++++ app/views/shared/_exhibit_navbar.html.erb | 6 +--- .../spotlight/home_pages/_sidebar.html.erb | 3 ++ lib/generators/spotlight/install_generator.rb | 5 +++ lib/spotlight/engine.rb | 1 + lib/spotlight/rails/routes.rb | 8 +++++ .../spotlight/home_pages_controller_spec.rb | 12 +++++++ .../shared/_exhibit_navbar.html.erb_spec.rb | 2 +- .../home_pages/_sidebar.html.erb_spec.rb | 12 +++++++ 10 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 app/helpers/spotlight/home_pages_helper.rb create mode 100644 app/views/spotlight/home_pages/_sidebar.html.erb create mode 100644 lib/spotlight/rails/routes.rb create mode 100644 spec/views/spotlight/home_pages/_sidebar.html.erb_spec.rb diff --git a/app/controllers/spotlight/home_pages_controller.rb b/app/controllers/spotlight/home_pages_controller.rb index b28a6bbc3..18bebc4c0 100644 --- a/app/controllers/spotlight/home_pages_controller.rb +++ b/app/controllers/spotlight/home_pages_controller.rb @@ -1,10 +1,41 @@ module Spotlight class HomePagesController < Spotlight::PagesController + include Blacklight::SolrHelper + skip_authorize_resource only: :show + def index redirect_to exhibit_feature_pages_path(@exhibit) end + def show + @page = @home_page = if params[:id] + Spotlight::HomePage.find_by(id: params[:id]) + else + Spotlight::Exhibit.default.home_page + end + + (@response, @document_list) = get_search_results + + if @page.nil? or !@page.published? + render '/catalog/index' + else + render 'show' + end + end + + def _prefixes + @_prefixes ||= super + ['catalog'] + end + private + def blacklight_config + if @page + @page.exhibit.blacklight_config + else + Spotlight::Exhibit.default.blacklight_config + end + end + def page_model :home_page end diff --git a/app/helpers/spotlight/home_pages_helper.rb b/app/helpers/spotlight/home_pages_helper.rb new file mode 100644 index 000000000..8c101c12c --- /dev/null +++ b/app/helpers/spotlight/home_pages_helper.rb @@ -0,0 +1,22 @@ +module Spotlight::HomePagesHelper + include Blacklight::UrlHelperBehavior + + ## + # Standard display of a facet value in a list. Used in both _facets sidebar + # partial and catalog/facet expanded list. Will output facet value name as + # a link to add that to your restrictions, with count in parens. + # + # @param [Blacklight::SolrResponse::Facets::FacetField] + # @param [String] facet item + # @param [Hash] options + # @option options [Boolean] :suppress_link display the facet, but don't link to it + # @option options [Rails::Engine] :route_set route set to use to render the link + # @return [String] + def render_facet_value(facet_solr_field, item, options ={}) + scope = options.delete(:route_set) || main_app + path = scope.catalog_index_url(add_facet_params_and_redirect(facet_solr_field, item).merge(only_path: true)) + content_tag(:span, :class => "facet-label") do + link_to_unless(options[:suppress_link], facet_display_value(facet_solr_field, item), path, :class=>"facet_select") + end + render_facet_count(item.hits) + end +end \ No newline at end of file diff --git a/app/views/shared/_exhibit_navbar.html.erb b/app/views/shared/_exhibit_navbar.html.erb index 71fffa3b1..d33b64b3c 100644 --- a/app/views/shared/_exhibit_navbar.html.erb +++ b/app/views/shared/_exhibit_navbar.html.erb @@ -3,11 +3,7 @@