From 19db486cda40c892afb1111bb3d35d482ab1fbb2 Mon Sep 17 00:00:00 2001 From: Radhika Chippada Date: Tue, 28 Apr 2015 14:06:28 -0400 Subject: [PATCH] 5622: when there are too many collections matching a pdh, show only 20 of them. --- .../app/assets/javascripts/infinite_scroll.js | 34 +++++++++++++++++++ .../app/controllers/collections_controller.rb | 4 ++- .../views/collections/hash_matches.html.erb | 8 ++++- .../test/integration/collections_test.rb | 20 +++++++++-- 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/apps/workbench/app/assets/javascripts/infinite_scroll.js b/apps/workbench/app/assets/javascripts/infinite_scroll.js index 81a3a4639b..6e467f5594 100644 --- a/apps/workbench/app/assets/javascripts/infinite_scroll.js +++ b/apps/workbench/app/assets/javascripts/infinite_scroll.js @@ -1,3 +1,37 @@ +// infinite_scroll.js displays a tab's content using automatic scrolling +// when the user scrolls to the bottom of the page and there is more data. +// +// Usage: +// +// 1. Adding infinite scrolling to a tab pane using "show" method +// +// The steps below describe adding scrolling to the project#show action. +// +// a. In the "app/views/projects/" folder add a file for your tab +// (ex: _show_jobs_and_pipelines.html.erb) +// In this file, add a div or tbody with data-infinite-scroller. +// Note: This page uses _show_tab_contents.html.erb so that +// several tabs can reuse this implementation. +// Also add the filters to be used for loading the tab content. +// +// b. Add a file named "_show_contents_rows.html.erb" that loads +// the data (by invoking get_objects_and_names from the controller). +// +// c. In the "app/controllers/projects_controller.rb, +// Update the show method to add a block for "params[:partial]" +// that loads the show_contents_rows partial. +// Optionally, add a "tab_counts" method that loads the total number +// of objects count to be displayed for this tab. +// +// 2. Adding infinite scrolling to the "Recent" tab in "index" page +// The steps below describe adding scrolling to the pipeline_instances index page. +// +// a. In the "app/views/pipeline_instances/_show_recent.html.erb/" file +// add a div or tbody with data-infinite-scroller. +// +// b. Add the partial "_show_recent_rows.html.erb" that displays the +// page contents on scroll using the @objects + function maybe_load_more_content(event) { var scroller = this; var $container = $(event.data.container); diff --git a/apps/workbench/app/controllers/collections_controller.rb b/apps/workbench/app/controllers/collections_controller.rb index 8d25e68eef..0610fd2e81 100644 --- a/apps/workbench/app/controllers/collections_controller.rb +++ b/apps/workbench/app/controllers/collections_controller.rb @@ -198,7 +198,7 @@ class CollectionsController < ApplicationController if current_user if Keep::Locator.parse params["uuid"] - @same_pdh = Collection.filter([["portable_data_hash", "=", @object.portable_data_hash]]) + @same_pdh = Collection.filter([["portable_data_hash", "=", @object.portable_data_hash]]).limit(20) if @same_pdh.results.size == 1 redirect_to collection_path(@same_pdh[0]["uuid"]) return @@ -206,6 +206,8 @@ class CollectionsController < ApplicationController owners = @same_pdh.map(&:owner_uuid).to_a.uniq preload_objects_for_dataclass Group, owners preload_objects_for_dataclass User, owners + uuids = @same_pdh.map(&:uuid).to_a.uniq + preload_links_for_objects uuids render 'hash_matches' return else diff --git a/apps/workbench/app/views/collections/hash_matches.html.erb b/apps/workbench/app/views/collections/hash_matches.html.erb index 7c4abb080e..c93b6acbda 100644 --- a/apps/workbench/app/views/collections/hash_matches.html.erb +++ b/apps/workbench/app/views/collections/hash_matches.html.erb @@ -1,3 +1,9 @@ +<% + message = "The following collections have this content:" + if @same_pdh.items_available > @same_pdh.results.size + message += ' (' + (@same_pdh.items_available - @same_pdh.results.size).to_s + ' more results are not shown)' + end +%>
@@ -5,7 +11,7 @@

<%= params["uuid"] %>

-

The following collections have this content:

+

<%= message %>

<% @same_pdh.sort { |a,b| b.created_at <=> a.created_at }.each do |c| %>
diff --git a/apps/workbench/test/integration/collections_test.rb b/apps/workbench/test/integration/collections_test.rb index 4a7014c37d..16c82402c0 100644 --- a/apps/workbench/test/integration/collections_test.rb +++ b/apps/workbench/test/integration/collections_test.rb @@ -212,7 +212,7 @@ class CollectionsTest < ActionDispatch::IntegrationTest end test "Collection portable data hash with multiple matches" do - pdh = api_fixture('collections')['baz_file']['portable_data_hash'] + pdh = api_fixture('collections')['foo_file']['portable_data_hash'] visit page_with_token('admin', "/collections/#{pdh}") matches = api_fixture('collections').select {|k,v| v["portable_data_hash"] == pdh} @@ -221,8 +221,22 @@ class CollectionsTest < ActionDispatch::IntegrationTest matches.each do |k,v| assert page.has_link?(v["name"]), "Page /collections/#{pdh} should contain link '#{v['name']}'" end - assert page.has_no_text?("Activity") - assert page.has_no_text?("Sharing and permissions") + assert_text 'The following collections have this content:' + assert_no_text 'more results are not shown' + assert_no_text 'Activity' + assert_no_text 'Sharing and permissions' + end + + test "Collection portable data hash with multiple matches with more than one page of results" do + pdh = api_fixture('collections')['baz_file']['portable_data_hash'] + visit page_with_token('admin', "/collections/#{pdh}") + + assert_selector 'a', text: 'Collection_1' + + assert_text 'The following collections have this content:' + assert_text 'more results are not shown' + assert_no_text 'Activity' + assert_no_text 'Sharing and permissions' end test "Filtering collection files by regexp" do -- 2.39.5