Skip to content

Commit

Permalink
Merge pull request #2467 from samvera/i240-featured-collections-columns
Browse files Browse the repository at this point in the history
I240 featured collections columns
  • Loading branch information
sjproctor authored Feb 20, 2025
2 parents d3a0541 + 1e3c7af commit a3c450c
Show file tree
Hide file tree
Showing 8 changed files with 355 additions and 10 deletions.
18 changes: 9 additions & 9 deletions app/views/hyrax/homepage/_featured_collection_section.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div id="featured_collections">
<% if @featured_collection_list.empty? %>
<p id='no-collections'><%= t('hyrax.homepage.featured_collections.no_collections') %></p>
<p id="no-collections"><%= t('hyrax.homepage.featured_collections.no_collections') %></p>
<% elsif can? :update, FeaturedCollection %>
<%= form_for [main_app, @featured_collection_list] do |f| %>
<div class="dd" id="ff">
Expand All @@ -10,24 +10,24 @@
<% end %>
</ol>
</div>
<%= f.submit("Save order", class: 'btn btn-secondary') %>
<%= f.submit('Save order', class: 'btn btn-secondary') %>
<% end %>
<% else %>
<div class="container-fluid">
<%= form_for [main_app, @featured_collection_list] do |f| %>
<div class="row">
<table class="table table-striped collection-highlights">
<tbody>
<%= form_for [main_app, @featured_collection_list] do |f| %>
<%= f.fields_for :featured_collections do |featured| %>
<%= render 'explore_collections', f: featured %>
<% end %>
</div>
<% end %>
</div>
<% end %>
</tbody>
</table>
<% end %>
</div>
<ul class="list-inline collection-highlights-list">
<li>
<%= link_to t('hyrax.homepage.admin_sets.link'),
main_app.search_catalog_path(f: { generic_type_sim: ["Collection"]}),
main_app.search_catalog_path(f: { generic_type_sim: ['Collection']}),
class: 'btn btn-secondary mt-1' %>
</li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<%# OVERRIDE Hyrax v5.0.4 for theming - cultural repository homepage featured collections uses a grid layout %>

<div id="featured_collections">
<% if @featured_collection_list.empty? %>
<p id="no-collections"><%= t('hyrax.homepage.featured_collections.no_collections') %></p>
<% elsif can? :update, FeaturedCollection %>
<%= form_for [main_app, @featured_collection_list] do |f| %>
<div class="dd" id="ff">
<ol id="featured_works">
<%= f.fields_for :featured_collections do |featured| %>
<%= render 'hyrax/homepage/sortable_featured_collections', f: featured %>
<% end %>
</ol>
</div>
<%= f.submit('Save order', class: 'btn btn-secondary') %>
<% end %>
<% else %>
<div class="container">
<%= form_for [main_app, @featured_collection_list] do |f| %>
<div class="row">
<%= f.fields_for :featured_collections do |featured| %>
<%= render 'explore_collections', f: featured %>
<% end %>
</div>
<% end %>
</div>
<% end %>
</div>
<ul class="list-inline collection-highlights-list">
<li>
<%= link_to t('hyrax.homepage.admin_sets.link'),
main_app.search_catalog_path(f: { generic_type_sim: ['Collection']}),
class: 'btn btn-secondary mt-1' %>
</li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<%# OVERRIDE Hyrax v5.0.4 for theming - institutional repository homepage featured collections uses a grid layout %>

<div id="featured_collections">
<% if @featured_collection_list.empty? %>
<p id="no-collections"><%= t('hyrax.homepage.featured_collections.no_collections') %></p>
<% elsif can? :update, FeaturedCollection %>
<%= form_for [main_app, @featured_collection_list] do |f| %>
<div class="dd" id="ff">
<ol id="featured_works">
<%= f.fields_for :featured_collections do |featured| %>
<%= render 'hyrax/homepage/sortable_featured_collections', f: featured %>
<% end %>
</ol>
</div>
<%= f.submit('Save order', class: 'btn btn-secondary') %>
<% end %>
<% else %>
<div class="container">
<%= form_for [main_app, @featured_collection_list] do |f| %>
<div class="row">
<%= f.fields_for :featured_collections do |featured| %>
<%= render 'explore_collections', f: featured %>
<% end %>
</div>
<% end %>
</div>
<% end %>
</div>
<ul class="list-inline collection-highlights-list">
<li>
<%= link_to t('hyrax.homepage.admin_sets.link'),
main_app.search_catalog_path(f: { generic_type_sim: ['Collection']}),
class: 'btn btn-secondary mt-1' %>
</li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<%# OVERRIDE Hyrax v5.0.4 for theming - neutral repository homepage featured collections uses a grid layout %>

<div id="featured_collections">
<% if @featured_collection_list.empty? %>
<p id="no-collections"><%= t('hyrax.homepage.featured_collections.no_collections') %></p>
<% elsif can? :update, FeaturedCollection %>
<%= form_for [main_app, @featured_collection_list] do |f| %>
<div class="dd" id="ff">
<ol id="featured_works">
<%= f.fields_for :featured_collections do |featured| %>
<%= render 'hyrax/homepage/sortable_featured_collections', f: featured %>
<% end %>
</ol>
</div>
<%= f.submit('Save order', class: 'btn btn-secondary') %>
<% end %>
<% else %>
<div class="container">
<%= form_for [main_app, @featured_collection_list] do |f| %>
<div class="row">
<%= f.fields_for :featured_collections do |featured| %>
<%= render 'explore_collections', f: featured %>
<% end %>
</div>
<% end %>
</div>
<% end %>
</div>
<ul class="list-inline collection-highlights-list">
<li>
<%= link_to t('hyrax.homepage.admin_sets.link'),
main_app.search_catalog_path(f: { generic_type_sim: ['Collection']}),
class: 'btn btn-secondary mt-1' %>
</li>
</ul>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

