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(include_linked: true,
86 offset: params[:offset] || 0)
87 @share_links = Link.filter([['head_uuid', '=', @object.uuid],
88 ['link_class', '=', 'permission']])
89 @logs = Log.limit(10).filter([['object_uuid', '=', @object.uuid]])
91 @objects_and_names = []
92 @objects.each do |object|
93 if !(name_links = @objects.links_for(object, 'name')).empty?
94 name_links.each do |name_link|
95 @objects_and_names << [object, name_link]
98 @objects_and_names << [object,
99 Link.new(owner_uuid: @object.uuid,
100 tail_uuid: @object.uuid,
101 head_uuid: object.uuid,
110 content: render_to_string(partial: 'show_contents_rows.html',
113 objects_and_names: @objects_and_names,
116 next_page_href: (next_page_offset and
117 url_for(offset: next_page_offset, partial: true))
127 @new_resource_attrs = (params['folder'] || {}).merge(group_class: 'folder')
128 @new_resource_attrs[:name] ||= 'New folder'
133 @updates = params['folder']