X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b74478a602b3cc5fcc18c2beb2962f98d1225ac4..42c20b25e1325124b88e3b9b285544dc41122b56:/apps/workbench/app/controllers/trash_items_controller.rb diff --git a/apps/workbench/app/controllers/trash_items_controller.rb b/apps/workbench/app/controllers/trash_items_controller.rb index 27cbb327f1..d8f7ae62c8 100644 --- a/apps/workbench/app/controllers/trash_items_controller.rb +++ b/apps/workbench/app/controllers/trash_items_controller.rb @@ -20,7 +20,7 @@ class TrashItemsController < ApplicationController trashed_items if @objects.any? - @objects = @objects.sort_by { |obj| obj.trash_at }.reverse + @objects = @objects.sort_by { |obj| obj.modified_at }.reverse @next_page_filters = next_page_filters('<=') @next_page_href = url_for(partial: params[:partial], filters: @next_page_filters.to_json) @@ -35,19 +35,19 @@ class TrashItemsController < ApplicationController def next_page_filters nextpage_operator next_page_filters = @filters.reject do |attr, op, val| - (attr == 'trash_at' and op == nextpage_operator) or + (attr == 'modified_at' and op == nextpage_operator) or (attr == 'uuid' and op == 'not in') end if @objects.any? - last_trash_at = @objects.last.trash_at + last_trash_at = @objects.last.modified_at last_uuids = [] @objects.each do |obj| last_uuids << obj.uuid if obj.trash_at.eql?(last_trash_at) end - next_page_filters += [['trash_at', nextpage_operator, last_trash_at]] + next_page_filters += [['modified_at', nextpage_operator, last_trash_at]] next_page_filters += [['uuid', 'not in', last_uuids]] end @@ -61,23 +61,61 @@ class TrashItemsController < ApplicationController query_on = Group end + last_mod_at = nil + last_uuids = [] + # API server index doesn't return manifest_text by default, but our # callers want it unless otherwise specified. - @select ||= query_on.columns.map(&:name) - %w(id updated_at) + #@select ||= query_on.columns.map(&:name) - %w(id updated_at) limit = if params[:limit] then params[:limit].to_i else 100 end offset = if params[:offset] then params[:offset].to_i else 0 end - base_search = query_on.select(@select).include_trash(true).where(is_trashed: true) - base_search = base_search.filter(params[:filters]) if params[:filters] + @objects = [] + while !@objects.any? + base_search = query_on - if params[:search].andand.length.andand > 0 - tags = Link.where(any: ['contains', params[:search]]) - base_search = base_search.limit(limit).offset(offset) - @objects = (base_search.where(uuid: tags.collect(&:head_uuid)) | - base_search.where(any: ['contains', params[:search]])). - uniq { |c| c.uuid } - else - @objects = base_search.limit(limit).offset(offset) + if !last_mod_at.nil? + base_search = base_search.filter([["modified_at", "<=", last_mod_at], ["uuid", "not in", last_uuids]]) + end + + base_search = base_search.include_trash(true).limit(limit).with_count("none").offset(offset) + + if params[:filters].andand.length.andand > 0 + tags = Link.filter(params[:filters]).with_count("none") + tagged = [] + if tags.results.length > 0 + tagged = query_on.include_trash(true).where(uuid: tags.collect(&:head_uuid)) + end + @objects = (tagged | base_search.filter(params[:filters])).uniq(&:uuid) + else + @objects = base_search.where(is_trashed: true) + end + + if @objects.any? + owner_uuids = @objects.collect(&:owner_uuid).uniq + @owners = {} + @not_trashed = {} + [Group, User].each do |owner_class| + owner_class.filter([["uuid", "in", owner_uuids]]).with_count("none") + .include_trash(true).fetch_multiple_pages(false) + .each do |owner| + @owners[owner.uuid] = owner + end + end + Group.filter([["uuid", "in", owner_uuids]]).with_count("none").select([:uuid]).each do |grp| + @not_trashed[grp.uuid] = true + end + else + return + end + + last_mod_at = @objects.last.modified_at + last_uuids = [] + @objects.each do |obj| + last_uuids << obj.uuid if obj.modified_at.eql?(last_mod_at) + end + + @objects = @objects.select {|item| item.is_trashed || @not_trashed[item.owner_uuid].nil? } end end @@ -86,15 +124,24 @@ class TrashItemsController < ApplicationController updates = {trash_at: nil} - klass = resource_class_for_uuid(params[:selection][0]) + if params[:selection].is_a? Array + klass = resource_class_for_uuid(params[:selection][0]) + else + klass = resource_class_for_uuid(params[:selection]) + end + first = nil klass.include_trash(1).where(uuid: params[:selection]).each do |c| + first = c c.untrash @untrashed_uuids << c.uuid end respond_to do |format| format.js + format.html do + redirect_to first + end end end end