gantt_edit_0.9.3_stable_3671.patch

gantt editting patch for v0.9.3 (r_3671) - Carlos Calvo, 2010-04-15 14:54

Download (20.7 KB)

View differences:

app/helpers/issues_helper.rb (working copy)
25 25
    @cached_label_priority ||= l(:field_priority)
26 26
    
27 27
    link_to_issue(issue) + "<br /><br />" +
28
      "<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />" +
29
      "<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />" +
28
      "<strong>#{@cached_label_start_date}</strong>: <span id='tooltip_start_date_#{issue.id}'>#{format_date(issue.start_date)}</span><br />" +
29
      "<strong>#{@cached_label_due_date}</strong>: <span id='tooltip_due_date_#{issue.id}'>#{format_date(issue.due_date)}</span><br />" +
30 30
      "<strong>#{@cached_label_assigned_to}</strong>: #{issue.assigned_to}<br />" +
31 31
      "<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}"
32 32
  end
......
196 196
    end
197 197
    export
198 198
  end
199

  
200
  def get_position(event, date_from, date_to, zoom_str)
201
    zoom = zoom_str.to_i
202
    i_start_date = (event.start_date >= date_from ? event.start_date : date_from )
203
    i_end_date = (event.due_before <= date_to ? event.due_before : date_to )
204

  
205
    i_done_date = event.start_date + ((event.due_before - event.start_date+1)*event.done_ratio/100).floor
206
    i_done_date = (i_done_date <= date_from ? date_from : i_done_date )
207
    i_done_date = (i_done_date >= date_to ? date_to : i_done_date )
208

  
209
    i_late_date = [i_end_date, Date.today].min if i_start_date <= Date.today
210

  
211
    i_left = ((i_start_date - date_from)*zoom).floor 	
212
    i_left = 0 if i_left < 0
213
    i_width = ((i_end_date - i_start_date + 1)*zoom).floor - 2                  # total width of the issue (- 2 for left and right borders)
214
    i_width = 0 if i_width < 0
215
    d_width = ((i_done_date - i_start_date)*zoom).floor - 2                     # done width
216
    d_width = 0 if d_width < 0
217
    l_width = i_late_date ? ((i_late_date - i_start_date+1)*zoom).floor - 2 : 0 # delay width
218
    l_width = 0 if l_width < 0
219
    return i_left, i_width, l_width, d_width
220
  end
199 221
end
app/models/issue.rb (working copy)
336 336
    end
337 337
    dependencies
338 338
  end
339

  
340
  def all_precedes_issues
341
    dependencies = []
342
    relations_from.each do |relation|
343
      next unless relation.relation_type == IssueRelation::TYPE_PRECEDES
344
      dependencies << relation.issue_to
345
      dependencies += relation.issue_to.all_dependent_issues
346
    end
347
    dependencies
348
  end
339 349
  
340 350
  # Returns an array of issues that duplicate this one
341 351
  def duplicates
app/controllers/issues_controller.rb (working copy)
19 19
  menu_item :new_issue, :only => :new
20 20
  default_search_scope :issues
21 21
  
22
  before_filter :find_issue, :only => [:show, :edit, :reply]
22
  before_filter :find_issue, :only => [:show, :edit, :reply, :edit_gantt]
23 23
  before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
24 24
  before_filter :find_project, :only => [:new, :update_form, :preview]
25
  before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :context_menu]
25
  before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :context_menu, :edit_gantt]
26 26
  before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar]
27 27
  accept_key_auth :index, :show, :changes
28 28

  
......
169 169
  # Attributes that can be updated on workflow transition (without :edit permission)
170 170
  # TODO: make it configurable (at least per role)
171 171
  UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
172

  
173
  def edit_gantt
174
    if !@issue.start_date || !@issue.due_before
175
      render :text=>l(:notice_locking_conflict), :status=>400
176
      return
177
    end
178
    @issue.init_journal(User.current)
