# HG changeset patch # User Chris Cannam # Date 1305025061 -3600 # Node ID 2008fa7fda29956986b8dd3eb0ac976ea1a1548b # Parent c759f8787b079abca9198273b4151f260b9ab0c8 Track the project tree explicitly through recursive functions rather than using lft, rgt ordering. Fixes #145 diff -r c759f8787b07 -r 2008fa7fda29 app/helpers/projects_helper.rb --- a/app/helpers/projects_helper.rb Tue May 10 11:39:42 2011 +0100 +++ b/app/helpers/projects_helper.rb Tue May 10 11:57:41 2011 +0100 @@ -95,68 +95,73 @@ end + def render_my_project_in_hierarchy(project) + + s = '' + + if User.current.member_of?(project) + + # set the project environment to please macros. + @project = project + + classes = (project.root? ? 'root' : 'child') + + s << "
  • " + + link_to_project(project, {}, :class => "project my-project") + if project.is_public? + s << " " << l("field_is_public") << "" + else + s << " " << l("field_is_private") << "" + end + s << render_project_short_description(project) + s << "
    \n" + + cs = '' + project.children.each do |child| + cs << render_my_project_in_hierarchy(child) + end + + if cs != '' + s << "\n"; + end + + end + + s + + end + # Renders a tree of projects where the current user belongs # as a nested set of unordered lists # The given collection may be a subset of the whole project tree # (eg. some intermediate nodes are private and can not be seen) def render_my_project_hierarchy(projects) + s = '' - a = '' + original_project = @project - # Flag to tell if user has any projects - t = FALSE - - if projects.any? - ancestors = [] - original_project = @project - projects.each do |project| - # set the project environment to please macros. - - @project = project - - if User.current.member_of?(project): - - t = TRUE - - if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) - s << "
  • \n" - end - end - - classes = (ancestors.empty? ? 'root' : 'child') - s << "
  • " + - link_to_project(project, {}, :class => "project my-project") - if project.is_public? - s << " " << l("field_is_public") << "" - else - s << " " << l("field_is_private") << "" - end - s << render_project_short_description(project) - s << "
    \n" - ancestors << project - end - end - s << ("
  • \n" * ancestors.size) - @project = original_project + projects.each do |project| + if project.root? || !projects.include?(project.parent) + s << render_my_project_in_hierarchy(project) + end end - if t == TRUE + @project = original_project + + if s != '' + a = '' a << "

    " a << l("label_my_project_plural") a << "

    " + a << "\n" + s = a end + + s - a end # Renders a tree of projects that the current user does not belong