##// END OF EJS Templates
Removed debug messages....
Jean-Philippe Lang -
r10904:114537530f3a
parent child
Show More
@@ -1,921 +1,918
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 include Redmine::Utils::DateCalculation
24 include Redmine::Utils::DateCalculation
25
25
26 # Relation types that are rendered
26 # Relation types that are rendered
27 DRAW_TYPES = {
27 DRAW_TYPES = {
28 IssueRelation::TYPE_BLOCKS => { :landscape_margin => 16, :color => '#F34F4F' },
28 IssueRelation::TYPE_BLOCKS => { :landscape_margin => 16, :color => '#F34F4F' },
29 IssueRelation::TYPE_PRECEDES => { :landscape_margin => 20, :color => '#628FEA' }
29 IssueRelation::TYPE_PRECEDES => { :landscape_margin => 20, :color => '#628FEA' }
30 }.freeze
30 }.freeze
31
31
32 # :nodoc:
32 # :nodoc:
33 # Some utility methods for the PDF export
33 # Some utility methods for the PDF export
34 class PDF
34 class PDF
35 MaxCharactorsForSubject = 45
35 MaxCharactorsForSubject = 45
36 TotalWidth = 280
36 TotalWidth = 280
37 LeftPaneWidth = 100
37 LeftPaneWidth = 100
38
38
39 def self.right_pane_width
39 def self.right_pane_width
40 TotalWidth - LeftPaneWidth
40 TotalWidth - LeftPaneWidth
41 end
41 end
42 end
42 end
43
43
44 attr_reader :year_from, :month_from, :date_from, :date_to, :zoom, :months, :truncated, :max_rows
44 attr_reader :year_from, :month_from, :date_from, :date_to, :zoom, :months, :truncated, :max_rows
45 attr_accessor :query
45 attr_accessor :query
46 attr_accessor :project
46 attr_accessor :project
47 attr_accessor :view
47 attr_accessor :view
48
48
49 def initialize(options={})
49 def initialize(options={})
50 options = options.dup
50 options = options.dup
51 if options[:year] && options[:year].to_i >0
51 if options[:year] && options[:year].to_i >0
52 @year_from = options[:year].to_i
52 @year_from = options[:year].to_i
53 if options[:month] && options[:month].to_i >=1 && options[:month].to_i <= 12
53 if options[:month] && options[:month].to_i >=1 && options[:month].to_i <= 12
54 @month_from = options[:month].to_i
54 @month_from = options[:month].to_i
55 else
55 else
56 @month_from = 1
56 @month_from = 1
57 end
57 end
58 else
58 else
59 @month_from ||= Date.today.month
59 @month_from ||= Date.today.month
60 @year_from ||= Date.today.year
60 @year_from ||= Date.today.year
61 end
61 end
62 zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i
62 zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i
63 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
63 @zoom = (zoom > 0 && zoom < 5) ? zoom : 2
64 months = (options[:months] || User.current.pref[:gantt_months]).to_i
64 months = (options[:months] || User.current.pref[:gantt_months]).to_i
65 @months = (months > 0 && months < 25) ? months : 6
65 @months = (months > 0 && months < 25) ? months : 6
66 # Save gantt parameters as user preference (zoom and months count)
66 # Save gantt parameters as user preference (zoom and months count)
67 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] ||
67 if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] ||
68 @months != User.current.pref[:gantt_months]))
68 @months != User.current.pref[:gantt_months]))
69 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
69 User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
70 User.current.preference.save
70 User.current.preference.save
71 end
71 end
72 @date_from = Date.civil(@year_from, @month_from, 1)
72 @date_from = Date.civil(@year_from, @month_from, 1)
73 @date_to = (@date_from >> @months) - 1
73 @date_to = (@date_from >> @months) - 1
74 @subjects = ''
74 @subjects = ''
75 @lines = ''
75 @lines = ''
76 @number_of_rows = nil
76 @number_of_rows = nil
77 @issue_ancestors = []
77 @issue_ancestors = []
78 @truncated = false
78 @truncated = false
79 if options.has_key?(:max_rows)
79 if options.has_key?(:max_rows)
80 @max_rows = options[:max_rows]
80 @max_rows = options[:max_rows]
81 else
81 else
82 @max_rows = Setting.gantt_items_limit.blank? ? nil : Setting.gantt_items_limit.to_i
82 @max_rows = Setting.gantt_items_limit.blank? ? nil : Setting.gantt_items_limit.to_i
83 end
83 end
84 end
84 end
85
85
86 def common_params
86 def common_params
87 { :controller => 'gantts', :action => 'show', :project_id => @project }
87 { :controller => 'gantts', :action => 'show', :project_id => @project }
88 end
88 end
89
89
90 def params
90 def params
91 common_params.merge({:zoom => zoom, :year => year_from,
91 common_params.merge({:zoom => zoom, :year => year_from,
92 :month => month_from, :months => months})
92 :month => month_from, :months => months})
93 end
93 end
94
94
95 def params_previous
95 def params_previous
96 common_params.merge({:year => (date_from << months).year,
96 common_params.merge({:year => (date_from << months).year,
97 :month => (date_from << months).month,
97 :month => (date_from << months).month,
98 :zoom => zoom, :months => months})
98 :zoom => zoom, :months => months})
99 end
99 end
100
100
101 def params_next
101 def params_next
102 common_params.merge({:year => (date_from >> months).year,
102 common_params.merge({:year => (date_from >> months).year,
103 :month => (date_from >> months).month,
103 :month => (date_from >> months).month,
104 :zoom => zoom, :months => months})
104 :zoom => zoom, :months => months})
105 end
105 end
106
106
107 # Returns the number of rows that will be rendered on the Gantt chart
107 # Returns the number of rows that will be rendered on the Gantt chart
108 def number_of_rows
108 def number_of_rows
109 return @number_of_rows if @number_of_rows
109 return @number_of_rows if @number_of_rows
110 rows = projects.inject(0) {|total, p| total += number_of_rows_on_project(p)}
110 rows = projects.inject(0) {|total, p| total += number_of_rows_on_project(p)}
111 rows > @max_rows ? @max_rows : rows
111 rows > @max_rows ? @max_rows : rows
112 end
112 end
113
113
114 # Returns the number of rows that will be used to list a project on
114 # Returns the number of rows that will be used to list a project on
115 # the Gantt chart. This will recurse for each subproject.
115 # the Gantt chart. This will recurse for each subproject.
116 def number_of_rows_on_project(project)
116 def number_of_rows_on_project(project)
117 return 0 unless projects.include?(project)
117 return 0 unless projects.include?(project)
118 count = 1
118 count = 1
119 count += project_issues(project).size
119 count += project_issues(project).size
120 count += project_versions(project).size
120 count += project_versions(project).size
121 count
121 count
122 end
122 end
123
123
124 # Renders the subjects of the Gantt chart, the left side.
124 # Renders the subjects of the Gantt chart, the left side.
125 def subjects(options={})
125 def subjects(options={})
126 render(options.merge(:only => :subjects)) unless @subjects_rendered
126 render(options.merge(:only => :subjects)) unless @subjects_rendered
127 @subjects
127 @subjects
128 end
128 end
129
129
130 # Renders the lines of the Gantt chart, the right side
130 # Renders the lines of the Gantt chart, the right side
131 def lines(options={})
131 def lines(options={})
132 render(options.merge(:only => :lines)) unless @lines_rendered
132 render(options.merge(:only => :lines)) unless @lines_rendered
133 @lines
133 @lines
134 end
134 end
135
135
136 # Returns issues that will be rendered
136 # Returns issues that will be rendered
137 def issues
137 def issues
138 @issues ||= @query.issues(
138 @issues ||= @query.issues(
139 :include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
139 :include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
140 :order => "#{Project.table_name}.lft ASC, #{Issue.table_name}.id ASC",
140 :order => "#{Project.table_name}.lft ASC, #{Issue.table_name}.id ASC",
141 :limit => @max_rows
141 :limit => @max_rows
142 )
142 )
143 end
143 end
144
144
145 # Returns a hash of the relations between the issues that are present on the gantt
145 # Returns a hash of the relations between the issues that are present on the gantt
146 # and that should be displayed, grouped by issue ids.
146 # and that should be displayed, grouped by issue ids.
147 def relations
147 def relations
148 return @relations if @relations
148 return @relations if @relations
149 if issues.any?
149 if issues.any?
150 issue_ids = issues.map(&:id)
150 issue_ids = issues.map(&:id)
151 @relations = IssueRelation.
151 @relations = IssueRelation.
152 where(:issue_from_id => issue_ids, :issue_to_id => issue_ids, :relation_type => DRAW_TYPES.keys).
152 where(:issue_from_id => issue_ids, :issue_to_id => issue_ids, :relation_type => DRAW_TYPES.keys).
153 group_by(&:issue_from_id)
153 group_by(&:issue_from_id)
154 else
154 else
155 @relations = {}
155 @relations = {}
156 end
156 end
157 end
157 end
158
158
159 # Return all the project nodes that will be displayed
159 # Return all the project nodes that will be displayed
160 def projects
160 def projects
161 return @projects if @projects
161 return @projects if @projects
162 ids = issues.collect(&:project).uniq.collect(&:id)
162 ids = issues.collect(&:project).uniq.collect(&:id)
163 if ids.any?
163 if ids.any?
164 # All issues projects and their visible ancestors
164 # All issues projects and their visible ancestors
165 @projects = Project.visible.all(
165 @projects = Project.visible.all(
166 :joins => "LEFT JOIN #{Project.table_name} child ON #{Project.table_name}.lft <= child.lft AND #{Project.table_name}.rgt >= child.rgt",
166 :joins => "LEFT JOIN #{Project.table_name} child ON #{Project.table_name}.lft <= child.lft AND #{Project.table_name}.rgt >= child.rgt",
167 :conditions => ["child.id IN (?)", ids],
167 :conditions => ["child.id IN (?)", ids],
168 :order => "#{Project.table_name}.lft ASC"
168 :order => "#{Project.table_name}.lft ASC"
169 ).uniq
169 ).uniq
170 else
170 else
171 @projects = []
171 @projects = []
172 end
172 end
173 end
173 end
174
174
175 # Returns the issues that belong to +project+
175 # Returns the issues that belong to +project+
176 def project_issues(project)
176 def project_issues(project)
177 @issues_by_project ||= issues.group_by(&:project)
177 @issues_by_project ||= issues.group_by(&:project)
178 @issues_by_project[project] || []
178 @issues_by_project[project] || []
179 end
179 end
180
180
181 # Returns the distinct versions of the issues that belong to +project+
181 # Returns the distinct versions of the issues that belong to +project+
182 def project_versions(project)
182 def project_versions(project)
183 project_issues(project).collect(&:fixed_version).compact.uniq
183 project_issues(project).collect(&:fixed_version).compact.uniq
184 end
184 end
185
185
186 # Returns the issues that belong to +project+ and are assigned to +version+
186 # Returns the issues that belong to +project+ and are assigned to +version+
187 def version_issues(project, version)
187 def version_issues(project, version)
188 project_issues(project).select {|issue| issue.fixed_version == version}
188 project_issues(project).select {|issue| issue.fixed_version == version}
189 end
189 end
190
190
191 def render(options={})
191 def render(options={})
192 options = {:top => 0, :top_increment => 20,
192 options = {:top => 0, :top_increment => 20,
193 :indent_increment => 20, :render => :subject,
193 :indent_increment => 20, :render => :subject,
194 :format => :html}.merge(options)
194 :format => :html}.merge(options)
195 indent = options[:indent] || 4
195 indent = options[:indent] || 4
196 @subjects = '' unless options[:only] == :lines
196 @subjects = '' unless options[:only] == :lines
197 @lines = '' unless options[:only] == :subjects
197 @lines = '' unless options[:only] == :subjects
198 @number_of_rows = 0
198 @number_of_rows = 0
199 Project.project_tree(projects) do |project, level|
199 Project.project_tree(projects) do |project, level|
200 options[:indent] = indent + level * options[:indent_increment]
200 options[:indent] = indent + level * options[:indent_increment]
201 render_project(project, options)
201 render_project(project, options)
202 break if abort?
202 break if abort?
203 end
203 end
204 @subjects_rendered = true unless options[:only] == :lines
204 @subjects_rendered = true unless options[:only] == :lines
205 @lines_rendered = true unless options[:only] == :subjects
205 @lines_rendered = true unless options[:only] == :subjects
206 render_end(options)
206 render_end(options)
207 end
207 end
208
208
209 def render_project(project, options={})
209 def render_project(project, options={})
210 subject_for_project(project, options) unless options[:only] == :lines
210 subject_for_project(project, options) unless options[:only] == :lines
211 line_for_project(project, options) unless options[:only] == :subjects
211 line_for_project(project, options) unless options[:only] == :subjects
212 options[:top] += options[:top_increment]
212 options[:top] += options[:top_increment]
213 options[:indent] += options[:indent_increment]
213 options[:indent] += options[:indent_increment]
214 @number_of_rows += 1
214 @number_of_rows += 1
215 return if abort?
215 return if abort?
216 issues = project_issues(project).select {|i| i.fixed_version.nil?}
216 issues = project_issues(project).select {|i| i.fixed_version.nil?}
217 sort_issues!(issues)
217 sort_issues!(issues)
218 if issues
218 if issues
219 render_issues(issues, options)
219 render_issues(issues, options)
220 return if abort?
220 return if abort?
221 end
221 end
222 versions = project_versions(project)
222 versions = project_versions(project)
223 versions.each do |version|
223 versions.each do |version|
224 render_version(project, version, options)
224 render_version(project, version, options)
225 end
225 end
226 # Remove indent to hit the next sibling
226 # Remove indent to hit the next sibling
227 options[:indent] -= options[:indent_increment]
227 options[:indent] -= options[:indent_increment]
228 end
228 end
229
229
230 def render_issues(issues, options={})
230 def render_issues(issues, options={})
231 @issue_ancestors = []
231 @issue_ancestors = []
232 issues.each do |i|
232 issues.each do |i|
233 subject_for_issue(i, options) unless options[:only] == :lines
233 subject_for_issue(i, options) unless options[:only] == :lines
234 line_for_issue(i, options) unless options[:only] == :subjects
234 line_for_issue(i, options) unless options[:only] == :subjects
235 options[:top] += options[:top_increment]
235 options[:top] += options[:top_increment]
236 @number_of_rows += 1
236 @number_of_rows += 1
237 break if abort?
237 break if abort?
238 end
238 end
239 options[:indent] -= (options[:indent_increment] * @issue_ancestors.size)
239 options[:indent] -= (options[:indent_increment] * @issue_ancestors.size)
240 end
240 end
241
241
242 def render_version(project, version, options={})
242 def render_version(project, version, options={})
243 # Version header
243 # Version header
244 subject_for_version(version, options) unless options[:only] == :lines
244 subject_for_version(version, options) unless options[:only] == :lines
245 line_for_version(version, options) unless options[:only] == :subjects
245 line_for_version(version, options) unless options[:only] == :subjects
246 options[:top] += options[:top_increment]
246 options[:top] += options[:top_increment]
247 @number_of_rows += 1
247 @number_of_rows += 1
248 return if abort?
248 return if abort?
249 issues = version_issues(project, version)
249 issues = version_issues(project, version)
250 if issues
250 if issues
251 sort_issues!(issues)
251 sort_issues!(issues)
252 # Indent issues
252 # Indent issues
253 options[:indent] += options[:indent_increment]
253 options[:indent] += options[:indent_increment]
254 render_issues(issues, options)
254 render_issues(issues, options)
255 options[:indent] -= options[:indent_increment]
255 options[:indent] -= options[:indent_increment]
256 end
256 end
257 end
257 end
258
258
259 def render_end(options={})
259 def render_end(options={})
260 case options[:format]
260 case options[:format]
261 when :pdf
261 when :pdf
262 options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
262 options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
263 end
263 end
264 end
264 end
265
265
266 def subject_for_project(project, options)
266 def subject_for_project(project, options)
267 case options[:format]
267 case options[:format]
268 when :html
268 when :html
269 html_class = ""
269 html_class = ""
270 html_class << 'icon icon-projects '
270 html_class << 'icon icon-projects '
271 html_class << (project.overdue? ? 'project-overdue' : '')
271 html_class << (project.overdue? ? 'project-overdue' : '')
272 s = view.link_to_project(project).html_safe
272 s = view.link_to_project(project).html_safe
273 subject = view.content_tag(:span, s,
273 subject = view.content_tag(:span, s,
274 :class => html_class).html_safe
274 :class => html_class).html_safe
275 html_subject(options, subject, :css => "project-name")
275 html_subject(options, subject, :css => "project-name")
276 when :image
276 when :image
277 image_subject(options, project.name)
277 image_subject(options, project.name)
278 when :pdf
278 when :pdf
279 pdf_new_page?(options)
279 pdf_new_page?(options)
280 pdf_subject(options, project.name)
280 pdf_subject(options, project.name)
281 end
281 end
282 end
282 end
283
283
284 def line_for_project(project, options)
284 def line_for_project(project, options)
285 # Skip versions that don't have a start_date or due date
285 # Skip versions that don't have a start_date or due date
286 if project.is_a?(Project) && project.start_date && project.due_date
286 if project.is_a?(Project) && project.start_date && project.due_date
287 options[:zoom] ||= 1
287 options[:zoom] ||= 1
288 options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
288 options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
289 coords = coordinates(project.start_date, project.due_date, nil, options[:zoom])
289 coords = coordinates(project.start_date, project.due_date, nil, options[:zoom])
290 label = h(project)
290 label = h(project)
291 case options[:format]
291 case options[:format]
292 when :html
292 when :html
293 html_task(options, coords, :css => "project task", :label => label, :markers => true)
293 html_task(options, coords, :css => "project task", :label => label, :markers => true)
294 when :image
294 when :image
295 image_task(options, coords, :label => label, :markers => true, :height => 3)
295 image_task(options, coords, :label => label, :markers => true, :height => 3)
296 when :pdf
296 when :pdf
297 pdf_task(options, coords, :label => label, :markers => true, :height => 0.8)
297 pdf_task(options, coords, :label => label, :markers => true, :height => 0.8)
298 end
298 end
299 else
299 else
300 ActiveRecord::Base.logger.debug "Gantt#line_for_project was not given a project with a start_date"
301 ''
300 ''
302 end
301 end
303 end
302 end
304
303
305 def subject_for_version(version, options)
304 def subject_for_version(version, options)
306 case options[:format]
305 case options[:format]
307 when :html
306 when :html
308 html_class = ""
307 html_class = ""
309 html_class << 'icon icon-package '
308 html_class << 'icon icon-package '
310 html_class << (version.behind_schedule? ? 'version-behind-schedule' : '') << " "
309 html_class << (version.behind_schedule? ? 'version-behind-schedule' : '') << " "
311 html_class << (version.overdue? ? 'version-overdue' : '')
310 html_class << (version.overdue? ? 'version-overdue' : '')
312 s = view.link_to_version(version).html_safe
311 s = view.link_to_version(version).html_safe
313 subject = view.content_tag(:span, s,
312 subject = view.content_tag(:span, s,
314 :class => html_class).html_safe
313 :class => html_class).html_safe
315 html_subject(options, subject, :css => "version-name")
314 html_subject(options, subject, :css => "version-name")
316 when :image
315 when :image
317 image_subject(options, version.to_s_with_project)
316 image_subject(options, version.to_s_with_project)
318 when :pdf
317 when :pdf
319 pdf_new_page?(options)
318 pdf_new_page?(options)
320 pdf_subject(options, version.to_s_with_project)
319 pdf_subject(options, version.to_s_with_project)
321 end
320 end
322 end
321 end
323
322
324 def line_for_version(version, options)
323 def line_for_version(version, options)
325 # Skip versions that don't have a start_date
324 # Skip versions that don't have a start_date
326 if version.is_a?(Version) && version.start_date && version.due_date
325 if version.is_a?(Version) && version.start_date && version.due_date
327 options[:zoom] ||= 1
326 options[:zoom] ||= 1
328 options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
327 options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
329 coords = coordinates(version.start_date,
328 coords = coordinates(version.start_date,
330 version.due_date, version.completed_percent,
329 version.due_date, version.completed_percent,
331 options[:zoom])
330 options[:zoom])
332 label = "#{h version} #{h version.completed_percent.to_i.to_s}%"
331 label = "#{h version} #{h version.completed_percent.to_i.to_s}%"
333 label = h("#{version.project} -") + label unless @project && @project == version.project
332 label = h("#{version.project} -") + label unless @project && @project == version.project
334 case options[:format]
333 case options[:format]
335 when :html
334 when :html
336 html_task(options, coords, :css => "version task", :label => label, :markers => true)
335 html_task(options, coords, :css => "version task", :label => label, :markers => true)
337 when :image
336 when :image
338 image_task(options, coords, :label => label, :markers => true, :height => 3)
337 image_task(options, coords, :label => label, :markers => true, :height => 3)
339 when :pdf
338 when :pdf
340 pdf_task(options, coords, :label => label, :markers => true, :height => 0.8)
339 pdf_task(options, coords, :label => label, :markers => true, :height => 0.8)
341 end
340 end
342 else
341 else
343 ActiveRecord::Base.logger.debug "Gantt#line_for_version was not given a version with a start_date"
344 ''
342 ''
345 end
343 end
346 end
344 end
347
345
348 def subject_for_issue(issue, options)
346 def subject_for_issue(issue, options)
349 while @issue_ancestors.any? && !issue.is_descendant_of?(@issue_ancestors.last)
347 while @issue_ancestors.any? && !issue.is_descendant_of?(@issue_ancestors.last)
350 @issue_ancestors.pop
348 @issue_ancestors.pop
351 options[:indent] -= options[:indent_increment]
349 options[:indent] -= options[:indent_increment]
352 end
350 end
353 output = case options[:format]
351 output = case options[:format]
354 when :html
352 when :html
355 css_classes = ''
353 css_classes = ''
356 css_classes << ' issue-overdue' if issue.overdue?
354 css_classes << ' issue-overdue' if issue.overdue?
357 css_classes << ' issue-behind-schedule' if issue.behind_schedule?
355 css_classes << ' issue-behind-schedule' if issue.behind_schedule?
358 css_classes << ' icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to
356 css_classes << ' icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to
359 s = "".html_safe
357 s = "".html_safe
360 if issue.assigned_to.present?
358 if issue.assigned_to.present?
361 assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name
359 assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name
362 s << view.avatar(issue.assigned_to,
360 s << view.avatar(issue.assigned_to,
363 :class => 'gravatar icon-gravatar',
361 :class => 'gravatar icon-gravatar',
364 :size => 10,
362 :size => 10,
365 :title => assigned_string).to_s.html_safe
363 :title => assigned_string).to_s.html_safe
366 end
364 end
367 s << view.link_to_issue(issue).html_safe
365 s << view.link_to_issue(issue).html_safe
368 subject = view.content_tag(:span, s, :class => css_classes).html_safe
366 subject = view.content_tag(:span, s, :class => css_classes).html_safe
369 html_subject(options, subject, :css => "issue-subject",
367 html_subject(options, subject, :css => "issue-subject",
370 :title => issue.subject) + "\n"
368 :title => issue.subject) + "\n"
371 when :image
369 when :image
372 image_subject(options, issue.subject)
370 image_subject(options, issue.subject)
373 when :pdf
371 when :pdf
374 pdf_new_page?(options)
372 pdf_new_page?(options)
375 pdf_subject(options, issue.subject)
373 pdf_subject(options, issue.subject)
376 end
374 end
377 unless issue.leaf?
375 unless issue.leaf?
378 @issue_ancestors << issue
376 @issue_ancestors << issue
379 options[:indent] += options[:indent_increment]
377 options[:indent] += options[:indent_increment]
380 end
378 end
381 output
379 output
382 end
380 end
383
381
384 def line_for_issue(issue, options)
382 def line_for_issue(issue, options)
385 # Skip issues that don't have a due_before (due_date or version's due_date)
383 # Skip issues that don't have a due_before (due_date or version's due_date)
386 if issue.is_a?(Issue) && issue.due_before
384 if issue.is_a?(Issue) && issue.due_before
387 coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom])
385 coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom])
388 label = "#{issue.status.name} #{issue.done_ratio}%"
386 label = "#{issue.status.name} #{issue.done_ratio}%"
389 case options[:format]
387 case options[:format]
390 when :html
388 when :html
391 html_task(options, coords,
389 html_task(options, coords,
392 :css => "task " + (issue.leaf? ? 'leaf' : 'parent'),
390 :css => "task " + (issue.leaf? ? 'leaf' : 'parent'),
393 :label => label, :issue => issue,
391 :label => label, :issue => issue,
394 :markers => !issue.leaf?)
392 :markers => !issue.leaf?)
395 when :image
393 when :image
396 image_task(options, coords, :label => label)
394 image_task(options, coords, :label => label)
397 when :pdf
395 when :pdf
398 pdf_task(options, coords, :label => label)
396 pdf_task(options, coords, :label => label)
399 end
397 end
400 else
398 else
401 ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before"
402 ''
399 ''
403 end
400 end
404 end
401 end
405
402
406 # Generates a gantt image
403 # Generates a gantt image
407 # Only defined if RMagick is avalaible
404 # Only defined if RMagick is avalaible
408 def to_image(format='PNG')
405 def to_image(format='PNG')
409 date_to = (@date_from >> @months) - 1
406 date_to = (@date_from >> @months) - 1
410 show_weeks = @zoom > 1
407 show_weeks = @zoom > 1
411 show_days = @zoom > 2
408 show_days = @zoom > 2
412 subject_width = 400
409 subject_width = 400
413 header_height = 18
410 header_height = 18
414 # width of one day in pixels
411 # width of one day in pixels
415 zoom = @zoom * 2
412 zoom = @zoom * 2
416 g_width = (@date_to - @date_from + 1) * zoom
413 g_width = (@date_to - @date_from + 1) * zoom
417 g_height = 20 * number_of_rows + 30
414 g_height = 20 * number_of_rows + 30
418 headers_height = (show_weeks ? 2 * header_height : header_height)
415 headers_height = (show_weeks ? 2 * header_height : header_height)
419 height = g_height + headers_height
416 height = g_height + headers_height
420 imgl = Magick::ImageList.new
417 imgl = Magick::ImageList.new
421 imgl.new_image(subject_width + g_width + 1, height)
418 imgl.new_image(subject_width + g_width + 1, height)
422 gc = Magick::Draw.new
419 gc = Magick::Draw.new
423 gc.font = Redmine::Configuration['rmagick_font_path'] || ""
420 gc.font = Redmine::Configuration['rmagick_font_path'] || ""
424 # Subjects
421 # Subjects
425 gc.stroke('transparent')
422 gc.stroke('transparent')
426 subjects(:image => gc, :top => (headers_height + 20), :indent => 4, :format => :image)
423 subjects(:image => gc, :top => (headers_height + 20), :indent => 4, :format => :image)
427 # Months headers
424 # Months headers
428 month_f = @date_from
425 month_f = @date_from
429 left = subject_width
426 left = subject_width
430 @months.times do
427 @months.times do
431 width = ((month_f >> 1) - month_f) * zoom
428 width = ((month_f >> 1) - month_f) * zoom
432 gc.fill('white')
429 gc.fill('white')
433 gc.stroke('grey')
430 gc.stroke('grey')
434 gc.stroke_width(1)
431 gc.stroke_width(1)
435 gc.rectangle(left, 0, left + width, height)
432 gc.rectangle(left, 0, left + width, height)
436 gc.fill('black')
433 gc.fill('black')
437 gc.stroke('transparent')
434 gc.stroke('transparent')
438 gc.stroke_width(1)
435 gc.stroke_width(1)
439 gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}")
436 gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}")
440 left = left + width
437 left = left + width
441 month_f = month_f >> 1
438 month_f = month_f >> 1
442 end
439 end
443 # Weeks headers
440 # Weeks headers
444 if show_weeks
441 if show_weeks
445 left = subject_width
442 left = subject_width
446 height = header_height
443 height = header_height
447 if @date_from.cwday == 1
444 if @date_from.cwday == 1
448 # date_from is monday
445 # date_from is monday
449 week_f = date_from
446 week_f = date_from
450 else
447 else
451 # find next monday after date_from
448 # find next monday after date_from
452 week_f = @date_from + (7 - @date_from.cwday + 1)
449 week_f = @date_from + (7 - @date_from.cwday + 1)
453 width = (7 - @date_from.cwday + 1) * zoom
450 width = (7 - @date_from.cwday + 1) * zoom
454 gc.fill('white')
451 gc.fill('white')
455 gc.stroke('grey')
452 gc.stroke('grey')
456 gc.stroke_width(1)
453 gc.stroke_width(1)
457 gc.rectangle(left, header_height, left + width, 2 * header_height + g_height - 1)
454 gc.rectangle(left, header_height, left + width, 2 * header_height + g_height - 1)
458 left = left + width
455 left = left + width
459 end
456 end
460 while week_f <= date_to
457 while week_f <= date_to
461 width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom
458 width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom
462 gc.fill('white')
459 gc.fill('white')
463 gc.stroke('grey')
460 gc.stroke('grey')
464 gc.stroke_width(1)
461 gc.stroke_width(1)
465 gc.rectangle(left.round, header_height, left.round + width, 2 * header_height + g_height - 1)
462 gc.rectangle(left.round, header_height, left.round + width, 2 * header_height + g_height - 1)
466 gc.fill('black')
463 gc.fill('black')
467 gc.stroke('transparent')
464 gc.stroke('transparent')
468 gc.stroke_width(1)
465 gc.stroke_width(1)
469 gc.text(left.round + 2, header_height + 14, week_f.cweek.to_s)
466 gc.text(left.round + 2, header_height + 14, week_f.cweek.to_s)
470 left = left + width
467 left = left + width
471 week_f = week_f + 7
468 week_f = week_f + 7
472 end
469 end
473 end
470 end
474 # Days details (week-end in grey)
471 # Days details (week-end in grey)
475 if show_days
472 if show_days
476 left = subject_width
473 left = subject_width
477 height = g_height + header_height - 1
474 height = g_height + header_height - 1
478 wday = @date_from.cwday
475 wday = @date_from.cwday
479 (date_to - @date_from + 1).to_i.times do
476 (date_to - @date_from + 1).to_i.times do
480 width = zoom
477 width = zoom
481 gc.fill(non_working_week_days.include?(wday) ? '#eee' : 'white')
478 gc.fill(non_working_week_days.include?(wday) ? '#eee' : 'white')
482 gc.stroke('#ddd')
479 gc.stroke('#ddd')
483 gc.stroke_width(1)
480 gc.stroke_width(1)
484 gc.rectangle(left, 2 * header_height, left + width, 2 * header_height + g_height - 1)
481 gc.rectangle(left, 2 * header_height, left + width, 2 * header_height + g_height - 1)
485 left = left + width
482 left = left + width
486 wday = wday + 1
483 wday = wday + 1
487 wday = 1 if wday > 7
484 wday = 1 if wday > 7
488 end
485 end
489 end
486 end
490 # border
487 # border
491 gc.fill('transparent')
488 gc.fill('transparent')
492 gc.stroke('grey')
489 gc.stroke('grey')
493 gc.stroke_width(1)
490 gc.stroke_width(1)
494 gc.rectangle(0, 0, subject_width + g_width, headers_height)
491 gc.rectangle(0, 0, subject_width + g_width, headers_height)
495 gc.stroke('black')
492 gc.stroke('black')
496 gc.rectangle(0, 0, subject_width + g_width, g_height + headers_height - 1)
493 gc.rectangle(0, 0, subject_width + g_width, g_height + headers_height - 1)
497 # content
494 # content
498 top = headers_height + 20
495 top = headers_height + 20
499 gc.stroke('transparent')
496 gc.stroke('transparent')
500 lines(:image => gc, :top => top, :zoom => zoom,
497 lines(:image => gc, :top => top, :zoom => zoom,
501 :subject_width => subject_width, :format => :image)
498 :subject_width => subject_width, :format => :image)
502 # today red line
499 # today red line
503 if Date.today >= @date_from and Date.today <= date_to
500 if Date.today >= @date_from and Date.today <= date_to
504 gc.stroke('red')
501 gc.stroke('red')
505 x = (Date.today - @date_from + 1) * zoom + subject_width
502 x = (Date.today - @date_from + 1) * zoom + subject_width
506 gc.line(x, headers_height, x, headers_height + g_height - 1)
503 gc.line(x, headers_height, x, headers_height + g_height - 1)
507 end
504 end
508 gc.draw(imgl)
505 gc.draw(imgl)
509 imgl.format = format
506 imgl.format = format
510 imgl.to_blob
507 imgl.to_blob
511 end if Object.const_defined?(:Magick)
508 end if Object.const_defined?(:Magick)
512
509
513 def to_pdf
510 def to_pdf
514 pdf = ::Redmine::Export::PDF::ITCPDF.new(current_language)
511 pdf = ::Redmine::Export::PDF::ITCPDF.new(current_language)
515 pdf.SetTitle("#{l(:label_gantt)} #{project}")
512 pdf.SetTitle("#{l(:label_gantt)} #{project}")
516 pdf.alias_nb_pages
513 pdf.alias_nb_pages
517 pdf.footer_date = format_date(Date.today)
514 pdf.footer_date = format_date(Date.today)
518 pdf.AddPage("L")
515 pdf.AddPage("L")
519 pdf.SetFontStyle('B', 12)
516 pdf.SetFontStyle('B', 12)
520 pdf.SetX(15)
517 pdf.SetX(15)
521 pdf.RDMCell(PDF::LeftPaneWidth, 20, project.to_s)
518 pdf.RDMCell(PDF::LeftPaneWidth, 20, project.to_s)
522 pdf.Ln
519 pdf.Ln
523 pdf.SetFontStyle('B', 9)
520 pdf.SetFontStyle('B', 9)
524 subject_width = PDF::LeftPaneWidth
521 subject_width = PDF::LeftPaneWidth
525 header_height = 5
522 header_height = 5
526 headers_height = header_height
523 headers_height = header_height
527 show_weeks = false
524 show_weeks = false
528 show_days = false
525 show_days = false
529 if self.months < 7
526 if self.months < 7
530 show_weeks = true
527 show_weeks = true
531 headers_height = 2 * header_height
528 headers_height = 2 * header_height
532 if self.months < 3
529 if self.months < 3
533 show_days = true
530 show_days = true
534 headers_height = 3 * header_height
531 headers_height = 3 * header_height
535 end
532 end
536 end
533 end
537 g_width = PDF.right_pane_width
534 g_width = PDF.right_pane_width
538 zoom = (g_width) / (self.date_to - self.date_from + 1)
535 zoom = (g_width) / (self.date_to - self.date_from + 1)
539 g_height = 120
536 g_height = 120
540 t_height = g_height + headers_height
537 t_height = g_height + headers_height
541 y_start = pdf.GetY
538 y_start = pdf.GetY
542 # Months headers
539 # Months headers
543 month_f = self.date_from
540 month_f = self.date_from
544 left = subject_width
541 left = subject_width
545 height = header_height
542 height = header_height
546 self.months.times do
543 self.months.times do
547 width = ((month_f >> 1) - month_f) * zoom
544 width = ((month_f >> 1) - month_f) * zoom
548 pdf.SetY(y_start)
545 pdf.SetY(y_start)
549 pdf.SetX(left)
546 pdf.SetX(left)
550 pdf.RDMCell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C")
547 pdf.RDMCell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C")
551 left = left + width
548 left = left + width
552 month_f = month_f >> 1
549 month_f = month_f >> 1
553 end
550 end
554 # Weeks headers
551 # Weeks headers
555 if show_weeks
552 if show_weeks
556 left = subject_width
553 left = subject_width
557 height = header_height
554 height = header_height
558 if self.date_from.cwday == 1
555 if self.date_from.cwday == 1
559 # self.date_from is monday
556 # self.date_from is monday
560 week_f = self.date_from
557 week_f = self.date_from
561 else
558 else
562 # find next monday after self.date_from
559 # find next monday after self.date_from
563 week_f = self.date_from + (7 - self.date_from.cwday + 1)
560 week_f = self.date_from + (7 - self.date_from.cwday + 1)
564 width = (7 - self.date_from.cwday + 1) * zoom-1
561 width = (7 - self.date_from.cwday + 1) * zoom-1
565 pdf.SetY(y_start + header_height)
562 pdf.SetY(y_start + header_height)
566 pdf.SetX(left)
563 pdf.SetX(left)
567 pdf.RDMCell(width + 1, height, "", "LTR")
564 pdf.RDMCell(width + 1, height, "", "LTR")
568 left = left + width + 1
565 left = left + width + 1
569 end
566 end
570 while week_f <= self.date_to
567 while week_f <= self.date_to
571 width = (week_f + 6 <= self.date_to) ? 7 * zoom : (self.date_to - week_f + 1) * zoom
568 width = (week_f + 6 <= self.date_to) ? 7 * zoom : (self.date_to - week_f + 1) * zoom
572 pdf.SetY(y_start + header_height)
569 pdf.SetY(y_start + header_height)
573 pdf.SetX(left)
570 pdf.SetX(left)
574 pdf.RDMCell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C")
571 pdf.RDMCell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C")
575 left = left + width
572 left = left + width
576 week_f = week_f + 7
573 week_f = week_f + 7
577 end
574 end
578 end
575 end
579 # Days headers
576 # Days headers
580 if show_days
577 if show_days
581 left = subject_width
578 left = subject_width
582 height = header_height
579 height = header_height
583 wday = self.date_from.cwday
580 wday = self.date_from.cwday
584 pdf.SetFontStyle('B', 7)
581 pdf.SetFontStyle('B', 7)
585 (self.date_to - self.date_from + 1).to_i.times do
582 (self.date_to - self.date_from + 1).to_i.times do
586 width = zoom
583 width = zoom
587 pdf.SetY(y_start + 2 * header_height)
584 pdf.SetY(y_start + 2 * header_height)
588 pdf.SetX(left)
585 pdf.SetX(left)
589 pdf.RDMCell(width, height, day_name(wday).first, "LTR", 0, "C")
586 pdf.RDMCell(width, height, day_name(wday).first, "LTR", 0, "C")
590 left = left + width
587 left = left + width
591 wday = wday + 1
588 wday = wday + 1
592 wday = 1 if wday > 7
589 wday = 1 if wday > 7
593 end
590 end
594 end
591 end
595 pdf.SetY(y_start)
592 pdf.SetY(y_start)
596 pdf.SetX(15)
593 pdf.SetX(15)
597 pdf.RDMCell(subject_width + g_width - 15, headers_height, "", 1)
594 pdf.RDMCell(subject_width + g_width - 15, headers_height, "", 1)
598 # Tasks
595 # Tasks
599 top = headers_height + y_start
596 top = headers_height + y_start
600 options = {
597 options = {
601 :top => top,
598 :top => top,
602 :zoom => zoom,
599 :zoom => zoom,
603 :subject_width => subject_width,
600 :subject_width => subject_width,
604 :g_width => g_width,
601 :g_width => g_width,
605 :indent => 0,
602 :indent => 0,
606 :indent_increment => 5,
603 :indent_increment => 5,
607 :top_increment => 5,
604 :top_increment => 5,
608 :format => :pdf,
605 :format => :pdf,
609 :pdf => pdf
606 :pdf => pdf
610 }
607 }
611 render(options)
608 render(options)
612 pdf.Output
609 pdf.Output
613 end
610 end
614
611
615 private
612 private
616
613
617 def coordinates(start_date, end_date, progress, zoom=nil)
614 def coordinates(start_date, end_date, progress, zoom=nil)
618 zoom ||= @zoom
615 zoom ||= @zoom
619 coords = {}
616 coords = {}
620 if start_date && end_date && start_date < self.date_to && end_date > self.date_from
617 if start_date && end_date && start_date < self.date_to && end_date > self.date_from
621 if start_date > self.date_from
618 if start_date > self.date_from
622 coords[:start] = start_date - self.date_from
619 coords[:start] = start_date - self.date_from
623 coords[:bar_start] = start_date - self.date_from
620 coords[:bar_start] = start_date - self.date_from
624 else
621 else
625 coords[:bar_start] = 0
622 coords[:bar_start] = 0
626 end
623 end
627 if end_date < self.date_to
624 if end_date < self.date_to
628 coords[:end] = end_date - self.date_from
625 coords[:end] = end_date - self.date_from
629 coords[:bar_end] = end_date - self.date_from + 1
626 coords[:bar_end] = end_date - self.date_from + 1
630 else
627 else
631 coords[:bar_end] = self.date_to - self.date_from + 1
628 coords[:bar_end] = self.date_to - self.date_from + 1
632 end
629 end
633 if progress
630 if progress
634 progress_date = start_date + (end_date - start_date + 1) * (progress / 100.0)
631 progress_date = start_date + (end_date - start_date + 1) * (progress / 100.0)
635 if progress_date > self.date_from && progress_date > start_date
632 if progress_date > self.date_from && progress_date > start_date
636 if progress_date < self.date_to
633 if progress_date < self.date_to
637 coords[:bar_progress_end] = progress_date - self.date_from
634 coords[:bar_progress_end] = progress_date - self.date_from
638 else
635 else
639 coords[:bar_progress_end] = self.date_to - self.date_from + 1
636 coords[:bar_progress_end] = self.date_to - self.date_from + 1
640 end
637 end
641 end
638 end
642 if progress_date < Date.today
639 if progress_date < Date.today
643 late_date = [Date.today, end_date].min
640 late_date = [Date.today, end_date].min
644 if late_date > self.date_from && late_date > start_date
641 if late_date > self.date_from && late_date > start_date
645 if late_date < self.date_to
642 if late_date < self.date_to
646 coords[:bar_late_end] = late_date - self.date_from + 1
643 coords[:bar_late_end] = late_date - self.date_from + 1
647 else
644 else
648 coords[:bar_late_end] = self.date_to - self.date_from + 1
645 coords[:bar_late_end] = self.date_to - self.date_from + 1
649 end
646 end
650 end
647 end
651 end
648 end
652 end
649 end
653 end
650 end
654 # Transforms dates into pixels witdh
651 # Transforms dates into pixels witdh
655 coords.keys.each do |key|
652 coords.keys.each do |key|
656 coords[key] = (coords[key] * zoom).floor
653 coords[key] = (coords[key] * zoom).floor
657 end
654 end
658 coords
655 coords
659 end
656 end
660
657
661 # Sorts a collection of issues by start_date, due_date, id for gantt rendering
658 # Sorts a collection of issues by start_date, due_date, id for gantt rendering
662 def sort_issues!(issues)
659 def sort_issues!(issues)
663 issues.sort! { |a, b| gantt_issue_compare(a, b) }
660 issues.sort! { |a, b| gantt_issue_compare(a, b) }
664 end
661 end
665
662
666 # TODO: top level issues should be sorted by start date
663 # TODO: top level issues should be sorted by start date
667 def gantt_issue_compare(x, y)
664 def gantt_issue_compare(x, y)
668 if x.root_id == y.root_id
665 if x.root_id == y.root_id
669 x.lft <=> y.lft
666 x.lft <=> y.lft
670 else
667 else
671 x.root_id <=> y.root_id
668 x.root_id <=> y.root_id
672 end
669 end
673 end
670 end
674
671
675 def current_limit
672 def current_limit
676 if @max_rows
673 if @max_rows
677 @max_rows - @number_of_rows
674 @max_rows - @number_of_rows
678 else
675 else
679 nil
676 nil
680 end
677 end
681 end
678 end
682
679
683 def abort?
680 def abort?
684 if @max_rows && @number_of_rows >= @max_rows
681 if @max_rows && @number_of_rows >= @max_rows
685 @truncated = true
682 @truncated = true
686 end
683 end
687 end
684 end
688
685
689 def pdf_new_page?(options)
686 def pdf_new_page?(options)
690 if options[:top] > 180
687 if options[:top] > 180
691 options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
688 options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
692 options[:pdf].AddPage("L")
689 options[:pdf].AddPage("L")
693 options[:top] = 15
690 options[:top] = 15
694 options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1)
691 options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1)
695 end
692 end
696 end
693 end
697
694
698 def html_subject(params, subject, options={})
695 def html_subject(params, subject, options={})
699 style = "position: absolute;top:#{params[:top]}px;left:#{params[:indent]}px;"
696 style = "position: absolute;top:#{params[:top]}px;left:#{params[:indent]}px;"
700 style << "width:#{params[:subject_width] - params[:indent]}px;" if params[:subject_width]
697 style << "width:#{params[:subject_width] - params[:indent]}px;" if params[:subject_width]
701 output = view.content_tag('div', subject,
698 output = view.content_tag('div', subject,
702 :class => options[:css], :style => style,
699 :class => options[:css], :style => style,
703 :title => options[:title])
700 :title => options[:title])
704 @subjects << output
701 @subjects << output
705 output
702 output
706 end
703 end
707
704
708 def pdf_subject(params, subject, options={})
705 def pdf_subject(params, subject, options={})
709 params[:pdf].SetY(params[:top])
706 params[:pdf].SetY(params[:top])
710 params[:pdf].SetX(15)
707 params[:pdf].SetX(15)
711 char_limit = PDF::MaxCharactorsForSubject - params[:indent]
708 char_limit = PDF::MaxCharactorsForSubject - params[:indent]
712 params[:pdf].RDMCell(params[:subject_width] - 15, 5,
709 params[:pdf].RDMCell(params[:subject_width] - 15, 5,
713 (" " * params[:indent]) +
710 (" " * params[:indent]) +
714 subject.to_s.sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'),
711 subject.to_s.sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'),
715 "LR")
712 "LR")
716 params[:pdf].SetY(params[:top])
713 params[:pdf].SetY(params[:top])
717 params[:pdf].SetX(params[:subject_width])
714 params[:pdf].SetX(params[:subject_width])
718 params[:pdf].RDMCell(params[:g_width], 5, "", "LR")
715 params[:pdf].RDMCell(params[:g_width], 5, "", "LR")
719 end
716 end
720
717
721 def image_subject(params, subject, options={})
718 def image_subject(params, subject, options={})
722 params[:image].fill('black')
719 params[:image].fill('black')
723 params[:image].stroke('transparent')
720 params[:image].stroke('transparent')
724 params[:image].stroke_width(1)
721 params[:image].stroke_width(1)
725 params[:image].text(params[:indent], params[:top] + 2, subject)
722 params[:image].text(params[:indent], params[:top] + 2, subject)
726 end
723 end
727
724
728 def issue_relations(issue)
725 def issue_relations(issue)
729 rels = {}
726 rels = {}
730 if relations[issue.id]
727 if relations[issue.id]
731 relations[issue.id].each do |relation|
728 relations[issue.id].each do |relation|
732 (rels[relation.relation_type] ||= []) << relation.issue_to_id
729 (rels[relation.relation_type] ||= []) << relation.issue_to_id
733 end
730 end
734 end
731 end
735 rels
732 rels
736 end
733 end
737
734
738 def html_task(params, coords, options={})
735 def html_task(params, coords, options={})
739 output = ''
736 output = ''
740 # Renders the task bar, with progress and late
737 # Renders the task bar, with progress and late
741 if coords[:bar_start] && coords[:bar_end]
738 if coords[:bar_start] && coords[:bar_end]
742 width = coords[:bar_end] - coords[:bar_start] - 2
739 width = coords[:bar_end] - coords[:bar_start] - 2
743 style = ""
740 style = ""
744 style << "top:#{params[:top]}px;"
741 style << "top:#{params[:top]}px;"
745 style << "left:#{coords[:bar_start]}px;"
742 style << "left:#{coords[:bar_start]}px;"
746 style << "width:#{width}px;"
743 style << "width:#{width}px;"
747 html_id = "task-todo-issue-#{options[:issue].id}" if options[:issue]
744 html_id = "task-todo-issue-#{options[:issue].id}" if options[:issue]
748 content_opt = {:style => style,
745 content_opt = {:style => style,
749 :class => "#{options[:css]} task_todo",
746 :class => "#{options[:css]} task_todo",
750 :id => html_id}
747 :id => html_id}
751 if options[:issue]
748 if options[:issue]
752 rels = issue_relations(options[:issue])
749 rels = issue_relations(options[:issue])
753 if rels.present?
750 if rels.present?
754 content_opt[:data] = {"rels" => rels.to_json}
751 content_opt[:data] = {"rels" => rels.to_json}
755 end
752 end
756 end
753 end
757 output << view.content_tag(:div, '&nbsp;'.html_safe, content_opt)
754 output << view.content_tag(:div, '&nbsp;'.html_safe, content_opt)
758 if coords[:bar_late_end]
755 if coords[:bar_late_end]
759 width = coords[:bar_late_end] - coords[:bar_start] - 2
756 width = coords[:bar_late_end] - coords[:bar_start] - 2
760 style = ""
757 style = ""
761 style << "top:#{params[:top]}px;"
758 style << "top:#{params[:top]}px;"
762 style << "left:#{coords[:bar_start]}px;"
759 style << "left:#{coords[:bar_start]}px;"
763 style << "width:#{width}px;"
760 style << "width:#{width}px;"
764 output << view.content_tag(:div, '&nbsp;'.html_safe,
761 output << view.content_tag(:div, '&nbsp;'.html_safe,
765 :style => style,
762 :style => style,
766 :class => "#{options[:css]} task_late")
763 :class => "#{options[:css]} task_late")
767 end
764 end
768 if coords[:bar_progress_end]
765 if coords[:bar_progress_end]
769 width = coords[:bar_progress_end] - coords[:bar_start] - 2
766 width = coords[:bar_progress_end] - coords[:bar_start] - 2
770 style = ""
767 style = ""
771 style << "top:#{params[:top]}px;"
768 style << "top:#{params[:top]}px;"
772 style << "left:#{coords[:bar_start]}px;"
769 style << "left:#{coords[:bar_start]}px;"
773 style << "width:#{width}px;"
770 style << "width:#{width}px;"
774 output << view.content_tag(:div, '&nbsp;'.html_safe,
771 output << view.content_tag(:div, '&nbsp;'.html_safe,
775 :style => style,
772 :style => style,
776 :class => "#{options[:css]} task_done")
773 :class => "#{options[:css]} task_done")
777 end
774 end
778 end
775 end
779 # Renders the markers
776 # Renders the markers
780 if options[:markers]
777 if options[:markers]
781 if coords[:start]
778 if coords[:start]
782 style = ""
779 style = ""
783 style << "top:#{params[:top]}px;"
780 style << "top:#{params[:top]}px;"
784 style << "left:#{coords[:start]}px;"
781 style << "left:#{coords[:start]}px;"
785 style << "width:15px;"
782 style << "width:15px;"
786 output << view.content_tag(:div, '&nbsp;'.html_safe,
783 output << view.content_tag(:div, '&nbsp;'.html_safe,
787 :style => style,
784 :style => style,
788 :class => "#{options[:css]} marker starting")
785 :class => "#{options[:css]} marker starting")
789 end
786 end
790 if coords[:end]
787 if coords[:end]
791 style = ""
788 style = ""
792 style << "top:#{params[:top]}px;"
789 style << "top:#{params[:top]}px;"
793 style << "left:#{coords[:end] + params[:zoom]}px;"
790 style << "left:#{coords[:end] + params[:zoom]}px;"
794 style << "width:15px;"
791 style << "width:15px;"
795 output << view.content_tag(:div, '&nbsp;'.html_safe,
792 output << view.content_tag(:div, '&nbsp;'.html_safe,
796 :style => style,
793 :style => style,
797 :class => "#{options[:css]} marker ending")
794 :class => "#{options[:css]} marker ending")
798 end
795 end
799 end
796 end
800 # Renders the label on the right
797 # Renders the label on the right
801 if options[:label]
798 if options[:label]
802 style = ""
799 style = ""
803 style << "top:#{params[:top]}px;"
800 style << "top:#{params[:top]}px;"
804 style << "left:#{(coords[:bar_end] || 0) + 8}px;"
801 style << "left:#{(coords[:bar_end] || 0) + 8}px;"
805 style << "width:15px;"
802 style << "width:15px;"
806 output << view.content_tag(:div, options[:label],
803 output << view.content_tag(:div, options[:label],
807 :style => style,
804 :style => style,
808 :class => "#{options[:css]} label")
805 :class => "#{options[:css]} label")
809 end
806 end
810 # Renders the tooltip
807 # Renders the tooltip
811 if options[:issue] && coords[:bar_start] && coords[:bar_end]
808 if options[:issue] && coords[:bar_start] && coords[:bar_end]
812 s = view.content_tag(:span,
809 s = view.content_tag(:span,
813 view.render_issue_tooltip(options[:issue]).html_safe,
810 view.render_issue_tooltip(options[:issue]).html_safe,
814 :class => "tip")
811 :class => "tip")
815 style = ""
812 style = ""
816 style << "position: absolute;"
813 style << "position: absolute;"
817 style << "top:#{params[:top]}px;"
814 style << "top:#{params[:top]}px;"
818 style << "left:#{coords[:bar_start]}px;"
815 style << "left:#{coords[:bar_start]}px;"
819 style << "width:#{coords[:bar_end] - coords[:bar_start]}px;"
816 style << "width:#{coords[:bar_end] - coords[:bar_start]}px;"
820 style << "height:12px;"
817 style << "height:12px;"
821 output << view.content_tag(:div, s.html_safe,
818 output << view.content_tag(:div, s.html_safe,
822 :style => style,
819 :style => style,
823 :class => "tooltip")
820 :class => "tooltip")
824 end
821 end
825 @lines << output
822 @lines << output
826 output
823 output
827 end
824 end
828
825
829 def pdf_task(params, coords, options={})
826 def pdf_task(params, coords, options={})
830 height = options[:height] || 2
827 height = options[:height] || 2
831 # Renders the task bar, with progress and late
828 # Renders the task bar, with progress and late
832 if coords[:bar_start] && coords[:bar_end]
829 if coords[:bar_start] && coords[:bar_end]
833 params[:pdf].SetY(params[:top] + 1.5)
830 params[:pdf].SetY(params[:top] + 1.5)
834 params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
831 params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
835 params[:pdf].SetFillColor(200, 200, 200)
832 params[:pdf].SetFillColor(200, 200, 200)
836 params[:pdf].RDMCell(coords[:bar_end] - coords[:bar_start], height, "", 0, 0, "", 1)
833 params[:pdf].RDMCell(coords[:bar_end] - coords[:bar_start], height, "", 0, 0, "", 1)
837 if coords[:bar_late_end]
834 if coords[:bar_late_end]
838 params[:pdf].SetY(params[:top] + 1.5)
835 params[:pdf].SetY(params[:top] + 1.5)
839 params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
836 params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
840 params[:pdf].SetFillColor(255, 100, 100)
837 params[:pdf].SetFillColor(255, 100, 100)
841 params[:pdf].RDMCell(coords[:bar_late_end] - coords[:bar_start], height, "", 0, 0, "", 1)
838 params[:pdf].RDMCell(coords[:bar_late_end] - coords[:bar_start], height, "", 0, 0, "", 1)
842 end
839 end
843 if coords[:bar_progress_end]
840 if coords[:bar_progress_end]
844 params[:pdf].SetY(params[:top] + 1.5)
841 params[:pdf].SetY(params[:top] + 1.5)
845 params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
842 params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
846 params[:pdf].SetFillColor(90, 200, 90)
843 params[:pdf].SetFillColor(90, 200, 90)
847 params[:pdf].RDMCell(coords[:bar_progress_end] - coords[:bar_start], height, "", 0, 0, "", 1)
844 params[:pdf].RDMCell(coords[:bar_progress_end] - coords[:bar_start], height, "", 0, 0, "", 1)
848 end
845 end
849 end
846 end
850 # Renders the markers
847 # Renders the markers
851 if options[:markers]
848 if options[:markers]
852 if coords[:start]
849 if coords[:start]
853 params[:pdf].SetY(params[:top] + 1)
850 params[:pdf].SetY(params[:top] + 1)
854 params[:pdf].SetX(params[:subject_width] + coords[:start] - 1)
851 params[:pdf].SetX(params[:subject_width] + coords[:start] - 1)
855 params[:pdf].SetFillColor(50, 50, 200)
852 params[:pdf].SetFillColor(50, 50, 200)
856 params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1)
853 params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1)
857 end
854 end
858 if coords[:end]
855 if coords[:end]
859 params[:pdf].SetY(params[:top] + 1)
856 params[:pdf].SetY(params[:top] + 1)
860 params[:pdf].SetX(params[:subject_width] + coords[:end] - 1)
857 params[:pdf].SetX(params[:subject_width] + coords[:end] - 1)
861 params[:pdf].SetFillColor(50, 50, 200)
858 params[:pdf].SetFillColor(50, 50, 200)
862 params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1)
859 params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1)
863 end
860 end
864 end
861 end
865 # Renders the label on the right
862 # Renders the label on the right
866 if options[:label]
863 if options[:label]
867 params[:pdf].SetX(params[:subject_width] + (coords[:bar_end] || 0) + 5)
864 params[:pdf].SetX(params[:subject_width] + (coords[:bar_end] || 0) + 5)
868 params[:pdf].RDMCell(30, 2, options[:label])
865 params[:pdf].RDMCell(30, 2, options[:label])
869 end
866 end
870 end
867 end
871
868
872 def image_task(params, coords, options={})
869 def image_task(params, coords, options={})
873 height = options[:height] || 6
870 height = options[:height] || 6
874 # Renders the task bar, with progress and late
871 # Renders the task bar, with progress and late
875 if coords[:bar_start] && coords[:bar_end]
872 if coords[:bar_start] && coords[:bar_end]
876 params[:image].fill('#aaa')
873 params[:image].fill('#aaa')
877 params[:image].rectangle(params[:subject_width] + coords[:bar_start],
874 params[:image].rectangle(params[:subject_width] + coords[:bar_start],
878 params[:top],
875 params[:top],
879 params[:subject_width] + coords[:bar_end],
876 params[:subject_width] + coords[:bar_end],
880 params[:top] - height)
877 params[:top] - height)
881 if coords[:bar_late_end]
878 if coords[:bar_late_end]
882 params[:image].fill('#f66')
879 params[:image].fill('#f66')
883 params[:image].rectangle(params[:subject_width] + coords[:bar_start],
880 params[:image].rectangle(params[:subject_width] + coords[:bar_start],
884 params[:top],
881 params[:top],
885 params[:subject_width] + coords[:bar_late_end],
882 params[:subject_width] + coords[:bar_late_end],
886 params[:top] - height)
883 params[:top] - height)
887 end
884 end
888 if coords[:bar_progress_end]
885 if coords[:bar_progress_end]
889 params[:image].fill('#00c600')
886 params[:image].fill('#00c600')
890 params[:image].rectangle(params[:subject_width] + coords[:bar_start],
887 params[:image].rectangle(params[:subject_width] + coords[:bar_start],
891 params[:top],
888 params[:top],
892 params[:subject_width] + coords[:bar_progress_end],
889 params[:subject_width] + coords[:bar_progress_end],
893 params[:top] - height)
890 params[:top] - height)
894 end
891 end
895 end
892 end
896 # Renders the markers
893 # Renders the markers
897 if options[:markers]
894 if options[:markers]
898 if coords[:start]
895 if coords[:start]
899 x = params[:subject_width] + coords[:start]
896 x = params[:subject_width] + coords[:start]
900 y = params[:top] - height / 2
897 y = params[:top] - height / 2
901 params[:image].fill('blue')
898 params[:image].fill('blue')
902 params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4)
899 params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4)
903 end
900 end
904 if coords[:end]
901 if coords[:end]
905 x = params[:subject_width] + coords[:end] + params[:zoom]
902 x = params[:subject_width] + coords[:end] + params[:zoom]
906 y = params[:top] - height / 2
903 y = params[:top] - height / 2
907 params[:image].fill('blue')
904 params[:image].fill('blue')
908 params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4)
905 params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4)
909 end
906 end
910 end
907 end
911 # Renders the label on the right
908 # Renders the label on the right
912 if options[:label]
909 if options[:label]
913 params[:image].fill('black')
910 params[:image].fill('black')
914 params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5,
911 params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5,
915 params[:top] + 1,
912 params[:top] + 1,
916 options[:label])
913 options[:label])
917 end
914 end
918 end
915 end
919 end
916 end
920 end
917 end
921 end
918 end
General Comments 0
You need to be logged in to leave comments. Login now