Gantt code cleanup.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4523 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2010-12-17 14:05:43 +00:00
parent 98c7c179ca
commit edc35d4d5b
3 changed files with 26 additions and 79 deletions

View File

@ -300,64 +300,10 @@ module Redmine
case options[:format] case options[:format]
when :html when :html
output = '' coords = coordinates(project.start_date, project.due_date, project.completed_percent(:include_subprojects => true), options[:zoom])
i_left = ((project.start_date - self.date_from)*options[:zoom]).floor label = "#{h project } #{h project.completed_percent(:include_subprojects => true).to_i.to_s}%"
output = html_task(options[:top], coords, :css => "project task", :label => label, :markers => true)
start_date = project.start_date
start_date ||= self.date_from
start_left = ((start_date - self.date_from)*options[:zoom]).floor
i_end_date = ((project.due_date <= self.date_to) ? project.due_date : self.date_to )
i_done_date = start_date + ((project.due_date - start_date+1)* project.completed_percent(:include_subprojects => true)/100).floor
i_done_date = (i_done_date <= self.date_from ? self.date_from : i_done_date )
i_done_date = (i_done_date >= self.date_to ? self.date_to : i_done_date )
i_late_date = [i_end_date, Date.today].min if start_date < Date.today
i_end = ((i_end_date - self.date_from) * options[:zoom]).floor
i_width = (i_end - i_left + 1).floor - 2 # total width of the issue (- 2 for left and right borders)
d_width = ((i_done_date - start_date)*options[:zoom]).floor - 2 # done width
l_width = i_late_date ? ((i_late_date - start_date+1)*options[:zoom]).floor - 2 : 0 # delay width
# Bar graphic
# Make sure that negative i_left and i_width don't
# overflow the subject
if i_end > 0 && i_left <= options[:g_width]
output << "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:#{ i_width }px;' class='task project_todo'>&nbsp;</div>"
end
if l_width > 0 && i_left <= options[:g_width]
output << "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:#{ l_width }px;' class='task project_late'>&nbsp;</div>"
end
if d_width > 0 && i_left <= options[:g_width]
output<< "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:#{ d_width }px;' class='task project_done'>&nbsp;</div>"
end
# Starting diamond
if start_left <= options[:g_width] && start_left > 0
output << "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:15px;' class='task project-line starting'>&nbsp;</div>"
output << "<div style='top:#{ options[:top] }px;left:#{ start_left + 12 }px;' class='task label'>"
output << "</div>"
end
# Ending diamond
# Don't show items too far ahead
if i_end <= options[:g_width] && i_end > 0
output << "<div style='top:#{ options[:top] }px;left:#{ i_end }px;width:15px;' class='task project-line ending'>&nbsp;</div>"
end
# DIsplay the Project name and %
if i_end <= options[:g_width]
# Display the status even if it's floated off to the left
status_px = i_end + 12 # 12px for the diamond
status_px = 0 if status_px <= 0
output << "<div style='top:#{ options[:top] }px;left:#{ status_px }px;' class='task label project-name'>"
output << "<strong>#{h project } #{h project.completed_percent(:include_subprojects => true).to_i.to_s}%</strong>"
output << "</div>"
end
@lines << output @lines << output
output output
when :image when :image

View File

@ -791,6 +791,7 @@ background-image:url('../images/close_hl.png');
} }
.task.label {width:100%;} .task.label {width:100%;}
.task.label.project, .task.label.version { font-weight: bold; }
.task_late { background:#f66 url(../images/task_late.png); border: 1px solid #f66; } .task_late { background:#f66 url(../images/task_late.png); border: 1px solid #f66; }
.task_done { background:#00c600 url(../images/task_done.png); border: 1px solid #00c600; } .task_done { background:#00c600 url(../images/task_done.png); border: 1px solid #00c600; }
@ -806,10 +807,10 @@ background-image:url('../images/close_hl.png');
.version.task_todo { background:#fff url(../images/milestone_todo.png); border: 1px solid #fff; height: 2px; margin-top: 3px;} .version.task_todo { background:#fff url(../images/milestone_todo.png); border: 1px solid #fff; height: 2px; margin-top: 3px;}
.version.marker { background-image:url(../images/version_marker.png); background-repeat: no-repeat; border: 0; } .version.marker { background-image:url(../images/version_marker.png); background-repeat: no-repeat; border: 0; }
.project-line { background-image:url(../images/project_marker.png); background-repeat: no-repeat; border: 0; } .project.task_late { background:#f66 url(../images/milestone_late.png); border: 1px solid #f66; height: 2px; margin-top: 3px;}
.project_late { background:#f66 url(../images/milestone_late.png); border: 1px solid #f66; height: 2px; margin-top: 3px;} .project.task_done { background:#00c600 url(../images/milestone_done.png); border: 1px solid #00c600; height: 2px; margin-top: 3px;}
.project_done { background:#00c600 url(../images/milestone_done.png); border: 1px solid #00c600; height: 2px; margin-top: 3px;} .project.task_todo { background:#fff url(../images/milestone_todo.png); border: 1px solid #fff; height: 2px; margin-top: 3px;}
.project_todo { background:#fff url(../images/milestone_todo.png); border: 1px solid #fff; height: 2px; margin-top: 3px;} .project.marker { background-image:url(../images/project_marker.png); background-repeat: no-repeat; border: 0; }
.version-behind-schedule a, .issue-behind-schedule a {color: #f66914;} .version-behind-schedule a, .issue-behind-schedule a {color: #f66914;}
.version-overdue a, .issue-overdue a, .project-overdue a {color: #f00;} .version-overdue a, .issue-overdue a, .project-overdue a {color: #f00;}

View File

@ -216,10 +216,10 @@ class Redmine::Helpers::GanttTest < ActiveSupport::TestCase
context "project" do context "project" do
should "be rendered" do should "be rendered" do
assert_select "div.project_todo" assert_select "div.project.task_todo"
assert_select "div.project-line.starting" assert_select "div.project.starting"
assert_select "div.project-line.ending" assert_select "div.project.ending"
assert_select "div.label.project-name", /#{@project.name}/ assert_select "div.label.project", /#{@project.name}/
end end
end end
@ -310,7 +310,7 @@ class Redmine::Helpers::GanttTest < ActiveSupport::TestCase
:tracker => @tracker, :tracker => @tracker,
:project => @project, :project => @project,
:done_ratio => 30, :done_ratio => 30,
:start_date => Date.yesterday, :start_date => 1.week.ago.to_date,
:due_date => 1.week.from_now.to_date) :due_date => 1.week.from_now.to_date)
end end
@ -318,12 +318,12 @@ class Redmine::Helpers::GanttTest < ActiveSupport::TestCase
context "todo line" do context "todo line" do
should "start from the starting point on the left" do should "start from the starting point on the left" do
@response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
assert_select "div.project_todo[style*=left:52px]" assert_select "div.project.task_todo[style*=left:28px]", true, @response.body
end end
should "be the total width of the project" do should "be the total width of the project" do
@response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
assert_select "div.project_todo[style*=width:31px]" assert_select "div.project.task_todo[style*=width:58px]", true, @response.body
end end
end end
@ -331,24 +331,24 @@ class Redmine::Helpers::GanttTest < ActiveSupport::TestCase
context "late line" do context "late line" do
should "start from the starting point on the left" do should "start from the starting point on the left" do
@response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
assert_select "div.project_late[style*=left:52px]" assert_select "div.project.task_late[style*=left:28px]", true, @response.body
end end
should "be the total delayed width of the project" do should "be the total delayed width of the project" do
@response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
assert_select "div.project_late[style*=width:6px]" assert_select "div.project.task_late[style*=width:30px]", true, @response.body
end end
end end
context "done line" do context "done line" do
should "start from the starting point on the left" do should "start from the starting point on the left" do
@response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
assert_select "div.project_done[style*=left:52px]" assert_select "div.project.task_done[style*=left:28px]", true, @response.body
end end
should "Be the total done width of the project" do should "Be the total done width of the project" do
@response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
assert_select "div.project_done[style*=left:52px]" assert_select "div.project.task_done[style*=width:18px]", true, @response.body
end end
end end
@ -358,12 +358,12 @@ class Redmine::Helpers::GanttTest < ActiveSupport::TestCase
@gantt.instance_variable_set('@date_from', Date.today) @gantt.instance_variable_set('@date_from', Date.today)
@response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
assert_select "div.project-line.starting", false assert_select "div.project.starting", false, @response.body
end end
should "appear at the starting point" do should "appear at the starting point" do
@response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
assert_select "div.project-line.starting[style*=left:52px]" assert_select "div.project.starting[style*=left:28px]", true, @response.body
end end
end end
@ -373,13 +373,13 @@ class Redmine::Helpers::GanttTest < ActiveSupport::TestCase
@gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date)
@response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
assert_select "div.project-line.ending", false assert_select "div.project.ending", false, @response.body
end end
should "appear at the end of the date range" do should "appear at the end of the date range" do
@response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
assert_select "div.project-line.ending[style*=left:84px]" assert_select "div.project.ending[style*=left:84px]", true, @response.body
end end
end end
@ -388,17 +388,17 @@ class Redmine::Helpers::GanttTest < ActiveSupport::TestCase
@gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date) @gantt.instance_variable_set('@date_to', 2.weeks.ago.to_date)
@response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
assert_select "div.project-name", /#{@project.name}/ assert_select "div.project.label", /#{@project.name}/
end end
should "show the project name" do should "show the project name" do
@response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
assert_select "div.project-name", /#{@project.name}/ assert_select "div.project.label", /#{@project.name}/
end end
should "show the percent complete" do should "show the percent complete" do
@response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_project(@project, {:format => :html, :zoom => 4})
assert_select "div.project-name", /0%/ assert_select "div.project.label", /0%/
end end
end end
end end