@@ -1,943 +1,943 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 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 | '' |
|
300 | '' | |
301 | end |
|
301 | end | |
302 | end |
|
302 | end | |
303 |
|
303 | |||
304 | def subject_for_version(version, options) |
|
304 | def subject_for_version(version, options) | |
305 | case options[:format] |
|
305 | case options[:format] | |
306 | when :html |
|
306 | when :html | |
307 | html_class = "" |
|
307 | html_class = "" | |
308 | html_class << 'icon icon-package ' |
|
308 | html_class << 'icon icon-package ' | |
309 | html_class << (version.behind_schedule? ? 'version-behind-schedule' : '') << " " |
|
309 | html_class << (version.behind_schedule? ? 'version-behind-schedule' : '') << " " | |
310 | html_class << (version.overdue? ? 'version-overdue' : '') |
|
310 | html_class << (version.overdue? ? 'version-overdue' : '') | |
311 | html_class << ' version-closed' unless version.open? |
|
311 | html_class << ' version-closed' unless version.open? | |
312 | if version.start_date && version.due_date && version.completed_pourcent |
|
312 | if version.start_date && version.due_date && version.completed_pourcent | |
313 | progress_date = calc_progress_date(version.start_date, |
|
313 | progress_date = calc_progress_date(version.start_date, | |
314 | version.due_date, version.completed_pourcent) |
|
314 | version.due_date, version.completed_pourcent) | |
315 | html_class << ' behind-start-date' if progress_date < self.date_from |
|
315 | html_class << ' behind-start-date' if progress_date < self.date_from | |
316 | html_class << ' over-end-date' if progress_date > self.date_to |
|
316 | html_class << ' over-end-date' if progress_date > self.date_to | |
317 | end |
|
317 | end | |
318 | s = view.link_to_version(version).html_safe |
|
318 | s = view.link_to_version(version).html_safe | |
319 | subject = view.content_tag(:span, s, |
|
319 | subject = view.content_tag(:span, s, | |
320 | :class => html_class).html_safe |
|
320 | :class => html_class).html_safe | |
321 | html_subject(options, subject, :css => "version-name", |
|
321 | html_subject(options, subject, :css => "version-name", | |
322 | :id => "version-#{version.id}") |
|
322 | :id => "version-#{version.id}") | |
323 | when :image |
|
323 | when :image | |
324 | image_subject(options, version.to_s_with_project) |
|
324 | image_subject(options, version.to_s_with_project) | |
325 | when :pdf |
|
325 | when :pdf | |
326 | pdf_new_page?(options) |
|
326 | pdf_new_page?(options) | |
327 | pdf_subject(options, version.to_s_with_project) |
|
327 | pdf_subject(options, version.to_s_with_project) | |
328 | end |
|
328 | end | |
329 | end |
|
329 | end | |
330 |
|
330 | |||
331 | def line_for_version(version, options) |
|
331 | def line_for_version(version, options) | |
332 | # Skip versions that don't have a start_date |
|
332 | # Skip versions that don't have a start_date | |
333 | if version.is_a?(Version) && version.due_date && version.start_date |
|
333 | if version.is_a?(Version) && version.due_date && version.start_date | |
334 | options[:zoom] ||= 1 |
|
334 | options[:zoom] ||= 1 | |
335 | options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom] |
|
335 | options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom] | |
336 | coords = coordinates(version.start_date, |
|
336 | coords = coordinates(version.start_date, | |
337 | version.due_date, version.completed_percent, |
|
337 | version.due_date, version.completed_percent, | |
338 | options[:zoom]) |
|
338 | options[:zoom]) | |
339 | label = "#{h version} #{h version.completed_percent.to_i.to_s}%" |
|
339 | label = "#{h version} #{h version.completed_percent.to_i.to_s}%" | |
340 | label = h("#{version.project} -") + label unless @project && @project == version.project |
|
340 | label = h("#{version.project} -") + label unless @project && @project == version.project | |
341 | case options[:format] |
|
341 | case options[:format] | |
342 | when :html |
|
342 | when :html | |
343 | html_task(options, coords, :css => "version task", |
|
343 | html_task(options, coords, :css => "version task", | |
344 | :label => label, :markers => true, :version => version) |
|
344 | :label => label, :markers => true, :version => version) | |
345 | when :image |
|
345 | when :image | |
346 | image_task(options, coords, :label => label, :markers => true, :height => 3) |
|
346 | image_task(options, coords, :label => label, :markers => true, :height => 3) | |
347 | when :pdf |
|
347 | when :pdf | |
348 | pdf_task(options, coords, :label => label, :markers => true, :height => 0.8) |
|
348 | pdf_task(options, coords, :label => label, :markers => true, :height => 0.8) | |
349 | end |
|
349 | end | |
350 | else |
|
350 | else | |
351 | '' |
|
351 | '' | |
352 | end |
|
352 | end | |
353 | end |
|
353 | end | |
354 |
|
354 | |||
355 | def subject_for_issue(issue, options) |
|
355 | def subject_for_issue(issue, options) | |
356 | while @issue_ancestors.any? && !issue.is_descendant_of?(@issue_ancestors.last) |
|
356 | while @issue_ancestors.any? && !issue.is_descendant_of?(@issue_ancestors.last) | |
357 | @issue_ancestors.pop |
|
357 | @issue_ancestors.pop | |
358 | options[:indent] -= options[:indent_increment] |
|
358 | options[:indent] -= options[:indent_increment] | |
359 | end |
|
359 | end | |
360 | output = case options[:format] |
|
360 | output = case options[:format] | |
361 | when :html |
|
361 | when :html | |
362 | css_classes = '' |
|
362 | css_classes = '' | |
363 | css_classes << ' issue-overdue' if issue.overdue? |
|
363 | css_classes << ' issue-overdue' if issue.overdue? | |
364 | css_classes << ' issue-behind-schedule' if issue.behind_schedule? |
|
364 | css_classes << ' issue-behind-schedule' if issue.behind_schedule? | |
365 | css_classes << ' icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to |
|
365 | css_classes << ' icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to | |
366 | css_classes << ' issue-closed' if issue.closed? |
|
366 | css_classes << ' issue-closed' if issue.closed? | |
367 | if issue.start_date && issue.due_before && issue.done_ratio |
|
367 | if issue.start_date && issue.due_before && issue.done_ratio | |
368 | progress_date = calc_progress_date(issue.start_date, |
|
368 | progress_date = calc_progress_date(issue.start_date, | |
369 | issue.due_before, issue.done_ratio) |
|
369 | issue.due_before, issue.done_ratio) | |
370 | css_classes << ' behind-start-date' if progress_date < self.date_from |
|
370 | css_classes << ' behind-start-date' if progress_date < self.date_from | |
371 | css_classes << ' over-end-date' if progress_date > self.date_to |
|
371 | css_classes << ' over-end-date' if progress_date > self.date_to | |
372 | end |
|
372 | end | |
373 | s = "".html_safe |
|
373 | s = "".html_safe | |
374 | if issue.assigned_to.present? |
|
374 | if issue.assigned_to.present? | |
375 | assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name |
|
375 | assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name | |
376 | s << view.avatar(issue.assigned_to, |
|
376 | s << view.avatar(issue.assigned_to, | |
377 | :class => 'gravatar icon-gravatar', |
|
377 | :class => 'gravatar icon-gravatar', | |
378 | :size => 10, |
|
378 | :size => 10, | |
379 | :title => assigned_string).to_s.html_safe |
|
379 | :title => assigned_string).to_s.html_safe | |
380 | end |
|
380 | end | |
381 | s << view.link_to_issue(issue).html_safe |
|
381 | s << view.link_to_issue(issue).html_safe | |
382 | subject = view.content_tag(:span, s, :class => css_classes).html_safe |
|
382 | subject = view.content_tag(:span, s, :class => css_classes).html_safe | |
383 | html_subject(options, subject, :css => "issue-subject", |
|
383 | html_subject(options, subject, :css => "issue-subject", | |
384 | :title => issue.subject, :id => "issue-#{issue.id}") + "\n" |
|
384 | :title => issue.subject, :id => "issue-#{issue.id}") + "\n" | |
385 | when :image |
|
385 | when :image | |
386 | image_subject(options, issue.subject) |
|
386 | image_subject(options, issue.subject) | |
387 | when :pdf |
|
387 | when :pdf | |
388 | pdf_new_page?(options) |
|
388 | pdf_new_page?(options) | |
389 | pdf_subject(options, issue.subject) |
|
389 | pdf_subject(options, issue.subject) | |
390 | end |
|
390 | end | |
391 | unless issue.leaf? |
|
391 | unless issue.leaf? | |
392 | @issue_ancestors << issue |
|
392 | @issue_ancestors << issue | |
393 | options[:indent] += options[:indent_increment] |
|
393 | options[:indent] += options[:indent_increment] | |
394 | end |
|
394 | end | |
395 | output |
|
395 | output | |
396 | end |
|
396 | end | |
397 |
|
397 | |||
398 | def line_for_issue(issue, options) |
|
398 | def line_for_issue(issue, options) | |
399 | # Skip issues that don't have a due_before (due_date or version's due_date) |
|
399 | # Skip issues that don't have a due_before (due_date or version's due_date) | |
400 | if issue.is_a?(Issue) && issue.due_before |
|
400 | if issue.is_a?(Issue) && issue.due_before | |
401 | coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom]) |
|
401 | coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom]) | |
402 | label = "#{issue.status.name} #{issue.done_ratio}%" |
|
402 | label = "#{issue.status.name} #{issue.done_ratio}%" | |
403 | case options[:format] |
|
403 | case options[:format] | |
404 | when :html |
|
404 | when :html | |
405 | html_task(options, coords, |
|
405 | html_task(options, coords, | |
406 | :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), |
|
406 | :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), | |
407 | :label => label, :issue => issue, |
|
407 | :label => label, :issue => issue, | |
408 | :markers => !issue.leaf?) |
|
408 | :markers => !issue.leaf?) | |
409 | when :image |
|
409 | when :image | |
410 | image_task(options, coords, :label => label) |
|
410 | image_task(options, coords, :label => label) | |
411 | when :pdf |
|
411 | when :pdf | |
412 | pdf_task(options, coords, :label => label) |
|
412 | pdf_task(options, coords, :label => label) | |
413 | end |
|
413 | end | |
414 | else |
|
414 | else | |
415 | '' |
|
415 | '' | |
416 | end |
|
416 | end | |
417 | end |
|
417 | end | |
418 |
|
418 | |||
419 | # Generates a gantt image |
|
419 | # Generates a gantt image | |
420 | # Only defined if RMagick is avalaible |
|
420 | # Only defined if RMagick is avalaible | |
421 | def to_image(format='PNG') |
|
421 | def to_image(format='PNG') | |
422 | date_to = (@date_from >> @months) - 1 |
|
422 | date_to = (@date_from >> @months) - 1 | |
423 | show_weeks = @zoom > 1 |
|
423 | show_weeks = @zoom > 1 | |
424 | show_days = @zoom > 2 |
|
424 | show_days = @zoom > 2 | |
425 | subject_width = 400 |
|
425 | subject_width = 400 | |
426 | header_height = 18 |
|
426 | header_height = 18 | |
427 | # width of one day in pixels |
|
427 | # width of one day in pixels | |
428 | zoom = @zoom * 2 |
|
428 | zoom = @zoom * 2 | |
429 | g_width = (@date_to - @date_from + 1) * zoom |
|
429 | g_width = (@date_to - @date_from + 1) * zoom | |
430 | g_height = 20 * number_of_rows + 30 |
|
430 | g_height = 20 * number_of_rows + 30 | |
431 | headers_height = (show_weeks ? 2 * header_height : header_height) |
|
431 | headers_height = (show_weeks ? 2 * header_height : header_height) | |
432 | height = g_height + headers_height |
|
432 | height = g_height + headers_height | |
433 | imgl = Magick::ImageList.new |
|
433 | imgl = Magick::ImageList.new | |
434 | imgl.new_image(subject_width + g_width + 1, height) |
|
434 | imgl.new_image(subject_width + g_width + 1, height) | |
435 | gc = Magick::Draw.new |
|
435 | gc = Magick::Draw.new | |
436 | gc.font = Redmine::Configuration['rmagick_font_path'] || "" |
|
436 | gc.font = Redmine::Configuration['rmagick_font_path'] || "" | |
437 | # Subjects |
|
437 | # Subjects | |
438 | gc.stroke('transparent') |
|
438 | gc.stroke('transparent') | |
439 | subjects(:image => gc, :top => (headers_height + 20), :indent => 4, :format => :image) |
|
439 | subjects(:image => gc, :top => (headers_height + 20), :indent => 4, :format => :image) | |
440 | # Months headers |
|
440 | # Months headers | |
441 | month_f = @date_from |
|
441 | month_f = @date_from | |
442 | left = subject_width |
|
442 | left = subject_width | |
443 | @months.times do |
|
443 | @months.times do | |
444 | width = ((month_f >> 1) - month_f) * zoom |
|
444 | width = ((month_f >> 1) - month_f) * zoom | |
445 | gc.fill('white') |
|
445 | gc.fill('white') | |
446 | gc.stroke('grey') |
|
446 | gc.stroke('grey') | |
447 | gc.stroke_width(1) |
|
447 | gc.stroke_width(1) | |
448 | gc.rectangle(left, 0, left + width, height) |
|
448 | gc.rectangle(left, 0, left + width, height) | |
449 | gc.fill('black') |
|
449 | gc.fill('black') | |
450 | gc.stroke('transparent') |
|
450 | gc.stroke('transparent') | |
451 | gc.stroke_width(1) |
|
451 | gc.stroke_width(1) | |
452 | gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}") |
|
452 | gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}") | |
453 | left = left + width |
|
453 | left = left + width | |
454 | month_f = month_f >> 1 |
|
454 | month_f = month_f >> 1 | |
455 | end |
|
455 | end | |
456 | # Weeks headers |
|
456 | # Weeks headers | |
457 | if show_weeks |
|
457 | if show_weeks | |
458 | left = subject_width |
|
458 | left = subject_width | |
459 | height = header_height |
|
459 | height = header_height | |
460 | if @date_from.cwday == 1 |
|
460 | if @date_from.cwday == 1 | |
461 | # date_from is monday |
|
461 | # date_from is monday | |
462 | week_f = date_from |
|
462 | week_f = date_from | |
463 | else |
|
463 | else | |
464 | # find next monday after date_from |
|
464 | # find next monday after date_from | |
465 | week_f = @date_from + (7 - @date_from.cwday + 1) |
|
465 | week_f = @date_from + (7 - @date_from.cwday + 1) | |
466 | width = (7 - @date_from.cwday + 1) * zoom |
|
466 | width = (7 - @date_from.cwday + 1) * zoom | |
467 | gc.fill('white') |
|
467 | gc.fill('white') | |
468 | gc.stroke('grey') |
|
468 | gc.stroke('grey') | |
469 | gc.stroke_width(1) |
|
469 | gc.stroke_width(1) | |
470 | gc.rectangle(left, header_height, left + width, 2 * header_height + g_height - 1) |
|
470 | gc.rectangle(left, header_height, left + width, 2 * header_height + g_height - 1) | |
471 | left = left + width |
|
471 | left = left + width | |
472 | end |
|
472 | end | |
473 | while week_f <= date_to |
|
473 | while week_f <= date_to | |
474 | width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom |
|
474 | width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom | |
475 | gc.fill('white') |
|
475 | gc.fill('white') | |
476 | gc.stroke('grey') |
|
476 | gc.stroke('grey') | |
477 | gc.stroke_width(1) |
|
477 | gc.stroke_width(1) | |
478 | gc.rectangle(left.round, header_height, left.round + width, 2 * header_height + g_height - 1) |
|
478 | gc.rectangle(left.round, header_height, left.round + width, 2 * header_height + g_height - 1) | |
479 | gc.fill('black') |
|
479 | gc.fill('black') | |
480 | gc.stroke('transparent') |
|
480 | gc.stroke('transparent') | |
481 | gc.stroke_width(1) |
|
481 | gc.stroke_width(1) | |
482 | gc.text(left.round + 2, header_height + 14, week_f.cweek.to_s) |
|
482 | gc.text(left.round + 2, header_height + 14, week_f.cweek.to_s) | |
483 | left = left + width |
|
483 | left = left + width | |
484 | week_f = week_f + 7 |
|
484 | week_f = week_f + 7 | |
485 | end |
|
485 | end | |
486 | end |
|
486 | end | |
487 | # Days details (week-end in grey) |
|
487 | # Days details (week-end in grey) | |
488 | if show_days |
|
488 | if show_days | |
489 | left = subject_width |
|
489 | left = subject_width | |
490 | height = g_height + header_height - 1 |
|
490 | height = g_height + header_height - 1 | |
491 | wday = @date_from.cwday |
|
491 | wday = @date_from.cwday | |
492 | (date_to - @date_from + 1).to_i.times do |
|
492 | (date_to - @date_from + 1).to_i.times do | |
493 | width = zoom |
|
493 | width = zoom | |
494 | gc.fill(non_working_week_days.include?(wday) ? '#eee' : 'white') |
|
494 | gc.fill(non_working_week_days.include?(wday) ? '#eee' : 'white') | |
495 | gc.stroke('#ddd') |
|
495 | gc.stroke('#ddd') | |
496 | gc.stroke_width(1) |
|
496 | gc.stroke_width(1) | |
497 | gc.rectangle(left, 2 * header_height, left + width, 2 * header_height + g_height - 1) |
|
497 | gc.rectangle(left, 2 * header_height, left + width, 2 * header_height + g_height - 1) | |
498 | left = left + width |
|
498 | left = left + width | |
499 | wday = wday + 1 |
|
499 | wday = wday + 1 | |
500 | wday = 1 if wday > 7 |
|
500 | wday = 1 if wday > 7 | |
501 | end |
|
501 | end | |
502 | end |
|
502 | end | |
503 | # border |
|
503 | # border | |
504 | gc.fill('transparent') |
|
504 | gc.fill('transparent') | |
505 | gc.stroke('grey') |
|
505 | gc.stroke('grey') | |
506 | gc.stroke_width(1) |
|
506 | gc.stroke_width(1) | |
507 | gc.rectangle(0, 0, subject_width + g_width, headers_height) |
|
507 | gc.rectangle(0, 0, subject_width + g_width, headers_height) | |
508 | gc.stroke('black') |
|
508 | gc.stroke('black') | |
509 | gc.rectangle(0, 0, subject_width + g_width, g_height + headers_height - 1) |
|
509 | gc.rectangle(0, 0, subject_width + g_width, g_height + headers_height - 1) | |
510 | # content |
|
510 | # content | |
511 | top = headers_height + 20 |
|
511 | top = headers_height + 20 | |
512 | gc.stroke('transparent') |
|
512 | gc.stroke('transparent') | |
513 | lines(:image => gc, :top => top, :zoom => zoom, |
|
513 | lines(:image => gc, :top => top, :zoom => zoom, | |
514 | :subject_width => subject_width, :format => :image) |
|
514 | :subject_width => subject_width, :format => :image) | |
515 | # today red line |
|
515 | # today red line | |
516 | if Date.today >= @date_from and Date.today <= date_to |
|
516 | if Date.today >= @date_from and Date.today <= date_to | |
517 | gc.stroke('red') |
|
517 | gc.stroke('red') | |
518 | x = (Date.today - @date_from + 1) * zoom + subject_width |
|
518 | x = (Date.today - @date_from + 1) * zoom + subject_width | |
519 | gc.line(x, headers_height, x, headers_height + g_height - 1) |
|
519 | gc.line(x, headers_height, x, headers_height + g_height - 1) | |
520 | end |
|
520 | end | |
521 | gc.draw(imgl) |
|
521 | gc.draw(imgl) | |
522 | imgl.format = format |
|
522 | imgl.format = format | |
523 | imgl.to_blob |
|
523 | imgl.to_blob | |
524 | end if Object.const_defined?(:Magick) |
|
524 | end if Object.const_defined?(:Magick) | |
525 |
|
525 | |||
526 | def to_pdf |
|
526 | def to_pdf | |
527 | pdf = ::Redmine::Export::PDF::ITCPDF.new(current_language) |
|
527 | pdf = ::Redmine::Export::PDF::ITCPDF.new(current_language) | |
528 | pdf.SetTitle("#{l(:label_gantt)} #{project}") |
|
528 | pdf.SetTitle("#{l(:label_gantt)} #{project}") | |
529 | pdf.alias_nb_pages |
|
529 | pdf.alias_nb_pages | |
530 | pdf.footer_date = format_date(Date.today) |
|
530 | pdf.footer_date = format_date(Date.today) | |
531 | pdf.AddPage("L") |
|
531 | pdf.AddPage("L") | |
532 | pdf.SetFontStyle('B', 12) |
|
532 | pdf.SetFontStyle('B', 12) | |
533 | pdf.SetX(15) |
|
533 | pdf.SetX(15) | |
534 | pdf.RDMCell(PDF::LeftPaneWidth, 20, project.to_s) |
|
534 | pdf.RDMCell(PDF::LeftPaneWidth, 20, project.to_s) | |
535 | pdf.Ln |
|
535 | pdf.Ln | |
536 | pdf.SetFontStyle('B', 9) |
|
536 | pdf.SetFontStyle('B', 9) | |
537 | subject_width = PDF::LeftPaneWidth |
|
537 | subject_width = PDF::LeftPaneWidth | |
538 | header_height = 5 |
|
538 | header_height = 5 | |
539 | headers_height = header_height |
|
539 | headers_height = header_height | |
540 | show_weeks = false |
|
540 | show_weeks = false | |
541 | show_days = false |
|
541 | show_days = false | |
542 | if self.months < 7 |
|
542 | if self.months < 7 | |
543 | show_weeks = true |
|
543 | show_weeks = true | |
544 | headers_height = 2 * header_height |
|
544 | headers_height = 2 * header_height | |
545 | if self.months < 3 |
|
545 | if self.months < 3 | |
546 | show_days = true |
|
546 | show_days = true | |
547 | headers_height = 3 * header_height |
|
547 | headers_height = 3 * header_height | |
548 | end |
|
548 | end | |
549 | end |
|
549 | end | |
550 | g_width = PDF.right_pane_width |
|
550 | g_width = PDF.right_pane_width | |
551 | zoom = (g_width) / (self.date_to - self.date_from + 1) |
|
551 | zoom = (g_width) / (self.date_to - self.date_from + 1) | |
552 | g_height = 120 |
|
552 | g_height = 120 | |
553 | t_height = g_height + headers_height |
|
553 | t_height = g_height + headers_height | |
554 | y_start = pdf.GetY |
|
554 | y_start = pdf.GetY | |
555 | # Months headers |
|
555 | # Months headers | |
556 | month_f = self.date_from |
|
556 | month_f = self.date_from | |
557 | left = subject_width |
|
557 | left = subject_width | |
558 | height = header_height |
|
558 | height = header_height | |
559 | self.months.times do |
|
559 | self.months.times do | |
560 | width = ((month_f >> 1) - month_f) * zoom |
|
560 | width = ((month_f >> 1) - month_f) * zoom | |
561 | pdf.SetY(y_start) |
|
561 | pdf.SetY(y_start) | |
562 | pdf.SetX(left) |
|
562 | pdf.SetX(left) | |
563 | pdf.RDMCell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C") |
|
563 | pdf.RDMCell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C") | |
564 | left = left + width |
|
564 | left = left + width | |
565 | month_f = month_f >> 1 |
|
565 | month_f = month_f >> 1 | |
566 | end |
|
566 | end | |
567 | # Weeks headers |
|
567 | # Weeks headers | |
568 | if show_weeks |
|
568 | if show_weeks | |
569 | left = subject_width |
|
569 | left = subject_width | |
570 | height = header_height |
|
570 | height = header_height | |
571 | if self.date_from.cwday == 1 |
|
571 | if self.date_from.cwday == 1 | |
572 | # self.date_from is monday |
|
572 | # self.date_from is monday | |
573 | week_f = self.date_from |
|
573 | week_f = self.date_from | |
574 | else |
|
574 | else | |
575 | # find next monday after self.date_from |
|
575 | # find next monday after self.date_from | |
576 | week_f = self.date_from + (7 - self.date_from.cwday + 1) |
|
576 | week_f = self.date_from + (7 - self.date_from.cwday + 1) | |
577 | width = (7 - self.date_from.cwday + 1) * zoom-1 |
|
577 | width = (7 - self.date_from.cwday + 1) * zoom-1 | |
578 | pdf.SetY(y_start + header_height) |
|
578 | pdf.SetY(y_start + header_height) | |
579 | pdf.SetX(left) |
|
579 | pdf.SetX(left) | |
580 | pdf.RDMCell(width + 1, height, "", "LTR") |
|
580 | pdf.RDMCell(width + 1, height, "", "LTR") | |
581 | left = left + width + 1 |
|
581 | left = left + width + 1 | |
582 | end |
|
582 | end | |
583 | while week_f <= self.date_to |
|
583 | while week_f <= self.date_to | |
584 | width = (week_f + 6 <= self.date_to) ? 7 * zoom : (self.date_to - week_f + 1) * zoom |
|
584 | width = (week_f + 6 <= self.date_to) ? 7 * zoom : (self.date_to - week_f + 1) * zoom | |
585 | pdf.SetY(y_start + header_height) |
|
585 | pdf.SetY(y_start + header_height) | |
586 | pdf.SetX(left) |
|
586 | pdf.SetX(left) | |
587 | pdf.RDMCell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C") |
|
587 | pdf.RDMCell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C") | |
588 | left = left + width |
|
588 | left = left + width | |
589 | week_f = week_f + 7 |
|
589 | week_f = week_f + 7 | |
590 | end |
|
590 | end | |
591 | end |
|
591 | end | |
592 | # Days headers |
|
592 | # Days headers | |
593 | if show_days |
|
593 | if show_days | |
594 | left = subject_width |
|
594 | left = subject_width | |
595 | height = header_height |
|
595 | height = header_height | |
596 | wday = self.date_from.cwday |
|
596 | wday = self.date_from.cwday | |
597 | pdf.SetFontStyle('B', 7) |
|
597 | pdf.SetFontStyle('B', 7) | |
598 | (self.date_to - self.date_from + 1).to_i.times do |
|
598 | (self.date_to - self.date_from + 1).to_i.times do | |
599 | width = zoom |
|
599 | width = zoom | |
600 | pdf.SetY(y_start + 2 * header_height) |
|
600 | pdf.SetY(y_start + 2 * header_height) | |
601 | pdf.SetX(left) |
|
601 | pdf.SetX(left) | |
602 | pdf.RDMCell(width, height, day_name(wday).first, "LTR", 0, "C") |
|
602 | pdf.RDMCell(width, height, day_name(wday).first, "LTR", 0, "C") | |
603 | left = left + width |
|
603 | left = left + width | |
604 | wday = wday + 1 |
|
604 | wday = wday + 1 | |
605 | wday = 1 if wday > 7 |
|
605 | wday = 1 if wday > 7 | |
606 | end |
|
606 | end | |
607 | end |
|
607 | end | |
608 | pdf.SetY(y_start) |
|
608 | pdf.SetY(y_start) | |
609 | pdf.SetX(15) |
|
609 | pdf.SetX(15) | |
610 | pdf.RDMCell(subject_width + g_width - 15, headers_height, "", 1) |
|
610 | pdf.RDMCell(subject_width + g_width - 15, headers_height, "", 1) | |
611 | # Tasks |
|
611 | # Tasks | |
612 | top = headers_height + y_start |
|
612 | top = headers_height + y_start | |
613 | options = { |
|
613 | options = { | |
614 | :top => top, |
|
614 | :top => top, | |
615 | :zoom => zoom, |
|
615 | :zoom => zoom, | |
616 | :subject_width => subject_width, |
|
616 | :subject_width => subject_width, | |
617 | :g_width => g_width, |
|
617 | :g_width => g_width, | |
618 | :indent => 0, |
|
618 | :indent => 0, | |
619 | :indent_increment => 5, |
|
619 | :indent_increment => 5, | |
620 | :top_increment => 5, |
|
620 | :top_increment => 5, | |
621 | :format => :pdf, |
|
621 | :format => :pdf, | |
622 | :pdf => pdf |
|
622 | :pdf => pdf | |
623 | } |
|
623 | } | |
624 | render(options) |
|
624 | render(options) | |
625 | pdf.Output |
|
625 | pdf.Output | |
626 | end |
|
626 | end | |
627 |
|
627 | |||
628 | private |
|
628 | private | |
629 |
|
629 | |||
630 | def coordinates(start_date, end_date, progress, zoom=nil) |
|
630 | def coordinates(start_date, end_date, progress, zoom=nil) | |
631 | zoom ||= @zoom |
|
631 | zoom ||= @zoom | |
632 | coords = {} |
|
632 | coords = {} | |
633 | if start_date && end_date && start_date < self.date_to && end_date > self.date_from |
|
633 | if start_date && end_date && start_date < self.date_to && end_date > self.date_from | |
634 | if start_date > self.date_from |
|
634 | if start_date > self.date_from | |
635 | coords[:start] = start_date - self.date_from |
|
635 | coords[:start] = start_date - self.date_from | |
636 | coords[:bar_start] = start_date - self.date_from |
|
636 | coords[:bar_start] = start_date - self.date_from | |
637 | else |
|
637 | else | |
638 | coords[:bar_start] = 0 |
|
638 | coords[:bar_start] = 0 | |
639 | end |
|
639 | end | |
640 | if end_date < self.date_to |
|
640 | if end_date < self.date_to | |
641 | coords[:end] = end_date - self.date_from |
|
641 | coords[:end] = end_date - self.date_from | |
642 | coords[:bar_end] = end_date - self.date_from + 1 |
|
642 | coords[:bar_end] = end_date - self.date_from + 1 | |
643 | else |
|
643 | else | |
644 | coords[:bar_end] = self.date_to - self.date_from + 1 |
|
644 | coords[:bar_end] = self.date_to - self.date_from + 1 | |
645 | end |
|
645 | end | |
646 | if progress |
|
646 | if progress | |
647 | progress_date = calc_progress_date(start_date, end_date, progress) |
|
647 | progress_date = calc_progress_date(start_date, end_date, progress) | |
648 | if progress_date > self.date_from && progress_date > start_date |
|
648 | if progress_date > self.date_from && progress_date > start_date | |
649 | if progress_date < self.date_to |
|
649 | if progress_date < self.date_to | |
650 | coords[:bar_progress_end] = progress_date - self.date_from |
|
650 | coords[:bar_progress_end] = progress_date - self.date_from | |
651 | else |
|
651 | else | |
652 | coords[:bar_progress_end] = self.date_to - self.date_from + 1 |
|
652 | coords[:bar_progress_end] = self.date_to - self.date_from + 1 | |
653 | end |
|
653 | end | |
654 | end |
|
654 | end | |
655 | if progress_date < Date.today |
|
655 | if progress_date < Date.today | |
656 | late_date = [Date.today, end_date].min |
|
656 | late_date = [Date.today, end_date].min | |
657 | if late_date > self.date_from && late_date > start_date |
|
657 | if late_date > self.date_from && late_date > start_date | |
658 | if late_date < self.date_to |
|
658 | if late_date < self.date_to | |
659 | coords[:bar_late_end] = late_date - self.date_from + 1 |
|
659 | coords[:bar_late_end] = late_date - self.date_from + 1 | |
660 | else |
|
660 | else | |
661 | coords[:bar_late_end] = self.date_to - self.date_from + 1 |
|
661 | coords[:bar_late_end] = self.date_to - self.date_from + 1 | |
662 | end |
|
662 | end | |
663 | end |
|
663 | end | |
664 | end |
|
664 | end | |
665 | end |
|
665 | end | |
666 | end |
|
666 | end | |
667 | # Transforms dates into pixels witdh |
|
667 | # Transforms dates into pixels witdh | |
668 | coords.keys.each do |key| |
|
668 | coords.keys.each do |key| | |
669 | coords[key] = (coords[key] * zoom).floor |
|
669 | coords[key] = (coords[key] * zoom).floor | |
670 | end |
|
670 | end | |
671 | coords |
|
671 | coords | |
672 | end |
|
672 | end | |
673 |
|
673 | |||
674 | def calc_progress_date(start_date, end_date, progress) |
|
674 | def calc_progress_date(start_date, end_date, progress) | |
675 | start_date + (end_date - start_date + 1) * (progress / 100.0) |
|
675 | start_date + (end_date - start_date + 1) * (progress / 100.0) | |
676 | end |
|
676 | end | |
677 |
|
677 | |||
678 | # Sorts a collection of issues by start_date, due_date, id for gantt rendering |
|
678 | # TODO: Sorts a collection of issues by start_date, due_date, id for gantt rendering | |
679 | def sort_issues!(issues) |
|
679 | def sort_issues!(issues) | |
680 | issues.sort! { |a, b| gantt_issue_compare(a, b) } |
|
680 | issues.sort! { |a, b| gantt_issue_compare(a, b) } | |
681 | end |
|
681 | end | |
682 |
|
682 | |||
683 | # TODO: top level issues should be sorted by start date |
|
683 | # TODO: top level issues should be sorted by start date | |
684 | def gantt_issue_compare(x, y) |
|
684 | def gantt_issue_compare(x, y) | |
685 | if x.root_id == y.root_id |
|
685 | if x.root_id == y.root_id | |
686 | x.lft <=> y.lft |
|
686 | x.lft <=> y.lft | |
687 | else |
|
687 | else | |
688 | x.root_id <=> y.root_id |
|
688 | x.root_id <=> y.root_id | |
689 | end |
|
689 | end | |
690 | end |
|
690 | end | |
691 |
|
691 | |||
692 | def current_limit |
|
692 | def current_limit | |
693 | if @max_rows |
|
693 | if @max_rows | |
694 | @max_rows - @number_of_rows |
|
694 | @max_rows - @number_of_rows | |
695 | else |
|
695 | else | |
696 | nil |
|
696 | nil | |
697 | end |
|
697 | end | |
698 | end |
|
698 | end | |
699 |
|
699 | |||
700 | def abort? |
|
700 | def abort? | |
701 | if @max_rows && @number_of_rows >= @max_rows |
|
701 | if @max_rows && @number_of_rows >= @max_rows | |
702 | @truncated = true |
|
702 | @truncated = true | |
703 | end |
|
703 | end | |
704 | end |
|
704 | end | |
705 |
|
705 | |||
706 | def pdf_new_page?(options) |
|
706 | def pdf_new_page?(options) | |
707 | if options[:top] > 180 |
|
707 | if options[:top] > 180 | |
708 | options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top]) |
|
708 | options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top]) | |
709 | options[:pdf].AddPage("L") |
|
709 | options[:pdf].AddPage("L") | |
710 | options[:top] = 15 |
|
710 | options[:top] = 15 | |
711 | options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1) |
|
711 | options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1) | |
712 | end |
|
712 | end | |
713 | end |
|
713 | end | |
714 |
|
714 | |||
715 | def html_subject(params, subject, options={}) |
|
715 | def html_subject(params, subject, options={}) | |
716 | style = "position: absolute;top:#{params[:top]}px;left:#{params[:indent]}px;" |
|
716 | style = "position: absolute;top:#{params[:top]}px;left:#{params[:indent]}px;" | |
717 | style << "width:#{params[:subject_width] - params[:indent]}px;" if params[:subject_width] |
|
717 | style << "width:#{params[:subject_width] - params[:indent]}px;" if params[:subject_width] | |
718 | output = view.content_tag(:div, subject, |
|
718 | output = view.content_tag(:div, subject, | |
719 | :class => options[:css], :style => style, |
|
719 | :class => options[:css], :style => style, | |
720 | :title => options[:title], |
|
720 | :title => options[:title], | |
721 | :id => options[:id]) |
|
721 | :id => options[:id]) | |
722 | @subjects << output |
|
722 | @subjects << output | |
723 | output |
|
723 | output | |
724 | end |
|
724 | end | |
725 |
|
725 | |||
726 | def pdf_subject(params, subject, options={}) |
|
726 | def pdf_subject(params, subject, options={}) | |
727 | params[:pdf].SetY(params[:top]) |
|
727 | params[:pdf].SetY(params[:top]) | |
728 | params[:pdf].SetX(15) |
|
728 | params[:pdf].SetX(15) | |
729 | char_limit = PDF::MaxCharactorsForSubject - params[:indent] |
|
729 | char_limit = PDF::MaxCharactorsForSubject - params[:indent] | |
730 | params[:pdf].RDMCell(params[:subject_width] - 15, 5, |
|
730 | params[:pdf].RDMCell(params[:subject_width] - 15, 5, | |
731 | (" " * params[:indent]) + |
|
731 | (" " * params[:indent]) + | |
732 | subject.to_s.sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), |
|
732 | subject.to_s.sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), | |
733 | "LR") |
|
733 | "LR") | |
734 | params[:pdf].SetY(params[:top]) |
|
734 | params[:pdf].SetY(params[:top]) | |
735 | params[:pdf].SetX(params[:subject_width]) |
|
735 | params[:pdf].SetX(params[:subject_width]) | |
736 | params[:pdf].RDMCell(params[:g_width], 5, "", "LR") |
|
736 | params[:pdf].RDMCell(params[:g_width], 5, "", "LR") | |
737 | end |
|
737 | end | |
738 |
|
738 | |||
739 | def image_subject(params, subject, options={}) |
|
739 | def image_subject(params, subject, options={}) | |
740 | params[:image].fill('black') |
|
740 | params[:image].fill('black') | |
741 | params[:image].stroke('transparent') |
|
741 | params[:image].stroke('transparent') | |
742 | params[:image].stroke_width(1) |
|
742 | params[:image].stroke_width(1) | |
743 | params[:image].text(params[:indent], params[:top] + 2, subject) |
|
743 | params[:image].text(params[:indent], params[:top] + 2, subject) | |
744 | end |
|
744 | end | |
745 |
|
745 | |||
746 | def issue_relations(issue) |
|
746 | def issue_relations(issue) | |
747 | rels = {} |
|
747 | rels = {} | |
748 | if relations[issue.id] |
|
748 | if relations[issue.id] | |
749 | relations[issue.id].each do |relation| |
|
749 | relations[issue.id].each do |relation| | |
750 | (rels[relation.relation_type] ||= []) << relation.issue_to_id |
|
750 | (rels[relation.relation_type] ||= []) << relation.issue_to_id | |
751 | end |
|
751 | end | |
752 | end |
|
752 | end | |
753 | rels |
|
753 | rels | |
754 | end |
|
754 | end | |
755 |
|
755 | |||
756 | def html_task(params, coords, options={}) |
|
756 | def html_task(params, coords, options={}) | |
757 | output = '' |
|
757 | output = '' | |
758 | # Renders the task bar, with progress and late |
|
758 | # Renders the task bar, with progress and late | |
759 | if coords[:bar_start] && coords[:bar_end] |
|
759 | if coords[:bar_start] && coords[:bar_end] | |
760 | width = coords[:bar_end] - coords[:bar_start] - 2 |
|
760 | width = coords[:bar_end] - coords[:bar_start] - 2 | |
761 | style = "" |
|
761 | style = "" | |
762 | style << "top:#{params[:top]}px;" |
|
762 | style << "top:#{params[:top]}px;" | |
763 | style << "left:#{coords[:bar_start]}px;" |
|
763 | style << "left:#{coords[:bar_start]}px;" | |
764 | style << "width:#{width}px;" |
|
764 | style << "width:#{width}px;" | |
765 | html_id = "task-todo-issue-#{options[:issue].id}" if options[:issue] |
|
765 | html_id = "task-todo-issue-#{options[:issue].id}" if options[:issue] | |
766 | html_id = "task-todo-version-#{options[:version].id}" if options[:version] |
|
766 | html_id = "task-todo-version-#{options[:version].id}" if options[:version] | |
767 | content_opt = {:style => style, |
|
767 | content_opt = {:style => style, | |
768 | :class => "#{options[:css]} task_todo", |
|
768 | :class => "#{options[:css]} task_todo", | |
769 | :id => html_id} |
|
769 | :id => html_id} | |
770 | if options[:issue] |
|
770 | if options[:issue] | |
771 | rels = issue_relations(options[:issue]) |
|
771 | rels = issue_relations(options[:issue]) | |
772 | if rels.present? |
|
772 | if rels.present? | |
773 | content_opt[:data] = {"rels" => rels.to_json} |
|
773 | content_opt[:data] = {"rels" => rels.to_json} | |
774 | end |
|
774 | end | |
775 | end |
|
775 | end | |
776 | output << view.content_tag(:div, ' '.html_safe, content_opt) |
|
776 | output << view.content_tag(:div, ' '.html_safe, content_opt) | |
777 | if coords[:bar_late_end] |
|
777 | if coords[:bar_late_end] | |
778 | width = coords[:bar_late_end] - coords[:bar_start] - 2 |
|
778 | width = coords[:bar_late_end] - coords[:bar_start] - 2 | |
779 | style = "" |
|
779 | style = "" | |
780 | style << "top:#{params[:top]}px;" |
|
780 | style << "top:#{params[:top]}px;" | |
781 | style << "left:#{coords[:bar_start]}px;" |
|
781 | style << "left:#{coords[:bar_start]}px;" | |
782 | style << "width:#{width}px;" |
|
782 | style << "width:#{width}px;" | |
783 | output << view.content_tag(:div, ' '.html_safe, |
|
783 | output << view.content_tag(:div, ' '.html_safe, | |
784 | :style => style, |
|
784 | :style => style, | |
785 | :class => "#{options[:css]} task_late") |
|
785 | :class => "#{options[:css]} task_late") | |
786 | end |
|
786 | end | |
787 | if coords[:bar_progress_end] |
|
787 | if coords[:bar_progress_end] | |
788 | width = coords[:bar_progress_end] - coords[:bar_start] - 2 |
|
788 | width = coords[:bar_progress_end] - coords[:bar_start] - 2 | |
789 | style = "" |
|
789 | style = "" | |
790 | style << "top:#{params[:top]}px;" |
|
790 | style << "top:#{params[:top]}px;" | |
791 | style << "left:#{coords[:bar_start]}px;" |
|
791 | style << "left:#{coords[:bar_start]}px;" | |
792 | style << "width:#{width}px;" |
|
792 | style << "width:#{width}px;" | |
793 | html_id = "task-done-issue-#{options[:issue].id}" if options[:issue] |
|
793 | html_id = "task-done-issue-#{options[:issue].id}" if options[:issue] | |
794 | html_id = "task-done-version-#{options[:version].id}" if options[:version] |
|
794 | html_id = "task-done-version-#{options[:version].id}" if options[:version] | |
795 | output << view.content_tag(:div, ' '.html_safe, |
|
795 | output << view.content_tag(:div, ' '.html_safe, | |
796 | :style => style, |
|
796 | :style => style, | |
797 | :class => "#{options[:css]} task_done", |
|
797 | :class => "#{options[:css]} task_done", | |
798 | :id => html_id) |
|
798 | :id => html_id) | |
799 | end |
|
799 | end | |
800 | end |
|
800 | end | |
801 | # Renders the markers |
|
801 | # Renders the markers | |
802 | if options[:markers] |
|
802 | if options[:markers] | |
803 | if coords[:start] |
|
803 | if coords[:start] | |
804 | style = "" |
|
804 | style = "" | |
805 | style << "top:#{params[:top]}px;" |
|
805 | style << "top:#{params[:top]}px;" | |
806 | style << "left:#{coords[:start]}px;" |
|
806 | style << "left:#{coords[:start]}px;" | |
807 | style << "width:15px;" |
|
807 | style << "width:15px;" | |
808 | output << view.content_tag(:div, ' '.html_safe, |
|
808 | output << view.content_tag(:div, ' '.html_safe, | |
809 | :style => style, |
|
809 | :style => style, | |
810 | :class => "#{options[:css]} marker starting") |
|
810 | :class => "#{options[:css]} marker starting") | |
811 | end |
|
811 | end | |
812 | if coords[:end] |
|
812 | if coords[:end] | |
813 | style = "" |
|
813 | style = "" | |
814 | style << "top:#{params[:top]}px;" |
|
814 | style << "top:#{params[:top]}px;" | |
815 | style << "left:#{coords[:end] + params[:zoom]}px;" |
|
815 | style << "left:#{coords[:end] + params[:zoom]}px;" | |
816 | style << "width:15px;" |
|
816 | style << "width:15px;" | |
817 | output << view.content_tag(:div, ' '.html_safe, |
|
817 | output << view.content_tag(:div, ' '.html_safe, | |
818 | :style => style, |
|
818 | :style => style, | |
819 | :class => "#{options[:css]} marker ending") |
|
819 | :class => "#{options[:css]} marker ending") | |
820 | end |
|
820 | end | |
821 | end |
|
821 | end | |
822 | # Renders the label on the right |
|
822 | # Renders the label on the right | |
823 | if options[:label] |
|
823 | if options[:label] | |
824 | style = "" |
|
824 | style = "" | |
825 | style << "top:#{params[:top]}px;" |
|
825 | style << "top:#{params[:top]}px;" | |
826 | style << "left:#{(coords[:bar_end] || 0) + 8}px;" |
|
826 | style << "left:#{(coords[:bar_end] || 0) + 8}px;" | |
827 | style << "width:15px;" |
|
827 | style << "width:15px;" | |
828 | output << view.content_tag(:div, options[:label], |
|
828 | output << view.content_tag(:div, options[:label], | |
829 | :style => style, |
|
829 | :style => style, | |
830 | :class => "#{options[:css]} label") |
|
830 | :class => "#{options[:css]} label") | |
831 | end |
|
831 | end | |
832 | # Renders the tooltip |
|
832 | # Renders the tooltip | |
833 | if options[:issue] && coords[:bar_start] && coords[:bar_end] |
|
833 | if options[:issue] && coords[:bar_start] && coords[:bar_end] | |
834 | s = view.content_tag(:span, |
|
834 | s = view.content_tag(:span, | |
835 | view.render_issue_tooltip(options[:issue]).html_safe, |
|
835 | view.render_issue_tooltip(options[:issue]).html_safe, | |
836 | :class => "tip") |
|
836 | :class => "tip") | |
837 | style = "" |
|
837 | style = "" | |
838 | style << "position: absolute;" |
|
838 | style << "position: absolute;" | |
839 | style << "top:#{params[:top]}px;" |
|
839 | style << "top:#{params[:top]}px;" | |
840 | style << "left:#{coords[:bar_start]}px;" |
|
840 | style << "left:#{coords[:bar_start]}px;" | |
841 | style << "width:#{coords[:bar_end] - coords[:bar_start]}px;" |
|
841 | style << "width:#{coords[:bar_end] - coords[:bar_start]}px;" | |
842 | style << "height:12px;" |
|
842 | style << "height:12px;" | |
843 | output << view.content_tag(:div, s.html_safe, |
|
843 | output << view.content_tag(:div, s.html_safe, | |
844 | :style => style, |
|
844 | :style => style, | |
845 | :class => "tooltip") |
|
845 | :class => "tooltip") | |
846 | end |
|
846 | end | |
847 | @lines << output |
|
847 | @lines << output | |
848 | output |
|
848 | output | |
849 | end |
|
849 | end | |
850 |
|
850 | |||
851 | def pdf_task(params, coords, options={}) |
|
851 | def pdf_task(params, coords, options={}) | |
852 | height = options[:height] || 2 |
|
852 | height = options[:height] || 2 | |
853 | # Renders the task bar, with progress and late |
|
853 | # Renders the task bar, with progress and late | |
854 | if coords[:bar_start] && coords[:bar_end] |
|
854 | if coords[:bar_start] && coords[:bar_end] | |
855 | params[:pdf].SetY(params[:top] + 1.5) |
|
855 | params[:pdf].SetY(params[:top] + 1.5) | |
856 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) |
|
856 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) | |
857 | params[:pdf].SetFillColor(200, 200, 200) |
|
857 | params[:pdf].SetFillColor(200, 200, 200) | |
858 | params[:pdf].RDMCell(coords[:bar_end] - coords[:bar_start], height, "", 0, 0, "", 1) |
|
858 | params[:pdf].RDMCell(coords[:bar_end] - coords[:bar_start], height, "", 0, 0, "", 1) | |
859 | if coords[:bar_late_end] |
|
859 | if coords[:bar_late_end] | |
860 | params[:pdf].SetY(params[:top] + 1.5) |
|
860 | params[:pdf].SetY(params[:top] + 1.5) | |
861 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) |
|
861 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) | |
862 | params[:pdf].SetFillColor(255, 100, 100) |
|
862 | params[:pdf].SetFillColor(255, 100, 100) | |
863 | params[:pdf].RDMCell(coords[:bar_late_end] - coords[:bar_start], height, "", 0, 0, "", 1) |
|
863 | params[:pdf].RDMCell(coords[:bar_late_end] - coords[:bar_start], height, "", 0, 0, "", 1) | |
864 | end |
|
864 | end | |
865 | if coords[:bar_progress_end] |
|
865 | if coords[:bar_progress_end] | |
866 | params[:pdf].SetY(params[:top] + 1.5) |
|
866 | params[:pdf].SetY(params[:top] + 1.5) | |
867 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) |
|
867 | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) | |
868 | params[:pdf].SetFillColor(90, 200, 90) |
|
868 | params[:pdf].SetFillColor(90, 200, 90) | |
869 | params[:pdf].RDMCell(coords[:bar_progress_end] - coords[:bar_start], height, "", 0, 0, "", 1) |
|
869 | params[:pdf].RDMCell(coords[:bar_progress_end] - coords[:bar_start], height, "", 0, 0, "", 1) | |
870 | end |
|
870 | end | |
871 | end |
|
871 | end | |
872 | # Renders the markers |
|
872 | # Renders the markers | |
873 | if options[:markers] |
|
873 | if options[:markers] | |
874 | if coords[:start] |
|
874 | if coords[:start] | |
875 | params[:pdf].SetY(params[:top] + 1) |
|
875 | params[:pdf].SetY(params[:top] + 1) | |
876 | params[:pdf].SetX(params[:subject_width] + coords[:start] - 1) |
|
876 | params[:pdf].SetX(params[:subject_width] + coords[:start] - 1) | |
877 | params[:pdf].SetFillColor(50, 50, 200) |
|
877 | params[:pdf].SetFillColor(50, 50, 200) | |
878 | params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1) |
|
878 | params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1) | |
879 | end |
|
879 | end | |
880 | if coords[:end] |
|
880 | if coords[:end] | |
881 | params[:pdf].SetY(params[:top] + 1) |
|
881 | params[:pdf].SetY(params[:top] + 1) | |
882 | params[:pdf].SetX(params[:subject_width] + coords[:end] - 1) |
|
882 | params[:pdf].SetX(params[:subject_width] + coords[:end] - 1) | |
883 | params[:pdf].SetFillColor(50, 50, 200) |
|
883 | params[:pdf].SetFillColor(50, 50, 200) | |
884 | params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1) |
|
884 | params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1) | |
885 | end |
|
885 | end | |
886 | end |
|
886 | end | |
887 | # Renders the label on the right |
|
887 | # Renders the label on the right | |
888 | if options[:label] |
|
888 | if options[:label] | |
889 | params[:pdf].SetX(params[:subject_width] + (coords[:bar_end] || 0) + 5) |
|
889 | params[:pdf].SetX(params[:subject_width] + (coords[:bar_end] || 0) + 5) | |
890 | params[:pdf].RDMCell(30, 2, options[:label]) |
|
890 | params[:pdf].RDMCell(30, 2, options[:label]) | |
891 | end |
|
891 | end | |
892 | end |
|
892 | end | |
893 |
|
893 | |||
894 | def image_task(params, coords, options={}) |
|
894 | def image_task(params, coords, options={}) | |
895 | height = options[:height] || 6 |
|
895 | height = options[:height] || 6 | |
896 | # Renders the task bar, with progress and late |
|
896 | # Renders the task bar, with progress and late | |
897 | if coords[:bar_start] && coords[:bar_end] |
|
897 | if coords[:bar_start] && coords[:bar_end] | |
898 | params[:image].fill('#aaa') |
|
898 | params[:image].fill('#aaa') | |
899 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], |
|
899 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], | |
900 | params[:top], |
|
900 | params[:top], | |
901 | params[:subject_width] + coords[:bar_end], |
|
901 | params[:subject_width] + coords[:bar_end], | |
902 | params[:top] - height) |
|
902 | params[:top] - height) | |
903 | if coords[:bar_late_end] |
|
903 | if coords[:bar_late_end] | |
904 | params[:image].fill('#f66') |
|
904 | params[:image].fill('#f66') | |
905 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], |
|
905 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], | |
906 | params[:top], |
|
906 | params[:top], | |
907 | params[:subject_width] + coords[:bar_late_end], |
|
907 | params[:subject_width] + coords[:bar_late_end], | |
908 | params[:top] - height) |
|
908 | params[:top] - height) | |
909 | end |
|
909 | end | |
910 | if coords[:bar_progress_end] |
|
910 | if coords[:bar_progress_end] | |
911 | params[:image].fill('#00c600') |
|
911 | params[:image].fill('#00c600') | |
912 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], |
|
912 | params[:image].rectangle(params[:subject_width] + coords[:bar_start], | |
913 | params[:top], |
|
913 | params[:top], | |
914 | params[:subject_width] + coords[:bar_progress_end], |
|
914 | params[:subject_width] + coords[:bar_progress_end], | |
915 | params[:top] - height) |
|
915 | params[:top] - height) | |
916 | end |
|
916 | end | |
917 | end |
|
917 | end | |
918 | # Renders the markers |
|
918 | # Renders the markers | |
919 | if options[:markers] |
|
919 | if options[:markers] | |
920 | if coords[:start] |
|
920 | if coords[:start] | |
921 | x = params[:subject_width] + coords[:start] |
|
921 | x = params[:subject_width] + coords[:start] | |
922 | y = params[:top] - height / 2 |
|
922 | y = params[:top] - height / 2 | |
923 | params[:image].fill('blue') |
|
923 | params[:image].fill('blue') | |
924 | params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4) |
|
924 | params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4) | |
925 | end |
|
925 | end | |
926 | if coords[:end] |
|
926 | if coords[:end] | |
927 | x = params[:subject_width] + coords[:end] + params[:zoom] |
|
927 | x = params[:subject_width] + coords[:end] + params[:zoom] | |
928 | y = params[:top] - height / 2 |
|
928 | y = params[:top] - height / 2 | |
929 | params[:image].fill('blue') |
|
929 | params[:image].fill('blue') | |
930 | params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4) |
|
930 | params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4) | |
931 | end |
|
931 | end | |
932 | end |
|
932 | end | |
933 | # Renders the label on the right |
|
933 | # Renders the label on the right | |
934 | if options[:label] |
|
934 | if options[:label] | |
935 | params[:image].fill('black') |
|
935 | params[:image].fill('black') | |
936 | params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5, |
|
936 | params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5, | |
937 | params[:top] + 1, |
|
937 | params[:top] + 1, | |
938 | options[:label]) |
|
938 | options[:label]) | |
939 | end |
|
939 | end | |
940 | end |
|
940 | end | |
941 | end |
|
941 | end | |
942 | end |
|
942 | end | |
943 | end |
|
943 | end |
General Comments 0
You need to be logged in to leave comments.
Login now