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