From 708c3c9ec6efd8359efe450371ac818d406f6fd4 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 7 Apr 2007 12:09:01 +0000 Subject: [PATCH] Added versions due dates on gantt chart. git-svn-id: http://redmine.rubyforge.org/svn/trunk@428 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/projects_controller.rb | 6 +- app/models/version.rb | 8 +++ app/views/projects/gantt.rfpdf | 81 ++++++++++++++++---------- app/views/projects/gantt.rhtml | 28 ++++++--- public/stylesheets/application.css | 1 + 5 files changed, 83 insertions(+), 41 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 80855889a..0cbc6b5a7 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -592,14 +592,16 @@ class ProjectsController < ApplicationController @date_from = Date.civil(@year_from, @month_from, 1) @date_to = (@date_from >> @months) - 1 + @events = [] @project.issues_with_subprojects(params[:with_subprojects]) do - @issues = Issue.find(:all, + @events += Issue.find(:all, :order => "start_date, due_date", :include => [:tracker, :status, :assigned_to, :priority], :conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date?)) and start_date is not null and due_date is not null and #{Issue.table_name}.tracker_id in (#{@selected_tracker_ids.join(',')}))", @date_from, @date_to, @date_from, @date_to, @date_from, @date_to] ) unless @selected_tracker_ids.empty? end - @issues ||=[] + @events += @project.versions.find(:all, :conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to]) + @events.sort! {|x,y| x.start_date <=> y.start_date } if params[:output]=='pdf' @options_for_rfpdf ||= {} diff --git a/app/models/version.rb b/app/models/version.rb index 611500c8c..ddae037a6 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -25,6 +25,14 @@ class Version < ActiveRecord::Base validates_uniqueness_of :name, :scope => [:project_id] validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :activerecord_error_not_a_date + def start_date + effective_date + end + + def due_date + effective_date + end + private def check_integrity raise "Can't delete version" if self.fixed_issues.find(:first) diff --git a/app/views/projects/gantt.rfpdf b/app/views/projects/gantt.rfpdf index 6f85ce742..f5e64b1b3 100644 --- a/app/views/projects/gantt.rfpdf +++ b/app/views/projects/gantt.rfpdf @@ -106,51 +106,70 @@ pdf.Cell(subject_width+g_width-15, headers_heigth, "", 1) # top = headers_heigth + y_start pdf.SetFontStyle('B',7) -@issues.each do |i| +@events.each do |i| pdf.SetY(top) pdf.SetX(15) - pdf.Cell(subject_width-15, 5, "#{i.tracker.name} #{i.id}: #{i.subject}".sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)'), "LR") + + if i.is_a? Issue + pdf.Cell(subject_width-15, 5, "#{i.tracker.name} #{i.id}: #{i.subject}".sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)'), "LR") + else + pdf.Cell(subject_width-15, 5, "#{l(:label_version)}: #{i.name}", "LR") + end pdf.SetY(top) pdf.SetX(subject_width) pdf.Cell(g_width, 5, "", "LR") + + pdf.SetY(top+1.5) - i_start_date = (i.start_date >= @date_from ? i.start_date : @date_from ) - i_end_date = (i.due_date <= @date_to ? i.due_date : @date_to ) - - i_done_date = i.start_date + ((i.due_date - i.start_date+1)*i.done_ratio/100).floor - i_done_date = (i_done_date <= @date_from ? @date_from : i_done_date ) - i_done_date = (i_done_date >= @date_to ? @date_to : i_done_date ) + if i.is_a? Issue + i_start_date = (i.start_date >= @date_from ? i.start_date : @date_from ) + i_end_date = (i.due_date <= @date_to ? i.due_date : @date_to ) + + i_done_date = i.start_date + ((i.due_date - i.start_date+1)*i.done_ratio/100).floor + i_done_date = (i_done_date <= @date_from ? @date_from : i_done_date ) + i_done_date = (i_done_date >= @date_to ? @date_to : i_done_date ) + + i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today + + i_left = ((i_start_date - @date_from)*zoom) + i_width = ((i_end_date - i_start_date + 1)*zoom) + d_width = ((i_done_date - i_start_date)*zoom) + l_width = ((i_late_date - i_start_date+1)*zoom) if i_late_date + l_width ||= 0 - i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today + pdf.SetX(subject_width + i_left) + pdf.SetFillColor(200,200,200) + pdf.Cell(i_width, 2, "", 0, 0, "", 1) - i_left = ((i_start_date - @date_from)*zoom) - i_width = ((i_end_date - i_start_date + 1)*zoom) - d_width = ((i_done_date - i_start_date)*zoom) - l_width = ((i_late_date - i_start_date+1)*zoom) if i_late_date - l_width ||= 0 - - pdf.SetY(top+1.5) - pdf.SetX(subject_width + i_left) - pdf.SetFillColor(200,200,200) - pdf.Cell(i_width, 2, "", 0, 0, "", 1) - - if l_width > 0 + if l_width > 0 + pdf.SetY(top+1.5) + pdf.SetX(subject_width + i_left) + pdf.SetFillColor(255,100,100) + pdf.Cell(l_width, 2, "", 0, 0, "", 1) + end + if d_width > 0 + pdf.SetY(top+1.5) + pdf.SetX(subject_width + i_left) + pdf.SetFillColor(100,100,255) + pdf.Cell(d_width, 2, "", 0, 0, "", 1) + end + pdf.SetY(top+1.5) + pdf.SetX(subject_width + i_left + i_width) + pdf.Cell(30, 2, "#{i.status.name} #{i.done_ratio}%") + else + i_left = ((i.start_date - @date_from)*zoom) + pdf.SetX(subject_width + i_left) - pdf.SetFillColor(255,100,100) - pdf.Cell(l_width, 2, "", 0, 0, "", 1) - end - if d_width > 0 + pdf.SetFillColor(50,200,50) + pdf.Cell(2, 2, "", 0, 0, "", 1) + pdf.SetY(top+1.5) - pdf.SetX(subject_width + i_left) - pdf.SetFillColor(100,100,255) - pdf.Cell(d_width, 2, "", 0, 0, "", 1) + pdf.SetX(subject_width + i_left + 3) + pdf.Cell(30, 2, "#{i.name}") end - pdf.SetY(top+1.5) - pdf.SetX(subject_width + i_left + i_width) - pdf.Cell(30, 2, "#{i.status.name} #{i.done_ratio}%") top = top + 5 pdf.SetDrawColor(200, 200, 200) diff --git a/app/views/projects/gantt.rhtml b/app/views/projects/gantt.rhtml index 8c6c5b635..4a10a7b4c 100644 --- a/app/views/projects/gantt.rhtml +++ b/app/views/projects/gantt.rhtml @@ -67,7 +67,7 @@ if @zoom >1 end g_width = (@date_to - @date_from + 1)*zoom -g_height = [(20 * @issues.length + 6)+150, 206].max +g_height = [(20 * @events.length + 6)+150, 206].max t_height = g_height + headers_height %> @@ -83,11 +83,15 @@ t_height = g_height + headers_height # Tasks subjects # top = headers_height + 8 -@issues.each do |i| %> -
- <%= link_to "#{i.tracker.name} ##{i.id}", { :controller => 'issues', :action => 'show', :id => i }, :title => "#{i.subject}" %>: - <%=h i.subject.sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)') %> -
+@events.each do |i| %> +
+ <% if i.is_a? Issue %> + <%= link_to "#{i.tracker.name} ##{i.id}", { :controller => 'issues', :action => 'show', :id => i }, :title => "#{i.subject}" %>: + <%=h i.subject.sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)') %> + <% else %> + <%= "#{l(:label_version)}: #{i.name}" %> + <% end %> +
<% top = top + 20 end %> @@ -180,8 +184,8 @@ if Date.today >= @date_from and Date.today <= @date_to %> # Tasks # top = headers_height + 10 -@issues.each do |i| %> - <% +@events.each do |i| + if i.is_a? Issue i_start_date = (i.start_date >= @date_from ? i.start_date : @date_from ) i_end_date = (i.due_date <= @date_to ? i.due_date : @date_to ) @@ -212,6 +216,14 @@ top = headers_height + 10 <%= render :partial => "issues/tooltip", :locals => { :issue => i }%> +<% else + i_left = ((i.start_date - @date_from)*zoom).floor + %> +
 
+
+ <%= i.name %> +
+<% end %> <% top = top + 20 end %> diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 185cfa87e..97ac05b71 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -559,6 +559,7 @@ font-size: 1em; .task_late { background:#f66 url(../images/task_late.png); border: 1px solid #f66; } .task_done { background:#66f url(../images/task_done.png); border: 1px solid #66f; } .task_todo { background:#aaa url(../images/task_todo.png); border: 1px solid #aaa; } +.milestone { background-image:url(../images/milestone.png); background-repeat: no-repeat; border: 0; } /***** Tooltips ******/ .tooltip{position:relative;z-index:24;} -- 2.39.5