From e5337814593c504ef71e9f517dc1d99d41e19784 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Sat, 9 Aug 2014 19:44:14 -0400 Subject: [PATCH] 3531: Refactor project tab infinite-scroll. Sort jobs and pipelines together by date, instead of sorting first by type. --- .../app/assets/javascripts/infinite_scroll.js | 3 +- .../app/controllers/application_controller.rb | 3 + .../app/controllers/projects_controller.rb | 71 +++++++++++++------ .../projects/_show_contents_rows.html.erb | 6 +- .../projects/_show_data_collections.html.erb | 12 ++-- .../_show_jobs_and_pipelines.html.erb | 12 ++-- .../projects/_show_other_objects.html.erb | 12 ++-- .../views/projects/_show_subprojects.html.erb | 12 ++-- .../projects/_show_tab_contents.html.erb | 4 +- 9 files changed, 75 insertions(+), 60 deletions(-) diff --git a/apps/workbench/app/assets/javascripts/infinite_scroll.js b/apps/workbench/app/assets/javascripts/infinite_scroll.js index 2cb9748dad..6299cc54a8 100644 --- a/apps/workbench/app/assets/javascripts/infinite_scroll.js +++ b/apps/workbench/app/assets/javascripts/infinite_scroll.js @@ -111,6 +111,7 @@ $(document). $scroller = $(window); $scroller. addClass('infinite-scroller'). - on('scroll', { container: this }, maybe_load_more_content); + on('scroll', { container: this }, maybe_load_more_content). + trigger('scroll'); }); }); diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb index 18397e1008..ae94dac8c8 100644 --- a/apps/workbench/app/controllers/application_controller.rb +++ b/apps/workbench/app/controllers/application_controller.rb @@ -89,6 +89,9 @@ class ApplicationController < ActionController::Base end def load_filters_and_paging_params + @order = params[:order] || 'created_at desc' + @order = [@order] unless @order.is_a? Array + @limit ||= 200 if params[:limit] @limit = params[:limit].to_i diff --git a/apps/workbench/app/controllers/projects_controller.rb b/apps/workbench/app/controllers/projects_controller.rb index 9f4c588775..ea3103d9a8 100644 --- a/apps/workbench/app/controllers/projects_controller.rb +++ b/apps/workbench/app/controllers/projects_controller.rb @@ -128,20 +128,52 @@ class ProjectsController < ApplicationController super end + def load_contents_objects kinds=[] + @limit = 5 + kind_filters = @filters.select do |attr,op,val| + op == 'is_a' and val.is_a? Array and val.count > 1 + end + if /^created_at/ =~ @order[0] and kind_filters.count == 1 + # If filtering on multiple types and sorting by date: Get the + # first page of each type, sort the entire set, truncate to one + # page, and use the last item on this page as a filter for + # retrieving the next page. Ideally the API would do this for + # us, but it doesn't (yet). + @objects = [] + kind_filters.each do |attr,op,val| + (val.is_a?(Array) ? val : [val]).each do |type| + @objects += @object.contents(order: @order, + limit: @limit, + include_linked: true, + filters: (@filters - kind_filters + [['uuid', 'is_a', type]]), + offset: @offset) + end + end + @objects = @objects.to_a.sort_by(&:created_at).reverse[0..@limit-1] + @next_page_filters = @filters.reject do |attr,op,val| + attr == 'created_at' and op == '<' + end + if @objects.any? + @next_page_filters += [['created_at', '<', @objects.last.created_at]] + @next_page_href = url_for(partial: :contents_rows, + filters: @next_page_filters.to_json) + else + @next_page_href = nil + end + else + @objects = @object.contents(order: @order, + limit: @limit, + include_linked: true, + filters: @filters, + offset: @offset) + @next_page_href = next_page_href(partial: :contents_rows) + end + end + def show if !@object return render_not_found("object not found") end - @objects = @object.contents(limit: 50, - include_linked: true, - filters: params[:filters], - offset: params[:offset] || 0) - @logs = Log.limit(10).filter([['object_uuid', '=', @object.uuid]]) - @users = User.limit(10000). - select(["uuid", "is_active", "first_name", "last_name"]). - filter([['is_active', '=', 'true']]) - @groups = Group.limit(10000). - select(["uuid", "name", "description"]) @user_is_manager = false @share_links = [] @@ -154,24 +186,19 @@ class ProjectsController < ApplicationController end end - @objects_and_names = get_objects_and_names @objects - if params[:partial] + load_contents_objects respond_to do |f| f.json { render json: { content: render_to_string(partial: 'show_contents_rows.html', - formats: [:html], - locals: { - objects_and_names: @objects_and_names, - project: @object - }), - next_page_href: (next_page_offset and - url_for(offset: next_page_offset, filters: params[:filters], partial: true)) + formats: [:html]), + next_page_href: @next_page_href } } end else + @objects = [] super end end @@ -188,10 +215,12 @@ class ProjectsController < ApplicationController end helper_method :get_objects_and_names - def get_objects_and_names(objects) + def get_objects_and_names(objects=nil) + objects = @objects if objects.nil? objects_and_names = [] objects.each do |object| - if !(name_links = objects.links_for(object, 'name')).empty? + if objects.respond_to? :links_for and + !(name_links = objects.links_for(object, 'name')).empty? name_links.each do |name_link| objects_and_names << [object, name_link] end diff --git a/apps/workbench/app/views/projects/_show_contents_rows.html.erb b/apps/workbench/app/views/projects/_show_contents_rows.html.erb index b690a1bf8f..9fc53a31f2 100644 --- a/apps/workbench/app/views/projects/_show_contents_rows.html.erb +++ b/apps/workbench/app/views/projects/_show_contents_rows.html.erb @@ -1,4 +1,4 @@ -<% objects_and_names.each do |object, name_link| %> +<% get_objects_and_names.each do |object, name_link| %> <% name_object = (object.respond_to?(:name) || !name_link) ? object : name_link %> <%= render partial: 'selection_checkbox', locals: {object: name_object, friendly_name: ((name_object.name rescue '') || '')} %> - <% if project.editable? %> - <%= link_to({action: 'remove_item', id: project.uuid, item_uuid: ((name_link && name_link.uuid) || object.uuid)}, method: :delete, remote: true, data: {confirm: "Remove #{object.class_for_display.downcase} #{name_object.name rescue object.uuid} from this project?", toggle: 'tooltip', placement: 'top'}, class: 'btn btn-sm btn-default btn-nodecorate', title: 'remove') do %> + <% if @object.editable? %> + <%= link_to({action: 'remove_item', id: @object.uuid, item_uuid: ((name_link && name_link.uuid) || object.uuid)}, method: :delete, remote: true, data: {confirm: "Remove #{object.class_for_display.downcase} #{name_object.name rescue object.uuid} from this project?", toggle: 'tooltip', placement: 'top'}, class: 'btn btn-sm btn-default btn-nodecorate', title: 'remove') do %> <% end %> <% else %> diff --git a/apps/workbench/app/views/projects/_show_data_collections.html.erb b/apps/workbench/app/views/projects/_show_data_collections.html.erb index 337629a4c8..26a8c93b95 100644 --- a/apps/workbench/app/views/projects/_show_data_collections.html.erb +++ b/apps/workbench/app/views/projects/_show_data_collections.html.erb @@ -59,11 +59,7 @@ <% end %> <% end %> -<% - filters = [['uuid', 'is_a', "arvados#collection"]] - @objects = @object.contents({limit: 50, include_linked: true, :filters => filters}) - objects_and_names = get_objects_and_names @objects - page_offset = next_page_offset @objects -%> - -<%= render partial: 'show_tab_contents', locals: {project: @object, objects_and_names: objects_and_names, filters: filters, page_offset: page_offset, tab_name: 'Data_collections'} %> +<%= render partial: 'show_tab_contents', locals: { + filters: [['uuid', 'is_a', "arvados#collection"]], + tab_name: 'Data_collections' + } %> diff --git a/apps/workbench/app/views/projects/_show_jobs_and_pipelines.html.erb b/apps/workbench/app/views/projects/_show_jobs_and_pipelines.html.erb index f9e6306a9d..f2e027588d 100644 --- a/apps/workbench/app/views/projects/_show_jobs_and_pipelines.html.erb +++ b/apps/workbench/app/views/projects/_show_jobs_and_pipelines.html.erb @@ -1,8 +1,4 @@ -<% - filters = [['uuid', 'is_a', ["arvados#pipelineInstance","arvados#job"]]] - @objects = @object.contents({limit: 50, include_linked: true, :filters => filters}) - objects_and_names = get_objects_and_names @objects - page_offset = next_page_offset @objects -%> - -<%= render partial: 'show_tab_contents', locals: {project: @object, objects_and_names: objects_and_names, filters: filters, page_offset: page_offset, tab_name: 'Jobs_and_pipelines'} %> +<%= render partial: 'show_tab_contents', locals: { + filters: [['uuid', 'is_a', ["arvados#job", "arvados#pipelineInstance"]]], + tab_name: 'Data_collections' + } %> diff --git a/apps/workbench/app/views/projects/_show_other_objects.html.erb b/apps/workbench/app/views/projects/_show_other_objects.html.erb index 308034ed54..41420a55aa 100644 --- a/apps/workbench/app/views/projects/_show_other_objects.html.erb +++ b/apps/workbench/app/views/projects/_show_other_objects.html.erb @@ -1,8 +1,4 @@ -<% - filters = [['uuid', 'is_a', ["arvados#human","arvados#specimen","arvados#trait"]]] - @objects = @object.contents({limit: 50, include_linked: true, :filters => filters}) - objects_and_names = get_objects_and_names @objects - page_offset = next_page_offset @objects -%> - -<%= render partial: 'show_tab_contents', locals: {project: @object, objects_and_names: objects_and_names, filters: filters, page_offset: page_offset, tab_name: 'Other_objects'} %> +<%= render partial: 'show_tab_contents', locals: { + filters: [['uuid', 'is_a', ["arvados#human", "arvados#specimen", "arvados#trait"]]], + tab_name: 'Data_collections' + } %> diff --git a/apps/workbench/app/views/projects/_show_subprojects.html.erb b/apps/workbench/app/views/projects/_show_subprojects.html.erb index 4497ca4ea7..640aee1f27 100644 --- a/apps/workbench/app/views/projects/_show_subprojects.html.erb +++ b/apps/workbench/app/views/projects/_show_subprojects.html.erb @@ -1,8 +1,4 @@ -<% - filters = [['uuid', 'is_a', "arvados#group"]] - @objects = @object.contents({limit: 50, include_linked: true, :filters => filters}) - objects_and_names = get_objects_and_names @objects - page_offset = next_page_offset @objects -%> - -<%= render partial: 'show_tab_contents', locals: {project: @object, objects_and_names: objects_and_names, filters: filters, page_offset: page_offset, tab_name: 'Subprojects'} %> +<%= render partial: 'show_tab_contents', locals: { + filters: [['uuid', 'is_a', ["arvados#group"]]], + tab_name: 'Data_collections' + } %> diff --git a/apps/workbench/app/views/projects/_show_tab_contents.html.erb b/apps/workbench/app/views/projects/_show_tab_contents.html.erb index df37d3e1c7..d767550eb6 100644 --- a/apps/workbench/app/views/projects/_show_tab_contents.html.erb +++ b/apps/workbench/app/views/projects/_show_tab_contents.html.erb @@ -42,8 +42,7 @@ - "> - <%= render partial: 'show_contents_rows', locals: {project: @object, objects_and_names: objects_and_names} %> + @@ -55,5 +54,4 @@ - -- 2.30.2