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