helper_method :all_projects
def all_projects
- @all_projects ||= Group.filter([['group_class','in',['project','folder']]])
+ @all_projects ||= Group.
+ filter([['group_class','in',['project','folder']]]).order('name')
end
helper_method :my_projects
end
end
+ helper_method :my_project_tree
+ def my_project_tree
+ build_project_trees
+ @my_project_tree
+ end
+
+ helper_method :shared_project_tree
+ def shared_project_tree
+ build_project_trees
+ @shared_project_tree
+ end
+
+ def build_project_trees
+ return if @my_project_tree and @shared_project_tree
+ parent_of = {current_user.uuid => 'me'}
+ all_projects.each do |ob|
+ parent_of[ob.uuid] = ob.owner_uuid
+ end
+ children_of = {false => [], 'me' => [current_user]}
+ all_projects.each do |ob|
+ if ob.owner_uuid != current_user.uuid and
+ not parent_of.has_key? ob.owner_uuid
+ parent_of[ob.uuid] = false
+ end
+ children_of[parent_of[ob.uuid]] ||= []
+ children_of[parent_of[ob.uuid]] << ob
+ end
+ buildtree = lambda do |children_of, root_uuid=false|
+ tree = {}
+ children_of[root_uuid].andand.each do |ob|
+ tree[ob] = buildtree.call(children_of, ob.uuid)
+ end
+ tree
+ end
+ sorted_paths = lambda do |tree, depth=0|
+ paths = []
+ tree.keys.sort_by { |ob|
+ ob.is_a?(String) ? ob : ob.friendly_link_name
+ }.each do |ob|
+ paths << {object: ob, depth: depth}
+ paths += sorted_paths.call tree[ob], depth+1
+ end
+ paths
+ end
+ @my_project_tree =
+ sorted_paths.call buildtree.call(children_of, 'me')
+ @shared_project_tree =
+ sorted_paths.call({'Shared with me' =>
+ buildtree.call(children_of, false)})
+ end
+
helper_method :get_object
def get_object uuid
if @get_object.nil? and @objects
end
def find_objects_for_index
- @objects = Group.
- filter([['group_class','in',['project','folder']]]).
- order('name')
+ @objects = all_projects
super
- parent_of = {current_user.uuid => 'me'}
- @objects.each do |ob|
- parent_of[ob.uuid] = ob.owner_uuid
- end
- children_of = {false => [], 'me' => [current_user]}
- @objects.each do |ob|
- if ob.owner_uuid != current_user.uuid and
- not parent_of.has_key? ob.owner_uuid
- parent_of[ob.uuid] = false
- end
- children_of[parent_of[ob.uuid]] ||= []
- children_of[parent_of[ob.uuid]] << ob
- end
- buildtree = lambda do |children_of, root_uuid=false|
- tree = {}
- children_of[root_uuid].andand.each do |ob|
- tree[ob] = buildtree.call(children_of, ob.uuid)
- end
- tree
- end
- sorted_paths = lambda do |tree, depth=0|
- paths = []
- tree.keys.sort_by { |ob|
- ob.is_a?(String) ? ob : ob.friendly_link_name
- }.each do |ob|
- paths << {object: ob, depth: depth}
- paths += sorted_paths.call tree[ob], depth+1
- end
- paths
- end
- @my_project_tree =
- sorted_paths.call buildtree.call(children_of, 'me')
- @shared_project_tree =
- sorted_paths.call({'Shared with me' =>
- buildtree.call(children_of, false)})
end
def show
<% end %>
My projects
</li>
- <% @my_project_tree.each do |pnode| %>
+ <% my_project_tree.each do |pnode| %>
<% next if pnode[:object].class != Group %>
<li style="padding-left: <%= pnode[:depth]-1 %>em">
<%= link_to(pnode[:object].name, project_path(pnode[:object].uuid)) %>
<li role="presentation" class="dropdown-header">
Projects shared with me
</li>
- <% @shared_project_tree.each do |pnode| %>
+ <% shared_project_tree.each do |pnode| %>
<% next if pnode[:object].class != Group %>
<li style="padding-left: <%= pnode[:depth]-1 %>em">
<%= link_to project_path(pnode[:object].uuid) do %>
<div class="modal-body">
<div class="selectable-container" style="height: 15em; overflow-y: scroll">
- <% [@my_project_tree, @shared_project_tree].each do |tree| %>
+ <% [my_project_tree, shared_project_tree].each do |tree| %>
<% tree.each do |projectnode| %>
<% if projectnode[:object].is_a? String %>
<div class="row" style="padding-left: <%= 1 + projectnode[:depth] %>em;">
</h3>
</div>
<div class="panel-body scroll-20em">
- <%= render partial: 'index_projects', locals: {tree: @my_project_tree, show_root_node: false} %>
+ <%= render partial: 'index_projects', locals: {tree: my_project_tree, show_root_node: false} %>
</div>
</div>
</div>
</h3>
</div>
<div class="panel-body scroll-20em">
- <%= render partial: 'index_projects', locals: {tree: @shared_project_tree, show_root_node: false} %>
+ <%= render partial: 'index_projects', locals: {tree: shared_project_tree, show_root_node: false} %>
</div>
</div>
</div>
test "Collection page renders default name links" do
uuid = api_fixture('collections')['foo_file']['uuid']
coll_name = api_fixture('links')['foo_collection_name_in_aproject']['name']
- visit page_with_token('active', "/collections/#{uuid}")
+ name_uuid = api_fixture('links')['foo_collection_name_in_aproject']['uuid']
+ visit page_with_token('active', "/collections/#{name_uuid}")
assert(page.has_text?(coll_name), "Collection page did not include name")
# Now check that the page is otherwise normal, and the collection name
# isn't only showing up in an error message.
end
wait_for_ajax
- click_link 'Move to...'
+ click_link 'Move project...'
find('.selectable', text: 'Project 1234').click
find('.modal-footer a,button', text: 'Move').click
wait_for_ajax