Skip to content

Commit 58c3ccc

Browse files
leefaisonrhackartisanbess
authored
Card image pagination
* 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 <[email protected]> Co-authored-by: Bess Sadler <[email protected]>
1 parent a38160c commit 58c3ccc

File tree

7 files changed

+48
-16
lines changed

7 files changed

+48
-16
lines changed

app/controllers/guide_cards_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ def search
2323
def show
2424
@guide_card = GuideCard.find(params[:id])
2525
@sub_guide_cards = @guide_card.children
26-
@card_images = CardImage.where(path: @guide_card.path)
26+
@card_images = CardImage.where(path: @guide_card.path).page(params[:page])
2727
end
2828
end

app/models/card_image.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Class for CardImage data models
44
class CardImage < ApplicationRecord
5-
paginates_per 8
5+
paginates_per 10
66
def iiif_url
77
"https://puliiif.princeton.edu/iiif/2/#{image_name.gsub('.tif', '')}/full/,500/0/default.jpg"
88
end
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
<h2>Guide: <%= @guide_card.heading %></h2>
22

3-
<%= render "shared/return_to_home" %>
3+
<% if @sub_guide_cards.present? %>
4+
<h3>SubGuide Cards</h3>
5+
<ul id="sg_index">
6+
<% @sub_guide_cards.each do |sub_guide| %>
7+
<li> <%= link_to sub_guide.heading, sub_guide_card_path(sub_guide.id) %> </li>
8+
<% end %>
9+
</ul>
10+
<% end %>
411

5-
<h3>List of SubGuide Cards</h3>
6-
<ul id="sg_index">
7-
<% @sub_guide_cards.each do |sub_guide| %>
8-
<li> <%= link_to sub_guide.heading, sub_guide_card_path(sub_guide.id) %> </li>
9-
<% end %>
10-
</ul>
11-
12-
<% @card_images.each do |image| %>
12+
<% @card_images.each do |image| %>
1313
<ul>
1414
<%= image_tag(image.iiif_url, alt: "Catalog Card") %>
1515
</ul>
16-
<% end %>
16+
<% end %>
17+
18+
<%= paginate @card_images %>

app/views/sub_guide_cards/index.html.erb

Lines changed: 0 additions & 2 deletions
This file was deleted.

app/views/sub_guide_cards/show.html.erb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<h2>SubGuide: <%= @sub_guide_card.heading %></h2>
22
<p><%= page_entries_info @card_images, entry_name: 'card' %></p>
33

4-
<%= render "shared/return_to_home" %>
5-
64
<%= paginate @card_images %>
75

86
<% if @sub_guide_card.children.present? %>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
RSpec.describe 'Card Images Pagination', type: :system, js: true do
6+
let(:guide_card_fixture) { Rails.root.join('spec', 'fixtures', 'guide_card_fixture.csv') }
7+
before do
8+
GuideCardLoadingService.new(csv_location: guide_card_fixture).import
9+
(1..21).each do |i|
10+
ci = CardImage.new
11+
ci.path = '14/0001/B4491'
12+
ci.image_name = "fake_image_#{i}.jpg"
13+
ci.save
14+
end
15+
end
16+
17+
describe 'GuideCards show page' do
18+
it 'displays and paginates through card images' do
19+
visit '/guide_cards/2'
20+
expect(page.all('div#main-content ul img').count).to eq 10
21+
expect(page.all('div#main-content ul img').last[:src]).to match(/fake_image_10.jpg/)
22+
expect(page).to have_link('Next', href: '/guide_cards/2?page=2')
23+
click_link('Next')
24+
expect(page.all('div#main-content ul img')[3][:src]).to match(/fake_image_14.jpg/)
25+
end
26+
end
27+
end

spec/system/guide_cards_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,11 @@
4141
expect(page).to have_selector('img[alt]')
4242
end
4343
end
44+
45+
context 'when a GuideCard has no SubGuide cards' do
46+
it 'displays text to that effect' do
47+
visit '/guide_cards/2'
48+
expect(page).not_to have_text('SubGuide Cards')
49+
end
50+
end
4451
end

0 commit comments

Comments
 (0)