Project

General

Profile

Feature #3034 » show.html.erb

Alex A, 2011-05-24 08:59

 
1
<% @gantt.view = self %>
2
<h2><%= l(:label_gantt) %></h2>
3

    
4
<% form_tag(gantt_path(:month => params[:month], :year => params[:year], :months => params[:months]), :method => :put, :id => 'query_form') do %>
5
  <%= hidden_field_tag('project_id', @project.to_param) if @project%>
6
<fieldset id="filters" class="collapsible">
7
  <legend onclick="toggleFieldset(this);"><%= l(:label_filter_plural) %></legend>
8
	<div>
9
    <%= render :partial => 'queries/filters', :locals => {:query => @query} %>
10
  </div>
11
</fieldset>
12

    
13
<p class="contextual">
14
  <%= gantt_zoom_link(@gantt, :in) %>
15
  <%= gantt_zoom_link(@gantt, :out) %>
16
</p>
17

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

    
25
<%= link_to_remote l(:button_apply), 
26
                   { :url => { :set_filter => (@query.new_record? ? 1 : nil) },
27
                     :update => "content",
28
                     :with => "Form.serialize('query_form')"
29
                   }, :class => 'icon icon-checked' %>
30
                   
31
<%= link_to_remote l(:button_clear),
32
                   { :url => { :project_id => @project, :set_filter => (@query.new_record? ? 1 : nil) }, 
33
                   	 :method => :put,
34
                     :update => "content",
35
                   }, :class => 'icon icon-reload' if @query.new_record? %>
36
</p>
37
<% end %>
38

    
39
<%= error_messages_for 'query' %>
40
<% if @query.valid? %>
41
<% zoom = 1
42
@gantt.zoom.times { zoom = zoom * 2 }
43

    
44
subject_width = 330
45
header_heigth = 18
46

    
47
headers_height = header_heigth
48
show_weeks = false
49
show_days = false
50

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

    
60
# Width of the entire chart    
61
g_width = (@gantt.date_to - @gantt.date_from + 1)*zoom
62

    
63
@gantt.render(:top => headers_height + 8, :zoom => zoom, :g_width => g_width, :subject_width => subject_width)
64

    
65
g_height = [(20 * (@gantt.number_of_rows + 6))+150, 206].max
66
t_height = g_height + headers_height
67

    
68

    
69
%>
70

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

    
75
<table width="100%" style="border:0; border-collapse: collapse;">
76
<tr>
77
<td style="width:<%= subject_width %>px; padding:0px;">
78

    
79
<div style="position:relative;height:<%= t_height + 24 %>px;width:<%= subject_width + 1 %>px;">
80
<div style="right:-2px;width:<%= subject_width %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div>
81
<div style="right:-2px;width:<%= subject_width %>px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div>
82

    
83
<div class="gantt_subjects">
84
<%= @gantt.subjects %>
85
</div>
86

    
87
</div>
88
</td>
89
<td>
90

    
91
<div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;">
92
<div style="width:<%= g_width-1 %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr">&nbsp;</div>
93
<% 
94
#
95
# Months headers
96
#
97
month_f = @gantt.date_from
98
left = 0
99
height = (show_weeks ? header_heigth : header_heigth + g_height)
100
@gantt.months.times do 
101
	width = ((month_f >> 1) - month_f) * zoom - 1
102
	%>
103
	<div style="left:<%= left %>px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">
104
	<%= 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}"%>
105
	</div>
106
	<% 
107
	left = left + width + 1
108
	month_f = month_f >> 1
109
end %>
110

    
111
<% 
112
#
113
# Weeks headers
114
#
115
if show_weeks
116
	left = 0
117
	height = (show_days ? header_heigth-1 : header_heigth-1 + g_height)
118
	if @gantt.date_from.cwday == 1
119
	    # @date_from is monday
120
        week_f = @gantt.date_from
121
	else
122
	    # find next monday after @date_from
123
		week_f = @gantt.date_from + (7 - @gantt.date_from.cwday + 1)
124
		width = (7 - @gantt.date_from.cwday + 1) * zoom-1
125
		%>
126
		<div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">&nbsp;</div>
127
		<% 
128
		left = left + width+1
129
	end %>
130
	<%
131
	while week_f <= @gantt.date_to
132
		width = (week_f + 6 <= @gantt.date_to) ? 7 * zoom -1 : (@gantt.date_to - week_f + 1) * zoom-1
133
		%>
134
		<div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">
135
		<small><%= week_f.cweek if width >= 16 %></small>
136
		</div>
137
		<% 
138
		left = left + width+1
139
		week_f = week_f+7
140
	end
141
end %>
142

    
143
<% 
144
#
145
# Days headers
146
#
147
if show_days
148
	left = 0
149
	height = g_height + header_heigth - 1
150
	wday = @gantt.date_from.cwday
151
	date = @gantt.date_from
152
	(@gantt.date_to - @gantt.date_from + 1).to_i.times do 
153
	width =  zoom - 1
154
	%>
155
	<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">	
156
	<%= 
157
	   date.mday 
158
	   #day_name(wday).first 
159
	%>
160
	</div>
161
	<% 
162
	left = left + width+1
163
	wday = wday + 1
164
	wday = 1 if wday > 7
165
	date = date.next
166
	end
167
end %>
168

    
169
<%= @gantt.lines %>
170

    
171
<%
172
#
173
# Today red line (excluded from cache)
174
#
175
if Date.today >= @gantt.date_from and Date.today <= @gantt.date_to %>
176
    <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;">&nbsp;</div>
177
<% end %>
178

    
179
</div>
180
</td>
181
</tr>
182
</table>
183

    
184
<table width="100%">
185
<tr>
186
<td align="left"><%= link_to_remote ('&#171; ' + l(:label_previous)), {:url => @gantt.params_previous, :method => :get, :update => 'content', :complete => 'window.scrollTo(0,0)'}, {:href => url_for(@gantt.params_previous)} %></td>
187
<td align="right"><%= link_to_remote (l(:label_next) + ' &#187;'), {:url => @gantt.params_next, :method => :get, :update => 'content', :complete => 'window.scrollTo(0,0)'}, {:href => url_for(@gantt.params_next)} %></td>
188
</tr>
189
</table>
190

    
191
<% other_formats_links do |f| %>
192
	<%= f.link_to 'PDF', :url => @gantt.params %>
193
	<%= f.link_to('PNG', :url => @gantt.params) if @gantt.respond_to?('to_image') %>
194
<% end %>
195
<% end # query.valid? %>
196

    
197
<% content_for :sidebar do %>
198
    <%= render :partial => 'issues/sidebar' %>
199
<% end %>
200

    
201
<% html_title(l(:label_gantt)) -%>
(1-1/6)