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