##// END OF EJS Templates
Gantt: Avoid unnecessary queries before rendering....
Jean-Philippe Lang -
r4362:4715a37937cb
parent child
Show More
@@ -1,187 +1,189
1 1 <% @gantt.view = self %>
2 2 <h2><%= l(:label_gantt) %></h2>
3 3
4 4 <% form_tag(gantt_path(:month => params[:month], :year => params[:year], :months => params[:months]), :method => :put, :id => 'query_form') do %>
5 5 <%= hidden_field_tag('project_id', @project.to_param) if @project%>
6 6 <fieldset id="filters" class="collapsible">
7 7 <legend onclick="toggleFieldset(this);"><%= l(:label_filter_plural) %></legend>
8 8 <div>
9 9 <%= render :partial => 'queries/filters', :locals => {:query => @query} %>
10 10 </div>
11 11 </fieldset>
12 12
13 13 <p class="contextual">
14 14 <%= gantt_zoom_link(@gantt, :in) %>
15 15 <%= gantt_zoom_link(@gantt, :out) %>
16 16 </p>
17 17
18 18 <p class="buttons">
19 19 <%= text_field_tag 'months', @gantt.months, :size => 2 %>
20 20 <%= l(:label_months_from) %>
21 21 <%= select_month(@gantt.month_from, :prefix => "month", :discard_type => true) %>
22 22 <%= select_year(@gantt.year_from, :prefix => "year", :discard_type => true) %>
23 23 <%= hidden_field_tag 'zoom', @gantt.zoom %>
24 24
25 25 <%= link_to_remote l(:button_apply),
26 26 { :url => { :set_filter => (@query.new_record? ? 1 : nil) },
27 27 :update => "content",
28 28 :with => "Form.serialize('query_form')"
29 29 }, :class => 'icon icon-checked' %>
30 30
31 31 <%= link_to_remote l(:button_clear),
32 32 { :url => { :project_id => @project, :set_filter => (@query.new_record? ? 1 : nil) },
33 33 :method => :put,
34 34 :update => "content",
35 35 }, :class => 'icon icon-reload' if @query.new_record? %>
36 36 </p>
37 37 <% end %>
38 38
39 39 <%= error_messages_for 'query' %>
40 40 <% if @query.valid? %>
41 41 <% zoom = 1
42 42 @gantt.zoom.times { zoom = zoom * 2 }
43 43
44 44 subject_width = 330
45 45 header_heigth = 18
46 46
47 47 headers_height = header_heigth
48 48 show_weeks = false
49 49 show_days = false
50 50
51 51 if @gantt.zoom >1
52 52 show_weeks = true
53 53 headers_height = 2*header_heigth
54 54 if @gantt.zoom > 2
55 55 show_days = true
56 56 headers_height = 3*header_heigth
57 57 end
58 58 end
59 59
60 60 # Width of the entire chart
61 61 g_width = (@gantt.date_to - @gantt.date_from + 1)*zoom
62 # Collect the number of issues on Versions
62
63 @gantt.render(:top => headers_height + 8, :zoom => zoom, :g_width => g_width)
64
63 65 g_height = [(20 * (@gantt.number_of_rows + 6))+150, 206].max
64 66 t_height = g_height + headers_height
65 67
66 @gantt.render(:top => headers_height + 8, :zoom => zoom, :g_width => g_width)
68
67 69 %>
68 70 <table width="100%" style="border:0; border-collapse: collapse;">
69 71 <tr>
70 72 <td style="width:<%= subject_width %>px; padding:0px;">
71 73
72 74 <div style="position:relative;height:<%= t_height + 24 %>px;width:<%= subject_width + 1 %>px;">
73 75 <div style="right:-2px;width:<%= subject_width %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div>
74 76 <div style="right:-2px;width:<%= subject_width %>px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div>
75 77
76 78 <%= @gantt.subjects %>
77 79
78 80 </div>
79 81 </td>
80 82 <td>
81 83
82 84 <div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;">
83 85 <div style="width:<%= g_width-1 %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr">&nbsp;</div>
84 86 <%
85 87 #
86 88 # Months headers
87 89 #
88 90 month_f = @gantt.date_from
89 91 left = 0
90 92 height = (show_weeks ? header_heigth : header_heigth + g_height)
91 93 @gantt.months.times do
92 94 width = ((month_f >> 1) - month_f) * zoom - 1
93 95 %>
94 96 <div style="left:<%= left %>px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">
95 97 <%= 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}"%>
96 98 </div>
97 99 <%
98 100 left = left + width + 1
99 101 month_f = month_f >> 1
100 102 end %>
101 103
102 104 <%
103 105 #
104 106 # Weeks headers
105 107 #
106 108 if show_weeks
107 109 left = 0
108 110 height = (show_days ? header_heigth-1 : header_heigth-1 + g_height)
109 111 if @gantt.date_from.cwday == 1
110 112 # @date_from is monday
111 113 week_f = @gantt.date_from
112 114 else
113 115 # find next monday after @date_from
114 116 week_f = @gantt.date_from + (7 - @gantt.date_from.cwday + 1)
115 117 width = (7 - @gantt.date_from.cwday + 1) * zoom-1
116 118 %>
117 119 <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">&nbsp;</div>
118 120 <%
119 121 left = left + width+1
120 122 end %>
121 123 <%
122 124 while week_f <= @gantt.date_to
123 125 width = (week_f + 6 <= @gantt.date_to) ? 7 * zoom -1 : (@gantt.date_to - week_f + 1) * zoom-1
124 126 %>
125 127 <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">
126 128 <small><%= week_f.cweek if width >= 16 %></small>
127 129 </div>
128 130 <%
129 131 left = left + width+1
130 132 week_f = week_f+7
131 133 end
132 134 end %>
133 135
134 136 <%
135 137 #
136 138 # Days headers
137 139 #
138 140 if show_days
139 141 left = 0
140 142 height = g_height + header_heigth - 1
141 143 wday = @gantt.date_from.cwday
142 144 (@gantt.date_to - @gantt.date_from + 1).to_i.times do
143 145 width = zoom - 1
144 146 %>
145 147 <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">
146 148 <%= day_name(wday).first %>
147 149 </div>
148 150 <%
149 151 left = left + width+1
150 152 wday = wday + 1
151 153 wday = 1 if wday > 7
152 154 end
153 155 end %>
154 156
155 157 <%= @gantt.lines %>
156 158
157 159 <%
158 160 #
159 161 # Today red line (excluded from cache)
160 162 #
161 163 if Date.today >= @gantt.date_from and Date.today <= @gantt.date_to %>
162 164 <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;">&nbsp;</div>
163 165 <% end %>
164 166
165 167 </div>
166 168 </td>
167 169 </tr>
168 170 </table>
169 171
170 172 <table width="100%">
171 173 <tr>
172 174 <td align="left"><%= link_to_remote ('&#171; ' + l(:label_previous)), {:url => @gantt.params_previous, :method => :get, :update => 'content', :complete => 'window.scrollTo(0,0)'}, {:href => url_for(@gantt.params_previous)} %></td>
173 175 <td align="right"><%= link_to_remote (l(:label_next) + ' &#187;'), {:url => @gantt.params_next, :method => :get, :update => 'content', :complete => 'window.scrollTo(0,0)'}, {:href => url_for(@gantt.params_next)} %></td>
174 176 </tr>
175 177 </table>
176 178
177 179 <% other_formats_links do |f| %>
178 180 <%= f.link_to 'PDF', :url => @gantt.params %>
179 181 <%= f.link_to('PNG', :url => @gantt.params) if @gantt.respond_to?('to_image') %>
180 182 <% end %>
181 183 <% end # query.valid? %>
182 184
183 185 <% content_for :sidebar do %>
184 186 <%= render :partial => 'issues/sidebar' %>
185 187 <% end %>
186 188
187 189 <% html_title(l(:label_gantt)) -%>
@@ -1,967 +1,974
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 module Redmine
19 19 module Helpers
20 20 # Simple class to handle gantt chart data
21 21 class Gantt
22 22 include ERB::Util
23 23 include Redmine::I18n
24 24
25 25 # :nodoc:
26 26 # Some utility methods for the PDF export
27 27 class PDF
28 28 MaxCharactorsForSubject = 45
29 29 TotalWidth = 280
30 30 LeftPaneWidth = 100
31 31
32 32 def self.right_pane_width
33 33 TotalWidth - LeftPaneWidth
34 34 end
35 35 end
36 36
37 37 attr_reader :year_from, :month_from, :date_from, :date_to, :zoom, :months
38 38 attr_accessor :query
39 39 attr_accessor :project
40 40 attr_accessor :view
41 41
42 42 def initialize(options={})
43 43 options = options.dup
44 44
45 45 if options[:year] && options[:year].to_i >0
46 46 @year_from = options[:year].to_i
47 47 if options[:month] && options[:month].to_i >=1 && options[:month].to_i <= 12
48 48 @month_from = options[:month].to_i
49 49 else
50 50 @month_from = 1
51 51 end
52 52 else
53 53 @month_from ||= Date.today.month
54 54 @year_from ||= Date.today.year
55 55 end
56 56
57 57 zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i
58 58 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
59 59 months = (options[:months] || User.current.pref[:gantt_months]).to_i
60 60 @months = (months > 0 && months < 25) ? months : 6
61 61
62 62 # Save gantt parameters as user preference (zoom and months count)
63 63 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months]))
64 64 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
65 65 User.current.preference.save
66 66 end
67 67
68 68 @date_from = Date.civil(@year_from, @month_from, 1)
69 69 @date_to = (@date_from >> @months) - 1
70 70
71 71 @subjects = ''
72 72 @lines = ''
73 @number_of_rows = nil
73 74 end
74 75
75 76 def common_params
76 77 { :controller => 'gantts', :action => 'show', :project_id => @project }
77 78 end
78 79
79 80 def params
80 81 common_params.merge({ :zoom => zoom, :year => year_from, :month => month_from, :months => months })
81 82 end
82 83
83 84 def params_previous
84 85 common_params.merge({:year => (date_from << months).year, :month => (date_from << months).month, :zoom => zoom, :months => months })
85 86 end
86 87
87 88 def params_next
88 89 common_params.merge({:year => (date_from >> months).year, :month => (date_from >> months).month, :zoom => zoom, :months => months })
89 90 end
90 91
91 92 ### Extracted from the HTML view/helpers
92 93 # Returns the number of rows that will be rendered on the Gantt chart
93 94 def number_of_rows
95 return @number_of_rows if @number_of_rows
96
94 97 if @project
95 98 return number_of_rows_on_project(@project)
96 99 else
97 100 Project.roots.visible.inject(0) do |total, project|
98 101 total += number_of_rows_on_project(project)
99 102 end
100 103 end
101 104 end
102 105
103 106 # Returns the number of rows that will be used to list a project on
104 107 # the Gantt chart. This will recurse for each subproject.
105 108 def number_of_rows_on_project(project)
106 109 # Remove the project requirement for Versions because it will
107 110 # restrict issues to only be on the current project. This
108 111 # ends up missing issues which are assigned to shared versions.
109 112 @query.project = nil if @query.project
110 113
111 114 # One Root project
112 115 count = 1
113 116 # Issues without a Version
114 117 count += project.issues.for_gantt.without_version.with_query(@query).count
115 118
116 119 # Versions
117 120 count += project.versions.count
118 121
119 122 # Issues on the Versions
120 123 project.versions.each do |version|
121 124 count += version.fixed_issues.for_gantt.with_query(@query).count
122 125 end
123 126
124 127 # Subprojects
125 128 project.children.visible.each do |subproject|
126 129 count += number_of_rows_on_project(subproject)
127 130 end
128 131
129 132 count
130 133 end
131 134
132 135 # Renders the subjects of the Gantt chart, the left side.
133 136 def subjects(options={})
134 137 render(options.merge(:only => :subjects)) unless @subjects_rendered
135 138 @subjects
136 139 end
137 140
138 141 # Renders the lines of the Gantt chart, the right side
139 142 def lines(options={})
140 143 render(options.merge(:only => :lines)) unless @lines_rendered
141 144 @lines
142 145 end
143 146
144 147 def render(options={})
145 148 options = {:indent => 4, :render => :subject, :format => :html}.merge(options)
146 149
147 150 @subjects = '' unless options[:only] == :lines
148 151 @lines = '' unless options[:only] == :subjects
152 @number_of_rows = 0
149 153
150 154 if @project
151 155 render_project(@project, options)
152 156 else
153 157 Project.roots.visible.each do |project|
154 158 render_project(project, options)
155 159 end
156 160 end
157 161
158 162 @subjects_rendered = true unless options[:only] == :lines
159 163 @lines_rendered = true unless options[:only] == :subjects
160 164
161 165 render_end(options)
162 166 end
163 167
164 168 def render_project(project, options={})
165 169 options[:top] = 0 unless options.key? :top
166 170 options[:indent_increment] = 20 unless options.key? :indent_increment
167 171 options[:top_increment] = 20 unless options.key? :top_increment
168 172
169 173 subject_for_project(project, options) unless options[:only] == :lines
170 174 line_for_project(project, options) unless options[:only] == :subjects
171 175
172 176 options[:top] += options[:top_increment]
173 177 options[:indent] += options[:indent_increment]
178 @number_of_rows += 1
174 179
175 180 # Second, Issues without a version
176 181 issues = project.issues.for_gantt.without_version.with_query(@query)
177 182 sort_issues!(issues)
178 183 if issues
179 184 render_issues(issues, options)
180 185 end
181 186
182 187 # Third, Versions
183 188 project.versions.sort.each do |version|
184 189 render_version(version, options)
185 190 end
186 191
187 192 # Fourth, subprojects
188 193 project.children.visible.each do |project|
189 194 render_project(project, options)
190 195 end
191 196
192 197 # Remove indent to hit the next sibling
193 198 options[:indent] -= options[:indent_increment]
194 199 end
195 200
196 201 def render_issues(issues, options={})
197 202 issues.each do |i|
198 203 subject_for_issue(i, options) unless options[:only] == :lines
199 204 line_for_issue(i, options) unless options[:only] == :subjects
200 205
201 206 options[:top] += options[:top_increment]
207 @number_of_rows += 1
202 208 end
203 209 end
204 210
205 211 def render_version(version, options={})
206 212 # Version header
207 213 subject_for_version(version, options) unless options[:only] == :lines
208 214 line_for_version(version, options) unless options[:only] == :subjects
209 215
210 216 options[:top] += options[:top_increment]
211
217 @number_of_rows += 1
218
212 219 # Remove the project requirement for Versions because it will
213 220 # restrict issues to only be on the current project. This
214 221 # ends up missing issues which are assigned to shared versions.
215 222 @query.project = nil if @query.project
216 223
217 224 issues = version.fixed_issues.for_gantt.with_query(@query)
218 225 if issues
219 226 sort_issues!(issues)
220 227 # Indent issues
221 228 options[:indent] += options[:indent_increment]
222 229 render_issues(issues, options)
223 230 options[:indent] -= options[:indent_increment]
224 231 end
225 232 end
226 233
227 234 def render_end(options={})
228 235 case options[:format]
229 236 when :pdf
230 237 options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
231 238 end
232 239 end
233 240
234 241 def subject_for_project(project, options)
235 242 case options[:format]
236 243 when :html
237 244 output = ''
238 245
239 246 output << "<div class='project-name' style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:#{options[:indent]}px;overflow:hidden;'><small> "
240 247 if project.is_a? Project
241 248 output << "<span class='icon icon-projects #{project.overdue? ? 'project-overdue' : ''}'>"
242 249 output << view.link_to_project(project)
243 250 output << '</span>'
244 251 else
245 252 ActiveRecord::Base.logger.debug "Gantt#subject_for_project was not given a project"
246 253 ''
247 254 end
248 255 output << "</small></div>"
249 256 @subjects << output
250 257 output
251 258 when :image
252 259
253 260 options[:image].fill('black')
254 261 options[:image].stroke('transparent')
255 262 options[:image].stroke_width(1)
256 263 options[:image].text(options[:indent], options[:top] + 2, project.name)
257 264 when :pdf
258 265 pdf_new_page?(options)
259 266 options[:pdf].SetY(options[:top])
260 267 options[:pdf].SetX(15)
261 268
262 269 char_limit = PDF::MaxCharactorsForSubject - options[:indent]
263 270 options[:pdf].Cell(options[:subject_width]-15, 5, (" " * options[:indent]) +"#{project.name}".sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR")
264 271
265 272 options[:pdf].SetY(options[:top])
266 273 options[:pdf].SetX(options[:subject_width])
267 274 options[:pdf].Cell(options[:g_width], 5, "", "LR")
268 275 end
269 276 end
270 277
271 278 def line_for_project(project, options)
272 279 # Skip versions that don't have a start_date or due date
273 280 if project.is_a?(Project) && project.start_date && project.due_date
274 281 options[:zoom] ||= 1
275 282 options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
276 283
277 284
278 285 case options[:format]
279 286 when :html
280 287 output = ''
281 288 i_left = ((project.start_date - self.date_from)*options[:zoom]).floor
282 289
283 290 start_date = project.start_date
284 291 start_date ||= self.date_from
285 292 start_left = ((start_date - self.date_from)*options[:zoom]).floor
286 293
287 294 i_end_date = ((project.due_date <= self.date_to) ? project.due_date : self.date_to )
288 295 i_done_date = start_date + ((project.due_date - start_date+1)* project.completed_percent(:include_subprojects => true)/100).floor
289 296 i_done_date = (i_done_date <= self.date_from ? self.date_from : i_done_date )
290 297 i_done_date = (i_done_date >= self.date_to ? self.date_to : i_done_date )
291 298
292 299 i_late_date = [i_end_date, Date.today].min if start_date < Date.today
293 300 i_end = ((i_end_date - self.date_from) * options[:zoom]).floor
294 301
295 302 i_width = (i_end - i_left + 1).floor - 2 # total width of the issue (- 2 for left and right borders)
296 303 d_width = ((i_done_date - start_date)*options[:zoom]).floor - 2 # done width
297 304 l_width = i_late_date ? ((i_late_date - start_date+1)*options[:zoom]).floor - 2 : 0 # delay width
298 305
299 306 # Bar graphic
300 307
301 308 # Make sure that negative i_left and i_width don't
302 309 # overflow the subject
303 310 if i_end > 0 && i_left <= options[:g_width]
304 311 output << "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:#{ i_width }px;' class='task project_todo'>&nbsp;</div>"
305 312 end
306 313
307 314 if l_width > 0 && i_left <= options[:g_width]
308 315 output << "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:#{ l_width }px;' class='task project_late'>&nbsp;</div>"
309 316 end
310 317 if d_width > 0 && i_left <= options[:g_width]
311 318 output<< "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:#{ d_width }px;' class='task project_done'>&nbsp;</div>"
312 319 end
313 320
314 321
315 322 # Starting diamond
316 323 if start_left <= options[:g_width] && start_left > 0
317 324 output << "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:15px;' class='task project-line starting'>&nbsp;</div>"
318 325 output << "<div style='top:#{ options[:top] }px;left:#{ start_left + 12 }px;' class='task label'>"
319 326 output << "</div>"
320 327 end
321 328
322 329 # Ending diamond
323 330 # Don't show items too far ahead
324 331 if i_end <= options[:g_width] && i_end > 0
325 332 output << "<div style='top:#{ options[:top] }px;left:#{ i_end }px;width:15px;' class='task project-line ending'>&nbsp;</div>"
326 333 end
327 334
328 335 # DIsplay the Project name and %
329 336 if i_end <= options[:g_width]
330 337 # Display the status even if it's floated off to the left
331 338 status_px = i_end + 12 # 12px for the diamond
332 339 status_px = 0 if status_px <= 0
333 340
334 341 output << "<div style='top:#{ options[:top] }px;left:#{ status_px }px;' class='task label project-name'>"
335 342 output << "<strong>#{h project } #{h project.completed_percent(:include_subprojects => true).to_i.to_s}%</strong>"
336 343 output << "</div>"
337 344 end
338 345 @lines << output
339 346 output
340 347 when :image
341 348 options[:image].stroke('transparent')
342 349 i_left = options[:subject_width] + ((project.due_date - self.date_from)*options[:zoom]).floor
343 350
344 351 # Make sure negative i_left doesn't overflow the subject
345 352 if i_left > options[:subject_width]
346 353 options[:image].fill('blue')
347 354 options[:image].rectangle(i_left, options[:top], i_left + 6, options[:top] - 6)
348 355 options[:image].fill('black')
349 356 options[:image].text(i_left + 11, options[:top] + 1, project.name)
350 357 end
351 358 when :pdf
352 359 options[:pdf].SetY(options[:top]+1.5)
353 360 i_left = ((project.due_date - @date_from)*options[:zoom])
354 361
355 362 # Make sure negative i_left doesn't overflow the subject
356 363 if i_left > 0
357 364 options[:pdf].SetX(options[:subject_width] + i_left)
358 365 options[:pdf].SetFillColor(50,50,200)
359 366 options[:pdf].Cell(2, 2, "", 0, 0, "", 1)
360 367
361 368 options[:pdf].SetY(options[:top]+1.5)
362 369 options[:pdf].SetX(options[:subject_width] + i_left + 3)
363 370 options[:pdf].Cell(30, 2, "#{project.name}")
364 371 end
365 372 end
366 373 else
367 374 ActiveRecord::Base.logger.debug "Gantt#line_for_project was not given a project with a start_date"
368 375 ''
369 376 end
370 377 end
371 378
372 379 def subject_for_version(version, options)
373 380 case options[:format]
374 381 when :html
375 382 output = ''
376 383 output << "<div class='version-name' style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:#{options[:indent]}px;overflow:hidden;'><small> "
377 384 if version.is_a? Version
378 385 output << "<span class='icon icon-package #{version.behind_schedule? ? 'version-behind-schedule' : ''} #{version.overdue? ? 'version-overdue' : ''}'>"
379 386 output << view.link_to_version(version)
380 387 output << '</span>'
381 388 else
382 389 ActiveRecord::Base.logger.debug "Gantt#subject_for_version was not given a version"
383 390 ''
384 391 end
385 392 output << "</small></div>"
386 393 @subjects << output
387 394 output
388 395 when :image
389 396 options[:image].fill('black')
390 397 options[:image].stroke('transparent')
391 398 options[:image].stroke_width(1)
392 399 options[:image].text(options[:indent], options[:top] + 2, version.to_s_with_project)
393 400 when :pdf
394 401 pdf_new_page?(options)
395 402 options[:pdf].SetY(options[:top])
396 403 options[:pdf].SetX(15)
397 404
398 405 char_limit = PDF::MaxCharactorsForSubject - options[:indent]
399 406 options[:pdf].Cell(options[:subject_width]-15, 5, (" " * options[:indent]) +"#{version.to_s_with_project}".sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR")
400 407
401 408 options[:pdf].SetY(options[:top])
402 409 options[:pdf].SetX(options[:subject_width])
403 410 options[:pdf].Cell(options[:g_width], 5, "", "LR")
404 411 end
405 412 end
406 413
407 414 def line_for_version(version, options)
408 415 # Skip versions that don't have a start_date
409 416 if version.is_a?(Version) && version.start_date && version.due_date
410 417 options[:zoom] ||= 1
411 418 options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
412 419
413 420 case options[:format]
414 421 when :html
415 422 output = ''
416 423 i_left = ((version.start_date - self.date_from)*options[:zoom]).floor
417 424 # TODO: or version.fixed_issues.collect(&:start_date).min
418 425 start_date = version.fixed_issues.minimum('start_date') if version.fixed_issues.present?
419 426 start_date ||= self.date_from
420 427 start_left = ((start_date - self.date_from)*options[:zoom]).floor
421 428
422 429 i_end_date = ((version.due_date <= self.date_to) ? version.due_date : self.date_to )
423 430 i_done_date = start_date + ((version.due_date - start_date+1)* version.completed_pourcent/100).floor
424 431 i_done_date = (i_done_date <= self.date_from ? self.date_from : i_done_date )
425 432 i_done_date = (i_done_date >= self.date_to ? self.date_to : i_done_date )
426 433
427 434 i_late_date = [i_end_date, Date.today].min if start_date < Date.today
428 435
429 436 i_width = (i_left - start_left + 1).floor - 2 # total width of the issue (- 2 for left and right borders)
430 437 d_width = ((i_done_date - start_date)*options[:zoom]).floor - 2 # done width
431 438 l_width = i_late_date ? ((i_late_date - start_date+1)*options[:zoom]).floor - 2 : 0 # delay width
432 439
433 440 i_end = ((i_end_date - self.date_from) * options[:zoom]).floor # Ending pixel
434 441
435 442 # Bar graphic
436 443
437 444 # Make sure that negative i_left and i_width don't
438 445 # overflow the subject
439 446 if i_width > 0 && i_left <= options[:g_width]
440 447 output << "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:#{ i_width }px;' class='task milestone_todo'>&nbsp;</div>"
441 448 end
442 449 if l_width > 0 && i_left <= options[:g_width]
443 450 output << "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:#{ l_width }px;' class='task milestone_late'>&nbsp;</div>"
444 451 end
445 452 if d_width > 0 && i_left <= options[:g_width]
446 453 output<< "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:#{ d_width }px;' class='task milestone_done'>&nbsp;</div>"
447 454 end
448 455
449 456
450 457 # Starting diamond
451 458 if start_left <= options[:g_width] && start_left > 0
452 459 output << "<div style='top:#{ options[:top] }px;left:#{ start_left }px;width:15px;' class='task milestone starting'>&nbsp;</div>"
453 460 output << "<div style='top:#{ options[:top] }px;left:#{ start_left + 12 }px;background:#fff;' class='task'>"
454 461 output << "</div>"
455 462 end
456 463
457 464 # Ending diamond
458 465 # Don't show items too far ahead
459 466 if i_left <= options[:g_width] && i_end > 0
460 467 output << "<div style='top:#{ options[:top] }px;left:#{ i_end }px;width:15px;' class='task milestone ending'>&nbsp;</div>"
461 468 end
462 469
463 470 # Display the Version name and %
464 471 if i_end <= options[:g_width]
465 472 # Display the status even if it's floated off to the left
466 473 status_px = i_end + 12 # 12px for the diamond
467 474 status_px = 0 if status_px <= 0
468 475
469 476 output << "<div style='top:#{ options[:top] }px;left:#{ status_px }px;' class='task label version-name'>"
470 477 output << h("#{version.project} -") unless @project && @project == version.project
471 478 output << "<strong>#{h version } #{h version.completed_pourcent.to_i.to_s}%</strong>"
472 479 output << "</div>"
473 480 end
474 481 @lines << output
475 482 output
476 483 when :image
477 484 options[:image].stroke('transparent')
478 485 i_left = options[:subject_width] + ((version.start_date - @date_from)*options[:zoom]).floor
479 486
480 487 # Make sure negative i_left doesn't overflow the subject
481 488 if i_left > options[:subject_width]
482 489 options[:image].fill('green')
483 490 options[:image].rectangle(i_left, options[:top], i_left + 6, options[:top] - 6)
484 491 options[:image].fill('black')
485 492 options[:image].text(i_left + 11, options[:top] + 1, version.name)
486 493 end
487 494 when :pdf
488 495 options[:pdf].SetY(options[:top]+1.5)
489 496 i_left = ((version.start_date - @date_from)*options[:zoom])
490 497
491 498 # Make sure negative i_left doesn't overflow the subject
492 499 if i_left > 0
493 500 options[:pdf].SetX(options[:subject_width] + i_left)
494 501 options[:pdf].SetFillColor(50,200,50)
495 502 options[:pdf].Cell(2, 2, "", 0, 0, "", 1)
496 503
497 504 options[:pdf].SetY(options[:top]+1.5)
498 505 options[:pdf].SetX(options[:subject_width] + i_left + 3)
499 506 options[:pdf].Cell(30, 2, "#{version.name}")
500 507 end
501 508 end
502 509 else
503 510 ActiveRecord::Base.logger.debug "Gantt#line_for_version was not given a version with a start_date"
504 511 ''
505 512 end
506 513 end
507 514
508 515 def subject_for_issue(issue, options)
509 516 case options[:format]
510 517 when :html
511 518 output = ''
512 519 output << "<div class='tooltip'>"
513 520 output << "<div class='issue-subject' style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:#{options[:indent]}px;overflow:hidden;'><small> "
514 521 if issue.is_a? Issue
515 522 css_classes = []
516 523 css_classes << 'issue-overdue' if issue.overdue?
517 524 css_classes << 'issue-behind-schedule' if issue.behind_schedule?
518 525 css_classes << 'icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to
519 526
520 527 if issue.assigned_to.present?
521 528 assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name
522 529 output << view.avatar(issue.assigned_to, :class => 'gravatar icon-gravatar', :size => 10, :title => assigned_string)
523 530 end
524 531 output << "<span class='#{css_classes.join(' ')}'>"
525 532 output << view.link_to_issue(issue)
526 533 output << '</span>'
527 534 else
528 535 ActiveRecord::Base.logger.debug "Gantt#subject_for_issue was not given an issue"
529 536 ''
530 537 end
531 538 output << "</small></div>"
532 539
533 540 # Tooltip
534 541 if issue.is_a? Issue
535 542 output << "<span class='tip' style='position: absolute;top:#{ options[:top].to_i + 16 }px;left:#{ options[:indent].to_i + 20 }px;'>"
536 543 output << view.render_issue_tooltip(issue)
537 544 output << "</span>"
538 545 end
539 546
540 547 output << "</div>"
541 548 @subjects << output
542 549 output
543 550 when :image
544 551 options[:image].fill('black')
545 552 options[:image].stroke('transparent')
546 553 options[:image].stroke_width(1)
547 554 options[:image].text(options[:indent], options[:top] + 2, issue.subject)
548 555 when :pdf
549 556 pdf_new_page?(options)
550 557 options[:pdf].SetY(options[:top])
551 558 options[:pdf].SetX(15)
552 559
553 560 char_limit = PDF::MaxCharactorsForSubject - options[:indent]
554 561 options[:pdf].Cell(options[:subject_width]-15, 5, (" " * options[:indent]) +"#{issue.tracker} #{issue.id}: #{issue.subject}".sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR")
555 562
556 563 options[:pdf].SetY(options[:top])
557 564 options[:pdf].SetX(options[:subject_width])
558 565 options[:pdf].Cell(options[:g_width], 5, "", "LR")
559 566 end
560 567 end
561 568
562 569 def line_for_issue(issue, options)
563 570 # Skip issues that don't have a due_before (due_date or version's due_date)
564 571 if issue.is_a?(Issue) && issue.due_before
565 572 case options[:format]
566 573 when :html
567 574 output = ''
568 575 # Handle nil start_dates, rare but can happen.
569 576 i_start_date = if issue.start_date && issue.start_date >= self.date_from
570 577 issue.start_date
571 578 else
572 579 self.date_from
573 580 end
574 581
575 582 i_end_date = ((issue.due_before && issue.due_before <= self.date_to) ? issue.due_before : self.date_to )
576 583 i_done_date = i_start_date + ((issue.due_before - i_start_date+1)*issue.done_ratio/100).floor
577 584 i_done_date = (i_done_date <= self.date_from ? self.date_from : i_done_date )
578 585 i_done_date = (i_done_date >= self.date_to ? self.date_to : i_done_date )
579 586
580 587 i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
581 588
582 589 i_left = ((i_start_date - self.date_from)*options[:zoom]).floor
583 590 i_width = ((i_end_date - i_start_date + 1)*options[:zoom]).floor - 2 # total width of the issue (- 2 for left and right borders)
584 591 d_width = ((i_done_date - i_start_date)*options[:zoom]).floor - 2 # done width
585 592 l_width = i_late_date ? ((i_late_date - i_start_date+1)*options[:zoom]).floor - 2 : 0 # delay width
586 593 css = "task " + (issue.leaf? ? 'leaf' : 'parent')
587 594
588 595 # Make sure that negative i_left and i_width don't
589 596 # overflow the subject
590 597 if i_width > 0
591 598 output << "<div style='top:#{ options[:top] }px;left:#{ i_left }px;width:#{ i_width }px;' class='#{css} task_todo'>&nbsp;</div>"
592 599 end
593 600 if l_width > 0
594 601 output << "<div style='top:#{ options[:top] }px;left:#{ i_left }px;width:#{ l_width }px;' class='#{css} task_late'>&nbsp;</div>"
595 602 end
596 603 if d_width > 0
597 604 output<< "<div style='top:#{ options[:top] }px;left:#{ i_left }px;width:#{ d_width }px;' class='#{css} task_done'>&nbsp;</div>"
598 605 end
599 606
600 607 # Display the status even if it's floated off to the left
601 608 status_px = i_left + i_width + 5
602 609 status_px = 5 if status_px <= 0
603 610
604 611 output << "<div style='top:#{ options[:top] }px;left:#{ status_px }px;' class='#{css} label issue-name'>"
605 612 output << issue.status.name
606 613 output << ' '
607 614 output << (issue.done_ratio).to_i.to_s
608 615 output << "%"
609 616 output << "</div>"
610 617
611 618 output << "<div class='tooltip' style='position: absolute;top:#{ options[:top] }px;left:#{ i_left }px;width:#{ i_width }px;height:12px;'>"
612 619 output << '<span class="tip">'
613 620 output << view.render_issue_tooltip(issue)
614 621 output << "</span></div>"
615 622 @lines << output
616 623 output
617 624
618 625 when :image
619 626 # Handle nil start_dates, rare but can happen.
620 627 i_start_date = if issue.start_date && issue.start_date >= @date_from
621 628 issue.start_date
622 629 else
623 630 @date_from
624 631 end
625 632
626 633 i_end_date = (issue.due_before <= date_to ? issue.due_before : date_to )
627 634 i_done_date = i_start_date + ((issue.due_before - i_start_date+1)*issue.done_ratio/100).floor
628 635 i_done_date = (i_done_date <= @date_from ? @date_from : i_done_date )
629 636 i_done_date = (i_done_date >= date_to ? date_to : i_done_date )
630 637 i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
631 638
632 639 i_left = options[:subject_width] + ((i_start_date - @date_from)*options[:zoom]).floor
633 640 i_width = ((i_end_date - i_start_date + 1)*options[:zoom]).floor # total width of the issue
634 641 d_width = ((i_done_date - i_start_date)*options[:zoom]).floor # done width
635 642 l_width = i_late_date ? ((i_late_date - i_start_date+1)*options[:zoom]).floor : 0 # delay width
636 643
637 644
638 645 # Make sure that negative i_left and i_width don't
639 646 # overflow the subject
640 647 if i_width > 0
641 648 options[:image].fill('grey')
642 649 options[:image].rectangle(i_left, options[:top], i_left + i_width, options[:top] - 6)
643 650 options[:image].fill('red')
644 651 options[:image].rectangle(i_left, options[:top], i_left + l_width, options[:top] - 6) if l_width > 0
645 652 options[:image].fill('blue')
646 653 options[:image].rectangle(i_left, options[:top], i_left + d_width, options[:top] - 6) if d_width > 0
647 654 end
648 655
649 656 # Show the status and % done next to the subject if it overflows
650 657 options[:image].fill('black')
651 658 if i_width > 0
652 659 options[:image].text(i_left + i_width + 5,options[:top] + 1, "#{issue.status.name} #{issue.done_ratio}%")
653 660 else
654 661 options[:image].text(options[:subject_width] + 5,options[:top] + 1, "#{issue.status.name} #{issue.done_ratio}%")
655 662 end
656 663
657 664 when :pdf
658 665 options[:pdf].SetY(options[:top]+1.5)
659 666 # Handle nil start_dates, rare but can happen.
660 667 i_start_date = if issue.start_date && issue.start_date >= @date_from
661 668 issue.start_date
662 669 else
663 670 @date_from
664 671 end
665 672
666 673 i_end_date = (issue.due_before <= @date_to ? issue.due_before : @date_to )
667 674
668 675 i_done_date = i_start_date + ((issue.due_before - i_start_date+1)*issue.done_ratio/100).floor
669 676 i_done_date = (i_done_date <= @date_from ? @date_from : i_done_date )
670 677 i_done_date = (i_done_date >= @date_to ? @date_to : i_done_date )
671 678
672 679 i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
673 680
674 681 i_left = ((i_start_date - @date_from)*options[:zoom])
675 682 i_width = ((i_end_date - i_start_date + 1)*options[:zoom])
676 683 d_width = ((i_done_date - i_start_date)*options[:zoom])
677 684 l_width = ((i_late_date - i_start_date+1)*options[:zoom]) if i_late_date
678 685 l_width ||= 0
679 686
680 687 # Make sure that negative i_left and i_width don't
681 688 # overflow the subject
682 689 if i_width > 0
683 690 options[:pdf].SetX(options[:subject_width] + i_left)
684 691 options[:pdf].SetFillColor(200,200,200)
685 692 options[:pdf].Cell(i_width, 2, "", 0, 0, "", 1)
686 693 end
687 694
688 695 if l_width > 0
689 696 options[:pdf].SetY(options[:top]+1.5)
690 697 options[:pdf].SetX(options[:subject_width] + i_left)
691 698 options[:pdf].SetFillColor(255,100,100)
692 699 options[:pdf].Cell(l_width, 2, "", 0, 0, "", 1)
693 700 end
694 701 if d_width > 0
695 702 options[:pdf].SetY(options[:top]+1.5)
696 703 options[:pdf].SetX(options[:subject_width] + i_left)
697 704 options[:pdf].SetFillColor(100,100,255)
698 705 options[:pdf].Cell(d_width, 2, "", 0, 0, "", 1)
699 706 end
700 707
701 708 options[:pdf].SetY(options[:top]+1.5)
702 709
703 710 # Make sure that negative i_left and i_width don't
704 711 # overflow the subject
705 712 if (i_left + i_width) >= 0
706 713 options[:pdf].SetX(options[:subject_width] + i_left + i_width)
707 714 else
708 715 options[:pdf].SetX(options[:subject_width])
709 716 end
710 717 options[:pdf].Cell(30, 2, "#{issue.status} #{issue.done_ratio}%")
711 718 end
712 719 else
713 720 ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before"
714 721 ''
715 722 end
716 723 end
717 724
718 725 # Generates a gantt image
719 726 # Only defined if RMagick is avalaible
720 727 def to_image(format='PNG')
721 728 date_to = (@date_from >> @months)-1
722 729 show_weeks = @zoom > 1
723 730 show_days = @zoom > 2
724 731
725 732 subject_width = 400
726 733 header_heigth = 18
727 734 # width of one day in pixels
728 735 zoom = @zoom*2
729 736 g_width = (@date_to - @date_from + 1)*zoom
730 737 g_height = 20 * number_of_rows + 30
731 738 headers_heigth = (show_weeks ? 2*header_heigth : header_heigth)
732 739 height = g_height + headers_heigth
733 740
734 741 imgl = Magick::ImageList.new
735 742 imgl.new_image(subject_width+g_width+1, height)
736 743 gc = Magick::Draw.new
737 744
738 745 # Subjects
739 746 subjects(:image => gc, :top => (headers_heigth + 20), :indent => 4, :format => :image)
740 747
741 748 # Months headers
742 749 month_f = @date_from
743 750 left = subject_width
744 751 @months.times do
745 752 width = ((month_f >> 1) - month_f) * zoom
746 753 gc.fill('white')
747 754 gc.stroke('grey')
748 755 gc.stroke_width(1)
749 756 gc.rectangle(left, 0, left + width, height)
750 757 gc.fill('black')
751 758 gc.stroke('transparent')
752 759 gc.stroke_width(1)
753 760 gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}")
754 761 left = left + width
755 762 month_f = month_f >> 1
756 763 end
757 764
758 765 # Weeks headers
759 766 if show_weeks
760 767 left = subject_width
761 768 height = header_heigth
762 769 if @date_from.cwday == 1
763 770 # date_from is monday
764 771 week_f = date_from
765 772 else
766 773 # find next monday after date_from
767 774 week_f = @date_from + (7 - @date_from.cwday + 1)
768 775 width = (7 - @date_from.cwday + 1) * zoom
769 776 gc.fill('white')
770 777 gc.stroke('grey')
771 778 gc.stroke_width(1)
772 779 gc.rectangle(left, header_heigth, left + width, 2*header_heigth + g_height-1)
773 780 left = left + width
774 781 end
775 782 while week_f <= date_to
776 783 width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom
777 784 gc.fill('white')
778 785 gc.stroke('grey')
779 786 gc.stroke_width(1)
780 787 gc.rectangle(left.round, header_heigth, left.round + width, 2*header_heigth + g_height-1)
781 788 gc.fill('black')
782 789 gc.stroke('transparent')
783 790 gc.stroke_width(1)
784 791 gc.text(left.round + 2, header_heigth + 14, week_f.cweek.to_s)
785 792 left = left + width
786 793 week_f = week_f+7
787 794 end
788 795 end
789 796
790 797 # Days details (week-end in grey)
791 798 if show_days
792 799 left = subject_width
793 800 height = g_height + header_heigth - 1
794 801 wday = @date_from.cwday
795 802 (date_to - @date_from + 1).to_i.times do
796 803 width = zoom
797 804 gc.fill(wday == 6 || wday == 7 ? '#eee' : 'white')
798 805 gc.stroke('grey')
799 806 gc.stroke_width(1)
800 807 gc.rectangle(left, 2*header_heigth, left + width, 2*header_heigth + g_height-1)
801 808 left = left + width
802 809 wday = wday + 1
803 810 wday = 1 if wday > 7
804 811 end
805 812 end
806 813
807 814 # border
808 815 gc.fill('transparent')
809 816 gc.stroke('grey')
810 817 gc.stroke_width(1)
811 818 gc.rectangle(0, 0, subject_width+g_width, headers_heigth)
812 819 gc.stroke('black')
813 820 gc.rectangle(0, 0, subject_width+g_width, g_height+ headers_heigth-1)
814 821
815 822 # content
816 823 top = headers_heigth + 20
817 824
818 825 lines(:image => gc, :top => top, :zoom => zoom, :subject_width => subject_width, :format => :image)
819 826
820 827 # today red line
821 828 if Date.today >= @date_from and Date.today <= date_to
822 829 gc.stroke('red')
823 830 x = (Date.today-@date_from+1)*zoom + subject_width
824 831 gc.line(x, headers_heigth, x, headers_heigth + g_height-1)
825 832 end
826 833
827 834 gc.draw(imgl)
828 835 imgl.format = format
829 836 imgl.to_blob
830 837 end if Object.const_defined?(:Magick)
831 838
832 839 def to_pdf
833 840 pdf = ::Redmine::Export::PDF::IFPDF.new(current_language)
834 841 pdf.SetTitle("#{l(:label_gantt)} #{project}")
835 842 pdf.AliasNbPages
836 843 pdf.footer_date = format_date(Date.today)
837 844 pdf.AddPage("L")
838 845 pdf.SetFontStyle('B',12)
839 846 pdf.SetX(15)
840 847 pdf.Cell(PDF::LeftPaneWidth, 20, project.to_s)
841 848 pdf.Ln
842 849 pdf.SetFontStyle('B',9)
843 850
844 851 subject_width = PDF::LeftPaneWidth
845 852 header_heigth = 5
846 853
847 854 headers_heigth = header_heigth
848 855 show_weeks = false
849 856 show_days = false
850 857
851 858 if self.months < 7
852 859 show_weeks = true
853 860 headers_heigth = 2*header_heigth
854 861 if self.months < 3
855 862 show_days = true
856 863 headers_heigth = 3*header_heigth
857 864 end
858 865 end
859 866
860 867 g_width = PDF.right_pane_width
861 868 zoom = (g_width) / (self.date_to - self.date_from + 1)
862 869 g_height = 120
863 870 t_height = g_height + headers_heigth
864 871
865 872 y_start = pdf.GetY
866 873
867 874 # Months headers
868 875 month_f = self.date_from
869 876 left = subject_width
870 877 height = header_heigth
871 878 self.months.times do
872 879 width = ((month_f >> 1) - month_f) * zoom
873 880 pdf.SetY(y_start)
874 881 pdf.SetX(left)
875 882 pdf.Cell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C")
876 883 left = left + width
877 884 month_f = month_f >> 1
878 885 end
879 886
880 887 # Weeks headers
881 888 if show_weeks
882 889 left = subject_width
883 890 height = header_heigth
884 891 if self.date_from.cwday == 1
885 892 # self.date_from is monday
886 893 week_f = self.date_from
887 894 else
888 895 # find next monday after self.date_from
889 896 week_f = self.date_from + (7 - self.date_from.cwday + 1)
890 897 width = (7 - self.date_from.cwday + 1) * zoom-1
891 898 pdf.SetY(y_start + header_heigth)
892 899 pdf.SetX(left)
893 900 pdf.Cell(width + 1, height, "", "LTR")
894 901 left = left + width+1
895 902 end
896 903 while week_f <= self.date_to
897 904 width = (week_f + 6 <= self.date_to) ? 7 * zoom : (self.date_to - week_f + 1) * zoom
898 905 pdf.SetY(y_start + header_heigth)
899 906 pdf.SetX(left)
900 907 pdf.Cell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C")
901 908 left = left + width
902 909 week_f = week_f+7
903 910 end
904 911 end
905 912
906 913 # Days headers
907 914 if show_days
908 915 left = subject_width
909 916 height = header_heigth
910 917 wday = self.date_from.cwday
911 918 pdf.SetFontStyle('B',7)
912 919 (self.date_to - self.date_from + 1).to_i.times do
913 920 width = zoom
914 921 pdf.SetY(y_start + 2 * header_heigth)
915 922 pdf.SetX(left)
916 923 pdf.Cell(width, height, day_name(wday).first, "LTR", 0, "C")
917 924 left = left + width
918 925 wday = wday + 1
919 926 wday = 1 if wday > 7
920 927 end
921 928 end
922 929
923 930 pdf.SetY(y_start)
924 931 pdf.SetX(15)
925 932 pdf.Cell(subject_width+g_width-15, headers_heigth, "", 1)
926 933
927 934 # Tasks
928 935 top = headers_heigth + y_start
929 936 options = {
930 937 :top => top,
931 938 :zoom => zoom,
932 939 :subject_width => subject_width,
933 940 :g_width => g_width,
934 941 :indent => 0,
935 942 :indent_increment => 5,
936 943 :top_increment => 5,
937 944 :format => :pdf,
938 945 :pdf => pdf
939 946 }
940 947 render(options)
941 948 pdf.Output
942 949 end
943 950
944 951 private
945 952
946 953 # Sorts a collection of issues by start_date, due_date, id for gantt rendering
947 954 def sort_issues!(issues)
948 955 issues.sort! do |a, b|
949 956 cmp = 0
950 957 cmp = (a.start_date <=> b.start_date) if a.start_date? && b.start_date?
951 958 cmp = (a.due_date <=> b.due_date) if cmp == 0 && a.due_date? && b.due_date?
952 959 cmp = (a.id <=> b.id) if cmp == 0
953 960 cmp
954 961 end
955 962 end
956 963
957 964 def pdf_new_page?(options)
958 965 if options[:top] > 180
959 966 options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
960 967 options[:pdf].AddPage("L")
961 968 options[:top] = 15
962 969 options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1)
963 970 end
964 971 end
965 972 end
966 973 end
967 974 end
General Comments 0
You need to be logged in to leave comments. Login now