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.trash_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 == 'trash_at' and op == nextpage_operator) or
39 (attr == 'uuid' and op == 'not in')
43 last_trash_at = @objects.last.trash_at
46 @objects.each do |obj|
47 last_uuids << obj.uuid if obj.trash_at.eql?(last_trash_at)
50 next_page_filters += [['trash_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"
64 # API server index doesn't return manifest_text by default, but our
65 # callers want it unless otherwise specified.
66 @select ||= query_on.columns.map(&:name) - %w(id updated_at)
67 limit = if params[:limit] then params[:limit].to_i else 100 end
68 offset = if params[:offset] then params[:offset].to_i else 0 end
70 base_search = query_on.select(@select).include_trash(true).where(is_trashed: true)
71 base_search = base_search.filter(params[:filters]) if params[:filters]
73 if params[:search].andand.length.andand > 0
74 tags = Link.where(any: ['contains', params[:search]])
75 base_search = base_search.limit(limit).offset(offset)
76 @objects = (base_search.where(uuid: tags.collect(&:head_uuid)) |
77 base_search.where(any: ['contains', params[:search]])).
80 @objects = base_search.limit(limit).offset(offset)
87 updates = {trash_at: nil}
89 klass = resource_class_for_uuid(params[:selection][0])
91 klass.include_trash(1).where(uuid: params[:selection]).each do |c|
93 @untrashed_uuids << c.uuid
96 respond_to do |format|