From e442dec86d3729d488ff934eb4c4d9216b7b94c0 Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Tue, 16 Jan 2018 08:04:29 -0500 Subject: [PATCH] show parent collections on collection show pages --- .../hyrax/collections_controller_behavior.rb | 8 +++++ .../hyrax/dashboard/collections_controller.rb | 8 +++++ .../_show_parent_collections.html.erb | 15 ++++++++ app/views/hyrax/collections/show.html.erb | 16 +++++++++ .../_show_parent_collections.html.erb | 15 ++++++++ .../hyrax/dashboard/collections/show.html.erb | 10 +++++- config/locales/hyrax.en.yml | 9 +++-- .../_show_descriptions.html.erb_spec.rb | 2 +- .../_show_parent_collections.html.erb_spec.rb | 36 +++++++++++++++++++ .../hyrax/collections/show.html.erb_spec.rb | 1 + .../_show_descriptions.html.erb_spec.rb | 2 +- .../_show_parent_collections.html.erb_spec.rb | 36 +++++++++++++++++++ .../collections/show.html.erb_spec.rb | 1 + 13 files changed, 153 insertions(+), 6 deletions(-) create mode 100644 app/views/hyrax/collections/_show_parent_collections.html.erb create mode 100644 app/views/hyrax/dashboard/collections/_show_parent_collections.html.erb create mode 100644 spec/views/hyrax/collections/_show_parent_collections.html.erb_spec.rb create mode 100644 spec/views/hyrax/dashboard/collections/_show_parent_collections.html.erb_spec.rb diff --git a/app/controllers/concerns/hyrax/collections_controller_behavior.rb b/app/controllers/concerns/hyrax/collections_controller_behavior.rb index 21501b96b8..d0b4f42247 100644 --- a/app/controllers/concerns/hyrax/collections_controller_behavior.rb +++ b/app/controllers/concerns/hyrax/collections_controller_behavior.rb @@ -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 @@ -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 diff --git a/app/controllers/hyrax/dashboard/collections_controller.rb b/app/controllers/hyrax/dashboard/collections_controller.rb index 96a344b24e..52e54d84ef 100644 --- a/app/controllers/hyrax/dashboard/collections_controller.rb +++ b/app/controllers/hyrax/dashboard/collections_controller.rb @@ -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 @@ -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' diff --git a/app/views/hyrax/collections/_show_parent_collections.html.erb b/app/views/hyrax/collections/_show_parent_collections.html.erb new file mode 100644 index 0000000000..8c3776f77d --- /dev/null +++ b/app/views/hyrax/collections/_show_parent_collections.html.erb @@ -0,0 +1,15 @@ +<% if @parent_collections.nil? || @parent_collections.empty? %> + +<% else %> +
+

+ <% @parent_collections.each do |document| %> +
    +
  • + <%= link_to document, [hyrax, document], id: "src_copy_link_#{document.id}" %> +
  • +
+ <% end %> +

+
+<% end %> diff --git a/app/views/hyrax/collections/show.html.erb b/app/views/hyrax/collections/show.html.erb index 4acc886f8c..b92da34e9f 100644 --- a/app/views/hyrax/collections/show.html.erb +++ b/app/views/hyrax/collections/show.html.erb @@ -55,6 +55,22 @@
<%= render 'collection_description', presenter: @presenter %> + + <% if @presenter.collection_type_is_nestable? && @parent_collection_count > 0 %> +
+
+

+ <%= t('.parent_collection_header') %> (<%= @parent_collection_count %>) +

+
+
+
+
+ <%= render 'show_parent_collections', collection: @parent_collections %> +
+
+ <% end %> +
-
+ + <% if @presenter.collection_type_is_nestable? %> +

<%= t('.parent_collection_header') %> (<%= @parent_collection_count %>)

+
+ <%= render 'hyrax/dashboard/collections/show_parent_collections', presenter: @presenter %> +
+ <% end %> + +
<%= render 'hyrax/collections/collection_description', presenter: @presenter %>
diff --git a/config/locales/hyrax.en.yml b/config/locales/hyrax.en.yml index 7cb46785d8..a106f94b09 100644 --- a/config/locales/hyrax.en.yml +++ b/config/locales/hyrax.en.yml @@ -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" @@ -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" @@ -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" diff --git a/spec/views/hyrax/collections/_show_descriptions.html.erb_spec.rb b/spec/views/hyrax/collections/_show_descriptions.html.erb_spec.rb index 3067c0872b..da07f45476 100644 --- a/spec/views/hyrax/collections/_show_descriptions.html.erb_spec.rb +++ b/spec/views/hyrax/collections/_show_descriptions.html.erb_spec.rb @@ -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' diff --git a/spec/views/hyrax/collections/_show_parent_collections.html.erb_spec.rb b/spec/views/hyrax/collections/_show_parent_collections.html.erb_spec.rb new file mode 100644 index 0000000000..497c3040e5 --- /dev/null +++ b/spec/views/hyrax/collections/_show_parent_collections.html.erb_spec.rb @@ -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 diff --git a/spec/views/hyrax/collections/show.html.erb_spec.rb b/spec/views/hyrax/collections/show.html.erb_spec.rb index dcd24dbb2c..b874d213cf 100644 --- a/spec/views/hyrax/collections/show.html.erb_spec.rb +++ b/spec/views/hyrax/collections/show.html.erb_spec.rb @@ -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" }]) diff --git a/spec/views/hyrax/dashboard/collections/_show_descriptions.html.erb_spec.rb b/spec/views/hyrax/dashboard/collections/_show_descriptions.html.erb_spec.rb index 1793133ed8..b8bcc25681 100644 --- a/spec/views/hyrax/dashboard/collections/_show_descriptions.html.erb_spec.rb +++ b/spec/views/hyrax/dashboard/collections/_show_descriptions.html.erb_spec.rb @@ -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' diff --git a/spec/views/hyrax/dashboard/collections/_show_parent_collections.html.erb_spec.rb b/spec/views/hyrax/dashboard/collections/_show_parent_collections.html.erb_spec.rb new file mode 100644 index 0000000000..92fcecddcf --- /dev/null +++ b/spec/views/hyrax/dashboard/collections/_show_parent_collections.html.erb_spec.rb @@ -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 diff --git a/spec/views/hyrax/dashboard/collections/show.html.erb_spec.rb b/spec/views/hyrax/dashboard/collections/show.html.erb_spec.rb index 264318892b..bb0a1e0d91 100644 --- a/spec/views/hyrax/dashboard/collections/show.html.erb_spec.rb +++ b/spec/views/hyrax/dashboard/collections/show.html.erb_spec.rb @@ -37,6 +37,7 @@ stub_template '_show_actions.html.erb' => '
THE COLLECTION ACTIONS
' stub_template '_show_subcollection_actions.html.erb' => '
THE SUBCOLLECTION ACTIONS
' stub_template '_show_add_items_actions.html.erb' => '
THE ADD ITEMS ACTIONS
' + stub_template '_show_parent_collections.html.erb' => '
THE PARENT COLLECTIONS LIST
' stub_template 'hyrax/collections/_paginate.html.erb' => 'paginate' stub_template 'hyrax/collections/_media_display.html.erb' => '' stub_template 'hyrax/my/collections/_modal_add_to_collection.html.erb' => 'modal add as subcollection'