Project

General

Profile

Defect #7114 ยป show_projects_having_a_descendant_with_issue_tracking.patch

Jean-Philippe Lang, 2010-12-16 11:16

View differences:

test/unit/lib/redmine/helpers/gantt_test.rb (copie de travail)
:start_date => Date.yesterday,
:due_date => 1.week.from_now.to_date)
@project.issues << @issue
@response.body = @gantt.subjects
end
context "project" do
should "be rendered" do
should "be rendered" do
@response.body = @gantt.subjects
assert_select "div.project-name a", /#{@project.name}/
end
should "have an indent of 4" do
should "have an indent of 4" do
@response.body = @gantt.subjects
assert_select "div.project-name[style*=left:4px]"
end
context "with descendants" do
setup do
@child = Project.generate!
@child.set_parent!(@project)
@child.enabled_module_names = ['issue_tracking']
@grandchild = Project.generate!
@grandchild.set_parent!(@child)
@grandchild.enabled_module_names = ['issue_tracking']
end
context ":html format" do
should "render descendants" do
@gantt.subjects
assert @gantt.subjects.match(/#{@child.name}/)
assert @gantt.subjects.match(/#{@grandchild.name}/)
end
should "render projects having a descendant with issue tracking enabled" do
@project.enabled_module_names = []
@child.enabled_module_names = []
@response.body = @gantt.subjects
assert @gantt.subjects.match(/#{@project.name}/)
assert @gantt.subjects.match(/#{@child.name}/)
assert @gantt.subjects.match(/#{@grandchild.name}/)
end
should "not render projects not having a descendant with issue tracking enabled" do
@project.enabled_module_names = []
@child.enabled_module_names = []
@grandchild.enabled_module_names = []
@response.body = @gantt.subjects
assert !@gantt.subjects.match(/#{@project.name}/)
end
end
end
end
context "version" do
should "be rendered" do
should "be rendered" do
@response.body = @gantt.subjects
assert_select "div.version-name a", /#{@version.name}/
end
should "be indented 24 (one level)" do
should "be indented 24 (one level)" do
@response.body = @gantt.subjects
assert_select "div.version-name[style*=left:24px]"
end
end
context "issue" do
should "be rendered" do
should "be rendered" do
@response.body = @gantt.subjects
assert_select "div.issue-subject", /#{@issue.subject}/
end
should "be indented 44 (two levels)" do
should "be indented 44 (two levels)" do
@response.body = @gantt.subjects
assert_select "div.issue-subject[style*=left:44px]"
end
end
app/models/project.rb (copie de travail)
enabled_modules.each {|mod| mod.destroy unless module_names.include?(mod.name)}
# add new modules
module_names.reject {|name| module_enabled?(name)}.each {|name| enabled_modules << EnabledModule.new(:name => name)}
enabled_modules.reload
else
enabled_modules.clear
end
lib/redmine/helpers/gantt.rb (copie de travail)
rows = if @project
number_of_rows_on_project(@project)
else
Project.roots.visible.has_module('issue_tracking').inject(0) do |total, project|
Project.roots.visible.inject(0) do |total, project|
total += number_of_rows_on_project(project)
end
end
......
# Returns the number of rows that will be used to list a project on
# the Gantt chart. This will recurse for each subproject.
def number_of_rows_on_project(project)
unless project.module_enabled?('issue_tracking') ||
(!project.leaf? && project.descendants.visible.has_module('issue_tracking').exists?)
return 0
end
# Remove the project requirement for Versions because it will
# restrict issues to only be on the current project. This
# ends up missing issues which are assigned to shared versions.
......
# One Root project
count = 1
# Issues without a Version
count += project.issues.for_gantt.without_version.with_query(@query).count
if project.module_enabled?('issue_tracking')
# Issues without a Version
count += project.issues.for_gantt.without_version.with_query(@query).count
# Versions
count += project.versions.count
# Versions
count += project.versions.count
# Issues on the Versions
project.versions.each do |version|
count += version.fixed_issues.for_gantt.with_query(@query).count
# Issues on the Versions
project.versions.each do |version|
count += version.fixed_issues.for_gantt.with_query(@query).count
end
end
# Subprojects
project.children.visible.has_module('issue_tracking').each do |subproject|
project.children.visible.each do |subproject|
count += number_of_rows_on_project(subproject)
end
end unless project.leaf?
count
end
......
if @project
render_project(@project, options)
else
Project.roots.visible.has_module('issue_tracking').each do |project|
Project.roots.visible.each do |project|
render_project(project, options)
break if abort?
end
......
end
def render_project(project, options={})
unless project.module_enabled?('issue_tracking') ||
(!project.leaf? && project.descendants.visible.has_module('issue_tracking').exists?)
return
end
options[:top] = 0 unless options.key? :top
options[:indent_increment] = 20 unless options.key? :indent_increment
options[:top_increment] = 20 unless options.key? :top_increment
......
@number_of_rows += 1
return if abort?
# Second, Issues without a version
issues = project.issues.for_gantt.without_version.with_query(@query).all(:limit => current_limit)
sort_issues!(issues)
if issues
render_issues(issues, options)
return if abort?
end
if project.module_enabled?('issue_tracking')
# Second, Issues without a version
issues = project.issues.for_gantt.without_version.with_query(@query).all(:limit => current_limit)
sort_issues!(issues)
if issues
render_issues(issues, options)
return if abort?
end
# Third, Versions
project.versions.sort.each do |version|
render_version(version, options)
return if abort?
# Third, Versions
project.versions.sort.each do |version|
render_version(version, options)
return if abort?
end
end
# Fourth, subprojects
project.children.visible.has_module('issue_tracking').each do |project|
project.children.visible.each do |project|
render_project(project, options)
return if abort?
end unless project.leaf?
    (1-1/1)