##// END OF EJS Templates
Gantt: iterate over all objects only once for html and pdf rendering (#6348)....
Jean-Philippe Lang -
r4358:b0a1a0400825
parent child
Show More
@@ -62,6 +62,8 g_width = (@gantt.date_to - @gantt.date_from + 1)*zoom
62 # Collect the number of issues on Versions
62 # Collect the number of issues on Versions
63 g_height = [(20 * (@gantt.number_of_rows + 6))+150, 206].max
63 g_height = [(20 * (@gantt.number_of_rows + 6))+150, 206].max
64 t_height = g_height + headers_height
64 t_height = g_height + headers_height
65
66 @gantt.render(:headers_height => headers_height, :top => headers_height + 8, :zoom => zoom, :g_width => g_width)
65 %>
67 %>
66 <table width="100%" style="border:0; border-collapse: collapse;">
68 <table width="100%" style="border:0; border-collapse: collapse;">
67 <tr>
69 <tr>
@@ -72,7 +74,7 t_height = g_height + headers_height
72 <div style="right:-2px;width:<%= subject_width %>px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div>
74 <div style="right:-2px;width:<%= subject_width %>px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div>
73 <% top = headers_height + 8 %>
75 <% top = headers_height + 8 %>
74
76
75 <%= @gantt.subjects(:headers_height => headers_height, :top => top, :g_width => g_width) %>
77 <%= @gantt.subjects %>
76
78
77 </div>
79 </div>
78 </td>
80 </td>
@@ -153,7 +155,7 end %>
153
155
154 <% top = headers_height + 10 %>
156 <% top = headers_height + 10 %>
155
157
156 <%= @gantt.lines(:top => top, :zoom => zoom, :g_width => g_width ) %>
158 <%= @gantt.lines %>
157
159
158 <%
160 <%
159 #
161 #
@@ -67,6 +67,9 module Redmine
67
67
68 @date_from = Date.civil(@year_from, @month_from, 1)
68 @date_from = Date.civil(@year_from, @month_from, 1)
69 @date_to = (@date_from >> @months) - 1
69 @date_to = (@date_from >> @months) - 1
70
71 @subjects = ''
72 @lines = ''
70 end
73 end
71
74
72 def common_params
75 def common_params
@@ -128,34 +131,32 module Redmine
128
131
129 # Renders the subjects of the Gantt chart, the left side.
132 # Renders the subjects of the Gantt chart, the left side.
130 def subjects(options={})
133 def subjects(options={})
131 options = {:indent => 4, :render => :subject, :format => :html}.merge(options)
134 render(options.merge(:only => :subjects)) unless @subjects_rendered
132
135 @subjects
133 output = ''
134 if @project
135 output << render_project(@project, options)
136 else
137 Project.roots.visible.each do |project|
138 output << render_project(project, options)
139 end
140 end
141
142 output
143 end
136 end
144
137
145 # Renders the lines of the Gantt chart, the right side
138 # Renders the lines of the Gantt chart, the right side
146 def lines(options={})
139 def lines(options={})
147 options = {:indent => 4, :render => :line, :format => :html}.merge(options)
140 render(options.merge(:only => :lines)) unless @lines_rendered
148 output = ''
141 @lines
149
142 end
143
144 def render(options={})
145 options = {:indent => 4, :render => :subject, :format => :html}.merge(options)
146
147 @subjects = '' unless options[:only] == :lines
148 @lines = '' unless options[:only] == :subjects
149
150 if @project
150 if @project
151 output << render_project(@project, options)
151 render_project(@project, options)
152 else
152 else
153 Project.roots.visible.each do |project|
153 Project.roots.visible.each do |project|
154 output << render_project(project, options)
154 render_project(project, options)
155 end
155 end
156 end
156 end
157
157
158 output
158 @subjects_rendered = true unless options[:only] == :lines
159 @lines_rendered = true unless options[:only] == :subjects
159 end
160 end
160
161
161 def render_project(project, options={})
162 def render_project(project, options={})
@@ -163,15 +164,8 module Redmine
163 options[:indent_increment] = 20 unless options.key? :indent_increment
164 options[:indent_increment] = 20 unless options.key? :indent_increment
164 options[:top_increment] = 20 unless options.key? :top_increment
165 options[:top_increment] = 20 unless options.key? :top_increment
165
166
166 output = ''
167 subject_for_project(project, options) unless options[:only] == :lines
167 # Project Header
168 line_for_project(project, options) unless options[:only] == :subjects
168 project_header = if options[:render] == :subject
169 subject_for_project(project, options)
170 else
171 # :line
172 line_for_project(project, options)
173 end
174 output << project_header if options[:format] == :html
175
169
176 options[:top] += options[:top_increment]
170 options[:top] += options[:top_increment]
177 options[:indent] += options[:indent_increment]
171 options[:indent] += options[:indent_increment]
@@ -180,54 +174,36 module Redmine
180 issues = project.issues.for_gantt.without_version.with_query(@query)
174 issues = project.issues.for_gantt.without_version.with_query(@query)
181 sort_issues!(issues)
175 sort_issues!(issues)
182 if issues
176 if issues
183 issue_rendering = render_issues(issues, options)
177 render_issues(issues, options)
184 output << issue_rendering if options[:format] == :html
185 end
178 end
186
179
187 # Third, Versions
180 # Third, Versions
188 project.versions.sort.each do |version|
181 project.versions.sort.each do |version|
189 version_rendering = render_version(version, options)
182 render_version(version, options)
190 output << version_rendering if options[:format] == :html
191 end
183 end
192
184
193 # Fourth, subprojects
185 # Fourth, subprojects
194 project.children.visible.each do |project|
186 project.children.visible.each do |project|
195 subproject_rendering = render_project(project, options)
187 render_project(project, options)
196 output << subproject_rendering if options[:format] == :html
197 end
188 end
198
189
199 # Remove indent to hit the next sibling
190 # Remove indent to hit the next sibling
200 options[:indent] -= options[:indent_increment]
191 options[:indent] -= options[:indent_increment]
201
202 output
203 end
192 end
204
193
205 def render_issues(issues, options={})
194 def render_issues(issues, options={})
206 output = ''
207 issues.each do |i|
195 issues.each do |i|
208 issue_rendering = if options[:render] == :subject
196 subject_for_issue(i, options) unless options[:only] == :lines
209 subject_for_issue(i, options)
197 line_for_issue(i, options) unless options[:only] == :subjects
210 else
198
211 # :line
212 line_for_issue(i, options)
213 end
214 output << issue_rendering if options[:format] == :html
215 options[:top] += options[:top_increment]
199 options[:top] += options[:top_increment]
216 end
200 end
217 output
218 end
201 end
219
202
220 def render_version(version, options={})
203 def render_version(version, options={})
221 output = ''
222 # Version header
204 # Version header
223 version_rendering = if options[:render] == :subject
205 subject_for_version(version, options) unless options[:only] == :lines
224 subject_for_version(version, options)
206 line_for_version(version, options) unless options[:only] == :subjects
225 else
226 # :line
227 line_for_version(version, options)
228 end
229
230 output << version_rendering if options[:format] == :html
231
207
232 options[:top] += options[:top_increment]
208 options[:top] += options[:top_increment]
233
209
@@ -241,11 +217,9 module Redmine
241 sort_issues!(issues)
217 sort_issues!(issues)
242 # Indent issues
218 # Indent issues
243 options[:indent] += options[:indent_increment]
219 options[:indent] += options[:indent_increment]
244 output << render_issues(issues, options)
220 render_issues(issues, options)
245 options[:indent] -= options[:indent_increment]
221 options[:indent] -= options[:indent_increment]
246 end
222 end
247
248 output
249 end
223 end
250
224
251 def subject_for_project(project, options)
225 def subject_for_project(project, options)
@@ -263,7 +237,7 module Redmine
263 ''
237 ''
264 end
238 end
265 output << "</small></div>"
239 output << "</small></div>"
266
240 @subjects << output
267 output
241 output
268 when :image
242 when :image
269
243
@@ -351,7 +325,7 module Redmine
351 output << "<strong>#{h project } #{h project.completed_percent(:include_subprojects => true).to_i.to_s}%</strong>"
325 output << "<strong>#{h project } #{h project.completed_percent(:include_subprojects => true).to_i.to_s}%</strong>"
352 output << "</div>"
326 output << "</div>"
353 end
327 end
354
328 @lines << output
355 output
329 output
356 when :image
330 when :image
357 options[:image].stroke('transparent')
331 options[:image].stroke('transparent')
@@ -399,7 +373,7 module Redmine
399 ''
373 ''
400 end
374 end
401 output << "</small></div>"
375 output << "</small></div>"
402
376 @subjects << output
403 output
377 output
404 when :image
378 when :image
405 options[:image].fill('black')
379 options[:image].fill('black')
@@ -486,7 +460,7 module Redmine
486 output << "<strong>#{h version } #{h version.completed_pourcent.to_i.to_s}%</strong>"
460 output << "<strong>#{h version } #{h version.completed_pourcent.to_i.to_s}%</strong>"
487 output << "</div>"
461 output << "</div>"
488 end
462 end
489
463 @lines << output
490 output
464 output
491 when :image
465 when :image
492 options[:image].stroke('transparent')
466 options[:image].stroke('transparent')
@@ -553,6 +527,7 module Redmine
553 end
527 end
554
528
555 output << "</div>"
529 output << "</div>"
530 @subjects << output
556 output
531 output
557 when :image
532 when :image
558 options[:image].fill('black')
533 options[:image].fill('black')
@@ -625,6 +600,7 module Redmine
625 output << '<span class="tip">'
600 output << '<span class="tip">'
626 output << view.render_issue_tooltip(issue)
601 output << view.render_issue_tooltip(issue)
627 output << "</span></div>"
602 output << "</span></div>"
603 @lines << output
628 output
604 output
629
605
630 when :image
606 when :image
@@ -938,18 +914,21 module Redmine
938
914
939 # Tasks
915 # Tasks
940 top = headers_heigth + y_start
916 top = headers_heigth + y_start
941 pdf_subjects_and_lines(pdf, {
917 options = {
942 :top => top,
918 :top => top,
943 :zoom => zoom,
919 :zoom => zoom,
944 :subject_width => subject_width,
920 :subject_width => subject_width,
945 :g_width => g_width
921 :g_width => g_width,
946 })
922 :indent => 0,
947
923 :indent_increment => 5,
924 :top_increment => 3,
925 :format => :pdf,
926 :pdf => pdf
927 }
928 render(options)
948
929
949 pdf.Line(15, top, subject_width+g_width, top)
930 pdf.Line(15, top, subject_width+g_width, top)
950 pdf.Output
931 pdf.Output
951
952
953 end
932 end
954
933
955 private
934 private
@@ -964,24 +943,6 module Redmine
964 cmp
943 cmp
965 end
944 end
966 end
945 end
967
968 # Renders both the subjects and lines of the Gantt chart for the
969 # PDF format
970 def pdf_subjects_and_lines(pdf, options = {})
971 subject_options = {:indent => 0, :indent_increment => 5, :top_increment => 3, :render => :subject, :format => :pdf, :pdf => pdf}.merge(options)
972 line_options = {:indent => 0, :indent_increment => 5, :top_increment => 3, :render => :line, :format => :pdf, :pdf => pdf}.merge(options)
973
974 if @project
975 render_project(@project, subject_options)
976 render_project(@project, line_options)
977 else
978 Project.roots.each do |project|
979 render_project(project, subject_options)
980 render_project(project, line_options)
981 end
982 end
983 end
984
985 end
946 end
986 end
947 end
987 end
948 end
General Comments 0
You need to be logged in to leave comments. Login now