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