179
    date_from = Date.parse(params[:date_from])
180
    old_start_date = @issue.start_date
181
    o = get_position(@issue, date_from, Date.parse(params[:date_to]), params[:zoom])
182
    text_for_revert = "#{@issue.id}=#{format_date(@issue.start_date)},#{@issue.start_date},#{format_date(@issue.due_before)},#{@issue.due_before},#{o[0]},#{o[1]},#{o[2]},#{o[3]}"
183
    
184
    if params[:day]
185
      #bar moved
186
      day = params[:day].to_i
187
      duration = @issue.due_before - @issue.start_date
188
      @issue.start_date = date_from + day
189
      @issue.due_date = @issue.start_date + duration.to_i if @issue.due_date
190
    elsif params[:start_date]
191
      #start date changed
192
      start_date = Date.parse(params[:start_date])
193
      if @issue.start_date == start_date
194
        render :text=>""
195
        return #nothing has changed
196
      end
197
      @issue.start_date = start_date
198
      @issue.due_date = start_date if @issue.due_date && start_date > @issue.due_date
199
    elsif params[:due_date]
200
      #due date changed
201
      due_date = Date.parse(params[:due_date])
202
      if @issue.due_date == due_date
203
        render :text=>""
204
        return #nothing has changed
205
      end
206
      @issue.due_date = due_date
207
      @issue.start_date = due_date if due_date < @issue.start_date
208
    end
209
    fv = @issue.fixed_version
210
    if fv && fv.effective_date && !@issue.due_date && fv.effective_date < @issue.start_date
211
      @issue.start_date = old_start_date
212
    end  
213
    
214
    begin
215
      @issue.save!
216
      o = get_position(@issue, date_from, Date.parse(params[:date_to]), params[:zoom])
217
      text = "#{@issue.id}=#{format_date(@issue.start_date)},#{@issue.start_date},#{format_date(@issue.due_before)},#{@issue.due_before},#{o[0]},#{o[1]},#{o[2]},#{o[3]}"
218

  
219
      #check dependencies
220
      issues = @issue.all_precedes_issues
221
      issues.each do |i|
222
        o = get_position(i, date_from, Date.parse(params[:date_to]), params[:zoom])
223
        text += "|#{i.id}=#{format_date(i.start_date)},#{i.start_date},#{format_date(i.due_before)},#{i.due_before},#{o[0]},#{o[1]},#{o[2]},#{o[3]}"
224
      end
225
      render :text=>text
226
    rescue 
227
      render :text=>@issue.errors.full_messages.join("\n") + "|" + text_for_revert  , :status=>400
228
    end
229
  end
172 230
  
173 231
  def edit
174 232
    @allowed_statuses = @issue.new_statuses_allowed_to(User.current)
app/views/issues/gantt.rhtml (working copy)
46 46
<% zoom = 1
47 47
@gantt.zoom.times { zoom = zoom * 2 }
48 48

  
49
subject_width = 330
49
subject_width = 280
50 50
header_heigth = 18
51 51

  
52 52
headers_height = header_heigth
......
66 66
g_height = [(20 * @gantt.events.length + 6)+150, 206].max
67 67
t_height = g_height + headers_height
68 68
%>
69
<input type="hidden" name="_date_from" id="i_date_from" value="<%=h(@gantt.date_from)%>" />
70
<input type="hidden" name="_date_to" id="i_date_to" value="<%=h(@gantt.date_to)%>" />
71
<input type="hidden" name="zm" id="i_zm" value="<%=h(zoom)%>" />
72
<script type='text/javascript'>
73
  function issue_moved(elem) {
74
    var id_str = elem.id.substring(3, elem.id.length);
75
    var v_date_from = document.getElementById('i_date_from').getAttribute("value");
76
    var v_date_to = document.getElementById('i_date_to').getAttribute("value");
77
    var v_zm = document.getElementById('i_zm').getAttribute("value");
78
    var url_str = '/issues/edit_gantt/' + id_str;
79
    var day = parseInt(elem.style.left)/parseInt(v_zm);
80
    new Ajax.Request(url_str, {asynchronous:true, evalScripts:true,
81
      parameters: 'day='+day+'&date_from='+v_date_from+'&date_to='+v_date_to+'&zoom='+v_zm,
82
      onSuccess:function(obj) {
83
        change_dates(obj.responseText);
84
      },
85
      onFailure:function(obj) {
86
        handle_failure(obj.responseText);
87
      }
88
    });
69 89

  
90
  }
