Skip to content

Commit

Permalink
show parent collections on collection show pages
Browse files Browse the repository at this point in the history
  • Loading branch information
elrayle committed Jan 16, 2018
1 parent 7f0c671 commit e442dec
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def _prefixes
def query_collection_members
member_works
member_subcollections if collection.collection_type.nestable?
parent_collections if collection.collection_type.nestable?
end

# Instantiate the membership query service
Expand All @@ -78,6 +79,13 @@ def member_works
@members_count = @response.total
end

def parent_collections
col = @collection
col = Collection.find(collection.id) if col.blank?
@parent_collections = col.member_of_collections
@parent_collection_count = @parent_collections.size
end

def member_subcollections
results = collection_member_service.available_member_subcollections
@subcollection_docs = results.documents
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/hyrax/dashboard/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ def set_default_permissions
def query_collection_members
member_works
member_subcollections if collection.collection_type.nestable?
parent_collections if collection.collection_type.nestable?
end

# Instantiate the membership query service
Expand All @@ -447,6 +448,13 @@ def member_subcollections
@subcollection_count = results.total
end

def parent_collections
col = @collection
col = Collection.find(collection.id) if col.blank?
@parent_collections = col.member_of_collections
@parent_collection_count = @parent_collections.size
end

# You can override this method if you need to provide additional
# inputs to the search builder. For example:
# search_field: 'all_fields'
Expand Down
15 changes: 15 additions & 0 deletions app/views/hyrax/collections/_show_parent_collections.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% if @parent_collections.nil? || @parent_collections.empty? %>
<div class="alert alert-warning" role="alert"><%= t('hyrax.collections.show.no_visible_parent_collections') %></div>
<% else %>
<div class="media-body">
<h4 class="media-heading">
<% @parent_collections.each do |document| %>
<ul>
<li>
<%= link_to document, [hyrax, document], id: "src_copy_link_#{document.id}" %>
</li>
</ul>
<% end %>
</h4>
</div>
<% end %>
16 changes: 16 additions & 0 deletions app/views/hyrax/collections/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@
<div class="row hyc-body">
<div class="col-md-8 hyc-description">
<%= render 'collection_description', presenter: @presenter %>

<% if @presenter.collection_type_is_nestable? && @parent_collection_count > 0 %>
<div class="row hyc-blacklight hyc-bl-title">
<div class="col-md-12">
<h2>
<%= t('.parent_collection_header') %> (<%= @parent_collection_count %>)
</h2>
</div>
</div>
<div class="row hyc-blacklight hyc-bl-results">
<div class="col-md-12">
<%= render 'show_parent_collections', collection: @parent_collections %>
</div>
</div>
<% end %>

</div>
<div class="col-md-4 hyc-metadata">
<% unless has_collection_search_parameters? %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% if @parent_collections.nil? || @parent_collections.empty? %>
<div class="alert alert-warning" role="alert"><%= t('hyrax.collections.show.no_visible_parent_collections') %></div>
<% else %>
<div class="media-body">
<h4 class="media-heading">
<% @parent_collections.each do |document| %>
<ul>
<li>
<%= link_to document, [hyrax, :dashboard, document], id: "src_copy_link_#{document.id}" %>
</li>
</ul>
<% end %>
</h4>
</div>
<% end %>
10 changes: 9 additions & 1 deletion app/views/hyrax/dashboard/collections/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@
<%= render 'hyrax/collections/media_display', presenter: @presenter %>
<%= link_to t('.public_view_label'), collection_path(id: @presenter.id) %>
</div>
<!-- Collection Description(s) -->
<div class="col-sm-9 collection-description-wrapper">
<!-- Parent Collection(s) -->
<% if @presenter.collection_type_is_nestable? %>
<h3><%= t('.parent_collection_header') %> (<%= @parent_collection_count %>)</h3>
<section class="parent-collections-wrapper">
<%= render 'hyrax/dashboard/collections/show_parent_collections', presenter: @presenter %>
</section>
<% end %>

