Skip to content

Commit

Permalink
Fix bookmarks.
Browse files Browse the repository at this point in the history
Enables Bootstrap/Blacklight JS
Replaces our form override with the new ViewComponent, passes the path
rather than overriding.

Closes #999
  • Loading branch information
tpendragon committed Sep 27, 2021
1 parent 335b316 commit 34694f6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
//= require jquery
//= require jquery_ujs
// Required by Blacklight
//= require popper
//= require bootstrap
//= require blacklight/blacklight
//= require 'blacklight_oembed/jquery.oembed.js'
//= require blacklight_gallery
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def unique_custom_fields
# Make browse results doc actions consistent with search result doc actions
config.browse.document_actions = config.index.document_actions

config.add_results_document_tool(:bookmark, partial: 'bookmark_control', if: :render_bookmarks_control?)

## Default parameters to send to solr for all search-like requests. See also SolrHelper#solr_search_params
# Group records by manifest in order to display a single result for a given
# resource in 'search across'
Expand Down
26 changes: 3 additions & 23 deletions app/views/catalog/_bookmark_control.html.erb
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
<% if current_or_guest_user %>
<%-
# Note these two forms are pretty similar but for different :methods, classes, and labels.
# but it was simpler to leave them seperate instead of DRYing them, got confusing trying that.
# the data-doc-id attribute is used by our JS that converts to a checkbox/label.
#
<%-
# Local override to use the actual document id for the form path as opposed to
# the noid id. This simple change makes all the existing bookmark
# functionality work rather than overriding functionality in several other
# places to stay consistent with the noid.
-%>
<% unless bookmarked? document %>
<%= form_tag( bookmarks_id_path(document), :method => :put, :class => "bookmark_toggle", "data-doc-id" => document.id, :'data-present' => t('blacklight.search.bookmarks.present'), :'data-absent' => t('blacklight.search.bookmarks.absent'), :'data-inprogress' => t('blacklight.search.bookmarks.inprogress')) do %>
<%= submit_tag(t('blacklight.bookmarks.add.button'), :id => "bookmark_toggle_#{document.id.to_s.parameterize}", :class => "bookmark_add btn btn-default") %>
<% end %>
<% else %>
<%= form_tag( bookmarks_id_path(document), :method => :delete, :class => "bookmark_toggle", "data-doc-id" => document.id, :'data-present' => t('blacklight.search.bookmarks.present'), :'data-absent' => t('blacklight.search.bookmarks.absent'), :'data-inprogress' => t('blacklight.search.bookmarks.inprogress')) do %>
<%= submit_tag(t('blacklight.bookmarks.remove.button'), :id => "bookmark_toggle_#{document.id.to_s.parameterize}", :class => "bookmark_remove btn btn-default") %>
<% end %>
<% end %>
<% else %>
&nbsp;
<% end %>
-%>
<%= render Blacklight::Document::BookmarkComponent.new(document: document, bookmark_path: bookmarks_id_path(document)) if current_or_guest_user %>
2 changes: 1 addition & 1 deletion spec/features/bookmarks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
iiif_resource1
iiif_resource2
visit spotlight.search_exhibit_catalog_path(exhibit, search_field: 'all_fields', q: '')
bookmark_box = "toggle_bookmark_#{solr_id}"
bookmark_box = "toggle-bookmark_#{solr_id}"
check bookmark_box
expect(page).to have_content "In Bookmarks"

Expand Down

0 comments on commit 34694f6

Please sign in to comment.