Skip to content

Commit

Permalink
Card image pagination
Browse files Browse the repository at this point in the history
* Delete unused template
* Do not show SubGuide heading if there are not any SubGuide cards 
* Removed home link from the show pages 

Co-authored-by: Anna Headley <hackartisan@users.noreply.github.com>
Co-authored-by: Bess Sadler <bess@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 2, 2023
1 parent a38160c commit 58c3ccc
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/controllers/guide_cards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ def search
def show
@guide_card = GuideCard.find(params[:id])
@sub_guide_cards = @guide_card.children
@card_images = CardImage.where(path: @guide_card.path)
@card_images = CardImage.where(path: @guide_card.path).page(params[:page])
end
end
2 changes: 1 addition & 1 deletion app/models/card_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Class for CardImage data models
class CardImage < ApplicationRecord
paginates_per 8
paginates_per 10
def iiif_url
"https://puliiif.princeton.edu/iiif/2/#{image_name.gsub('.tif', '')}/full/,500/0/default.jpg"
end
Expand Down
22 changes: 12 additions & 10 deletions app/views/guide_cards/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<h2>Guide: <%= @guide_card.heading %></h2>

<%= render "shared/return_to_home" %>
<% if @sub_guide_cards.present? %>
<h3>SubGuide Cards</h3>
<ul id="sg_index">
<% @sub_guide_cards.each do |sub_guide| %>
<li> <%= link_to sub_guide.heading, sub_guide_card_path(sub_guide.id) %> </li>
<% end %>
</ul>
<% end %>

<h3>List of SubGuide Cards</h3>
<ul id="sg_index">
<% @sub_guide_cards.each do |sub_guide| %>
<li> <%= link_to sub_guide.heading, sub_guide_card_path(sub_guide.id) %> </li>
<% end %>
</ul>

<% @card_images.each do |image| %>
<% @card_images.each do |image| %>
<ul>
<%= image_tag(image.iiif_url, alt: "Catalog Card") %>
</ul>
<% end %>
<% end %>

<%= paginate @card_images %>
2 changes: 0 additions & 2 deletions app/views/sub_guide_cards/index.html.erb

This file was deleted.

2 changes: 0 additions & 2 deletions app/views/sub_guide_cards/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<h2>SubGuide: <%= @sub_guide_card.heading %></h2>
<p><%= page_entries_info @card_images, entry_name: 'card' %></p>

<%= render "shared/return_to_home" %>

<%= paginate @card_images %>

<% if @sub_guide_card.children.present? %>
Expand Down
27 changes: 27 additions & 0 deletions spec/system/card_image_pagination_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Card Images Pagination', type: :system, js: true do
let(:guide_card_fixture) { Rails.root.join('spec', 'fixtures', 'guide_card_fixture.csv') }
before do
GuideCardLoadingService.new(csv_location: guide_card_fixture).import
(1..21).each do |i|
ci = CardImage.new
ci.path = '14/0001/B4491'
ci.image_name = "fake_image_#{i}.jpg"
ci.save
end
end

describe 'GuideCards show page' do
it 'displays and paginates through card images' do
visit '/guide_cards/2'
expect(page.all('div#main-content ul img').count).to eq 10
expect(page.all('div#main-content ul img').last[:src]).to match(/fake_image_10.jpg/)
expect(page).to have_link('Next', href: '/guide_cards/2?page=2')
click_link('Next')
expect(page.all('div#main-content ul img')[3][:src]).to match(/fake_image_14.jpg/)
end
end
end
7 changes: 7 additions & 0 deletions spec/system/guide_cards_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,11 @@
expect(page).to have_selector('img[alt]')
end
end

context 'when a GuideCard has no SubGuide cards' do
it 'displays text to that effect' do
visit '/guide_cards/2'
expect(page).not_to have_text('SubGuide Cards')
end
end
end

0 comments on commit 58c3ccc

Please sign in to comment.