Commit 2986afc0 authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

Adds support for free ticket filtering and custom queries on Gantt chart.

ProjectsController#gantt moved to IssuesController.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1797 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent a8e3ddf3
......@@ -20,7 +20,7 @@ class IssuesController < ApplicationController
before_filter :find_issue, :only => [:show, :edit, :reply, :destroy_attachment]
before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
before_filter :find_project, :only => [:new, :update_form, :preview]
before_filter :find_project, :only => [:new, :update_form, :preview, :gantt]
before_filter :authorize, :except => [:index, :changes, :preview, :update_form, :context_menu]
before_filter :find_optional_project, :only => [:index, :changes]
accept_key_auth :index, :changes
......@@ -322,6 +322,38 @@ class IssuesController < ApplicationController
redirect_to :action => 'show', :id => @issue
end
def gantt
@gantt = Redmine::Helpers::Gantt.new(params)
retrieve_query
if @query.valid?
events = []
# Issues that have start and due dates
events += Issue.find(:all,
:order => "start_date, due_date",
:include => [:tracker, :status, :assigned_to, :priority, :project],
:conditions => ["(#{@query.statement}) AND (((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
)
# Issues that don't have a due date but that are assigned to a version with a date
events += Issue.find(:all,
:order => "start_date, effective_date",
:include => [:tracker, :status, :assigned_to, :priority, :project, :fixed_version],
:conditions => ["(#{@query.statement}) AND (((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to]
)
# Related versions
version_ids = events.collect(&:fixed_version_id).compact.uniq
events += Version.find_all_by_id(version_ids, :include => :project,
:conditions => ["effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to]) unless version_ids.empty?
@gantt.events = events
end
respond_to do |format|
format.html { render :template => "issues/gantt.rhtml", :layout => !request.xhr? }
format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png") } if @gantt.respond_to?('to_image')
format.pdf { send_data(render(:template => "issues/gantt.rfpdf", :layout => false), :type => 'application/pdf', :filename => "#{@project.identifier}-gantt.pdf") }
end
end
def context_menu
@issues = Issue.find_all_by_id(params[:ids], :include => :project)
if (@issues.size == 1)
......
......@@ -272,69 +272,6 @@ class ProjectsController < ApplicationController
@calendar.events = events
render :layout => false if request.xhr?
end
def gantt
@trackers = @project.rolled_up_trackers
retrieve_selected_tracker_ids(@trackers)
if params[:year] and params[:year].to_i >0
@year_from = params[:year].to_i
if params[:month] and params[:month].to_i >=1 and params[:month].to_i <= 12
@month_from = params[:month].to_i
else
@month_from = 1
end
else
@month_from ||= Date.today.month
@year_from ||= Date.today.year
end
zoom = (params[:zoom] || User.current.pref[:gantt_zoom]).to_i
@zoom = (zoom > 0 && zoom < 5) ? zoom : 2
months = (params[:months] || User.current.pref[:gantt_months]).to_i
@months = (months > 0 && months < 25) ? months : 6
# Save gantt paramters as user preference (zoom and months count)
if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
User.current.preference.save
end
@date_from = Date.civil(@year_from, @month_from, 1)
@date_to = (@date_from >> @months) - 1
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
@events = []
@project.issues_with_subprojects(@with_subprojects) do
# Issues that have start and due dates
@events += Issue.find(:all,
:order => "start_date, due_date",
:include => [:tracker, :status, :assigned_to, :priority, :project],
:conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_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?
# Issues that don't have a due date but that are assigned to a version with a date
@events += Issue.find(:all,
:order => "start_date, effective_date",
:include => [:tracker, :status, :assigned_to, :priority, :project, :fixed_version],
:conditions => ["(((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_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?
@events += Version.find(:all, :include => :project,
:conditions => ["effective_date BETWEEN ? AND ?", @date_from, @date_to])
end
@events.sort! {|x,y| x.start_date <=> y.start_date }
if params[:format]=='pdf'
@options_for_rfpdf ||= {}
@options_for_rfpdf[:file_name] = "#{@project.identifier}-gantt.pdf"
render :template => "projects/gantt.rfpdf", :layout => false
elsif params[:format]=='png' && respond_to?('gantt_image')
image = gantt_image(@events, @date_from, @months, @zoom)
image.format = 'PNG'
send_data(image.to_blob, :disposition => 'inline', :type => 'image/png', :filename => "#{@project.identifier}-gantt.png")
else
render :template => "projects/gantt.rhtml"
end
end
private
......
......@@ -45,154 +45,4 @@ module ProjectsHelper
]
tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
end
# Generates a gantt image
# Only defined if RMagick is avalaible
def gantt_image(events, date_from, months, zoom)
date_to = (date_from >> months)-1
show_weeks = zoom > 1
show_days = zoom > 2
subject_width = 320
header_heigth = 18
# width of one day in pixels
zoom = zoom*2
g_width = (date_to - date_from + 1)*zoom
g_height = 20 * events.length + 20
headers_heigth = (show_weeks ? 2*header_heigth : header_heigth)
height = g_height + headers_heigth
imgl = Magick::ImageList.new
imgl.new_image(subject_width+g_width+1, height)
gc = Magick::Draw.new
# Subjects
top = headers_heigth + 20
gc.fill('black')
gc.stroke('transparent')
gc.stroke_width(1)
events.each do |i|
gc.text(4, top + 2, (i.is_a?(Issue) ? i.subject : i.name))
top = top + 20
end
# Months headers
month_f = date_from
left = subject_width
months.times do
width = ((month_f >> 1) - month_f) * zoom
gc.fill('white')
gc.stroke('grey')
gc.stroke_width(1)
gc.rectangle(left, 0, left + width, height)
gc.fill('black')
gc.stroke('transparent')
gc.stroke_width(1)
gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}")
left = left + width
month_f = month_f >> 1
end
# Weeks headers
if show_weeks
left = subject_width
height = header_heigth
if date_from.cwday == 1
# date_from is monday
week_f = date_from
else
# find next monday after date_from
week_f = date_from + (7 - date_from.cwday + 1)
width = (7 - date_from.cwday + 1) * zoom
gc.fill('white')
gc.stroke('grey')
gc.stroke_width(1)
gc.rectangle(left, header_heigth, left + width, 2*header_heigth + g_height-1)
left = left + width
end
while week_f <= date_to
width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom
gc.fill('white')
gc.stroke('grey')
gc.stroke_width(1)
gc.rectangle(left.round, header_heigth, left.round + width, 2*header_heigth + g_height-1)
gc.fill('black')
gc.stroke('transparent')
gc.stroke_width(1)
gc.text(left.round + 2, header_heigth + 14, week_f.cweek.to_s)
left = left + width
week_f = week_f+7
end
end
# Days details (week-end in grey)
if show_days
left = subject_width
height = g_height + header_heigth - 1
wday = date_from.cwday
(date_to - date_from + 1).to_i.times do
width = zoom
gc.fill(wday == 6 || wday == 7 ? '#eee' : 'white')
gc.stroke('grey')
gc.stroke_width(1)
gc.rectangle(left, 2*header_heigth, left + width, 2*header_heigth + g_height-1)
left = left + width
wday = wday + 1
wday = 1 if wday > 7
end
end
# border
gc.fill('transparent')
gc.stroke('grey')
gc.stroke_width(1)
gc.rectangle(0, 0, subject_width+g_width, headers_heigth)
gc.stroke('black')
gc.rectangle(0, 0, subject_width+g_width, g_height+ headers_heigth-1)
# content
top = headers_heigth + 20
gc.stroke('transparent')
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 )
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 = subject_width + ((i_start_date - date_from)*zoom).floor
i_width = ((i_end_date - i_start_date + 1)*zoom).floor # total width of the issue
d_width = ((i_done_date - i_start_date)*zoom).floor # done width
l_width = i_late_date ? ((i_late_date - i_start_date+1)*zoom).floor : 0 # delay width
gc.fill('grey')
gc.rectangle(i_left, top, i_left + i_width, top - 6)
gc.fill('red')
gc.rectangle(i_left, top, i_left + l_width, top - 6) if l_width > 0
gc.fill('blue')
gc.rectangle(i_left, top, i_left + d_width, top - 6) if d_width > 0
gc.fill('black')
gc.text(i_left + i_width + 5,top + 1, "#{i.status.name} #{i.done_ratio}%")
else
i_left = subject_width + ((i.start_date - date_from)*zoom).floor
gc.fill('green')
gc.rectangle(i_left, top, i_left + 6, top - 6)
gc.fill('black')
gc.text(i_left + 11, top + 1, i.name)
end
top = top + 20
end
# today red line
if Date.today >= date_from and Date.today <= date_to
gc.stroke('red')
x = (Date.today-date_from+1)*zoom + subject_width
gc.line(x, headers_heigth, x, headers_heigth + g_height-1)
end
gc.draw(imgl)
imgl
end if Object.const_defined?(:Magick)
end
......@@ -3,12 +3,22 @@
<% if @project %>
<%= link_to l(:field_summary), :controller => 'reports', :action => 'issue_report', :id => @project %><br />
<%= link_to l(:label_change_log), :controller => 'projects', :action => 'changelog', :id => @project %>
<% planning_links = []
planning_links << link_to_if_authorized(l(:label_calendar), :controller => 'projects', :action => 'calendar', :id => @project)
planning_links << link_to_if_authorized(l(:label_gantt), :action => 'gantt', :project_id => @project)
planning_links.compact!
unless planning_links.empty? %>
<h3><%= l(:label_planning) %></h3>
<p><%= planning_links.join(' | ') %></p>
<% end %>
<% end %>
<% unless sidebar_queries.empty? -%>
<h3><%= l(:label_query_plural) %></h3>
<% sidebar_queries.each do |query| -%>
<%= link_to query.name, :controller => 'issues', :action => 'index', :project_id => @project, :query_id => query %><br />
<%= link_to query.name, :query_id => query %><br />
<% end -%>
<% end -%>
......@@ -17,17 +17,17 @@ headers_heigth = header_heigth
show_weeks = false
show_days = false
if @months < 7
if @gantt.months < 7
show_weeks = true
headers_heigth = 2*header_heigth
if @months < 3
if @gantt.months < 3
show_days = true
headers_heigth = 3*header_heigth
end
end
g_width = 210
zoom = (g_width) / (@date_to - @date_from + 1)
zoom = (g_width) / (@gantt.date_to - @gantt.date_from + 1)
g_height = 120
t_height = g_height + headers_heigth
......@@ -37,10 +37,10 @@ y_start = pdf.GetY
#
# Months headers
#
month_f = @date_from
month_f = @gantt.date_from
left = subject_width
height = header_heigth
@months.times do
@gantt.months.times do
width = ((month_f >> 1) - month_f) * zoom
pdf.SetY(y_start)
pdf.SetX(left)
......@@ -55,20 +55,20 @@ end
if show_weeks
left = subject_width
height = header_heigth
if @date_from.cwday == 1
# @date_from is monday
week_f = @date_from
if @gantt.date_from.cwday == 1
# @gantt.date_from is monday
week_f = @gantt.date_from
else
# find next monday after @date_from
week_f = @date_from + (7 - @date_from.cwday + 1)
width = (7 - @date_from.cwday + 1) * zoom-1
# find next monday after @gantt.date_from
week_f = @gantt.date_from + (7 - @gantt.date_from.cwday + 1)
width = (7 - @gantt.date_from.cwday + 1) * zoom-1
pdf.SetY(y_start + header_heigth)
pdf.SetX(left)
pdf.Cell(width + 1, height, "", "LTR")
left = left + width+1
end
while week_f <= @date_to
width = (week_f + 6 <= @date_to) ? 7 * zoom : (@date_to - week_f + 1) * zoom
while week_f <= @gantt.date_to
width = (week_f + 6 <= @gantt.date_to) ? 7 * zoom : (@gantt.date_to - week_f + 1) * zoom
pdf.SetY(y_start + header_heigth)
pdf.SetX(left)
pdf.Cell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C")
......@@ -83,9 +83,9 @@ end
if show_days
left = subject_width
height = header_heigth
wday = @date_from.cwday
wday = @gantt.date_from.cwday
pdf.SetFontStyle('B',7)
(@date_to - @date_from + 1).to_i.times do
(@gantt.date_to - @gantt.date_from + 1).to_i.times do
width = zoom
pdf.SetY(y_start + 2 * header_heigth)
pdf.SetX(left)
......@@ -106,7 +106,7 @@ pdf.Cell(subject_width+g_width-15, headers_heigth, "", 1)
#
top = headers_heigth + y_start
pdf.SetFontStyle('B',7)
@events.each do |i|
@gantt.events.each do |i|
pdf.SetY(top)
pdf.SetX(15)
......@@ -123,16 +123,16 @@ pdf.SetFontStyle('B',7)
pdf.SetY(top+1.5)
if i.is_a? Issue
i_start_date = (i.start_date >= @date_from ? i.start_date : @date_from )
i_end_date = (i.due_before <= @date_to ? i.due_before : @date_to )
i_start_date = (i.start_date >= @gantt.date_from ? i.start_date : @gantt.date_from )
i_end_date = (i.due_before <= @gantt.date_to ? i.due_before : @gantt.date_to )
i_done_date = i.start_date + ((i.due_before - 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_done_date = (i_done_date <= @gantt.date_from ? @gantt.date_from : i_done_date )
i_done_date = (i_done_date >= @gantt.date_to ? @gantt.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_left = ((i_start_date - @gantt.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
......@@ -159,7 +159,7 @@ pdf.SetFontStyle('B',7)
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)
i_left = ((i.start_date - @gantt.date_from)*zoom)
pdf.SetX(subject_width + i_left)
pdf.SetFillColor(50,200,50)
......
......@@ -58,7 +58,7 @@
<% content_for :sidebar do %>
<% planning_links = []
planning_links << link_to_if_authorized(l(:label_calendar), :action => 'calendar', :id => @project)
planning_links << link_to_if_authorized(l(:label_gantt), :action => 'gantt', :id => @project)
planning_links << link_to_if_authorized(l(:label_gantt), :controller => 'issues', :action => 'gantt', :project_id => @project)
planning_links.compact!
unless planning_links.empty? %>
<h3><%= l(:label_planning) %></h3>
......
......@@ -2,3 +2,4 @@
Mime::SET << Mime::CSV unless Mime::SET.include?(Mime::CSV)
Mime::Type.register 'application/pdf', :pdf
Mime::Type.register 'image/png', :png
......@@ -45,7 +45,7 @@ Redmine::AccessControl.map do |map|
map.permission :manage_public_queries, {:queries => [:new, :edit, :destroy]}, :require => :member
map.permission :save_queries, {:queries => [:new, :edit, :destroy]}, :require => :loggedin
# Gantt & calendar
map.permission :view_gantt, :projects => :gantt
map.permission :view_gantt, :issues => :gantt
map.permission :view_calendar, :projects => :calendar
# Watchers
map.permission :view_issue_watchers, {}
......
# Redmine - project management software
# Copyright (C) 2006-2008 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module Redmine
module Helpers
# Simple class to handle gantt chart data
class Gantt
attr_reader :year_from, :month_from, :date_from, :date_to, :zoom, :months, :events
def initialize(options={})
options = options.dup
@events = []
if options[:year] && options[:year].to_i >0
@year_from = options[:year].to_i
if options[:month] && options[:month].to_i >=1 && options[:month].to_i <= 12
@month_from = options[:month].to_i
else
@month_from = 1
end
else
@month_from ||= Date.today.month
@year_from ||= Date.today.year
end
zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i
@zoom = (zoom > 0 && zoom < 5) ? zoom : 2
months = (options[:months] || User.current.pref[:gantt_months]).to_i
@months = (months > 0 && months < 25) ? months : 6
# Save gantt parameters as user preference (zoom and months count)
if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
User.current.preference.save
end
@date_from = Date.civil(@year_from, @month_from, 1)
@date_to = (@date_from >> @months) - 1
end
def events=(e)
@events = e.sort {|x,y| x.start_date <=> y.start_date }
end
def params
{ :zoom => zoom, :year => year_from, :month => month_from, :months => months }
end
def params_previous
{ :year => (date_from << months).year, :month => (date_from << months).month, :zoom => zoom, :months => months }
end
def params_next
{ :year => (date_from >> months).year, :month => (date_from >> months).month, :zoom => zoom, :months => months }
end
# Generates a gantt image
# Only defined if RMagick is avalaible
def to_image(format='PNG')
date_to = (@date_from >> @months)-1
show_weeks = @zoom > 1
show_days = @zoom > 2
subject_width = 320
header_heigth = 18
# width of one day in pixels
zoom = @zoom*2
g_width = (@date_to - @date_from + 1)*zoom
g_height = 20 * events.length + 20
headers_heigth = (show_weeks ? 2*header_heigth : header_heigth)
height = g_height + headers_heigth
imgl = Magick::ImageList.new
imgl.new_image(subject_width+g_width+1, height)
gc = Magick::Draw.new
# Subjects
top = headers_heigth + 20
gc.fill('black')
gc.stroke('transparent')
gc.stroke_width(1)
events.each do |i|
gc.text(4, top + 2, (i.is_a?(Issue) ? i.subject : i.name))
top = top + 20
end
# Months headers
month_f = @date_from
left = subject_width
@months.times do
width = ((month_f >> 1) - month_f) * zoom
gc.fill('white')
gc.stroke('grey')
gc.stroke_width(1)
gc.rectangle(left, 0, left + width, height)
gc.fill('black')
gc.stroke('transparent')
gc.stroke_width(1)
gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}")
left = left + width
month_f = month_f >> 1
end
# Weeks headers
if show_weeks
left = subject_width
height = header_heigth
if @date_from.cwday == 1
# date_from is monday
week_f = date_from
else
# find next monday after date_from
week_f = @date_from + (7 - @date_from.cwday + 1)
width = (7 - @date_from.cwday + 1) * zoom
gc.fill('white')
gc.stroke('grey')
gc.stroke_width(1)
gc.rectangle(left, header_heigth, left + width, 2*header_heigth + g_height-1)
left = left + width
end
while week_f <= date_to
width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom
gc.fill('white')
gc.stroke('grey')
gc.stroke_width(1)
gc.rectangle(left.round, header_heigth, left.round + width, 2*header_heigth + g_height-1)
gc.fill('black')
gc.stroke('transparent')
gc.stroke_width(1)
gc.text(left.round + 2, header_heigth + 14, week_f.cweek.to_s)
left = left + width
week_f = week_f+7
end
end
# Days details (week-end in grey)
if show_days
left = subject_width
height = g_height + header_heigth - 1
wday = @date_from.cwday
(date_to - @date_from + 1).to_i.times do
width = zoom
gc.fill(wday == 6 || wday == 7 ? '#eee' : 'white')
gc.stroke('grey')
gc.stroke_width(1)
gc.rectangle(left, 2*header_heigth, left + width, 2*header_heigth + g_height-1)
left = left + width
wday = wday + 1
wday = 1 if wday > 7
end
end
# border
gc.fill('transparent')
gc.stroke('grey')
gc.stroke_width(1)
gc.rectangle(0, 0, subject_width+g_width, headers_heigth)
gc.stroke('black')
gc.rectangle(0, 0, subject_width+g_width, g_height+ headers_heigth-1)
# content
top = headers_heigth + 20
gc.stroke('transparent')
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_before <= date_to ? i.due_before : date_to )
i_done_date = i.start_date + ((i.due_before - 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 = subject_width + ((i_start_date - @date_from)*zoom).floor
i_width = ((i_end_date - i_start_date + 1)*zoom).floor # total width of the issue
d_width = ((i_done_date - i_start_date)*zoom).floor # done width
l_width = i_late_date ? ((i_late_date - i_start_date+1)*zoom).floor : 0 # delay width
gc.fill('grey')
gc.rectangle(i_left, top, i_left + i_width, top - 6)
gc.fill('red')
gc.rectangle(i_left, top, i_left + l_width, top - 6) if l_width > 0
gc.fill('blue')
gc.rectangle(i_left, top, i_left + d_width, top - 6) if d_width > 0
gc.fill('black')
gc.text(i_left + i_width + 5,top + 1, "#{i.status.name} #{i.done_ratio}%")
else
i_left = subject_width + ((i.start_date - @date_from)*zoom).floor
gc.fill('green')
gc.rectangle(i_left, top, i_left + 6, top - 6)
gc.fill('black')
gc.text(i_left + 11, top + 1, i.name)
end
top = top + 20
end
# today red line
if Date.today >= @date_from and Date.today <= date_to
gc.stroke('red')
x = (Date.today-@date_from+1)*zoom + subject_width
gc.line(x, headers_heigth, x, headers_heigth + g_height-1)
end
gc.draw(imgl)
imgl.format = format
imgl.to_blob
end if Object.const_defined?(:Magick)
end
end
end
......@@ -84,7 +84,6 @@ table.list td { vertical-align: top; }
table.list td.id { width: 2%; text-align: center;}
table.list td.checkbox { width: 15px; padding: 0px;}
table.list.issues { margin-top: 10px; }
tr.issue { text-align: center; white-space: nowrap; }
tr.issue td.subject, tr.issue td.category { white-space: normal; }
tr.issue td.subject { text-align: left; }
......@@ -165,7 +164,7 @@ div.issue {background:#ffffdd; padding:6px; margin-bottom:6px;border: 1px solid
p.breadcrumb { font-size: 0.9em; margin: 4px 0 4px 0;}
p.subtitle { font-size: 0.9em; margin: -6px 0 12px 0; font-style: italic; }
fieldset#filters { padding: 0.7em; }
fieldset#filters, fieldset#date-range { padding: 0.7em; margin-bottom: 8px; }
fieldset#filters p { margin: 1.2em 0 0.8em 2px; }
fieldset#filters .buttons { font-size: 0.9em; }
fieldset#filters table { border-collapse: collapse; }
......
......@@ -125,6 +125,41 @@ class IssuesControllerTest < Test::Unit::TestCase
assert_not_nil assigns(:issues)
assert_equal 'application/pdf', @response.content_type
end
def test_gantt
get :gantt, :project_id => 1
assert_response :success
assert_template 'gantt.rhtml'
assert_not_nil assigns(:gantt)
events = assigns(:gantt).events
assert_not_nil events
# Issue with start and due dates
i = Issue.find(1)
assert_not_nil i.due_date
assert events.include?(Issue.find(1))
# Issue with without due date but targeted to a version with date
i = Issue.find(2)
assert_nil i.due_date
assert events.include?(i)
end
def test_gantt_export_to_pdf
get :gantt, :project_id => 1, :format => 'pdf'
assert_response :success
assert_template 'gantt.rfpdf'
assert_equal 'application/pdf', @response.content_type
assert_not_nil assigns(:gantt)
end
if Object.const_defined?(:Magick)
def test_gantt_image
get :gantt, :project_id => 1, :format => 'png'
assert_response :success
assert_equal 'image/png', @response.content_type
end
else
puts "RMagick not installed. Skipping tests !!!"
end
def test_changes
get :changes, :project_id => 1
......
......@@ -231,47 +231,6 @@ class ProjectsControllerTest < Test::Unit::TestCase
assert_not_nil assigns(:calendar)
assert_tag :tag => 'a', :content => /#6/
end
def test_gantt
get :gantt, :id => 1
assert_response :success
assert_template 'gantt.rhtml'
events = assigns(:events)
assert_not_nil events
# Issue with start and due dates
i = Issue.find(1)
assert_not_nil i.due_date
assert events.include?(Issue.find(1))
# Issue with without due date but targeted to a version with date
i = Issue.find(2)
assert_nil i.due_date
assert events.include?(i)
end
def test_gantt_with_subprojects_should_not_show_private_subprojects
get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
assert_response :success
assert_template 'gantt.rhtml'
assert_not_nil assigns(:events)
assert_no_tag :tag => 'a', :content => /#6/
end
def test_gantt_with_subprojects_should_show_private_subprojects
@request.session[:user_id] = 2
get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
assert_response :success
assert_template 'gantt.rhtml'
assert_not_nil assigns(:events)
assert_tag :tag => 'a', :content => /#6/
end
def test_gantt_export_to_pdf
get :gantt, :id => 1, :format => 'pdf'
assert_response :success
assert_template 'gantt.rfpdf'
assert_equal 'application/pdf', @response.content_type
assert_not_nil assigns(:events)
end
def test_archive
@request.session[:user_id] = 1 # admin
......
# redMine - project management software
# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.dirname(__FILE__) + '/../../test_helper'
class ProjectsHelperTest < HelperTestCase
include ProjectsHelper
include ActionView::Helpers::TextHelper
fixtures :projects, :trackers, :issue_statuses, :issues, :enumerations, :users, :issue_categories
def setup
super
end
if Object.const_defined?(:Magick)
def test_gantt_image
assert gantt_image(Issue.find(:all, :conditions => "start_date IS NOT NULL AND due_date IS NOT NULL"), Date.today, 6, 2)
end
def test_gantt_image_with_days
assert gantt_image(Issue.find(:all, :conditions => "start_date IS NOT NULL AND due_date IS NOT NULL"), Date.today, 3, 4)
end
else
puts "RMagick not installed. Skipping tests !!!"
def test_fake; assert true 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