##// END OF EJS Templates
gantt correction...
Jean-Philippe Lang -
r51:67e81b0ae9f2
parent child
Show More
@@ -1,168 +1,168
1 1 <%
2 2 pdf=IfpdfHelper::IFPDF.new
3 3 pdf.AliasNbPages
4 4 pdf.footer_date = format_date(Date.today)
5 5 pdf.AddPage("L")
6 6 pdf.SetFont('Arial','B',12)
7 7 pdf.SetX(15)
8 8 pdf.Cell(70, 20, @project.name)
9 9 pdf.Ln
10 10 pdf.SetFont('Arial','B',9)
11 11
12 12 subject_width = 70
13 13 header_heigth = 5
14 14
15 15 headers_heigth = header_heigth
16 16 show_weeks = false
17 17 show_days = false
18 18
19 19 if @months < 7
20 20 show_weeks = true
21 21 headers_heigth = 2*header_heigth
22 22 if @months < 3
23 23 show_days = true
24 24 headers_heigth = 3*header_heigth
25 25 end
26 26 end
27 27
28 28 g_width = 210
29 29 zoom = (g_width) / (@date_to - @date_from + 1)
30 30 g_height = 120
31 31 t_height = g_height + headers_heigth
32 32
33 33 y_start = pdf.GetY
34 34
35 35
36 36 #
37 37 # Months headers
38 38 #
39 39 month_f = @date_from
40 40 left = subject_width
41 41 height = header_heigth
42 42 @months.times do
43 43 width = ((month_f >> 1) - month_f) * zoom
44 44 pdf.SetY(y_start)
45 45 pdf.SetX(left)
46 46 pdf.Cell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C")
47 47 left = left + width
48 48 month_f = month_f >> 1
49 49 end
50 50
51 51 #
52 52 # Weeks headers
53 53 #
54 54 if show_weeks
55 55 left = subject_width
56 56 height = header_heigth
57 57 if @date_from.cwday == 1
58 58 # @date_from is monday
59 59 week_f = @date_from
60 60 else
61 61 # find next monday after @date_from
62 62 week_f = @date_from + (7 - @date_from.cwday + 1)
63 63 width = (7 - @date_from.cwday + 1) * zoom-1
64 64 pdf.SetY(y_start + header_heigth)
65 65 pdf.SetX(left)
66 66 pdf.Cell(width + 1, height, "", "LTR")
67 67 left = left + width+1
68 68 end
69 69 while week_f < @date_to
70 70 width = (week_f + 6 <= @date_to) ? 7 * zoom : (@date_to - week_f + 1) * zoom
71 71 pdf.SetY(y_start + header_heigth)
72 72 pdf.SetX(left)
73 73 pdf.Cell(width, height, week_f.cweek.to_s, "LTR", 0, "C")
74 74 left = left + width
75 75 week_f = week_f+7
76 76 end
77 77 end
78 78
79 79 #
80 80 # Days headers
81 81 #
82 82 if show_days
83 83 left = subject_width
84 84 height = header_heigth
85 85 wday = @date_from.cwday
86 86 pdf.SetFont('Arial','B',7)
87 87 (@date_to - @date_from + 1).to_i.times do
88 88 width = zoom
89 89 pdf.SetY(y_start + 2 * header_heigth)
90 90 pdf.SetX(left)
91 91 pdf.Cell(width, height, day_name(wday)[0,1], "LTR", 0, "C")
92 92 left = left + width
93 93 wday = wday + 1
94 94 wday = 1 if wday > 7
95 95 end
96 96 end
97 97
98 98 pdf.SetY(y_start)
99 99 pdf.SetX(15)
100 100 pdf.Cell(subject_width+g_width-15, headers_heigth, "", 1)
101 101
102 102
103 103 #
104 104 # Tasks
105 105 #
106 106 top = headers_heigth + y_start
107 107 pdf.SetFont('Arial','B',7)
108 108 @issues.each do |i|
109 109 pdf.SetY(top)
110 110 pdf.SetX(15)
111 111 pdf.Cell(subject_width-15, 5, i.id.to_s + " " + i.subject.sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)'), "LR")
112 112
113 113 pdf.SetY(top)
114 114 pdf.SetX(subject_width)
115 115 pdf.Cell(g_width, 5, "", "LR")
116 116
117 117 i_start_date = (i.start_date >= @date_from ? i.start_date : @date_from )
118 118 i_end_date = (i.due_date <= @date_to ? i.due_date : @date_to )
119 119
120 i_done_date = i.start_date + ((i.due_date - i.start_date)*i.done_ratio/100).floor
120 i_done_date = i.start_date + ((i.due_date - i.start_date+1)*i.done_ratio/100).floor
121 121 i_done_date = (i_done_date <= @date_from ? @date_from : i_done_date )
122 122 i_done_date = (i_done_date >= @date_to ? @date_to : i_done_date )
123 123
124 124 i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
125 125
126 126 i_left = ((i_start_date - @date_from)*zoom)
127 127 i_width = ((i_end_date - i_start_date + 1)*zoom)
128 128 d_width = ((i_done_date - i_start_date)*zoom)
129 129 l_width = ((i_late_date - i_start_date+1)*zoom) if i_late_date
130 130 l_width ||= 0
131 131
132 132 pdf.SetY(top+1.5)
133 133 pdf.SetX(subject_width + i_left)
134 134 pdf.SetFillColor(200,200,200)
135 135 pdf.Cell(i_width, 2, "", 0, 0, "", 1)
136 136
137 137 if l_width > 0
138 138 pdf.SetY(top+1.5)
139 139 pdf.SetX(subject_width + i_left)
140 140 pdf.SetFillColor(255,100,100)
141 141 pdf.Cell(l_width, 2, "", 0, 0, "", 1)
142 142 end
143 143 if d_width > 0
144 144 pdf.SetY(top+1.5)
145 145 pdf.SetX(subject_width + i_left)
146 146 pdf.SetFillColor(100,100,255)
147 147 pdf.Cell(d_width, 2, "", 0, 0, "", 1)
148 148 end
149 149
150 150 pdf.SetY(top+1.5)
151 151 pdf.SetX(subject_width + i_left + i_width)
152 152 pdf.Cell(30, 2, "#{i.status.name} #{i.done_ratio}%")
153 153
154 154 top = top + 5
155 155 pdf.SetDrawColor(200, 200, 200)
156 156 pdf.Line(15, top, subject_width+g_width, top)
157 157 if pdf.GetY() > 180
158 158 pdf.AddPage("L")
159 159 top = 20
160 160 pdf.Line(15, top, subject_width+g_width, top)
161 161 end
162 162 pdf.SetDrawColor(0, 0, 0)
163 163 end
164 164
165 165 pdf.Line(15, top, subject_width+g_width, top)
166 166
167 167 %>
168 168 <%= pdf.Output %> No newline at end of file
@@ -1,241 +1,241
1 1 <h2><%= l(:label_gantt_chart) %></h2>
2 2 <div class="topright">
3 3 <small>
4 4 <%= link_to 'PDF ', :zoom => @zoom, :year => @year_from, :month => @month_from, :months => @months, :output => 'pdf' %>
5 5 </small>
6 6 </div>
7 7
8 8 <table width="100%">
9 9 <tr>
10 10 <td align="left">
11 11 <%= start_form_tag %>
12 12 <input type="text" name="months" size="2" value="<%= @months %>">
13 13 <%= l(:label_months_from) %>
14 14 <%= select_month(@month_from, :prefix => "month", :discard_type => true) %>
15 15 <%= select_year(@year_from, :prefix => "year", :discard_type => true) %>
16 16 <%= hidden_field_tag 'zoom', @zoom %>
17 17 <%= submit_tag l(:button_submit), :class => "button-small" %>
18 18 <%= end_form_tag %>
19 19 </td>
20 20 <td align="right">
21 21 <%= if @zoom < 4
22 22 link_to image_tag('zoom_in'), {:zoom => (@zoom+1), :year => @year_from, :month => @month_from, :months => @months}
23 23 else
24 24 image_tag 'zoom_in_g'
25 25 end %>
26 26 <%= if @zoom > 1
27 27 link_to image_tag('zoom_out'), :zoom => (@zoom-1), :year => @year_from, :month => @month_from, :months => @months
28 28 else
29 29 image_tag 'zoom_out_g'
30 30 end %>
31 31 </td>
32 32 </tr>
33 33 </table>
34 34 <br />
35 35
36 36 <style>
37 37 .m_bg {
38 38 position:absolute;
39 39 top:0;
40 40 height:16px;
41 41 border-top: 1px solid #c0c0c0;
42 42 border-bottom: 1px solid #c0c0c0;
43 43 border-right: 1px solid #c0c0c0;
44 44 text-align: center;
45 45 }
46 46
47 47 .task {
48 48 position: absolute;
49 49 height:8px;
50 50 font-size:0.8em;
51 51 color:#888;
52 52 background:#aaa;
53 53 padding:0;
54 54 margin:0;
55 55 line-height:0.8em;
56 56 }
57 57
58 58 .task_late {
59 59 background:#f66;
60 60 }
61 61
62 62 .task_done {
63 63 background:#66f;
64 64 }
65 65 </style>
66 66
67 67 <% zoom = 1
68 68 @zoom.times { zoom = zoom * 2 }
69 69
70 70 subject_width = 260
71 71 header_heigth = 18
72 72
73 73 headers_heigth = header_heigth
74 74 show_weeks = false
75 75 show_days = false
76 76
77 77 if @zoom >1
78 78 show_weeks = true
79 79 headers_heigth = 2*header_heigth
80 80 if @zoom > 2
81 81 show_days = true
82 82 headers_heigth = 3*header_heigth
83 83 end
84 84 end
85 85
86 86 g_width = (@date_to - @date_from + 1)*zoom
87 87 g_height = [(20 * @issues.length + 6), 206].max
88 88 t_height = g_height + headers_heigth
89 89 %>
90 90
91 91 <table width="100%" border=0 cellspacing=0 cellpading=0>
92 92 <tr>
93 93 <td width=260>
94 94
95 95 <div style="position:relative;height:<%= t_height + 24 %>px;width:<%= subject_width + 1 %>px;">
96 96 <div style="right:-2px;width:<%= subject_width %>px;height:<%= headers_heigth %>px;" class="m_bg"></div>
97 97 <div style="right:-2px;width:<%= subject_width %>px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;" class="m_bg"></div>
98 98 <%
99 99 #
100 100 # Tasks subjects
101 101 #
102 102 top = headers_heigth + 8
103 103 @issues.each do |i| %>
104 104 <div style="position: absolute;line-height:1em;height:16px;top:<%= top %>px;left:4px;width:<%= subject_width - 5 %>px;overflow:hidden;">
105 105 <small><%= link_to i.id, :controller => 'issues', :action => 'show', :id => i %>
106 106 <%= i.subject.sub(/^(.{30}[^\s]*\s).*$/, '\1 (...)') %></small>
107 107 </div>
108 108 <% top = top + 20
109 109 end %>
110 110 </div>
111 111 </td>
112 112 <td>
113 113
114 114 <div style="position:relative;height:<%= t_height + 24 %>px;width:<%= subject_width %>;overflow:auto;">
115 115 <div style="width:<%= g_width-1 %>px;height:<%= headers_heigth %>px;" class="m_bg">&nbsp;</div>
116 116 <%
117 117 #
118 118 # Months headers
119 119 #
120 120 month_f = @date_from
121 121 left = 0
122 122 height = (show_weeks ? header_heigth : header_heigth + g_height)
123 123 @months.times do
124 124 width = ((month_f >> 1) - month_f) * zoom - 1
125 125 %>
126 126 <div style="left:<%= left %>px;width:<%= width %>px;height:<%= height %>px;" class="m_bg">
127 127 <%= link_to "#{month_f.year}-#{month_f.month}", :year => month_f.year, :month => month_f.month, :zoom => @zoom, :months => @months %>
128 128 </div>
129 129 <%
130 130 left = left + width + 1
131 131 month_f = month_f >> 1
132 132 end %>
133 133
134 134 <%
135 135 #
136 136 # Weeks headers
137 137 #
138 138 if show_weeks
139 139 left = 0
140 140 height = (show_days ? header_heigth-1 : header_heigth-1 + g_height)
141 141 if @date_from.cwday == 1
142 142 # @date_from is monday
143 143 week_f = @date_from
144 144 else
145 145 # find next monday after @date_from
146 146 week_f = @date_from + (7 - @date_from.cwday + 1)
147 147 width = (7 - @date_from.cwday + 1) * zoom-1
148 148 %>
149 149 <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="m_bg">&nbsp;</div>
150 150 <%
151 151 left = left + width+1
152 152 end %>
153 153 <%
154 154 while week_f < @date_to
155 155 width = (week_f + 6 <= @date_to) ? 7 * zoom -1 : (@date_to - week_f + 1) * zoom-1
156 156 %>
157 157 <div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="m_bg">
158 158 <small><%= week_f.cweek %></small>
159 159 </div>
160 160 <%
161 161 left = left + width+1
162 162 week_f = week_f+7
163 163 end
164 164 end %>
165 165
166 166 <%
167 167 #
168 168 # Days headers
169 169 #
170 170 if show_days
171 171 left = 0
172 172 height = g_height + header_heigth - 1
173 173 wday = @date_from.cwday
174 174 (@date_to - @date_from + 1).to_i.times do
175 175 width = zoom - 1
176 176 %>
177 177 <div style="left:<%= left %>px;top:37px;width:<%= width %>px;height:<%= height %>px;font-size:0.7em;<%= "background:#f1f1f1;" if wday > 5 %>" class="m_bg">
178 178 <%= day_name(wday)[0,1] %>
179 179 </div>
180 180 <%
181 181 left = left + width+1
182 182 wday = wday + 1
183 183 wday = 1 if wday > 7
184 184 end
185 185 end %>
186 186
187 187 <%
188 188 #
189 189 # Today red line
190 190 #
191 191 if Date.today >= @date_from and Date.today <= @date_to %>
192 192 <div style="position: absolute;height:<%= g_height %>px;top:<%= headers_heigth + 1 %>px;left:<%= ((Date.today-@date_from+1)*zoom).floor()-1 %>px;width:10px;border-left: 1px dashed red;">&nbsp;</div>
193 193 <% end %>
194 194
195 195 <%
196 196 #
197 197 # Tasks
198 198 #
199 199 top = headers_heigth + 12
200 200 @issues.each do |i| %>
201 201 <%
202 202 i_start_date = (i.start_date >= @date_from ? i.start_date : @date_from )
203 203 i_end_date = (i.due_date <= @date_to ? i.due_date : @date_to )
204 204
205 i_done_date = i.start_date + ((i.due_date - i.start_date)*i.done_ratio/100).floor
205 i_done_date = i.start_date + ((i.due_date - i.start_date+1)*i.done_ratio/100).floor
206 206 i_done_date = (i_done_date <= @date_from ? @date_from : i_done_date )
207 207 i_done_date = (i_done_date >= @date_to ? @date_to : i_done_date )
208 208
209 209 i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
210 210
211 211 i_left = ((i_start_date - @date_from)*zoom).floor
212 212 i_width = ((i_end_date - i_start_date + 1)*zoom).floor
213 213 d_width = ((i_done_date - i_start_date)*zoom).floor
214 214 l_width = ((i_late_date - i_start_date+1)*zoom).floor if i_late_date
215 215 l_width ||= 0
216 216 %>
217 217 <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;" class="task">&nbsp;</div>
218 218 <% if l_width > 0 %>
219 219 <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= l_width %>px;" class="task task_late">&nbsp;</div>
220 220 <% end %>
221 221 <% if d_width > 0 %>
222 222 <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= d_width %>px;" class="task task_done">&nbsp;</div>
223 223 <% end %>
224 224 <div style="top:<%= top %>px;left:<%= i_left + i_width + 5 %>px;background:#fff;" class="task">
225 225 <%= i.status.name %>
226 226 <%= (i.done_ratio).to_i %>%
227 227 </div>
228 228 <% top = top + 20
229 229 end %>
230 230 </div>
231 231 </td>
232 232 </tr>
233 233 </table>
234 234
235 235 <table width="100%">
236 236 <tr>
237 237 <td align="left"><%= link_to ('&#171; ' + l(:label_previous)), :year => (@date_from << @months).year, :month => (@date_from << @months).month, :zoom => @zoom, :months => @months %></td>
238 238 <td>
239 239 <td align="right"><%= link_to (l(:label_next) + ' &#187;'), :year => (@date_from >> @months).year, :month => (@date_from >> @months).month, :zoom => @zoom, :months => @months %></td>
240 240 </tr>
241 241 </table> No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now