show.html.erb 11.4 KB
Newer Older
edavis10's avatar
edavis10 committed
1
<% @gantt.view = self %>
2 3 4 5 6 7 8
<div class="contextual">
<% if !@query.new_record? && @query.editable_by?(User.current) %>
  <%= link_to l(:button_edit), edit_query_path(@query, :gantt => 1), :class => 'icon icon-edit' %>
  <%= delete_link query_path(@query, :gantt => 1) %>
<% end %>
</div>

jplang's avatar
jplang committed
9
<h2><%= @query.new_record? ? l(:label_gantt) : @query.name %></h2>
10

jplang's avatar
jplang committed
11 12 13 14
<%= form_tag({:controller => 'gantts', :action => 'show',
             :project_id => @project, :month => params[:month],
             :year => params[:year], :months => params[:months]},
             :method => :get, :id => 'query_form') do %>
15
<%= hidden_field_tag 'set_filter', '1' %>
16
<%= hidden_field_tag 'gantt', '1' %>
17
<fieldset id="filters" class="collapsible <%= @query.new_record? ? "" : "collapsed" %>">
18
  <legend onclick="toggleFieldset(this);"><%= l(:label_filter_plural) %></legend>
19
  <div style="<%= @query.new_record? ? "" : "display: none;" %>">
20
    <%= render :partial => 'queries/filters', :locals => {:query => @query} %>
21 22
  </div>
</fieldset>
23
<fieldset id="options" class="collapsible collapsed">
24 25
  <legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
  <div style="display: none;">
jplang's avatar
jplang committed
26 27 28 29 30
    <table>
      <tr>
        <td>
          <fieldset>
            <legend><%= l(:label_related_issues) %></legend>
31 32
            <label for="draw_relations">
              <%= check_box 'query', 'draw_relations', :id => 'draw_relations' %>
jplang's avatar
jplang committed
33 34 35 36 37 38 39 40 41 42 43 44 45
              <% rels = [IssueRelation::TYPE_BLOCKS, IssueRelation::TYPE_PRECEDES] %>
              <% rels.each do |rel| %>
                <% color = Redmine::Helpers::Gantt::DRAW_TYPES[rel][:color] %>
                <%= content_tag(:span, '&nbsp;&nbsp;&nbsp;'.html_safe,
                                :style => "background-color: #{color}") %>
                <%= l(IssueRelation::TYPES[rel][:name]) %>
              <% end %>
            </label>
          </fieldset>
        </td>
        <td>
          <fieldset>
            <legend><%= l(:label_gantt_progress_line) %></legend>
46 47
            <label for="draw_progress_line">
              <%= check_box 'query', 'draw_progress_line', :id => 'draw_progress_line' %>
jplang's avatar
jplang committed
48 49 50 51 52 53 54 55
              <%= l(:label_display) %>
            </label>
          </fieldset>
        </td>
      </tr>
    </table>
  </div>
</fieldset>
56

57
<p class="contextual">
58 59
  <%= gantt_zoom_link(@gantt, :in) %>
  <%= gantt_zoom_link(@gantt, :out) %>
60 61 62
</p>

<p class="buttons">
63 64 65 66 67 68
<%= text_field_tag 'months', @gantt.months, :size => 2 %>
<%= l(:label_months_from) %>
<%= select_month(@gantt.month_from, :prefix => "month", :discard_type => true) %>
<%= select_year(@gantt.year_from, :prefix => "year", :discard_type => true) %>
<%= hidden_field_tag 'zoom', @gantt.zoom %>

69 70 71 72
<%= link_to_function l(:button_apply), '$("#query_form").submit()',
                     :class => 'icon icon-checked' %>
<%= link_to l(:button_clear), { :project_id => @project, :set_filter => 1 },
            :class => 'icon icon-reload' %>
73 74 75 76 77
<% if @query.new_record? && User.current.allowed_to?(:save_queries, @project, :global => true) %>
  <%= link_to_function l(:button_save),
                       "$('#query_form').attr('action', '#{ @project ? new_project_query_path(@project) : new_query_path }').submit();",
                       :class => 'icon icon-save' %>
<% end %>
78 79 80 81 82
</p>
<% end %>

<%= error_messages_for 'query' %>
<% if @query.valid? %>
83
<%
84 85
  zoom = 1
  @gantt.zoom.times { zoom = zoom * 2 }
86

87
  subject_width = 330
88
  header_height = 18
89

90
  headers_height = header_height
91 92
  show_weeks = false
  show_days  = false
93
  show_day_num = false
94

95
  if @gantt.zoom > 1
96
    show_weeks = true
97
    headers_height = 2 * header_height
98
    if @gantt.zoom > 2
99
        show_days = true
100
        headers_height = 3 * header_height
101 102 103 104
        if @gantt.zoom > 3
          show_day_num = true
          headers_height = 4 * header_height
        end
105
    end
106
  end
107

108 109 110 111 112 113 114 115
  # Width of the entire chart
  g_width = ((@gantt.date_to - @gantt.date_from + 1) * zoom).to_i
  @gantt.render(:top => headers_height + 8,
                :zoom => zoom,
                :g_width => g_width,
                :subject_width => subject_width)
  g_height = [(20 * (@gantt.number_of_rows + 6)) + 150, 206].max
  t_height = g_height + headers_height
116
%>
117 118

<% if @gantt.truncated %>
119
  <p class="warning"><%= l(:notice_gantt_chart_truncated, :max => @gantt.max_rows) %></p>
120 121
<% end %>

122
<table style="width:100%; border:0; border-collapse: collapse;">
123
<tr>
124
<td style="width:<%= subject_width %>px; padding:0px;">
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
  <%
    style  = ""
    style += "position:relative;"
    style += "height: #{t_height + 24}px;"
    style += "width: #{subject_width + 1}px;"
  %>
  <%= content_tag(:div, :style => style) do %>
    <%
      style  = ""
      style += "right:-2px;"
      style += "width: #{subject_width}px;"
      style += "height: #{headers_height}px;"
      style += 'background: #eee;'
    %>
    <%= content_tag(:div, "", :style => style, :class => "gantt_hdr") %>
    <%
      style  = ""
      style += "right:-2px;"
      style += "width: #{subject_width}px;"
      style += "height: #{t_height}px;"
      style += 'border-left: 1px solid #c0c0c0;'
      style += 'overflow: hidden;'
    %>
    <%= content_tag(:div, "", :style => style, :class => "gantt_hdr") %>
    <%= content_tag(:div, :class => "gantt_subjects") do %>
      <%= @gantt.subjects.html_safe %>
    <% end %>
  <% end %>
153 154
</td>

155
<td>
156
<div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;" id="gantt_area">
157 158 159 160 161 162 163
<%
  style  = ""
  style += "width: #{g_width - 1}px;"
  style += "height: #{headers_height}px;"
  style += 'background: #eee;'
%>
<%= content_tag(:div, '&nbsp;'.html_safe, :style => style, :class => "gantt_hdr") %>
164 165

<% ###### Months headers ###### %>
166
<%
167 168
  month_f = @gantt.date_from
  left = 0
169
  height = (show_weeks ? header_height : header_height + g_height)
170 171
%>
<% @gantt.months.times do %>
172
  <%
173 174 175 176 177 178 179
    width = (((month_f >> 1) - month_f) * zoom - 1).to_i
    style  = ""
    style += "left: #{left}px;"
    style += "width: #{width}px;"
    style += "height: #{height}px;"
  %>
  <%= content_tag(:div, :style => style, :class => "gantt_hdr") do %>
jplang's avatar
jplang committed
180
    <%= link_to "#{month_f.year}-#{month_f.month}",
181 182
                @gantt.params.merge(:year => month_f.year, :month => month_f.month),
                :title => "#{month_name(month_f.month)} #{month_f.year}" %>
183
  <% end %>
184
  <%
185 186
    left = left + width + 1
    month_f = month_f >> 1
187 188
  %>
<% end %>
189

190
<% ###### Weeks headers ###### %>
191 192
<% if show_weeks %>
  <%
193
    left = 0
194
    height = (show_days ? header_height - 1 : header_height - 1 + g_height)
195 196 197
  %>
  <% if @gantt.date_from.cwday == 1 %>
    <%
198 199
      # @date_from is monday
      week_f = @gantt.date_from
200 201 202
    %>
  <% else %>
    <%
203 204 205 206 207 208 209 210
      # find next monday after @date_from
      week_f = @gantt.date_from + (7 - @gantt.date_from.cwday + 1)
      width = (7 - @gantt.date_from.cwday + 1) * zoom - 1
      style  = ""
      style += "left: #{left}px;"
      style += "top: 19px;"
      style += "width: #{width}px;"
      style += "height: #{height}px;"
211
    %>
212 213
    <%= content_tag(:div, '&nbsp;'.html_safe,
                    :style => style, :class => "gantt_hdr") %>
214 215 216
    <% left = left + width + 1 %>
  <% end %>
  <% while week_f <= @gantt.date_to %>
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
    <%
      width = ((week_f + 6 <= @gantt.date_to) ?
                  7 * zoom - 1 :
                  (@gantt.date_to - week_f + 1) * zoom - 1).to_i
      style  = ""
      style += "left: #{left}px;"
      style += "top: 19px;"
      style += "width: #{width}px;"
      style += "height: #{height}px;"
    %>
    <%= content_tag(:div, :style => style, :class => "gantt_hdr") do %>
      <%= content_tag(:small) do %>
        <%= week_f.cweek if width >= 16 %>
      <% end %>
    <% end %>
232
    <%
233 234
      left = left + width + 1
      week_f = week_f + 7
235 236 237
    %>
  <% end %>
<% end %>
238

239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
<% ###### Day numbers headers ###### %>
<% if show_day_num %>
  <%
    left = 0
    height = g_height + header_height*2 - 1
    wday = @gantt.date_from.cwday
    day_num = @gantt.date_from
  %>
  <% (@gantt.date_to - @gantt.date_from + 1).to_i.times do %>
    <%
      width =  zoom - 1
      style = ""
      style += "left:#{left}px;"
      style += "top:37px;"
      style += "width:#{width}px;"
      style += "height:#{height}px;"
      style += "font-size:0.7em;"
      clss = "gantt_hdr"
      clss << " nwday" if @gantt.non_working_week_days.include?(wday)
    %>
    <%= content_tag(:div, :style => style, :class => clss) do %>
      <%= day_num.day %>
    <% end %>
    <%
     left = left + width+1
     day_num = day_num + 1
     wday = wday + 1
     wday = 1 if wday > 7
    %>
  <% end %>
<% end %> 

271
<% ###### Days headers ####### %>
272 273
<% if show_days %>
  <%
274
    left = 0
275
    height = g_height + header_height - 1
276
    top = (show_day_num ? 55 : 37)
277
    wday = @gantt.date_from.cwday
278 279
  %>
  <% (@gantt.date_to - @gantt.date_from + 1).to_i.times do %>
280 281 282 283
    <%
      width =  zoom - 1
      style  = ""
      style += "left: #{left}px;"
284
      style += "top: #{top}px;"
285 286 287
      style += "width: #{width}px;"
      style += "height: #{height}px;"
      style += "font-size:0.7em;"
288 289
      clss = "gantt_hdr"
      clss << " nwday" if @gantt.non_working_week_days.include?(wday)
290
    %>
291
    <%= content_tag(:div, :style => style, :class => clss) do %>
292 293
      <%= day_letter(wday) %>
    <% end %>
294
    <%
295 296 297
      left = left + width + 1
      wday = wday + 1
      wday = 1 if wday > 7
298 299 300
    %>
  <% end %>
<% end %>
301

302
<%= @gantt.lines.html_safe %>
303

304
<% ###### Today red line (excluded from cache) ###### %>
305
<% if User.current.today >= @gantt.date_from and User.current.today <= @gantt.date_to %>
306
  <%
307
    today_left = (((User.current.today - @gantt.date_from + 1) * zoom).floor() - 1).to_i
308 309 310 311
    style  = ""
    style += "position: absolute;"
    style += "height: #{g_height}px;"
    style += "top: #{headers_height + 1}px;"
312
    style += "left: #{today_left}px;"
313 314
    style += "width:10px;"
    style += "border-left: 1px dashed red;"
315
  %>
jplang's avatar
jplang committed
316
  <%= content_tag(:div, '&nbsp;'.html_safe, :style => style, :id => 'today_line') %>
317
<% end %>
318 319 320 321 322 323 324 325 326
<%
  style  = ""
  style += "position: absolute;"
  style += "height: #{g_height}px;"
  style += "top: #{headers_height + 1}px;"
  style += "left: 0px;"
  style += "width: #{g_width - 1}px;"
%>
<%= content_tag(:div, '', :style => style, :id => "gantt_draw_area") %>
327 328 329 330 331
</div>
</td>
</tr>
</table>

332
<table style="width:100%">
333
<tr>
334
  <td style="text-align:left;">
jplang's avatar
jplang committed
335
    <%= link_to("\xc2\xab " + l(:label_previous),
jplang's avatar
jplang committed
336
                               {:params => request.query_parameters.merge(@gantt.params_previous)},
337
                               :accesskey => accesskey(:previous)) %>
338
  </td>
339
  <td style="text-align:right;">
jplang's avatar
jplang committed
340
    <%= link_to(l(:label_next) + " \xc2\xbb",
jplang's avatar
jplang committed
341
                               {:params => request.query_parameters.merge(@gantt.params_next)},
342
                               :accesskey => accesskey(:next)) %>
343
  </td>
344
</tr>
345
</table>
jplang's avatar
jplang committed
346

347
<% other_formats_links do |f| %>
jplang's avatar
jplang committed
348 349
  <%= f.link_to_with_query_parameters 'PDF', @gantt.params %>
  <%= f.link_to_with_query_parameters('PNG', @gantt.params) if @gantt.respond_to?('to_image') %>
350 351
<% end %>
<% end # query.valid? %>
jplang's avatar
jplang committed
352 353

<% content_for :sidebar do %>
354
  <%= render :partial => 'issues/sidebar' %>
jplang's avatar
jplang committed
355
<% end %>
356

357
<% html_title(l(:label_gantt)) -%>
358 359 360 361 362 363 364 365 366 367

<% content_for :header_tags do %>
  <%= javascript_include_tag 'raphael' %>
  <%= javascript_include_tag 'gantt' %>
<% end %>

<%= javascript_tag do %>
  var issue_relation_type = <%= raw Redmine::Helpers::Gantt::DRAW_TYPES.to_json %>;
  $(document).ready(drawGanttHandler);
  $(window).resize(drawGanttHandler);
jplang's avatar
jplang committed
368
  $(function() {
369
    $("#draw_relations").change(drawGanttHandler);
jplang's avatar
jplang committed
370 371
    $("#draw_progress_line").change(drawGanttHandler);
  });
372
<% end %>