Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imagecat i157 tidy up #159

Merged
merged 7 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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