91

  
92
  function handle_failure(res_text) {
93
    var text = res_text.split('|');
94
    alert(text[0]);
95
    if (text.length == 1) {
96
      return;
97
    }
98
    change_dates(text[1]);//revert
99
  }
100

  
101
  function change_dates(issue_infos) {
102
    if (!issue_infos) {
103
      return;
104
    }
105
    var issue_list = issue_infos.split("|");
106
    for (i = 0; i < issue_list.length; i++) {
107
      change_date(issue_list[i]);
108
    }
109
  }
110

  
111
  function change_date(text) {
112
    if (!text) {
113
      return;
114
    }
115
    var issue_info = text.split("=");
116
    var elem_id = issue_info[0];
117
    var vals = issue_info[1].split(',');
118
    var start_date_elem = document.getElementById(elem_id + '_start_date_str');
119
    if (!start_date_elem) {
120
      //target not exists
121
      return;
122
    }
123
    start_date_elem.innerHTML = vals[0];
124
    var tooltip_start_date_elem = document.getElementById('tooltip_start_date_' + elem_id);
125
    tooltip_start_date_elem.innerHTML = vals[0];
126
    var due_date_elem = document.getElementById(elem_id + '_due_date_str');
127
    due_date_elem.innerHTML = vals[2];
128
    var tooltip_due_date_elem = document.getElementById('tooltip_due_date_' + elem_id);
129
    tooltip_due_date_elem.innerHTML = vals[2];
130

  
131
    var ev_elem = document.getElementById('ev_' + elem_id);
132
    ev_elem.style.left = vals[4] + 'px';
133
    ev_elem.style.width = (parseInt(vals[5])+100)+'px';
134
    var todo_elem = document.getElementById('task_todo_' + elem_id);
135
    todo_elem.style.width = vals[5] + 'px';
136
    var late_elem = document.getElementById('task_late_' + elem_id);
137
    if (late_elem) {
138
      late_elem.style.width = vals[6] + 'px';
139
      if (vals[6] == '0') {
140
        late_elem.className = 'task task_none';
141
      } else {
142
        late_elem.className = 'task task_late';
143
      }
144
    }
145
    var done_elem = document.getElementById('task_done_' + elem_id);
146
    if (done_elem) {
147
      done_elem.style.width = vals[7] + 'px';
148
      if (vals[7] == '0') {
149
        done_elem.className = 'task task_none';
150
      } else {
151
        done_elem.className = 'task task_done';
152
      }
153
    }
154
    var task_elem = document.getElementById('task_task_' + elem_id);
155
    if (task_elem) {
156
      task_elem.style.left = (parseInt(vals[5])+5) + 'px';
157
    }
158
    var tooltip = document.getElementById("tt_" + elem_id);
159
    tooltip.style.left = ev_elem.style.left;
160

  
161
    //change calendar date
162
    document.getElementById(elem_id+"_hidden_start_date").value = vals[1];
163
    document.getElementById(elem_id+"_start_date").value = vals[1];
164
    document.getElementById(elem_id+"_hidden_due_date").value = vals[3];
165
    document.getElementById(elem_id+"_due_date").value = vals[3];
166
  }
167
</script>
168

  
70 169
<table width="100%" style="border:0; border-collapse: collapse;">
71 170
<tr>
72 171
<td style="width:<%= subject_width %>px; padding:0px;">
......
80 179
#
81 180
top = headers_height + 8
82 181
@gantt.events.each do |i| %>
83
    <div style="position: absolute;line-height:1.2em;height:16px;top:<%= top %>px;left:4px;overflow:hidden;"><small>    
