1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 class TrashItemsController < ApplicationController
11 %w(Trashed_collections Trashed_projects)
14 def find_objects_for_index
15 # If it's not the index rows partial display, just return
16 # The /index request will again be invoked to display the
17 # partial at which time, we will be using the objects found.
18 return if !params[:partial]
23 @objects = @objects.sort_by { |obj| obj.modified_at }.reverse
24 @next_page_filters = next_page_filters('<=')
25 @next_page_href = url_for(partial: params[:partial],
26 filters: @next_page_filters.to_json)
32 def next_page_href with_params={}
36 def next_page_filters nextpage_operator
37 next_page_filters = @filters.reject do |attr, op, val|
38 (attr == 'modified_at' and op == nextpage_operator) or
39 (attr == 'uuid' and op == 'not in')
43 last_trash_at = @objects.last.modified_at
46 @objects.each do |obj|
47 last_uuids << obj.uuid if obj.trash_at.eql?(last_trash_at)
50 next_page_filters += [['modified_at', nextpage_operator, last_trash_at]]
51 next_page_filters += [['uuid', 'not in', last_uuids]]
58 if params[:partial] == "trashed_collection_rows"
60 elsif params[:partial] == "trashed_project_rows"
67 # API server index doesn't return manifest_text by default, but our
68 # callers want it unless otherwise specified.
69 #@select ||= query_on.columns.map(&:name) - %w(id updated_at)
70 limit = if params[:limit] then params[:limit].to_i else 100 end
71 offset = if params[:offset] then params[:offset].to_i else 0 end
75 base_search = query_on
78 base_search = base_search.filter([["modified_at", "<=", last_mod_at], ["uuid", "not in", last_uuids]])
81 base_search = base_search.include_trash(true).limit(limit).with_count("none").offset(offset)
83 if params[:filters].andand.length.andand > 0
84 tags = Link.filter(params[:filters]).with_count("none")
86 if tags.results.length > 0
87 tagged = query_on.include_trash(true).where(uuid: tags.collect(&:head_uuid))
89 @objects = (tagged | base_search.filter(params[:filters])).uniq(&:uuid)
91 @objects = base_search.where(is_trashed: true)
95 owner_uuids = @objects.collect(&:owner_uuid).uniq
98 [Group, User].each do |owner_class|
99 owner_class.filter([["uuid", "in", owner_uuids]]).with_count("none")
100 .include_trash(true).fetch_multiple_pages(false)
102 @owners[owner.uuid] = owner
105 Group.filter([["uuid", "in", owner_uuids]]).with_count("none").select([:uuid]).each do |grp|
106 @not_trashed[grp.uuid] = true
112 last_mod_at = @objects.last.modified_at
114 @objects.each do |obj|
115 last_uuids << obj.uuid if obj.modified_at.eql?(last_mod_at)
118 @objects = @objects.select {|item| item.is_trashed || @not_trashed[item.owner_uuid].nil? }
123 @untrashed_uuids = []
125 updates = {trash_at: nil}
127 if params[:selection].is_a? Array
128 klass = resource_class_for_uuid(params[:selection][0])
130 klass = resource_class_for_uuid(params[:selection])
134 klass.include_trash(1).where(uuid: params[:selection]).each do |c|
137 @untrashed_uuids << c.uuid
140 respond_to do |format|