Skip to content

Commit

Permalink
Merge pull request #2879 from projectblacklight/bookmark-component-te…
Browse files Browse the repository at this point in the history
…mplate

Update the configuration to use the component for bookmarks
  • Loading branch information
thatbudakguy committed Dec 15, 2022
2 parents 7a2fb40 + b4b8e57 commit f35b82c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/components/blacklight/document/actions_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Blacklight
module Document
# Render a bookmark widget to bookmark / unbookmark a document
# Render a the set of actions for a document. One of the default actions is the bookmark control.
class ActionsComponent < Blacklight::Component
renders_many :actions, (lambda do |action:, component: nil, **kwargs|
component ||= action.component || Blacklight::Document::ActionComponent
Expand Down
5 changes: 3 additions & 2 deletions app/components/blacklight/document/bookmark_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
module Blacklight
module Document
# Render a bookmark widget to bookmark / unbookmark a document
class BookmarkComponent < Blacklight::Component
class BookmarkComponent < Blacklight::Document::ActionComponent
# @param [Blacklight::Document] document
# @param [Boolean] checked
# @param [Object] bookmark_path the rails route to use for bookmarks
def initialize(document:, checked: nil, bookmark_path: nil)
def initialize(document:, action: nil, checked: nil, bookmark_path: nil, **kwargs)
@document = document
@checked = checked
@bookmark_path = bookmark_path
super(document: document, action: action, **kwargs)
end

def bookmarked?
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_bookmark_control.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= render Blacklight::Document::BookmarkComponent.new(document: document) %>
<%= render Blacklight::Document::BookmarkComponent.new(document: document, action: document_action_config) %>
4 changes: 2 additions & 2 deletions lib/generators/blacklight/templates/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ class <%= controller_name.classify %>Controller < ApplicationController
# config.index.search_bar_component = MyApp::SearchBarComponent
# config.index.document_actions.delete(:bookmark)
config.add_results_document_tool(:bookmark, partial: 'bookmark_control', if: :render_bookmarks_control?)
config.add_results_document_tool(:bookmark, component: Blacklight::Document::BookmarkComponent, if: :render_bookmarks_control?)
config.add_results_collection_tool(:sort_widget)
config.add_results_collection_tool(:per_page_widget)
config.add_results_collection_tool(:view_type_group)
config.add_show_tools_partial(:bookmark, partial: 'bookmark_control', if: :render_bookmarks_control?)
config.add_show_tools_partial(:bookmark, component: Blacklight::Document::BookmarkComponent, if: :render_bookmarks_control?)
config.add_show_tools_partial(:email, callback: :email_action, validator: :validate_email_params)
config.add_show_tools_partial(:sms, if: :render_sms_action?, callback: :sms_action, validator: :validate_sms_params)
config.add_show_tools_partial(:citation)
Expand Down

0 comments on commit f35b82c

Please sign in to comment.