Commit 0ca74df6 authored by Eric Davis's avatar Eric Davis

Refactor: move method to model with compatibility wrapper

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4282 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent a6f891d1
......@@ -238,15 +238,10 @@ module ApplicationHelper
end
# Yields the given block for each project with its level in the tree
#
# Wrapper for Project#project_tree
def project_tree(projects, &block)
ancestors = []
projects.sort_by(&:lft).each do |project|
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
ancestors.pop
end
yield project, ancestors.size
ancestors << project
end
Project.project_tree(projects, &block)
end
def project_nested_ul(projects, &block)
......
......@@ -565,6 +565,18 @@ class Project < ActiveRecord::Base
return nil
end
end
# Yields the given block for each project with its level in the tree
def self.project_tree(projects, &block)
ancestors = []
projects.sort_by(&:lft).each do |project|
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
ancestors.pop
end
yield project, ancestors.size
ancestors << project
end
end
private
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment