Project

General

Profile

Feature #3034 » show.html.erb

Nuno Ribeiro, 2013-03-20 20:35

 
1
<% @gantt.view = self %>
2
<h2><%= @query.new_record? ? l(:label_gantt) : h(@query.name) %></h2>
3

    
4
<%= form_tag({:controller => 'gantts', :action => 'show',
5
             :project_id => @project, :month => params[:month],
6
             :year => params[:year], :months => params[:months]},
7
             :method => :get, :id => 'query_form') do %>
8
<%= hidden_field_tag 'set_filter', '1' %>
9
<fieldset id="filters" class="collapsible <%= @query.new_record? ? "" : "collapsed" %>">
10
  <legend onclick="toggleFieldset(this);"><%= l(:label_filter_plural) %></legend>
11
  <div style="<%= @query.new_record? ? "" : "display: none;" %>">
12
    <%= render :partial => 'queries/filters', :locals => {:query => @query} %>
13
  </div>
14
</fieldset>
15

    
16
<p class="contextual">
17
  <%= gantt_zoom_link(@gantt, :in) %>
18
  <%= gantt_zoom_link(@gantt, :out) %>
19
</p>
20

    
21
<p class="buttons">
22
<%= text_field_tag 'months', @gantt.months, :size => 2 %>
23
<%= l(:label_months_from) %>
24
<%= select_month(@gantt.month_from, :prefix => "month", :discard_type => true) %>
25
<%= select_year(@gantt.year_from, :prefix => "year", :discard_type => true) %>
26
<%= hidden_field_tag 'zoom', @gantt.zoom %>
27

    
28
<%= link_to_function l(:button_apply), '$("#query_form").submit()',
29
                     :class => 'icon icon-checked' %>
30
<%= link_to l(:button_clear), { :project_id => @project, :set_filter => 1 },
31
            :class => 'icon icon-reload' %>
32
</p>
33
<% end %>
34

    
35
<%= error_messages_for 'query' %>
36
<% if @query.valid? %>
37
<%
38
  zoom = 1
39
  @gantt.zoom.times { zoom = zoom * 2 }
40

    
41
  subject_width = 330
42
  header_heigth = 18
43

    
44
  headers_height = header_heigth
45
  show_weeks = false
46
  show_days  = false
47
  show_day_num = false
48

    
49
  if @gantt.zoom > 1
50
    show_weeks = true
51
    headers_height = 2 * header_heigth
52
    if @gantt.zoom > 2
53
        show_days = true
54
        headers_height = 3 * header_heigth
55
        if @gantt.zoom > 3
56
          show_day_num = true
57
          headers_height = 4 * header_heigth
58
        end
59
    end
60
  end
61

    
62
  # Width of the entire chart
63
  g_width = ((@gantt.date_to - @gantt.date_from + 1) * zoom).to_i
64
  @gantt.render(:top => headers_height + 8,
65
                :zoom => zoom,
66
                :g_width => g_width,
67
                :subject_width => subject_width)
68
  g_height = [(20 * (@gantt.number_of_rows + 6)) + 150, 206].max
69
  t_height = g_height + headers_height
70
%>
71

    
72
<% if @gantt.truncated %>
73
  <p class="warning"><%= l(:notice_gantt_chart_truncated, :max => @gantt.max_rows) %></p>
74
<% end %>
75

    
76
<table style="width:100%; border:0; border-collapse: collapse;">
77
<tr>
78
<td style="width:<%= subject_width %>px; padding:0px;">
79
  <%
80
    style  = ""
81
    style += "position:relative;"
82
    style += "height: #{t_height + 24}px;"
83
    style += "width: #{subject_width + 1}px;"
84
  %>
85
  <%= content_tag(:div, :style => style) do %>
86
    <%
87
      style  = ""
88
      style += "right:-2px;"
89
      style += "width: #{subject_width}px;"
90
      style += "height: #{headers_height}px;"
91
      style += 'background: #eee;'
92
    %>
93
    <%= content_tag(:div, "", :style => style, :class => "gantt_hdr") %>
94
    <%
95
      style  = ""
96
      style += "right:-2px;"
97
      style += "width: #{subject_width}px;"
98
      style += "height: #{t_height}px;"
99
      style += 'border-left: 1px solid #c0c0c0;'
100
      style += 'overflow: hidden;'
101
    %>
102
    <%= content_tag(:div, "", :style => style, :class => "gantt_hdr") %>
103
    <%= content_tag(:div, :class => "gantt_subjects") do %>
104
      <%= @gantt.subjects.html_safe %>
105
    <% end %>
106
  <% end %>
107
</td>
108

    
109
<td>
110
<div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;">
111
<%
112
  style  = ""
113
  style += "width: #{g_width - 1}px;"
114
  style += "height: #{headers_height}px;"
115
  style += 'background: #eee;'
116
%>
117
<%= content_tag(:div, '&nbsp;'.html_safe, :style => style, :class => "gantt_hdr") %>
118

    
119
<% ###### Months headers ###### %>
120
<%
121
  month_f = @gantt.date_from
122
  left = 0
123
  height = (show_weeks ? header_heigth : header_heigth + g_height)
124
%>
125
<% @gantt.months.times do %>
126
  <%
127
    width = (((month_f >> 1) - month_f) * zoom - 1).to_i
128
    style  = ""
129
    style += "left: #{left}px;"
130
    style += "width: #{width}px;"
131
    style += "height: #{height}px;"
132
  %>
133
  <%= content_tag(:div, :style => style, :class => "gantt_hdr") do %>
134
    <%= link_to h("#{month_f.year}-#{month_f.month}"),
135
                @gantt.params.merge(:year => month_f.year, :month => month_f.month),
136
                :title => "#{month_name(month_f.month)} #{month_f.year}" %>
137
  <% end %>
138
  <%
139
    left = left + width + 1
140
    month_f = month_f >> 1
141
  %>
142
<% end %>
143

    
144
<% ###### Weeks headers ###### %>
145
<% if show_weeks %>
146
  <%
147
    left = 0
148
    height = (show_days ? header_heigth - 1 : header_heigth - 1 + g_height)
149
  %>
150
  <% if @gantt.date_from.cwday == 1 %>
151
    <%
152
      # @date_from is monday
153
      week_f = @gantt.date_from
154
    %>
155
  <% else %>
156
    <%
157
      # find next monday after @date_from
158
      week_f = @gantt.date_from + (7 - @gantt.date_from.cwday + 1)
159
      width = (7 - @gantt.date_from.cwday + 1) * zoom - 1
160
      style  = ""
161
      style += "left: #{left}px;"
162
      style += "top: 19px;"
163
      style += "width: #{width}px;"
164
      style += "height: #{height}px;"
165
    %>
166
    <%= content_tag(:div, '&nbsp;'.html_safe,
167
                    :style => style, :class => "gantt_hdr") %>
168
    <% left = left + width + 1 %>
169
  <% end %>
170
  <% while week_f <= @gantt.date_to %>
171
    <%
172
      width = ((week_f + 6 <= @gantt.date_to) ?
173
                  7 * zoom - 1 :
174
                  (@gantt.date_to - week_f + 1) * zoom - 1).to_i
175
      style  = ""
176
      style += "left: #{left}px;"
177
      style += "top: 19px;"
178
      style += "width: #{width}px;"
179
      style += "height: #{height}px;"
180
    %>
181
    <%= content_tag(:div, :style => style, :class => "gantt_hdr") do %>
182
      <%= content_tag(:small) do %>
183
        <%= week_f.cweek if width >= 16 %>
184
      <% end %>
185
    <% end %>
186
    <%
187
      left = left + width + 1
188
      week_f = week_f + 7
189
    %>
190
  <% end %>
191
<% end %>
192

    
193
<%
194
#
195
# Days headers Num
196
#
197
if show_day_num
198
  left = 0
199
  height = g_height + header_heigth*2 - 1
200
  wday = @gantt.date_from.cwday
201
  day_num = @gantt.date_from
202
  (@gantt.date_to - @gantt.date_from + 1).to_i.times do
203
  width =  zoom - 1 
204
%>
205
  <div style="left:<%= left %>px;top:37px;width:<%= width %>px;height:<%= height %>px;font-size:0.7em;<%= "background:#f1f1f1;" if wday > 5 %><%= "color:blue;" if wday == 6 %><%= "color:red;" if wday == 7 %>" class="gantt_hdr">
206
  <%= day_num.day %>
207
  </div>
208
  <%
209
   left = left + width+1
210
   day_num = day_num + 1
211
   wday = wday + 1
212
   wday = 1 if wday > 7
213
   end
214
end %> 
215

    
216
<% ###### Days headers ####### %>
217
<% if show_days %>
218
  <%
219
    left = 0
220
    height = g_height + header_heigth - 1
221
    top = (show_day_num ? 55 : 37)
222
    wday = @gantt.date_from.cwday
223
  %>
224
  <% (@gantt.date_to - @gantt.date_from + 1).to_i.times do %>
225
    <%
226
      width =  zoom - 1
227
      style  = ""
228
      style += "left: #{left}px;"
229
      style += "top: #{top}px;"
230
      style += "width: #{width}px;"
231
      style += "height: #{height}px;"
232
      style += "font-size:0.7em;"
233
      clss = "gantt_hdr"
234
      clss << " nwday" if @gantt.non_working_week_days.include?(wday)
235
    %>
236
    <%= content_tag(:div, :style => style, :class => clss) do %>
237
      <%= day_letter(wday) %>
238
    <% end %>
239
    <%
240
      left = left + width + 1
241
      wday = wday + 1
242
      wday = 1 if wday > 7
243
    %>
244
  <% end %>
245
<% end %>
246

    
247
<%= @gantt.lines.html_safe %>
248

    
249
<% ###### Today red line (excluded from cache) ###### %>
250
<% if Date.today >= @gantt.date_from and Date.today <= @gantt.date_to %>
251
  <%
252
    today_left = (((Date.today - @gantt.date_from + 1) * zoom).floor() - 1).to_i
253
    style  = ""
254
    style += "position: absolute;"
255
    style += "height: #{g_height}px;"
256
    style += "top: #{headers_height + 1}px;"
257
    style += "left: #{today_left}px;"
258
    style += "width:10px;"
259
    style += "border-left: 1px dashed red;"
260
  %>
261
  <%= content_tag(:div, '&nbsp;'.html_safe, :style => style) %>
262
<% end %>
263

    
264
</div>
265
</td>
266
</tr>
267
</table>
268

    
269
<table style="width:100%">
270
<tr>
271
  <td align="left">
272
    <%= link_to_content_update("\xc2\xab " + l(:label_previous),
273
                               params.merge(@gantt.params_previous)) %>
274
  </td>
275
  <td align="right">
276
    <%= link_to_content_update(l(:label_next) + " \xc2\xbb",
277
                               params.merge(@gantt.params_next)) %>
278
  </td>
279
</tr>
280
</table>
281

    
282
<% other_formats_links do |f| %>
283
  <%= f.link_to 'PDF', :url => params.merge(@gantt.params) %>
284
  <%= f.link_to('PNG', :url => params.merge(@gantt.params)) if @gantt.respond_to?('to_image') %>
285
<% end %>
286
<% end # query.valid? %>
287

    
288
<% content_for :sidebar do %>
289
  <%= render :partial => 'issues/sidebar' %>
290
<% end %>
291

    
292
<% html_title(l(:label_gantt)) -%>
(2-2/6)