182
    <div style="position: absolute;line-height:1.2em;height:16px;top:<%= top %>px;left:4px;overflow:hidden;"><small>
84 183
    <% if i.is_a? Issue %>
85 184
      	<%= h("#{i.project} -") unless @project && @project == i.project %>
86 185
      	<%= link_to_issue i %>
......
88 187
		<span class="icon icon-package">
89 188
	      	<%= link_to_version i %>
90 189
		</span>
91
  	<% end %>  	
190
  	<% end %>
92 191
  	</small></div>
93 192
    <% top = top + 20
94 193
end %>
95 194
</div>
96 195
</td>
196
<td style="width:225px; padding:0px;">
197
<div style="position:relative;height:<%= t_height + 24 %>px;width:225px;">
198
<div style="width:225px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div>
199
<div style="width:225px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div>
200
<%
201
top = headers_height + 8
202
@gantt.events.each do |i| %>
203
  <div style="position: absolute;line-height:1.2em;height:16px;top:<%= top %>px;"><small>
204
  <% if i.is_a? Issue %>
205
    <span id="<%=i.id%>_start_date_str" style="font-size: 7pt;"><%= format_date(i.start_date) %></span>
206
    <input type="hidden" size="12" id="<%=i.id%>_hidden_start_date" value="<%= i.start_date %>">
207
    <input type="hidden" size="12" id="<%=i.id%>_start_date" value="<%= i.start_date %>"><%= calendar_for("#{i.id}_start_date") if i.is_a? Issue %>
208
<script type="text/javascript">
209
//<![CDATA[
210
new Form.Element.Observer('<%=i.id%>_start_date', 0.25,
211
  function(element, value) {
212
    if (value == document.getElementById('<%=i.id%>_hidden_start_date').value) {
213
      return ;
214
    }
215
    new Ajax.Request('<%=url_for(:controller=>:issues, :action => :edit_gantt, :id=>i.id, :date_from=>@gantt.date_from.strftime("%Y-%m-%d"), :date_to=>@gantt.date_to.strftime("%Y-%m-%d"), :zoom=>zoom, :escape => false) %>', {asynchronous:true, evalScripts:true, onFailure:function(request){handle_failure(request.responseText)}, onSuccess:function(request){change_dates(request.responseText)}, parameters:'start_date=' + encodeURIComponent(value)});
216
  })
217
//]]>
218
</script>
219
    <span id="<%=i.id%>_due_date_str" style="font-size: 7pt;<%= "color: blue;" unless i.due_date%>">
220
      <%= format_date(i.due_before) %>
221
    </span>
222
    <input type="hidden" size="12" id="<%=i.id%>_hidden_due_date" value="<%= i.due_date %>">
223
    <input type="hidden" size="12" id="<%=i.id%>_due_date" value="<%= i.due_date %>"><%= calendar_for("#{i.id}_due_date") if i.due_date%>
224
<script type="text/javascript">
225
//<![CDATA[
226
new Form.Element.Observer('<%=i.id%>_due_date', 0.25,
227
  function(element, value) {
228
    if (value == document.getElementById('<%=i.id%>_hidden_due_date').value) {
229
      return ;
230
    }
231
    new Ajax.Request('<%=url_for(:controller=>:issues, :action => :edit_gantt, :id=>i.id, :date_from=>@gantt.date_from.strftime("%Y-%m-%d"), :date_to=>@gantt.date_to.strftime("%Y-%m-%d"), :zoom=>zoom, :escape => false) %>', {asynchronous:true, evalScripts:true, onFailure:function(request){handle_failure(request.responseText)}, onSuccess:function(request){change_dates(request.responseText)}, parameters:'due_date=' + encodeURIComponent(value)});
232
  })
