1 class FoldersController < ApplicationController
13 item = ArvadosBase.find params[:item_uuid]
14 if (item.class == Link and
15 item.link_class == 'name' and
16 item.tail_uuid = @object.uuid)
17 # Given uuid is a name link, linking an object to this
18 # folder. First follow the link to find the item we're removing,
19 # then delete the link.
21 item = ArvadosBase.find item.head_uuid
23 # Given uuid is an object. Delete all names.
24 links += Link.where(tail_uuid: @object.uuid,
29 @removed_uuids << link.uuid
32 if item.owner_uuid == @object.uuid
33 # Object is owned by this folder. Remove it from the folder by
34 # changing owner to the current user.
35 item.update_attributes owner_uuid: current_user
36 @removed_uuids << item.uuid
41 @objects = Group.where(group_class: 'folder').order('name')
42 parent_of = {current_user.uuid => 'me'}
44 parent_of[ob.uuid] = ob.owner_uuid
46 children_of = {false => [], 'me' => [current_user]}
48 if ob.owner_uuid != current_user.uuid and
49 not parent_of.has_key? ob.owner_uuid
50 parent_of[ob.uuid] = false
52 children_of[parent_of[ob.uuid]] ||= []
53 children_of[parent_of[ob.uuid]] << ob
55 buildtree = lambda do |children_of, root_uuid=false|
57 children_of[root_uuid].andand.each do |ob|
58 tree[ob] = buildtree.call(children_of, ob.uuid)
62 sorted_paths = lambda do |tree, depth=0|
64 tree.keys.sort_by { |ob| ob.friendly_link_name }.each do |ob|
65 paths << {object: ob, depth: depth}
66 paths += sorted_paths.call tree[ob], depth+1
70 @my_folder_tree = sorted_paths.call buildtree.call(children_of, 'me')
71 @shared_folder_tree = sorted_paths.call buildtree.call(children_of, false)
76 render partial: 'choose'
80 @objects = @object.contents include_linked: true
81 @share_links = Link.filter([['head_uuid', '=', @object.uuid],
82 ['link_class', '=', 'permission']])
83 @logs = Log.limit(10).filter([['object_uuid', '=', @object.uuid]])
85 @objects_and_names = []
86 @objects.each do |object|
87 if !(name_links = @objects.links_for(object, 'name')).empty?
88 name_links.each do |name_link|
89 @objects_and_names << [object, name_link]
92 @objects_and_names << [object,
93 Link.new(tail_uuid: @object.uuid,
94 head_uuid: object.uuid,
104 @new_resource_attrs = (params['folder'] || {}).merge(group_class: 'folder')
105 @new_resource_attrs[:name] ||= 'New folder'
110 @updates = params['folder']