From e50eeb3e452036bdd5e782adad5c34225604c0b8 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Tue, 18 Nov 2014 21:00:36 -0600 Subject: [PATCH] The Navbar links should be dynamically configurable --- .../blacklight/blacklight_helper_behavior.rb | 33 ++++++++++-- app/views/_user_util_links.html.erb | 17 +------ app/views/blacklight/nav/_bookmark.html.erb | 4 ++ .../blacklight/nav/_saved_searches.html.erb | 1 + .../blacklight/nav/_search_history.html.erb | 1 + lib/blacklight/catalog.rb | 28 +++------- .../catalog/component_configuration.rb | 51 +++++++++++++++++++ lib/blacklight/catalog/index_tools.rb | 39 -------------- lib/blacklight/configuration.rb | 39 ++++++++++++++ spec/controllers/alternate_controller_spec.rb | 8 +-- spec/helpers/blacklight_helper_spec.rb | 32 +++++++----- spec/views/_user_util_links.html.erb_spec.rb | 9 ++-- .../_index_header_default.html.erb_spec.rb | 5 -- 13 files changed, 163 insertions(+), 104 deletions(-) create mode 100644 app/views/blacklight/nav/_bookmark.html.erb create mode 100644 app/views/blacklight/nav/_saved_searches.html.erb create mode 100644 app/views/blacklight/nav/_search_history.html.erb create mode 100644 lib/blacklight/catalog/component_configuration.rb delete mode 100644 lib/blacklight/catalog/index_tools.rb diff --git a/app/helpers/blacklight/blacklight_helper_behavior.rb b/app/helpers/blacklight/blacklight_helper_behavior.rb index 6ed27d4355..c58746cfcd 100644 --- a/app/helpers/blacklight/blacklight_helper_behavior.rb +++ b/app/helpers/blacklight/blacklight_helper_behavior.rb @@ -93,7 +93,17 @@ def render_search_bar end ## - # Render "docuemnt actions" area for search results view + # Render "document actions" area for navigation header + # (normally renders "Saved Searches", "History", "Bookmarks") + # + # @param [Hash] options + # @return [String] + def render_nav_actions(options={}, &block) + render_filtered_partials(blacklight_config.navbar.partials, options, &block) + end + + ## + # Render "document actions" area for search results view # (normally renders next to title in the list view) # # @param [SolrDocument] document @@ -102,13 +112,20 @@ def render_search_bar # @return [String] def render_index_doc_actions(document, options={}) wrapping_class = options.delete(:wrapping_class) || "index-document-functions" + rendered = render_filtered_partials(blacklight_config.index.document_actions, { document: document }.merge(options)) + content_tag("div", rendered, class: wrapping_class) + end + def render_filtered_partials(partials, options={}, &block) content = [] - index_tool_partials.select { |_, config| evaluate_if_unless_configuration config, @document }.each do |_, config| - content << render(config.partial, { document: document }.merge(options)) + partials.select { |_, config| evaluate_if_unless_configuration config, options }.each do |_, config| + if block_given? + yield render(config.partial, options) + else + content << render(config.partial, options) + end end - - content_tag("div", safe_join(content, "\n"), class: wrapping_class) + safe_join(content, "\n") unless block_given? end ## @@ -575,6 +592,12 @@ def render_bookmarks_control? has_user_authentication_provider? and current_or_guest_user.present? end + ## + # Determine whether to render the saved searches link + def render_saved_searches? + has_user_authentication_provider? and current_user + end + ## # Returns a document presenter for the given document def presenter(document) diff --git a/app/views/_user_util_links.html.erb b/app/views/_user_util_links.html.erb index cb65fc8b57..7277ecf9bf 100644 --- a/app/views/_user_util_links.html.erb +++ b/app/views/_user_util_links.html.erb @@ -1,21 +1,8 @@