summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2010-10-22 22:38:45 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2010-10-22 22:38:45 +0000
commit0ca74df6040371e448bcb3c718b84cdb635f07ee (patch)
tree85ab58e2700f94c4827087b28d4acd68413accda
parenta6f891d1b18446bac798629487c0c55dbaa98220 (diff)
downloadredmine-0ca74df6040371e448bcb3c718b84cdb635f07ee.tar.gz
redmine-0ca74df6040371e448bcb3c718b84cdb635f07ee.zip
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
-rw-r--r--app/helpers/application_helper.rb11
-rw-r--r--app/models/project.rb12
2 files changed, 15 insertions, 8 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 39c2ebda1..38d43e5b8 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -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)
diff --git a/app/models/project.rb b/app/models/project.rb
index 000efa7c2..16c97441e 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -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