multilevel-tree.diff

Sebastian Kurfuerst, 2008-04-24 21:19

Download (4.7 KB)

 
redmine_2008_02_06/app/controllers/projects_controller.rb 2008-04-22 21:22:28.000000000 +0200
102 102

  
103 103
  def settings
104 104
    @root_projects = Project.find(:all,
105
                                  :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
105
                                  :conditions => ["status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
106 106
                                  :order => 'name')
107
    @root_projects = @root_projects - @project.fetch_all_subprojects_recursively()
108 107
    @custom_fields = IssueCustomField.find(:all)
109 108
    @issue_category ||= IssueCategory.new
110 109
    @member ||= @project.members.new
redmine_2008_02_06/app/models/project.rb 2008-04-22 21:25:46.000000000 +0200
46 46
                          
47 47
  acts_as_tree :order => "name", :counter_cache => true
48 48

  
49
  def fetch_all_subprojects_recursively
50
    ret = Array.new
51
    if self.children.size > 0
52
      self.children.each { |subproject|
53
        ret << subproject
54
        ret += subproject.fetch_all_subprojects_recursively()
55
      }
56
    end
57
    return ret
58
  end
59

  
60

  
61

  
62 49
  acts_as_searchable :columns => ['name', 'description'], :project_key => 'id'
63 50
  acts_as_event :title => Proc.new {|o| "#{l(:label_project)}: #{o.name}"},
64 51
                :url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o.id}}
......
229 216
protected
230 217
  def validate
231 218
    errors.add(parent_id, " must be a root project") if parent and parent.parent
219
    errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0
232 220
    errors.add(:identifier, :activerecord_error_invalid) if !identifier.blank? && identifier.match(/^\d*$/)
233 221
  end
234 222
  
redmine_2008_02_06/vendor/plugins/flow_start/app/controllers/start_controller.rb 2008-04-22 21:57:56.000000000 +0200
7 7
  def index
8 8
    @news = News.latest User.current
9 9
    #@projects = Project.list User.current
10
    projects = Project.find :all,                                                                                           
11
                :conditions => Project.visible_by(User.current),                                                
12
		:include => :parent                                                                             
13
    @project_tree = projects.group_by {|p| p.parent || p}                                                                   
14
    @project_tree.each_key {|p| @project_tree[p] -= [p]} 
10
    
11
    @project_tree = Project.find :all,
12
                :conditions => "parent_id IS NULL and " + Project.visible_by(User.current)
13 15
  end
14 16
end
redmine_2008_02_06/vendor/plugins/flow_start/app/views/start/index.rhtml 2008-04-22 21:18:39.000000000 +0200
1 1
<h2><%= l(:label_home) %></h2>
2 2
<div class="splitcontentleft">
3 3
		<div class="box">
4
  		<% @project_tree.keys.sort.each do |project| %>
4
  		<% @project_tree.each do |project| %>
5 5
		<h3><%= link_to h(project.name), {:controller => 'projects', :action => 'show', :id => project}, :class => (User.current.member_of?(project) ? "icon icon-fav" : "") %></h3>
6 6
		<%= textilizable(project.description, :project => project) %>
7 7

  
8
		<% if @project_tree[project].any? %>
8
		<% if project.children.any? %>
9 9
		    <p><%= l(:label_subproject_plural) %>:
10
		    <%= @project_tree[project].sort.collect {|subproject| 
10
		    <%= project.fetch_all_subprojects_recursively().sort.collect {|subproject| 
11 11
		       link_to(h(subproject.name), {:controller => 'projects', :action => 'show', :id => subproject}, :class => (User.current.member_of?(subproject) ? "icon icon-fav" : ""))}.join(', ') %></p>
12 12
		<% end %>
13 13
		<% end %>