diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-08-10 17:09:48 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-08-10 17:09:48 +0000 |
commit | 0a6c1d9c136b271913bfba12e08d2169e6afa99f (patch) | |
tree | 5524fc28f3e0af083c156d38ff5e2fc1e0fc55a2 | |
parent | e52219f09d23d81dc0678d8a772986263144600a (diff) | |
download | redmine-0a6c1d9c136b271913bfba12e08d2169e6afa99f.tar.gz redmine-0a6c1d9c136b271913bfba12e08d2169e6afa99f.zip |
Extract code to render nested listed of projects in an helper (#11539).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10188 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/helpers/application_helper.rb | 33 | ||||
-rw-r--r-- | app/helpers/projects_helper.rb | 35 |
2 files changed, 39 insertions, 29 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 983f3fd8b..c25bff049 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -195,6 +195,39 @@ module ApplicationHelper end end + # Renders a tree of projects 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_project_nested_lists(projects) + s = '' + if projects.any? + ancestors = [] + original_project = @project + projects.each do |project| + # set the project environment to please macros. + @project = project + if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) + s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n" + else + ancestors.pop + s << "</li>" + while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) + ancestors.pop + s << "</ul></li>\n" + end + end + classes = (ancestors.empty? ? 'root' : 'child') + s << "<li class='#{classes}'><div class='#{classes}'>" + s << h(block_given? ? yield(project) : project.name) + s << "</div>\n" + ancestors << project + end + s << ("</li></ul>\n" * ancestors.size) + @project = original_project + end + s.html_safe + end + def render_page_hierarchy(pages, node=nil, options={}) content = '' if pages[node] diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 9d538c966..81c97e75a 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -51,38 +51,15 @@ module ProjectsHelper content_tag('select', options.html_safe, :name => 'project[parent_id]', :id => 'project_parent_id') end - # Renders a tree of projects 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) + # Renders the projects index def render_project_hierarchy(projects) - s = '' - if projects.any? - ancestors = [] - original_project = @project - projects.each do |project| - # set the project environment to please macros. - @project = project - if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) - s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n" - else - ancestors.pop - s << "</li>" - while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) - ancestors.pop - s << "</ul></li>\n" - end - end - classes = (ancestors.empty? ? 'root' : 'child') - s << "<li class='#{classes}'><div class='#{classes}'>" + - link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'my-project' : nil}") - s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank? - s << "</div>\n" - ancestors << project + render_project_nested_lists(projects) do |project| + s = link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'my-project' : nil}") + if project.description.present? + s << content_tag('div', textilizable(project.short_description, :project => project), :class => 'wiki description') end - s << ("</li></ul>\n" * ancestors.size) - @project = original_project + s end - s.html_safe end # Returns a set of options for a select field, grouped by project. |