Skip to content

Commit

Permalink
Merge pull request #605 from pulibrary/567-bookmarks-2
Browse files Browse the repository at this point in the history
Turn bookmarks back on
  • Loading branch information
tpendragon committed Sep 18, 2019
2 parents c208c82 + 39481e0 commit ad54bc4
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 12 deletions.
2 changes: 0 additions & 2 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ def unique_custom_fields
config.response_model = AdjustedGroupedResponse
config.show.document_presenter_class = RTLShowPresenter
config.index.document_presenter_class = RTLIndexPresenter
config.navbar.partials = []
config.index.document_actions.delete(:bookmark)
config.repository_class = ::FriendlyIdRepository
config.http_method = :post
end
Expand Down
6 changes: 6 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ def document_thumbnail(document, image_options = {})
image_tag url, image_options if url.present?
end

# Gives the bookmarks path by document id instead of access id
# Use as an alternative to bookmark_path
def bookmarks_id_path(document)
Pathname.new('/').join("bookmarks", document.id).to_s
end

private

# Generate the URL for the configuration for the UV
Expand Down
3 changes: 3 additions & 0 deletions app/views/_user_util_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<li class="divider"></li>
<% end %>

<li>
<%= render partial: 'blacklight/nav/bookmark' %>
</li>
<li>
<%= link_to t('spotlight.header_links.logout'), main_app.destroy_user_session_path %>
</li>
Expand Down
27 changes: 27 additions & 0 deletions app/views/catalog/_bookmark_control.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<% 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 %>
21 changes: 11 additions & 10 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
end

mount Blacklight::Engine => '/'

concern :exportable, Blacklight::Routes::Exportable.new

resources :bookmarks do
concerns :exportable

collection do
delete 'clear'
end
end

root to: 'spotlight/exhibits#index'
resource :site, only: [:edit, :update], controller: 'spotlight/sites' do
collection do
Expand All @@ -34,20 +45,10 @@
get '/viewers', to: 'pages#viewers', as: 'viewers_page'
mount Spotlight::Engine, at: '/'

concern :exportable, Blacklight::Routes::Exportable.new

resources :solr_documents, only: [:show], path: '/catalog', controller: 'catalog' do
concerns :exportable
end

resources :bookmarks do
concerns :exportable

collection do
delete 'clear'
end
end

# Dynamic robots.txt
get '/robots.:format' => 'pages#robots'
mount Riiif::Engine => '/images', as: 'riiif'
Expand Down
45 changes: 45 additions & 0 deletions spec/features/bookmarks_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'rails_helper'

RSpec.describe 'Bookmarks', type: :feature, js: true do
let(:exhibit) { FactoryBot.create(:exhibit, title: 'Exhibit Title', slug: 'exhibit-title') }
let(:admin) { FactoryBot.create(:exhibit_admin, exhibit: exhibit) }
let(:id) { "67890" }
let(:id2) { "12345" }
let(:access_id) { '1r66j4408' }
let(:access_id2) { '2r66j4408' }
let(:document) { SolrDocument.new(id: id) }
let(:document2) { SolrDocument.new(id: id2) }

before do
sign_in admin
Spotlight::SolrDocumentSidecar.create!(
document: document2, exhibit: exhibit,
data: { "access_identifier_ssim" => [access_id2] }
)
Spotlight::SolrDocumentSidecar.create!(
document: document, exhibit: exhibit,
data: { "access_identifier_ssim" => [access_id] }
)

document.make_public! exhibit
document2.make_public! exhibit
document.reindex
document2.reindex
Blacklight.default_index.connection.commit
end

context "when checking the bookmark box" do
it "Adds bookmarks to the bookmark page" do
visit "/catalog?search_field=all_fields&q="
bookmark_box = "toggle_bookmark_#{id}"
check bookmark_box
expect(page).to have_content "In Bookmarks"

visit "/bookmarks"
expect(page).to have_content "1 entry found"

visit "/catalog?search_field=all_fields&q="
expect(page).to have_content "In Bookmarks"
end
end
end

0 comments on commit ad54bc4

Please sign in to comment.