Feature #594 » subproject_no_level.diff
redmine/app/controllers/projects_controller.rb 2008-09-11 08:57:41.546391600 +0200 | ||
---|---|---|
65 | 65 |
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
66 | 66 |
@trackers = Tracker.all |
67 | 67 |
@root_projects = Project.find(:all, |
68 |
:conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}",
|
|
68 |
:conditions => "status = #{Project::STATUS_ACTIVE}",
|
|
69 | 69 |
:order => 'name') |
70 |
if @project != nil |
|
71 |
@root_projects = @root_projects - @project.fetch_all_subprojects_id_recursively() |
|
72 |
end |
|
70 | 73 |
@project = Project.new(params[:project]) |
71 | 74 |
if request.get? |
72 | 75 |
@project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? |
... | ... | |
108 | 111 |
|
109 | 112 |
def settings |
110 | 113 |
@root_projects = Project.find(:all, |
111 |
:conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
|
|
114 |
:conditions => ["status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id],
|
|
112 | 115 |
:order => 'name') |
116 |
if @project != nil |
|
117 |
@root_projects = @root_projects - @project.fetch_all_subprojects_id_recursively() |
|
118 |
end |
|
113 | 119 |
@issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") |
114 | 120 |
@issue_category ||= IssueCategory.new |
115 | 121 |
@member ||= @project.members.new |
redmine/app/models/project.rb 2008-09-11 16:27:18.421875000 +0200 | ||
---|---|---|
71 | 71 |
errors[:identifier].nil? && !(new_record? || identifier.blank?) |
72 | 72 |
end |
73 | 73 |
|
74 |
def fetch_all_subprojects_recursively |
|
75 |
ret = Array.new |
|
76 |
if self.children.size > 0 |
|
77 |
self.children.each { |subproject| |
|
78 |
ret << subproject |
|
79 |
ret += subproject.fetch_all_subprojects_recursively() |
|
80 |
} |
|
81 |
end |
|
82 |
return ret |
|
83 |
end |
|
84 |
|
|
85 |
def fetch_all_subprojects_id_recursively |
|
86 |
ret = Array.new |
|
87 |
if self.children.size > 0 |
|
88 |
self.children.each { |subproject| |
|
89 |
ret << subproject.id.to_s |
|
90 |
ret += subproject.fetch_all_subprojects_id_recursively() |
|
91 |
} |
|
92 |
end |
|
93 |
return ret |
|
94 |
end |
|
95 |
|
|
74 | 96 |
def issues_with_subprojects(include_subprojects=false) |
75 | 97 |
conditions = nil |
76 | 98 |
if include_subprojects |
77 |
ids = [id] + child_ids
|
|
99 |
ids = [id] + fetch_all_subprojects_id_recursively()
|
|
78 | 100 |
conditions = ["#{Project.table_name}.id IN (#{ids.join(',')}) AND #{Project.visible_by}"] |
79 | 101 |
end |
80 | 102 |
conditions ||= ["#{Project.table_name}.id = ?", id] |
... | ... | |
247 | 269 |
|
248 | 270 |
protected |
249 | 271 |
def validate |
250 |
errors.add(parent_id, " must be a root project") if parent and parent.parent |
|
251 |
errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0 |
|
252 | 272 |
errors.add(:identifier, :activerecord_error_invalid) if !identifier.blank? && identifier.match(/^\d*$/) |
253 | 273 |
end |
254 | 274 |
|
redmine/app/models/query.rb 2008-09-11 08:52:04.204289400 +0200 | ||
---|---|---|
269 | 269 |
# main project only |
270 | 270 |
else |
271 | 271 |
# all subprojects |
272 |
ids += project.child_ids
|
|
272 |
ids += project.fetch_all_subprojects_id_recursively()
|
|
273 | 273 |
end |
274 | 274 |
elsif Setting.display_subprojects_issues? |
275 |
ids += project.child_ids
|
|
275 |
ids += project.fetch_all_subprojects_id_recursively()
|
|
276 | 276 |
end |
277 | 277 |
project_clauses << "#{Issue.table_name}.project_id IN (%s)" % ids.join(',') |
278 | 278 |
elsif project |