<!-- Collection Description(s) -->
<section>
<%= render 'hyrax/collections/collection_description', presenter: @presenter %>
</section>
Expand Down
9 changes: 6 additions & 3 deletions config/locales/hyrax.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,11 @@ en:
label: "Search Collection %{title}"
placeholder: "Search subcollections and works in this collection"
show:
works_in_collection: "Works"
subcollection_count: "Subcollections"
no_visible_parent_collections: "There are no visible parent collections."
no_visible_subcollections: "There are no visible subcollections."
parent_collection_header: "Parent Collections"
subcollection_count: "Subcollections"
works_in_collection: "Works"
collection_type:
default_title: "User Collection"
admin_set_title: "Admin Set"
Expand Down Expand Up @@ -626,6 +628,7 @@ en:
show:
header: "Collection"
item_count: "Works"
parent_collection_header: "Parent Collections"
public_view_label: "Public view of Collection"
search_results: "Search Results within this Collection"
subcollection_count: "Subcollections"
Expand Down Expand Up @@ -1109,7 +1112,7 @@ en:
labels:
collection:
size: "Size"
total_items: "Total works"
total_items: "Total items"
collection_type:
allow_multiple_membership: "MULTIPLE MEMBERSHIP"
assigns_workflow: "WORKFLOW"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
render
expect(rendered).to have_content 'Date Created'
expect(rendered).to include('itemprop="dateCreated"')
expect(rendered).to have_content 'Total works'
expect(rendered).to have_content 'Total items'
expect(rendered).to have_content '2'
expect(rendered).to have_content 'Size'
expect(rendered).to have_content '118 MB'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
RSpec.describe 'hyrax/collections/_show_parent_collections.html.erb', type: :view do
let(:collection) { build(:named_collection, id: '123') }

context 'when parent collection list is empty' do
let(:parentcollection) { nil }

before do
assign(:parent_collections, parentcollection)
end

it "posts a warning message" do
render('show_parent_collections.html.erb', collection: parentcollection)
expect(rendered).to have_text("There are no visible parent collections.")
end
end

context 'when parent collection list is not empty' do
let(:parentcollection) { [collection] }

before do
assign(:parent_collections, parentcollection)
assign(:document, collection)
allow(collection).to receive(:title_or_label).and_return(collection.title)
allow(collection).to receive(:persisted?).and_return true
render('show_parent_collections.html.erb', collection: parentcollection)
end

it "posts the collection's title with a link to the collection" do
expect(rendered).to have_link(collection.title.first)
end

xit 'includes a count of the parent collections' do
# TODO: add test when actual count is added to page
end
end
end
1 change: 1 addition & 0 deletions spec/views/hyrax/collections/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
allow(presenter).to receive(:collection_type_is_nestable?).and_return(true)
allow(presenter).to receive(:total_items).and_return(0)
assign(:subcollection_count, 0)
assign(:parent_collection_count, 0)
assign(:members_count, 0)
allow(presenter).to receive(:banner_file).and_return("banner.gif")
allow(presenter).to receive(:logo_record).and_return([{ linkurl: "logo link url", alttext: "logo alt text", file_location: "logo.gif" }])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
render
expect(rendered).to have_content 'Date Created'
expect(rendered).to include('itemprop="dateCreated"')
expect(rendered).to have_content 'Total works'
expect(rendered).to have_content 'Total items'
expect(rendered).to have_content '2'
expect(rendered).to have_content 'Size'
expect(rendered).to have_content '118 MB'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
RSpec.describe 'hyrax/dashboard/collections/_show_parent_collections.html.erb', type: :view do
let(:collection) { build(:named_collection, id: '123') }

context 'when parent collection list is empty' do
let(:parentcollection) { nil }

before do
assign(:parent_collections, parentcollection)
end

it "posts a warning message" do
render('show_parent_collections.html.erb', collection: parentcollection)
expect(rendered).to have_text("There are no visible parent collections.")
end
end

context 'when parent collection list is not empty' do
let(:parentcollection) { [collection] }

before do
assign(:parent_collections, parentcollection)
assign(:document, collection)
allow(collection).to receive(:title_or_label).and_return(collection.title)
allow(collection).to receive(:persisted?).and_return true
render('show_parent_collections.html.erb', collection: parentcollection)
end

it "posts the collection's title with a link to the collection" do
expect(rendered).to have_link(collection.title.first)
end

xit 'includes a count of the parent collections' do
# TODO: add test when actual count is added to page
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
stub_template '_show_actions.html.erb' => '<div class="stubbed-actions">THE COLLECTION ACTIONS</div>'
stub_template '_show_subcollection_actions.html.erb' => '<div class="stubbed-actions">THE SUBCOLLECTION ACTIONS</div>'
stub_template '_show_add_items_actions.html.erb' => '<div class="stubbed-actions">THE ADD ITEMS ACTIONS</div>'
stub_template '_show_parent_collections.html.erb' => '<div class="stubbed-actions">THE PARENT COLLECTIONS LIST</div>'
stub_template 'hyrax/collections/_paginate.html.erb' => 'paginate'
stub_template 'hyrax/collections/_media_display.html.erb' => '<span class="fa fa-cubes collection-icon-search"></span>'
stub_template 'hyrax/my/collections/_modal_add_to_collection.html.erb' => 'modal add as subcollection'
Expand Down

0 comments on commit e442dec

Please sign in to comment.