233
//]]>
234
</script>
235
  <% else %>
236
    <span style="font-size: 7pt;"><%= format_date(i.start_date) %></span>
237
  <% end %>
238
  </small></div>
239
<% top = top + 20
240
end %>
241
</div>
242
</td>
97 243
<td>
98 244

  
99
<div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;">
245
<div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;" id="gantt-container">
100 246
<div style="width:<%= g_width-1 %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr">&nbsp;</div>
101
<% 
247
<%
102 248
#
103 249
# Months headers
104 250
#
105 251
month_f = @gantt.date_from
106 252
left = 0
107 253
height = (show_weeks ? header_heigth : header_heigth + g_height)
108
@gantt.months.times do 
254
@gantt.months.times do
109 255
	width = ((month_f >> 1) - month_f) * zoom - 1
110 256
	%>
111 257
	<div style="left:<%= left %>px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">
112 258
	<%= 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}"%>
113 259
	</div>
114
	<% 
260
	<%
115 261
	left = left + width + 1
116 262
	month_f = month_f >> 1
117 263
end %>
118 264

  
119
<% 
265
<%
120 266
#
121 267
# Weeks headers
122 268
#
......
132 278
		width = (7 - @gantt.date_from.cwday + 1) * zoom-1
133 279
		%>
134 280
		<div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">&nbsp;</div>
135
		<% 
281
		<%
136 282
		left = left + width+1
137 283
	end %>
138 284
	<%
......
142 288
		<div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">
143 289
		<small><%= week_f.cweek if width >= 16 %></small>
144 290
		</div>
145
		<% 
291
		<%
146 292
		left = left + width+1
147 293
		week_f = week_f+7
148 294
	end
149 295
end %>
150 296

  
151
<% 
297
<%
152 298
#
153 299
# Days headers
154 300
#
......
156 302
	left = 0
157 303
	height = g_height + header_heigth - 1
158 304
	wday = @gantt.date_from.cwday
159
	(@gantt.date_to - @gantt.date_from + 1).to_i.times do 
305
  dt = @gantt.date_from
306
	(@gantt.date_to - @gantt.date_from + 1).to_i.times do
160 307
	width =  zoom - 1
161 308
	%>
162 309
	<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">
163
	<%= day_name(wday).first %>
310
	<%=  "#{dt.day}<br>"if @gantt.zoom == 4 %><%= day_name(wday).first %>
164 311
	</div>
165
	<% 
312
	<%
166 313
	left = left + width+1
167 314
	wday = wday + 1
315
  dt = dt + 1
168 316
	wday = 1 if wday > 7
169 317
	end
170 318
end %>
......
174 322
# Tasks
175 323
#
176 324
top = headers_height + 10
177
@gantt.events.each do |i| 
178
  if i.is_a? Issue 
179
	i_start_date = (i.start_date >= @gantt.date_from ? i.start_date : @gantt.date_from )
180
	i_end_date = (i.due_before <= @gantt.date_to ? i.due_before : @gantt.date_to )
181
	
182
	i_done_date = i.start_date + ((i.due_before - i.start_date+1)*i.done_ratio/100).floor
183
	i_done_date = (i_done_date <= @gantt.date_from ? @gantt.date_from : i_done_date )
184
	i_done_date = (i_done_date >= @gantt.date_to ? @gantt.date_to : i_done_date )
185
	
186
	i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
187
	
188
	i_left = ((i_start_date - @gantt.date_from)*zoom).floor 	
189
	i_width = ((i_end_date - i_start_date + 1)*zoom).floor - 2                  # total width of the issue (- 2 for left and right borders)
190
	d_width = ((i_done_date - i_start_date)*zoom).floor - 2                     # done width
191
	l_width = i_late_date ? ((i_late_date - i_start_date+1)*zoom).floor - 2 : 0 # delay width
325
@gantt.events.each do |i|
326
  if i.is_a? Issue
327
    i_left, i_width, l_width, d_width = get_position(i, @gantt.date_from, @gantt.date_to, zoom)
192 328
	%>
193
	<div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;" class="task task_todo">&nbsp;</div>
194
	<% if l_width > 0 %>
195
	    <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= l_width %>px;" class="task task_late">&nbsp;</div>
196
	<% end %>
197
	<% if d_width > 0 %>
198
	    <div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= d_width %>px;" class="task task_done">&nbsp;</div>
199
	<% end %>
200
	<div style="top:<%= top %>px;left:<%= i_left + i_width + 5 %>px;background:#fff;" class="task">
201
	<%= i.status.name %>
202
	<%= (i.done_ratio).to_i %>%
203
	</div>
204
	<div class="tooltip" style="position: absolute;top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;height:12px;">
205
	<span class="tip">
329
  <div id="ev_<%=i.id%>" style="position:absolute;left:<%= i_left %>px;top:<%= top %>px;padding-top:3px;height:18px;width:<%= i_width+100 %>px;" class="handle">
330
    <div id="task_todo_<%=i.id%>" style="float:left:0px; width:<%= i_width %>px;" class="task task_todo">&nbsp;</div>
331
    <div id="task_late_<%=i.id%>" style="float:left:0px; width:<%= l_width %>px;" class="<%= l_width == 0 ? 'task task_none' : 'task task_late' %>">&nbsp;</div>
332
    <div id="task_done_<%=i.id%>" style="float:left:0px; width:<%= d_width %>px;" class="<%= d_width == 0 ? 'task task_none' : 'task task_done' %>">&nbsp;</div>
333
    <div id="task_task_<%=i.id%>" style="position:absolute;left:<%= (i_width + 5) %>px;background:#fff;" class="task">
334
    <%= h(i.status.name) %>
335
    <%= (i.done_ratio).to_i %>%
336
    <% if !i.due_date && i.fixed_version %>
337
      -&nbsp;<strong><%= h(i.fixed_version.name)  %></strong>
338
    <% end %>
339
    </div>
340
  </div>
341
	<%# === tooltip === %>
342
	<div id="tt_<%=i.id%>" class="tooltip" style="position: absolute;top:<%= top+14 %>px;left:<%= i_left %>px;width:<%= i_width %>px;height:8px;">
343
	<span class="tip" style="position: relative;top:-2px;">
206 344
    <%= render_issue_tooltip i %>
207 345
	</span></div>
208
<% else 
346
  <%= draggable_element("ev_#{i.id}",
347
    :revert =>false, :scroll=>"'gantt-container'", :constraint => "'horizontal'", :snap=>zoom,
348
       :onEnd=>"function( draggable, event )  {issue_moved(draggable.element);}"
349
    ) %>
350

  
351
<% else
209 352
    i_left = ((i.start_date - @gantt.date_from)*zoom).floor
210 353
    %>
211
    <div style="top:<%= top %>px;left:<%= i_left %>px;width:15px;" class="task milestone">&nbsp;</div>
354
  <div style="top:<%= top %>px;left:<%= i_left %>px;width:15px;" class="task milestone">&nbsp;</div>
212 355
	<div style="top:<%= top %>px;left:<%= i_left + 12 %>px;background:#fff;" class="task">
213 356
		<strong><%= format_version_name i %></strong>
214 357
	</div>
public/stylesheets/application.css (working copy)
734 734
.task_late { background:#f66 url(../images/task_late.png); border: 1px solid #f66; }
735 735
.task_done { background:#66f url(../images/task_done.png); border: 1px solid #66f; }  
736 736
.task_todo { background:#aaa url(../images/task_todo.png); border: 1px solid #aaa; }
737
.task_none { background:transparent; border-style: none; }
738
.task_none { background:transparent; border-style: none; }
737 739
.milestone { background-image:url(../images/milestone.png); background-repeat: no-repeat; border: 0; }
738 740

  
739 741
/***** Icons *****/