[ARVADOS] created: e5337814593c504ef71e9f517dc1d99d41e19784
git at public.curoverse.com
git at public.curoverse.com
Sat Aug 9 19:44:43 EDT 2014
at e5337814593c504ef71e9f517dc1d99d41e19784 (commit)
commit e5337814593c504ef71e9f517dc1d99d41e19784
Author: Tom Clegg <tom at curoverse.com>
Date: Sat Aug 9 19:44:14 2014 -0400
3531: Refactor project tab infinite-scroll. Sort jobs and pipelines
together by date, instead of sorting first by type.
diff --git a/apps/workbench/app/assets/javascripts/infinite_scroll.js b/apps/workbench/app/assets/javascripts/infinite_scroll.js
index 2cb9748..6299cc5 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 18397e1..ae94dac 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 9f4c588..ea3103d 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.. at 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 b690a1b..9fc53a3 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 %>
<tr class="filterable"
data-object-uuid="<%= name_object.uuid %>"
@@ -7,8 +7,8 @@
<td>
<%= 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 %>
<i class="fa fa-fw fa-trash-o"></i>
<% 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 337629a..26a8c93 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 f9e6306..f2e0275 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 308034e..41420a5 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 4497ca4..640aee1 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 df37d3e..d767550 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 @@
<col width="40%" />
<col width="60%" />
</colgroup>
- <tbody data-infinite-scroller="#<%= tab_name %>-scroll" data-infinite-content-href="<%= url_for(format: :json, partial: :contents_rows, offset: page_offset, filters: "#{filters}") if page_offset %>">
- <%= render partial: 'show_contents_rows', locals: {project: @object, objects_and_names: objects_and_names} %>
+ <tbody data-infinite-scroller="#<%= tab_name %>-scroll" data-infinite-content-href="<%= url_for partial: :contents_rows, filters: filters.to_json %>">
</tbody>
<thead>
<tr>
@@ -55,5 +54,4 @@
</tr>
</thead>
</table>
-
</div>
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list