1 class FoldersController < ApplicationController
11 %w(Contents Permissions Advanced)
15 params[:item_uuids] = [params[:item_uuid]]
17 render template: 'folders/remove_items'
23 params[:item_uuids].collect { |uuid| ArvadosBase.find uuid }.each do |item|
24 if (item.class == Link and
25 item.link_class == 'name' and
26 item.tail_uuid == @object.uuid)
27 # Given uuid is a name link, linking an object to this
28 # folder. First follow the link to find the item we're removing,
29 # then delete the link.
31 item = ArvadosBase.find item.head_uuid
33 # Given uuid is an object. Delete all names.
34 links += Link.where(tail_uuid: @object.uuid,
39 @removed_uuids << link.uuid
42 if item.owner_uuid == @object.uuid
43 # Object is owned by this folder. Remove it from the folder by
44 # changing owner to the current user.
45 item.update_attributes owner_uuid: current_user.uuid
46 @removed_uuids << item.uuid
51 def find_objects_for_index
52 @objects = Group.where(group_class: 'folder').order('name')
54 parent_of = {current_user.uuid => 'me'}
56 parent_of[ob.uuid] = ob.owner_uuid
58 children_of = {false => [], 'me' => [current_user]}
60 if ob.owner_uuid != current_user.uuid and
61 not parent_of.has_key? ob.owner_uuid
62 parent_of[ob.uuid] = false
64 children_of[parent_of[ob.uuid]] ||= []
65 children_of[parent_of[ob.uuid]] << ob
67 buildtree = lambda do |children_of, root_uuid=false|
69 children_of[root_uuid].andand.each do |ob|
70 tree[ob] = buildtree.call(children_of, ob.uuid)
74 sorted_paths = lambda do |tree, depth=0|
76 tree.keys.sort_by { |ob|
77 ob.is_a?(String) ? ob : ob.friendly_link_name
79 paths << {object: ob, depth: depth}
80 paths += sorted_paths.call tree[ob], depth+1
85 sorted_paths.call buildtree.call(children_of, 'me')
87 sorted_paths.call({'Shared with me' =>
88 buildtree.call(children_of, false)})
92 @objects = @object.contents(limit: 50,
94 offset: params[:offset] || 0)
95 @share_links = Link.filter([['head_uuid', '=', @object.uuid],
96 ['link_class', '=', 'permission']])
97 @logs = Log.limit(10).filter([['object_uuid', '=', @object.uuid]])
99 @objects_and_names = []
100 @objects.each do |object|
101 if !(name_links = @objects.links_for(object, 'name')).empty?
102 name_links.each do |name_link|
103 @objects_and_names << [object, name_link]
105 elsif object.respond_to? :name
106 @objects_and_names << [object, object]
108 @objects_and_names << [object,
109 Link.new(owner_uuid: @object.uuid,
110 tail_uuid: @object.uuid,
111 head_uuid: object.uuid,
120 content: render_to_string(partial: 'show_contents_rows.html',
123 objects_and_names: @objects_and_names,
126 next_page_href: (next_page_offset and
127 url_for(offset: next_page_offset, partial: true))
137 @new_resource_attrs = (params['folder'] || {}).merge(group_class: 'folder')
138 @new_resource_attrs[:name] ||= 'New folder'
143 @updates = params['folder']