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
This commit is contained in:
parent
a6f891d1b1
commit
0ca74df604
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue