Commit 98c7c179 authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

Gantt code cleanup.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4522 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 8f7da034
...@@ -435,65 +435,11 @@ module Redmine ...@@ -435,65 +435,11 @@ module Redmine
case options[:format] case options[:format]
when :html when :html
output = '' coords = coordinates(version.fixed_issues.minimum('start_date'), version.due_date, version.completed_pourcent, options[:zoom])
i_left = ((version.start_date - self.date_from)*options[:zoom]).floor label = "#{h version } #{h version.completed_pourcent.to_i.to_s}%"
# TODO: or version.fixed_issues.collect(&:start_date).min label = h("#{version.project} -") + label unless @project && @project == version.project
start_date = version.fixed_issues.minimum('start_date') if version.fixed_issues.present? output = html_task(options[:top], coords, :css => "version task", :label => label, :markers => true)
start_date ||= self.date_from
start_left = ((start_date - self.date_from)*options[:zoom]).floor
i_end_date = ((version.due_date <= self.date_to) ? version.due_date : self.date_to )
i_done_date = start_date + ((version.due_date - start_date+1)* version.completed_pourcent/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_width = (i_left - start_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
i_end = ((i_end_date - self.date_from) * options[:zoom]).floor # Ending pixel
# Bar graphic
# Make sure that negative i_left and i_width don't
# overflow the subject
if i_width > 0 && i_left <= options[:g_width]
output << "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:#{ i_width }px;' class='task milestone_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 milestone_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 milestone_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 milestone starting'>&nbsp;</div>"
output << "<div style='top:#{ options[:top] }px;left:#{ start_left + 12 }px;background:#fff;' class='task'>"
output << "</div>"
end
# Ending diamond
# Don't show items too far ahead
if i_left <= options[:g_width] && i_end > 0
output << "<div style='top:#{ options[:top] }px;left:#{ i_end }px;width:15px;' class='task milestone ending'>&nbsp;</div>"
end
# Display the Version 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 version-name'>"
output << h("#{version.project} -") unless @project && @project == version.project
output << "<strong>#{h version } #{h version.completed_pourcent.to_i.to_s}%</strong>"
output << "</div>"
end
@lines << output @lines << output
output output
when :image when :image
...@@ -1017,6 +963,15 @@ module Redmine ...@@ -1017,6 +963,15 @@ module Redmine
output << "<div style='top:#{ top }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_progress_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_done'>&nbsp;</div>" output << "<div style='top:#{ top }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_progress_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_done'>&nbsp;</div>"
end end
end end
# Renders the markers
if options[:markers]
if coords[:start]
output << "<div style='top:#{ top }px;left:#{ coords[:start] }px;width:15px;' class='#{options[:css]} marker starting'>&nbsp;</div>"
end
if coords[:end]
output << "<div style='top:#{ top }px;left:#{ coords[:end] }px;width:15px;' class='#{options[:css]} marker ending'>&nbsp;</div>"
end
end
# Renders the label on the right # Renders the label on the right
if options[:label] if options[:label]
output << "<div style='top:#{ top }px;left:#{ (coords[:bar_end] || 0) + 5 }px;' class='#{options[:css]} label'>" output << "<div style='top:#{ top }px;left:#{ (coords[:bar_end] || 0) + 5 }px;' class='#{options[:css]} label'>"
......
...@@ -801,10 +801,11 @@ background-image:url('../images/close_hl.png'); ...@@ -801,10 +801,11 @@ background-image:url('../images/close_hl.png');
.task_todo.parent .left { position: absolute; background: url(../images/task_parent_end.png) no-repeat 0 0; width: 8px; height: 16px; margin-left: -5px; left: 0px; top: -1px;} .task_todo.parent .left { position: absolute; background: url(../images/task_parent_end.png) no-repeat 0 0; width: 8px; height: 16px; margin-left: -5px; left: 0px; top: -1px;}
.task_todo.parent .right { position: absolute; background: url(../images/task_parent_end.png) no-repeat 0 0; width: 8px; height: 16px; margin-right: -5px; right: 0px; top: -1px;} .task_todo.parent .right { position: absolute; background: url(../images/task_parent_end.png) no-repeat 0 0; width: 8px; height: 16px; margin-right: -5px; right: 0px; top: -1px;}
.milestone { background-image:url(../images/version_marker.png); background-repeat: no-repeat; border: 0; } .version.task_late { background:#f66 url(../images/milestone_late.png); border: 1px solid #f66; height: 2px; margin-top: 3px;}
.milestone_late { background:#f66 url(../images/milestone_late.png); border: 1px solid #f66; height: 2px; margin-top: 3px;} .version.task_done { background:#00c600 url(../images/milestone_done.png); border: 1px solid #00c600; height: 2px; margin-top: 3px;}
.milestone_done { background:#00c600 url(../images/milestone_done.png); border: 1px solid #00c600; height: 2px; margin-top: 3px;} .version.task_todo { background:#fff url(../images/milestone_todo.png); border: 1px solid #fff; height: 2px; margin-top: 3px;}
.milestone_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; }
.project-line { background-image:url(../images/project_marker.png); background-repeat: no-repeat; border: 0; } .project-line { background-image:url(../images/project_marker.png); background-repeat: no-repeat; border: 0; }
.project_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_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;}
......
...@@ -225,10 +225,10 @@ class Redmine::Helpers::GanttTest < ActiveSupport::TestCase ...@@ -225,10 +225,10 @@ class Redmine::Helpers::GanttTest < ActiveSupport::TestCase
context "version" do context "version" do
should "be rendered" do should "be rendered" do
assert_select "div.milestone_todo" assert_select "div.version.task_todo"
assert_select "div.milestone.starting" assert_select "div.version.starting"
assert_select "div.milestone.ending" assert_select "div.version.ending"
assert_select "div.label.version-name", /#{@version.name}/ assert_select "div.label.version", /#{@version.name}/
end end
end end
...@@ -477,7 +477,7 @@ class Redmine::Helpers::GanttTest < ActiveSupport::TestCase ...@@ -477,7 +477,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
...@@ -485,12 +485,12 @@ class Redmine::Helpers::GanttTest < ActiveSupport::TestCase ...@@ -485,12 +485,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_version(@version, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
assert_select "div.milestone_todo[style*=left:52px]" assert_select "div.version.task_todo[style*=left:28px]", true, @response.body
end end
should "be the total width of the version" do should "be the total width of the version" do
@response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
assert_select "div.milestone_todo[style*=width:31px]" assert_select "div.version.task_todo[style*=width:58px]", true, @response.body
end end
end end
...@@ -498,24 +498,24 @@ class Redmine::Helpers::GanttTest < ActiveSupport::TestCase ...@@ -498,24 +498,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_version(@version, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
assert_select "div.milestone_late[style*=left:52px]" assert_select "div.version.task_late[style*=left:28px]", true, @response.body
end end
should "be the total delayed width of the version" do should "be the total delayed width of the version" do
@response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
assert_select "div.milestone_late[style*=width:6px]" assert_select "div.version.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_version(@version, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
assert_select "div.milestone_done[style*=left:52px]" assert_select "div.version.task_done[style*=left:28px]", true, @response.body
end end
should "Be the total done width of the version" do should "Be the total done width of the version" do
@response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
assert_select "div.milestone_done[style*=left:52px]" assert_select "div.version.task_done[style*=width:18px]", true, @response.body
end end
end end
...@@ -525,12 +525,12 @@ class Redmine::Helpers::GanttTest < ActiveSupport::TestCase ...@@ -525,12 +525,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_version(@version, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
assert_select "div.milestone.starting", false assert_select "div.version.starting", false
end end
should "appear at the starting point" do should "appear at the starting point" do
@response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
assert_select "div.milestone.starting[style*=left:52px]" assert_select "div.version.starting[style*=left:28px]", true, @response.body
end end
end end
...@@ -540,13 +540,13 @@ class Redmine::Helpers::GanttTest < ActiveSupport::TestCase ...@@ -540,13 +540,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_version(@version, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
assert_select "div.milestone.ending", false assert_select "div.version.ending", false
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_version(@version, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
assert_select "div.milestone.ending[style*=left:84px]" assert_select "div.version.ending[style*=left:84px]", true, @response.body
end end
end end
...@@ -555,17 +555,17 @@ class Redmine::Helpers::GanttTest < ActiveSupport::TestCase ...@@ -555,17 +555,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_version(@version, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
assert_select "div.version-name", /#{@version.name}/ assert_select "div.version.label", /#{@version.name}/
end end
should "show the version name" do should "show the version name" do
@response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
assert_select "div.version-name", /#{@version.name}/ assert_select "div.version.label", /#{@version.name}/
end end
should "show the percent complete" do should "show the percent complete" do
@response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4}) @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
assert_select "div.version-name", /30%/ assert_select "div.version.label", /30%/
end end
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment