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
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)
@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
]
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
<% 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 -%>
--- /dev/null
+<%\r
+pdf=IfpdfHelper::IFPDF.new(current_language)\r
+pdf.SetTitle("#{@project.name} - #{l(:label_gantt)}")\r
+pdf.AliasNbPages\r
+pdf.footer_date = format_date(Date.today)\r
+pdf.AddPage("L")\r
+pdf.SetFontStyle('B',12)\r
+pdf.SetX(15)\r
+pdf.Cell(70, 20, @project.name)\r
+pdf.Ln\r
+pdf.SetFontStyle('B',9)\r
+\r
+subject_width = 70\r
+header_heigth = 5\r
+\r
+headers_heigth = header_heigth\r
+show_weeks = false\r
+show_days = false\r
+\r
+if @gantt.months < 7\r
+ show_weeks = true\r
+ headers_heigth = 2*header_heigth\r
+ if @gantt.months < 3\r
+ show_days = true\r
+ headers_heigth = 3*header_heigth\r
+ end\r
+end\r
+\r
+g_width = 210\r
+zoom = (g_width) / (@gantt.date_to - @gantt.date_from + 1)\r
+g_height = 120\r
+t_height = g_height + headers_heigth\r
+\r
+y_start = pdf.GetY\r
+\r
+\r
+#\r
+# Months headers\r
+#\r
+month_f = @gantt.date_from\r
+left = subject_width\r
+height = header_heigth\r
+@gantt.months.times do \r
+ width = ((month_f >> 1) - month_f) * zoom \r
+ pdf.SetY(y_start)\r
+ pdf.SetX(left)\r
+ pdf.Cell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C")\r
+ left = left + width\r
+ month_f = month_f >> 1\r
+end \r
+\r
+#\r
+# Weeks headers\r
+#\r
+if show_weeks\r
+ left = subject_width\r
+ height = header_heigth\r
+ if @gantt.date_from.cwday == 1\r
+ # @gantt.date_from is monday\r
+ week_f = @gantt.date_from\r
+ else\r
+ # find next monday after @gantt.date_from\r
+ week_f = @gantt.date_from + (7 - @gantt.date_from.cwday + 1)\r
+ width = (7 - @gantt.date_from.cwday + 1) * zoom-1\r
+ pdf.SetY(y_start + header_heigth)\r
+ pdf.SetX(left)\r
+ pdf.Cell(width + 1, height, "", "LTR")\r
+ left = left + width+1\r
+ end\r
+ while week_f <= @gantt.date_to\r
+ width = (week_f + 6 <= @gantt.date_to) ? 7 * zoom : (@gantt.date_to - week_f + 1) * zoom\r
+ pdf.SetY(y_start + header_heigth)\r
+ pdf.SetX(left)\r
+ pdf.Cell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C")\r
+ left = left + width\r
+ week_f = week_f+7\r
+ end\r
+end\r
+\r
+#\r
+# Days headers\r
+#\r
+if show_days\r
+ left = subject_width\r
+ height = header_heigth\r
+ wday = @gantt.date_from.cwday\r
+ pdf.SetFontStyle('B',7)\r
+ (@gantt.date_to - @gantt.date_from + 1).to_i.times do \r
+ width = zoom\r
+ pdf.SetY(y_start + 2 * header_heigth)\r
+ pdf.SetX(left)\r
+ pdf.Cell(width, height, day_name(wday).first, "LTR", 0, "C")\r
+ left = left + width\r
+ wday = wday + 1\r
+ wday = 1 if wday > 7\r
+ end\r
+end\r
+\r
+pdf.SetY(y_start)\r
+pdf.SetX(15)\r
+pdf.Cell(subject_width+g_width-15, headers_heigth, "", 1)\r
+\r
+\r
+#\r
+# Tasks\r
+#\r
+top = headers_heigth + y_start\r
+pdf.SetFontStyle('B',7)\r
+@gantt.events.each do |i|\r
+ pdf.SetY(top)\r
+ pdf.SetX(15)\r
+ \r
+ if i.is_a? Issue\r
+ pdf.Cell(subject_width-15, 5, "#{i.tracker.name} #{i.id}: #{i.subject}".sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)'), "LR")\r
+ else\r
+ pdf.Cell(subject_width-15, 5, "#{l(:label_version)}: #{i.name}", "LR")\r
+ end\r
+\r
+ pdf.SetY(top)\r
+ pdf.SetX(subject_width)\r
+ pdf.Cell(g_width, 5, "", "LR")\r
+\r
+ pdf.SetY(top+1.5)\r
+ \r
+ if i.is_a? Issue\r
+ i_start_date = (i.start_date >= @gantt.date_from ? i.start_date : @gantt.date_from )\r
+ i_end_date = (i.due_before <= @gantt.date_to ? i.due_before : @gantt.date_to )\r
+ \r
+ i_done_date = i.start_date + ((i.due_before - i.start_date+1)*i.done_ratio/100).floor\r
+ i_done_date = (i_done_date <= @gantt.date_from ? @gantt.date_from : i_done_date )\r
+ i_done_date = (i_done_date >= @gantt.date_to ? @gantt.date_to : i_done_date )\r
+ \r
+ i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today\r
+ \r
+ i_left = ((i_start_date - @gantt.date_from)*zoom) \r
+ i_width = ((i_end_date - i_start_date + 1)*zoom)\r
+ d_width = ((i_done_date - i_start_date)*zoom)\r
+ l_width = ((i_late_date - i_start_date+1)*zoom) if i_late_date\r
+ l_width ||= 0\r
+ \r
+ pdf.SetX(subject_width + i_left)\r
+ pdf.SetFillColor(200,200,200)\r
+ pdf.Cell(i_width, 2, "", 0, 0, "", 1)\r
+ \r
+ if l_width > 0\r
+ pdf.SetY(top+1.5)\r
+ pdf.SetX(subject_width + i_left)\r
+ pdf.SetFillColor(255,100,100)\r
+ pdf.Cell(l_width, 2, "", 0, 0, "", 1)\r
+ end \r
+ if d_width > 0\r
+ pdf.SetY(top+1.5)\r
+ pdf.SetX(subject_width + i_left)\r
+ pdf.SetFillColor(100,100,255)\r
+ pdf.Cell(d_width, 2, "", 0, 0, "", 1)\r
+ end\r
+ \r
+ pdf.SetY(top+1.5)\r
+ pdf.SetX(subject_width + i_left + i_width)\r
+ pdf.Cell(30, 2, "#{i.status.name} #{i.done_ratio}%")\r
+ else\r
+ i_left = ((i.start_date - @gantt.date_from)*zoom) \r
+ \r
+ pdf.SetX(subject_width + i_left)\r
+ pdf.SetFillColor(50,200,50)\r
+ pdf.Cell(2, 2, "", 0, 0, "", 1) \r
+\r
+ pdf.SetY(top+1.5)\r
+ pdf.SetX(subject_width + i_left + 3)\r
+ pdf.Cell(30, 2, "#{i.name}")\r
+ end\r
+ \r
+ \r
+ top = top + 5\r
+ pdf.SetDrawColor(200, 200, 200)\r
+ pdf.Line(15, top, subject_width+g_width, top)\r
+ if pdf.GetY() > 180\r
+ pdf.AddPage("L")\r
+ top = 20\r
+ pdf.Line(15, top, subject_width+g_width, top)\r
+ end\r
+ pdf.SetDrawColor(0, 0, 0)\r
+end\r
+\r
+pdf.Line(15, top, subject_width+g_width, top)\r
+\r
+%>\r
+<%= pdf.Output %>
\ No newline at end of file
--- /dev/null
+<% form_tag(params.merge(:month => nil, :year => nil, :months => nil), :id => 'query_form') do %>
+<% if @query.new_record? %>
+ <h2><%=l(:label_gantt)%></h2>
+ <fieldset id="filters"><legend><%= l(:label_filter_plural) %></legend>
+ <%= render :partial => 'queries/filters', :locals => {:query => @query} %>
+ </fieldset>
+<% else %>
+ <h2><%=h @query.name %></h2>
+ <div id="query_form"></div>
+ <% html_title @query.name %>
+<% end %>
+
+<fieldset id="date-range"><legend><%= l(:label_date_range) %></legend>
+ <%= text_field_tag 'months', @gantt.months, :size => 2 %>
+ <%= l(:label_months_from) %>
+ <%= select_month(@gantt.month_from, :prefix => "month", :discard_type => true) %>
+ <%= select_year(@gantt.year_from, :prefix => "year", :discard_type => true) %>
+ <%= hidden_field_tag 'zoom', @gantt.zoom %>
+</fieldset>
+
+<p style="float:right; margin:0px;">
+<%= if @gantt.zoom < 4
+ link_to_remote image_tag('zoom_in.png'), {:url => @gantt.params.merge(:zoom => (@gantt.zoom+1)), :update => 'content'}, {:href => url_for(@gantt.params.merge(:zoom => (@gantt.zoom+1)))}
+ else
+ image_tag 'zoom_in_g.png'
+ end %>
+<%= if @gantt.zoom > 1
+ link_to_remote image_tag('zoom_out.png'), {:url => @gantt.params.merge(:zoom => (@gantt.zoom-1)), :update => 'content'}, {:href => url_for(@gantt.params.merge(:zoom => (@gantt.zoom-1)))}
+ else
+ image_tag 'zoom_out_g.png'
+ end %>
+</p>
+
+<p class="buttons">
+<%= link_to_remote l(:button_apply),
+ { :url => { :set_filter => (@query.new_record? ? 1 : nil) },
+ :update => "content",
+ :with => "Form.serialize('query_form')"
+ }, :class => 'icon icon-checked' %>
+
+<%= link_to_remote l(:button_clear),
+ { :url => { :set_filter => (@query.new_record? ? 1 : nil) },
+ :update => "content",
+ }, :class => 'icon icon-reload' if @query.new_record? %>
+</p>
+<% end %>
+
+<%= error_messages_for 'query' %>
+<% if @query.valid? %>
+<% zoom = 1
+@gantt.zoom.times { zoom = zoom * 2 }
+
+subject_width = 330
+header_heigth = 18
+
+headers_height = header_heigth
+show_weeks = false
+show_days = false
+
+if @gantt.zoom >1
+ show_weeks = true
+ headers_height = 2*header_heigth
+ if @gantt.zoom > 2
+ show_days = true
+ headers_height = 3*header_heigth
+ end
+end
+
+g_width = (@gantt.date_to - @gantt.date_from + 1)*zoom
+g_height = [(20 * @gantt.events.length + 6)+150, 206].max
+t_height = g_height + headers_height
+%>
+
+<table width="100%" style="border:0; border-collapse: collapse;">
+<tr>
+<td style="width:<%= subject_width %>px; padding:0px;">
+
+<div style="position:relative;height:<%= t_height + 24 %>px;width:<%= subject_width + 1 %>px;">
+<div style="right:-2px;width:<%= subject_width %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div>
+<div style="right:-2px;width:<%= subject_width %>px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div>
+<%
+#
+# Tasks subjects
+#
+top = headers_height + 8
+@gantt.events.each do |i| %>
+ <div style="position: absolute;line-height:1.2em;height:16px;top:<%= top %>px;left:4px;overflow:hidden;"><small>
+ <% if i.is_a? Issue %>
+ <%= h("#{i.project} -") unless @project && @project == i.project %>
+ <%= link_to_issue i %>: <%=h i.subject %>
+ <% else %>
+ <span class="icon icon-package">
+ <%= h("#{i.project} -") unless @project && @project == i.project %>
+ <%= link_to_version i %>
+ </span>
+ <% end %>
+ </small></div>
+ <% top = top + 20
+end %>
+</div>
+</td>
+<td>
+
+<div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;">
+<div style="width:<%= g_width-1 %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"> </div>
+<%
+#
+# Months headers
+#
+month_f = @gantt.date_from
+left = 0
+height = (show_weeks ? header_heigth : header_heigth + g_height)
+@gantt.months.times do
+ width = ((month_f >> 1) - month_f) * zoom - 1
+ %>
+ <div style="left:<%= left %>px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">
+ <%= link_to "#{month_f.year}-#{month_f.month}", @gantt.params.merge(:year => month_f.year, :month => month_f.month), :title => "#{month_name(month_f.month)} #{month_f.year}"%>
+ </div>
+ <%
+ left = left + width + 1
+ month_f = month_f >> 1
+end %>
+
+<%
+#
+# Weeks headers
+#
+if show_weeks
+ left = 0
+ height = (show_days ? header_heigth-1 : header_heigth-1 + g_height)
+ if @gantt.date_from.cwday == 1
+ # @date_from is monday
+ week_f = @gantt.date_from
+ else
+ # find next monday after @date_from
+ week_f = @gantt.date_from + (7 - @gantt.date_from.cwday + 1)
+ width = (7 - @gantt.date_from.cwday + 1) * zoom-1
+ %>
+ <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr"> </div>
+ <%
+ left = left + width+1
+ end %>
+ <%
+ while week_f <= @gantt.date_to
+ width = (week_f + 6 <= @gantt.date_to) ? 7 * zoom -1 : (@gantt.date_to - week_f + 1) * zoom-1
+ %>
+ <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">
+ <small><%= week_f.cweek if width >= 16 %></small>
+ </div>
+ <%
+ left = left + width+1
+ week_f = week_f+7
+ end
+end %>
+
+<%
+#
+# Days headers
+#
+if show_days
+ left = 0
+ height = g_height + header_heigth - 1
+ wday = @gantt.date_from.cwday
+ (@gantt.date_to - @gantt.date_from + 1).to_i.times do
+ width = zoom - 1
+ %>
+ <div style="left:<%= left %>px;top:37px;width:<%= width %>px;height:<%= height %>px;font-size:0.7em;<%= "background:#f1f1f1;" if wday > 5 %>" class="gantt_hdr">
+ <%= day_name(wday).first %>
+ </div>
+ <%
+ left = left + width+1
+ wday = wday + 1
+ wday = 1 if wday > 7
+ end
+end %>
+
+<%
+#
+# Tasks
+#
+top = headers_height + 10
+@gantt.events.each do |i|
+ if i.is_a? Issue
+ 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 <= @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 - @gantt.date_from)*zoom).floor
+ i_width = ((i_end_date - i_start_date + 1)*zoom).floor - 2 # total width of the issue (- 2 for left and right borders)
+ d_width = ((i_done_date - i_start_date)*zoom).floor - 2 # done width
+ l_width = i_late_date ? ((i_late_date - i_start_date+1)*zoom).floor - 2 : 0 # delay width
+ %>
+ <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;" class="task task_todo"> </div>
+ <% if l_width > 0 %>
+ <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= l_width %>px;" class="task task_late"> </div>
+ <% end %>
+ <% if d_width > 0 %>
+ <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= d_width %>px;" class="task task_done"> </div>
+ <% end %>
+ <div style="top:<%= top %>px;left:<%= i_left + i_width + 5 %>px;background:#fff;" class="task">
+ <%= i.status.name %>
+ <%= (i.done_ratio).to_i %>%
+ </div>
+ <div class="tooltip" style="position: absolute;top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;height:12px;">
+ <span class="tip">
+ <%= render_issue_tooltip i %>
+ </span></div>
+<% else
+ i_left = ((i.start_date - @gantt.date_from)*zoom).floor
+ %>
+ <div style="top:<%= top %>px;left:<%= i_left %>px;width:15px;" class="task milestone"> </div>
+ <div style="top:<%= top %>px;left:<%= i_left + 12 %>px;background:#fff;" class="task">
+ <%= h("#{i.project} -") unless @project && @project == i.project %>
+ <strong><%=h i %></strong>
+ </div>
+<% end %>
+ <% top = top + 20
+end %>
+
+<%
+#
+# Today red line (excluded from cache)
+#
+if Date.today >= @gantt.date_from and Date.today <= @gantt.date_to %>
+ <div style="position: absolute;height:<%= g_height %>px;top:<%= headers_height + 1 %>px;left:<%= ((Date.today-@gantt.date_from+1)*zoom).floor()-1 %>px;width:10px;border-left: 1px dashed red;"> </div>
+<% end %>
+
+</div>
+</td>
+</tr>
+</table>
+
+<table width="100%">
+<tr>
+<td align="left"><%= link_to_remote ('« ' + l(:label_previous)), {:url => @gantt.params_previous, :update => 'content', :complete => 'window.scrollTo(0,0)'}, {:href => url_for(@gantt.params_previous)} %></td>
+<td align="right"><%= link_to_remote (l(:label_next) + ' »'), {:url => @gantt.params_next, :update => 'content', :complete => 'window.scrollTo(0,0)'}, {:href => url_for(@gantt.params_next)} %></td>
+</tr>
+</table>
+
+<p class="other-formats">
+<%= l(:label_export_to) %>
+<span><%= link_to 'PDF', @gantt.params.merge(:format => 'pdf'), :class => 'pdf' %></span>
+<% if @gantt.respond_to?('to_image') %>
+<span><%= link_to 'PNG', @gantt.params.merge(:format => 'png'), :class => 'image' %></span>
+<% end %>
+</p>
+<% end # query.valid? %>
+
+<% content_for :sidebar do %>
+ <%= render :partial => 'issues/sidebar' %>
+<% end %>
+
+<% html_title(l(:label_gantt)) -%>
+++ /dev/null
-<%\r
-pdf=IfpdfHelper::IFPDF.new(current_language)\r
-pdf.SetTitle("#{@project.name} - #{l(:label_gantt)}")\r
-pdf.AliasNbPages\r
-pdf.footer_date = format_date(Date.today)\r
-pdf.AddPage("L")\r
-pdf.SetFontStyle('B',12)\r
-pdf.SetX(15)\r
-pdf.Cell(70, 20, @project.name)\r
-pdf.Ln\r
-pdf.SetFontStyle('B',9)\r
-\r
-subject_width = 70\r
-header_heigth = 5\r
-\r
-headers_heigth = header_heigth\r
-show_weeks = false\r
-show_days = false\r
-\r
-if @months < 7\r
- show_weeks = true\r
- headers_heigth = 2*header_heigth\r
- if @months < 3\r
- show_days = true\r
- headers_heigth = 3*header_heigth\r
- end\r
-end\r
-\r
-g_width = 210\r
-zoom = (g_width) / (@date_to - @date_from + 1)\r
-g_height = 120\r
-t_height = g_height + headers_heigth\r
-\r
-y_start = pdf.GetY\r
-\r
-\r
-#\r
-# Months headers\r
-#\r
-month_f = @date_from\r
-left = subject_width\r
-height = header_heigth\r
-@months.times do \r
- width = ((month_f >> 1) - month_f) * zoom \r
- pdf.SetY(y_start)\r
- pdf.SetX(left)\r
- pdf.Cell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C")\r
- left = left + width\r
- month_f = month_f >> 1\r
-end \r
-\r
-#\r
-# Weeks headers\r
-#\r
-if show_weeks\r
- left = subject_width\r
- height = header_heigth\r
- if @date_from.cwday == 1\r
- # @date_from is monday\r
- week_f = @date_from\r
- else\r
- # find next monday after @date_from\r
- week_f = @date_from + (7 - @date_from.cwday + 1)\r
- width = (7 - @date_from.cwday + 1) * zoom-1\r
- pdf.SetY(y_start + header_heigth)\r
- pdf.SetX(left)\r
- pdf.Cell(width + 1, height, "", "LTR")\r
- left = left + width+1\r
- end\r
- while week_f <= @date_to\r
- width = (week_f + 6 <= @date_to) ? 7 * zoom : (@date_to - week_f + 1) * zoom\r
- pdf.SetY(y_start + header_heigth)\r
- pdf.SetX(left)\r
- pdf.Cell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C")\r
- left = left + width\r
- week_f = week_f+7\r
- end\r
-end\r
-\r
-#\r
-# Days headers\r
-#\r
-if show_days\r
- left = subject_width\r
- height = header_heigth\r
- wday = @date_from.cwday\r
- pdf.SetFontStyle('B',7)\r
- (@date_to - @date_from + 1).to_i.times do \r
- width = zoom\r
- pdf.SetY(y_start + 2 * header_heigth)\r
- pdf.SetX(left)\r
- pdf.Cell(width, height, day_name(wday).first, "LTR", 0, "C")\r
- left = left + width\r
- wday = wday + 1\r
- wday = 1 if wday > 7\r
- end\r
-end\r
-\r
-pdf.SetY(y_start)\r
-pdf.SetX(15)\r
-pdf.Cell(subject_width+g_width-15, headers_heigth, "", 1)\r
-\r
-\r
-#\r
-# Tasks\r
-#\r
-top = headers_heigth + y_start\r
-pdf.SetFontStyle('B',7)\r
-@events.each do |i|\r
- pdf.SetY(top)\r
- pdf.SetX(15)\r
- \r
- if i.is_a? Issue\r
- pdf.Cell(subject_width-15, 5, "#{i.tracker.name} #{i.id}: #{i.subject}".sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)'), "LR")\r
- else\r
- pdf.Cell(subject_width-15, 5, "#{l(:label_version)}: #{i.name}", "LR")\r
- end\r
-\r
- pdf.SetY(top)\r
- pdf.SetX(subject_width)\r
- pdf.Cell(g_width, 5, "", "LR")\r
-\r
- pdf.SetY(top+1.5)\r
- \r
- if i.is_a? Issue\r
- i_start_date = (i.start_date >= @date_from ? i.start_date : @date_from )\r
- i_end_date = (i.due_before <= @date_to ? i.due_before : @date_to )\r
- \r
- i_done_date = i.start_date + ((i.due_before - i.start_date+1)*i.done_ratio/100).floor\r
- i_done_date = (i_done_date <= @date_from ? @date_from : i_done_date )\r
- i_done_date = (i_done_date >= @date_to ? @date_to : i_done_date )\r
- \r
- i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today\r
- \r
- i_left = ((i_start_date - @date_from)*zoom) \r
- i_width = ((i_end_date - i_start_date + 1)*zoom)\r
- d_width = ((i_done_date - i_start_date)*zoom)\r
- l_width = ((i_late_date - i_start_date+1)*zoom) if i_late_date\r
- l_width ||= 0\r
- \r
- pdf.SetX(subject_width + i_left)\r
- pdf.SetFillColor(200,200,200)\r
- pdf.Cell(i_width, 2, "", 0, 0, "", 1)\r
- \r
- if l_width > 0\r
- pdf.SetY(top+1.5)\r
- pdf.SetX(subject_width + i_left)\r
- pdf.SetFillColor(255,100,100)\r
- pdf.Cell(l_width, 2, "", 0, 0, "", 1)\r
- end \r
- if d_width > 0\r
- pdf.SetY(top+1.5)\r
- pdf.SetX(subject_width + i_left)\r
- pdf.SetFillColor(100,100,255)\r
- pdf.Cell(d_width, 2, "", 0, 0, "", 1)\r
- end\r
- \r
- pdf.SetY(top+1.5)\r
- pdf.SetX(subject_width + i_left + i_width)\r
- pdf.Cell(30, 2, "#{i.status.name} #{i.done_ratio}%")\r
- else\r
- i_left = ((i.start_date - @date_from)*zoom) \r
- \r
- pdf.SetX(subject_width + i_left)\r
- pdf.SetFillColor(50,200,50)\r
- pdf.Cell(2, 2, "", 0, 0, "", 1) \r
-\r
- pdf.SetY(top+1.5)\r
- pdf.SetX(subject_width + i_left + 3)\r
- pdf.Cell(30, 2, "#{i.name}")\r
- end\r
- \r
- \r
- top = top + 5\r
- pdf.SetDrawColor(200, 200, 200)\r
- pdf.Line(15, top, subject_width+g_width, top)\r
- if pdf.GetY() > 180\r
- pdf.AddPage("L")\r
- top = 20\r
- pdf.Line(15, top, subject_width+g_width, top)\r
- end\r
- pdf.SetDrawColor(0, 0, 0)\r
-end\r
-\r
-pdf.Line(15, top, subject_width+g_width, top)\r
-\r
-%>\r
-<%= pdf.Output %>
\ No newline at end of file
+++ /dev/null
-<% zoom = 1
-@zoom.times { zoom = zoom * 2 }
-
-subject_width = 330
-header_heigth = 18
-
-headers_height = header_heigth
-show_weeks = false
-show_days = false
-
-if @zoom >1
- show_weeks = true
- headers_height = 2*header_heigth
- if @zoom > 2
- show_days = true
- headers_height = 3*header_heigth
- end
-end
-
-g_width = (@date_to - @date_from + 1)*zoom
-g_height = [(20 * @events.length + 6)+150, 206].max
-t_height = g_height + headers_height
-%>
-
-<div class="contextual">
-</div>
-
-<h2><%= l(:label_gantt) %></h2>
-
-<% form_tag(params.merge(:month => nil, :year => nil, :months => nil)) do %>
-<table width="100%">
-<tr>
-<td align="left">
- <input type="text" name="months" size="2" value="<%= @months %>" />
- <%= l(:label_months_from) %>
- <%= select_month(@month_from, :prefix => "month", :discard_type => true) %>
- <%= select_year(@year_from, :prefix => "year", :discard_type => true) %>
- <%= hidden_field_tag 'zoom', @zoom %>
- <%= submit_tag l(:button_submit), :class => "button-small" %>
-</td>
-
-<td align="right">
-<%= if @zoom < 4
- link_to image_tag('zoom_in.png'), {:zoom => (@zoom+1), :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects]}
- else
- image_tag 'zoom_in_g.png'
- end %>
-<%= if @zoom > 1
- link_to image_tag('zoom_out.png'),{:zoom => (@zoom-1), :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects]}
- else
- image_tag 'zoom_out_g.png'
- end %>
-</td>
-</tr>
-</table>
-<% end %>
-
-<table width="100%" style="border:0; border-collapse: collapse;">
-<tr>
-<td style="width:<%= subject_width %>px;">
-
-<div style="position:relative;height:<%= t_height + 24 %>px;width:<%= subject_width + 1 %>px;">
-<div style="right:-2px;width:<%= subject_width %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div>
-<div style="right:-2px;width:<%= subject_width %>px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div>
-<%
-#
-# Tasks subjects
-#
-top = headers_height + 8
-@events.each do |i| %>
- <div style="position: absolute;line-height:1.2em;height:16px;top:<%= top %>px;left:4px;overflow:hidden;"><small>
- <% if i.is_a? Issue %>
- <%= h("#{i.project} -") unless @project && @project == i.project %>
- <%= link_to_issue i %>: <%=h i.subject %>
- <% else %>
- <span class="icon icon-package">
- <%= h("#{i.project} -") unless @project && @project == i.project %>
- <%= link_to_version i %>
- </span>
- <% end %>
- </small></div>
- <% top = top + 20
-end %>
-</div>
-</td>
-<td>
-
-<div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;">
-<div style="width:<%= g_width-1 %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"> </div>
-<%
-#
-# Months headers
-#
-month_f = @date_from
-left = 0
-height = (show_weeks ? header_heigth : header_heigth + g_height)
-@months.times do
- width = ((month_f >> 1) - month_f) * zoom - 1
- %>
- <div style="left:<%= left %>px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">
- <%= link_to "#{month_f.year}-#{month_f.month}", { :year => month_f.year, :month => month_f.month, :zoom => @zoom, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] }, :title => "#{month_name(month_f.month)} #{month_f.year}"%>
- </div>
- <%
- left = left + width + 1
- month_f = month_f >> 1
-end %>
-
-<%
-#
-# Weeks headers
-#
-if show_weeks
- left = 0
- height = (show_days ? header_heigth-1 : header_heigth-1 + g_height)
- 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-1
- %>
- <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr"> </div>
- <%
- left = left + width+1
- end %>
- <%
- while week_f <= @date_to
- width = (week_f + 6 <= @date_to) ? 7 * zoom -1 : (@date_to - week_f + 1) * zoom-1
- %>
- <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">
- <small><%= week_f.cweek if width >= 16 %></small>
- </div>
- <%
- left = left + width+1
- week_f = week_f+7
- end
-end %>
-
-<%
-#
-# Days headers
-#
-if show_days
- left = 0
- height = g_height + header_heigth - 1
- wday = @date_from.cwday
- (@date_to - @date_from + 1).to_i.times do
- width = zoom - 1
- %>
- <div style="left:<%= left %>px;top:37px;width:<%= width %>px;height:<%= height %>px;font-size:0.7em;<%= "background:#f1f1f1;" if wday > 5 %>" class="gantt_hdr">
- <%= day_name(wday).first %>
- </div>
- <%
- left = left + width+1
- wday = wday + 1
- wday = 1 if wday > 7
- end
-end %>
-
-<%
-#
-# Tasks
-#
-top = headers_height + 10
-@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 = ((i_start_date - @date_from)*zoom).floor
- i_width = ((i_end_date - i_start_date + 1)*zoom).floor - 2 # total width of the issue (- 2 for left and right borders)
- d_width = ((i_done_date - i_start_date)*zoom).floor - 2 # done width
- l_width = i_late_date ? ((i_late_date - i_start_date+1)*zoom).floor - 2 : 0 # delay width
- %>
- <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;" class="task task_todo"> </div>
- <% if l_width > 0 %>
- <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= l_width %>px;" class="task task_late"> </div>
- <% end %>
- <% if d_width > 0 %>
- <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= d_width %>px;" class="task task_done"> </div>
- <% end %>
- <div style="top:<%= top %>px;left:<%= i_left + i_width + 5 %>px;background:#fff;" class="task">
- <%= i.status.name %>
- <%= (i.done_ratio).to_i %>%
- </div>
- <div class="tooltip" style="position: absolute;top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;height:12px;">
- <span class="tip">
- <%= render_issue_tooltip i %>
- </span></div>
-<% else
- i_left = ((i.start_date - @date_from)*zoom).floor
- %>
- <div style="top:<%= top %>px;left:<%= i_left %>px;width:15px;" class="task milestone"> </div>
- <div style="top:<%= top %>px;left:<%= i_left + 12 %>px;background:#fff;" class="task">
- <%= h("#{i.project} -") unless @project && @project == i.project %>
- <strong><%=h i %></strong>
- </div>
-<% end %>
- <% top = top + 20
-end %>
-
-<%
-#
-# Today red line (excluded from cache)
-#
-if Date.today >= @date_from and Date.today <= @date_to %>
- <div style="position: absolute;height:<%= g_height %>px;top:<%= headers_height + 1 %>px;left:<%= ((Date.today-@date_from+1)*zoom).floor()-1 %>px;width:10px;border-left: 1px dashed red;"> </div>
-<% end %>
-
-</div>
-</td>
-</tr>
-</table>
-
-<table width="100%">
-<tr>
-<td align="left"><%= link_to ('« ' + l(:label_previous)), :year => (@date_from << @months).year, :month => (@date_from << @months).month, :zoom => @zoom, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] %></td>
-<td align="right"><%= link_to (l(:label_next) + ' »'), :year => (@date_from >> @months).year, :month => (@date_from >> @months).month, :zoom => @zoom, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects] %></td>
-</tr>
-</table>
-
-<p class="other-formats">
-<%= l(:label_export_to) %>
-<span><%= link_to 'PDF', {:zoom => @zoom, :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects], :format => 'pdf'}, :class => 'pdf' %></span>
-<%= content_tag('span', link_to('PNG', {:zoom => @zoom, :year => @year_from, :month => @month_from, :months => @months, :tracker_ids => @selected_tracker_ids, :with_subprojects => params[:with_subprojects], :format => 'png'}, :class => 'image')) if respond_to?('gantt_image') %>
-</p>
-
-<% content_for :sidebar do %>
- <h3><%= l(:label_gantt) %></h3>
- <% form_tag(params.merge(:tracker_ids => nil, :with_subprojects => nil), :method => :get) do %>
- <% @trackers.each do |tracker| %>
- <label><%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %> <%= tracker.name %></label><br />
- <% end %>
- <% if @project.active_children.any? %>
- <br /><label><%= check_box_tag 'with_subprojects', 1, @with_subprojects %> <%=l(:label_subproject_plural)%></label>
- <%= hidden_field_tag 'with_subprojects', 0 %>
- <% end %>
- <p><%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %></p>
- <% end %>
-<% end %>
-
-<% html_title(l(:label_gantt)) -%>
<% 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>
Mime::SET << Mime::CSV unless Mime::SET.include?(Mime::CSV)
Mime::Type.register 'application/pdf', :pdf
+Mime::Type.register 'image/png', :png
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, {}
--- /dev/null
+# 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
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; }
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; }
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
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
+++ /dev/null
-# 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