before do
allow(view).to receive(:can?).with(:update, FeaturedCollection).and_return(false)
allow(view).to receive(:render_thumbnail_tag).with(presenter, any_args).and_return("thumbnail")
allow(view).to receive(:render_thumbnail_tag).with(presenter, any_args).and_return('thumbnail')
allow(list).to receive(:empty?).and_return(false)
allow(list).to receive(:featured_collections).and_return([featured_collection])
allow(featured_collection).to receive(:presenter).and_return(presenter)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# frozen_string_literal: true

RSpec.describe "themes/cultural_repository/hyrax/homepage/_featured_collection_section.html.erb", type: :view do
let(:list) { FeaturedCollectionList.new }
let(:presenter) do
Hyku::WorkShowPresenter.new(
SolrDocument.new(
id: '123',
title_tesim: ['Featured Collection'],
has_model_ssim: ['Collection']
),
nil
)
end
let(:featured_collection) { FeaturedCollection.new }
let(:rendered_template) { render }

before do
assign(:featured_collection_list, list)
allow(view).to receive(:can?).with(:update, FeaturedCollection).and_return(false)
allow(view).to receive(:render_thumbnail_tag).with(presenter, any_args).and_return('thumbnail')
allow(view).to receive(:main_app).and_return(main_app)
end

context "when there are no featured collections" do
before { render }

it "displays the 'no collections' message" do
expect(rendered).to have_content(t('hyrax.homepage.featured_collections.no_collections'))
end

it "does not show the form" do
expect(rendered).not_to have_selector('form')
end
end

context "when user can update featured collections" do
before do
allow(view).to receive(:can?).with(:update, FeaturedCollection).and_return(true)
allow(view).to receive(:can?).with(:destroy, FeaturedCollection).and_return(true)
allow(list).to receive(:empty?).and_return(false)
allow(list).to receive(:featured_collections).and_return([featured_collection])
allow(featured_collection).to receive(:presenter).and_return(presenter)

allow(view).to receive(:render_thumbnail_tag).with(
presenter.solr_document,
{ alt: "Featured Collection Thumbnail" },
{ suppress_link: true }
).and_return('thumbnail')

render
end

it "displays the form for reordering" do
expect(rendered).to have_selector('form')
expect(rendered).to have_selector('#ff')
expect(rendered).to have_selector('#featured_works')
expect(rendered).to have_selector('input[type="submit"][value="Save order"]')
end
end

context "when user cannot update featured collections" do
before do
allow(list).to receive(:empty?).and_return(false)
allow(list).to receive(:featured_collections).and_return([featured_collection])
allow(featured_collection).to receive(:presenter).and_return(presenter)
render
end

it "displays the collections in a grid" do
expect(rendered).to have_selector('.container')
expect(rendered).to have_selector('.row')
end

it "displays the link to browse all collections" do
expect(rendered).to have_selector('.collection-highlights-list')
expect(rendered).to have_link(t('hyrax.homepage.admin_sets.link'))
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# frozen_string_literal: true

RSpec.describe "themes/institutional_repository/hyrax/homepage/_featured_collection_section.html.erb", type: :view do
let(:list) { FeaturedCollectionList.new }
let(:presenter) do
Hyku::WorkShowPresenter.new(
SolrDocument.new(
id: '123',
title_tesim: ['Featured Collection'],
has_model_ssim: ['Collection']
),
nil
)
end
let(:featured_collection) { FeaturedCollection.new }
let(:rendered_template) { render }

before do
assign(:featured_collection_list, list)
allow(view).to receive(:can?).with(:update, FeaturedCollection).and_return(false)
allow(view).to receive(:render_thumbnail_tag).with(presenter, any_args).and_return('thumbnail')
allow(view).to receive(:main_app).and_return(main_app)
end

context "when there are no featured collections" do
before { render }

it "displays the 'no collections' message" do
expect(rendered).to have_content(t('hyrax.homepage.featured_collections.no_collections'))
end

it "does not show the form" do
expect(rendered).not_to have_selector('form')
end
end

context "when user can update featured collections" do
before do
allow(view).to receive(:can?).with(:update, FeaturedCollection).and_return(true)
allow(view).to receive(:can?).with(:destroy, FeaturedCollection).and_return(true)
allow(list).to receive(:empty?).and_return(false)
allow(list).to receive(:featured_collections).and_return([featured_collection])
allow(featured_collection).to receive(:presenter).and_return(presenter)

allow(view).to receive(:render_thumbnail_tag).with(
presenter.solr_document,
{ alt: "Featured Collection Thumbnail" },
{ suppress_link: true }
).and_return('thumbnail')

render
end

it "displays the form for reordering" do
expect(rendered).to have_selector('form')
expect(rendered).to have_selector('#ff')
expect(rendered).to have_selector('#featured_works')
expect(rendered).to have_selector('input[type="submit"][value="Save order"]')
end
end

context "when user cannot update featured collections" do
before do
allow(list).to receive(:empty?).and_return(false)
allow(list).to receive(:featured_collections).and_return([featured_collection])
allow(featured_collection).to receive(:presenter).and_return(presenter)
render
end

it "displays the collections in a grid" do
expect(rendered).to have_selector('.container')
expect(rendered).to have_selector('.row')
end

it "displays the link to browse all collections" do
expect(rendered).to have_selector('.collection-highlights-list')
expect(rendered).to have_link(t('hyrax.homepage.admin_sets.link'))
end
end
end
Loading

0 comments on commit a3c450c

Please sign in to comment.