@@ -238,15 +238,10 module ApplicationHelper | |||||
238 | end |
|
238 | end | |
239 |
|
239 | |||
240 | # Yields the given block for each project with its level in the tree |
|
240 | # Yields the given block for each project with its level in the tree | |
|
241 | # | |||
|
242 | # Wrapper for Project#project_tree | |||
241 | def project_tree(projects, &block) |
|
243 | def project_tree(projects, &block) | |
242 | ancestors = [] |
|
244 | Project.project_tree(projects, &block) | |
243 | projects.sort_by(&:lft).each do |project| |
|
|||
244 | while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) |
|
|||
245 | ancestors.pop |
|
|||
246 | end |
|
|||
247 | yield project, ancestors.size |
|
|||
248 | ancestors << project |
|
|||
249 | end |
|
|||
250 | end |
|
245 | end | |
251 |
|
246 | |||
252 | def project_nested_ul(projects, &block) |
|
247 | def project_nested_ul(projects, &block) |
@@ -565,6 +565,18 class Project < ActiveRecord::Base | |||||
565 | return nil |
|
565 | return nil | |
566 | end |
|
566 | end | |
567 | end |
|
567 | end | |
|
568 | ||||
|
569 | # Yields the given block for each project with its level in the tree | |||
|
570 | def self.project_tree(projects, &block) | |||
|
571 | ancestors = [] | |||
|
572 | projects.sort_by(&:lft).each do |project| | |||
|
573 | while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) | |||
|
574 | ancestors.pop | |||
|
575 | end | |||
|
576 | yield project, ancestors.size | |||
|
577 | ancestors << project | |||
|
578 | end | |||
|
579 | end | |||
568 |
|
580 | |||
569 | private |
|
581 | private | |
570 |
|
582 |
General Comments 0
You need to be logged in to leave comments.
Login now