1 class FoldersController < ApplicationController
11 %w(Contents Permissions Advanced)
17 item = ArvadosBase.find params[:item_uuid]
18 if (item.class == Link and
19 item.link_class == 'name' and
20 item.tail_uuid = @object.uuid)
21 # Given uuid is a name link, linking an object to this
22 # folder. First follow the link to find the item we're removing,
23 # then delete the link.
25 item = ArvadosBase.find item.head_uuid
27 # Given uuid is an object. Delete all names.
28 links += Link.where(tail_uuid: @object.uuid,
33 @removed_uuids << link.uuid
36 if item.owner_uuid == @object.uuid
37 # Object is owned by this folder. Remove it from the folder by
38 # changing owner to the current user.
39 item.update_attributes owner_uuid: current_user.uuid
40 @removed_uuids << item.uuid
44 def find_objects_for_index
45 @objects = Group.where(group_class: 'folder').order('name')
47 parent_of = {current_user.uuid => 'me'}
49 parent_of[ob.uuid] = ob.owner_uuid
51 children_of = {false => [], 'me' => [current_user]}
53 if ob.owner_uuid != current_user.uuid and
54 not parent_of.has_key? ob.owner_uuid
55 parent_of[ob.uuid] = false
57 children_of[parent_of[ob.uuid]] ||= []
58 children_of[parent_of[ob.uuid]] << ob
60 buildtree = lambda do |children_of, root_uuid=false|
62 children_of[root_uuid].andand.each do |ob|
63 tree[ob] = buildtree.call(children_of, ob.uuid)
67 sorted_paths = lambda do |tree, depth=0|
69 tree.keys.sort_by { |ob|
70 ob.is_a?(String) ? ob : ob.friendly_link_name
72 paths << {object: ob, depth: depth}
73 paths += sorted_paths.call tree[ob], depth+1
78 sorted_paths.call buildtree.call(children_of, 'me')
80 sorted_paths.call({'Shared with me' =>
81 buildtree.call(children_of, false)})
85 @objects = @object.contents(limit: 50,
87 offset: params[:offset] || 0)
88 @share_links = Link.filter([['head_uuid', '=', @object.uuid],
89 ['link_class', '=', 'permission']])
90 @logs = Log.limit(10).filter([['object_uuid', '=', @object.uuid]])
92 @objects_and_names = []
93 @objects.each do |object|
94 if !(name_links = @objects.links_for(object, 'name')).empty?
95 name_links.each do |name_link|
96 @objects_and_names << [object, name_link]
99 @objects_and_names << [object,
100 Link.new(owner_uuid: @object.uuid,
101 tail_uuid: @object.uuid,
102 head_uuid: object.uuid,
111 content: render_to_string(partial: 'show_contents_rows.html',
114 objects_and_names: @objects_and_names,
117 next_page_href: (next_page_offset and
118 url_for(offset: next_page_offset, partial: true))
128 @new_resource_attrs = (params['folder'] || {}).merge(group_class: 'folder')
129 @new_resource_attrs[:name] ||= 'New folder'
134 @updates = params['folder']