Project

General

Profile

Feature #2024 » gantt-editting-r1928.patch

against revision 1928 - Hiroyuki Yoshioka, 2008-10-12 01:54

View differences:

app/controllers/issues_controller.rb (working copy)
class IssuesController < ApplicationController
menu_item :new_issue, :only => :new
before_filter :find_issue, :only => [:show, :edit, :reply, :destroy_attachment]
before_filter :find_issue, :only => [:show, :edit, :reply, :destroy_attachment, :edit_gantt]
before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
before_filter :find_project, :only => [:new, :update_form, :preview, :gantt, :calendar]
before_filter :authorize, :except => [:index, :changes, :preview, :update_form, :context_menu]
before_filter :authorize, :except => [:index, :changes, :preview, :update_form, :context_menu, :edit_gantt]
before_filter :find_optional_project, :only => [:index, :changes]
accept_key_auth :index, :changes
......
# Attributes that can be updated on workflow transition (without :edit permission)
# TODO: make it configurable (at least per role)
UPDATABLE_ATTRS_ON_TRANSITION = %w(status_id assigned_to_id fixed_version_id done_ratio) unless const_defined?(:UPDATABLE_ATTRS_ON_TRANSITION)
def edit_gantt
date_from = Date.parse(params[:date_from])
if params[:day]
#bar moved
day = params[:day].to_i
duration = @issue.due_date - @issue.start_date
@issue.start_date = date_from + day
@issue.due_date = @issue.start_date + duration.to_i
elsif params[:start_date]
#start date changed
start_date = Date.parse(params[:start_date])
@issue.start_date = start_date
@issue.due_date = start_date if start_date > @issue.due_date
elsif params[:due_date]
#due date changed
due_date = Date.parse(params[:due_date])
@issue.due_date = due_date
@issue.start_date = due_date if due_date < @issue.start_date
end
@issue.save!
o = get_position(@issue, date_from, Date.parse(params[:date_to]), params[:zoom])
render :text=>"#{format_date(@issue.start_date)},#{format_date(@issue.due_date)},#{o[0]},#{o[1]},#{o[2]},#{o[3]}"
end
def edit
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
app/helpers/issues_helper.rb (working copy)
@cached_label_priority ||= l(:field_priority)
link_to_issue(issue) + ": #{h(issue.subject)}<br /><br />" +
"<strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />" +
"<strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />" +
"<strong>#{@cached_label_start_date}</strong>: <span id='tooltip_start_date_#{issue.id}'>#{format_date(issue.start_date)}</span><br />" +
"<strong>#{@cached_label_due_date}</strong>: <span id='tooltip_due_date_#{issue.id}'>#{format_date(issue.due_date)}</span><br />" +
"<strong>#{@cached_label_assigned_to}</strong>: #{issue.assigned_to}<br />" +
"<strong>#{@cached_label_priority}</strong>: #{issue.priority.name}"
end
......
export.rewind
export
end
def get_position(event, date_from, date_to, zoom_str)
zoom = zoom_str.to_i
i_start_date = (event.start_date >= date_from ? event.start_date : date_from )
i_end_date = (event.due_date <= date_to ? event.due_date : date_to )
i_done_date = event.start_date + ((event.due_date - event.start_date+1)*event.done_ratio/100).floor
i_done_date = (i_done_date <= date_from ? date_from : i_done_date )
i_done_date = (i_done_date >= date_to ? date_to : i_done_date )
i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
i_left = ((i_start_date - date_from)*zoom).floor
i_left = 0 if i_left < 0
i_width = ((i_end_date - i_start_date + 1)*zoom).floor - 2 # total width of the issue (- 2 for left and right borders)
i_width = 0 if i_width < 0
d_width = ((i_done_date - i_start_date)*zoom).floor - 2 # done width
d_width = 0 if d_width < 0
l_width = i_late_date ? ((i_late_date - i_start_date+1)*zoom).floor - 2 : 0 # delay width
l_width = 0 if l_width < 0
return i_left, i_width, l_width, d_width
end
end
app/views/issues/gantt.rhtml (working copy)
<% zoom = 1
@gantt.zoom.times { zoom = zoom * 2 }
subject_width = 330
subject_width = 280
header_heigth = 18
headers_height = header_heigth
......
t_height = g_height + headers_height
%>
<script type='text/javascript'>
<!--
function issue_moved(elem) {
id_str = elem.id.substring(3, elem.id.length);
url_str = '/issues/edit_gantt/' + id_str;
day = parseInt(elem.style.left)/parseInt(<%=zoom%>);
new Ajax.Request(url_str, {asynchronous:true, evalScripts:true,
parameters: 'day='+day+'&date_from=<%=@gantt.date_from.strftime("%Y-%m-%d")%>&date_to=<%=@gantt.date_to.strftime("%Y-%m-%d")%>&zoom=<%=zoom%>',
onSuccess:function(obj) {
change_date(id_str, obj.responseText);
}
});
}
function change_date(elem_id, text) {
vals = text.split(',');
start_date_elem = document.getElementById(elem_id + '_start_date_str');
start_date_elem.innerHTML = vals[0];
tooltip_start_date_elem = document.getElementById('tooltip_start_date_' + elem_id);
tooltip_start_date_elem.innerHTML = vals[0];
due_date_elem = document.getElementById(elem_id + '_due_date_str');
due_date_elem.innerHTML = vals[1];
tooltip_due_date_elem = document.getElementById('tooltip_due_date_' + elem_id);
tooltip_due_date_elem.innerHTML = vals[1];
ev_elem = document.getElementById('ev_' + elem_id);
ev_elem.style.left = vals[2] + 'px';
ev_elem.style.width = (parseInt(vals[3])+100)+'px';
todo_elem = document.getElementById('task_todo_' + elem_id);
todo_elem.style.width = vals[3] + 'px';
late_elem = document.getElementById('task_late_' + elem_id);
if (late_elem) {
late_elem.style.width = vals[4] + 'px';
}
done_elem = document.getElementById('task_done_' + elem_id);
if (done_elem) {
done_elem.style.width = vals[5] + 'px';
}
task_elem = document.getElementById('task_task_' + elem_id);
if (task_elem) {
task_elem.style.left = (parseInt(vals[3])+5) + 'px';
}
tooltip = document.getElementById("tt_" + id_str);
tooltip.style.left = ev_elem.style.left;
tooltip.style.width = todo_elem.style.width;
}
// -->
</script>
<table width="100%" style="border:0; border-collapse: collapse;">
<tr>
<td style="width:<%= subject_width %>px; padding:0px;">
......
end %>
</div>
</td>
<td style="width:225px; padding:0px;">
<div style="position:relative;height:<%= t_height + 24 %>px;width:225px;">
<div style="width:225px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr"></div>
<div style="width:225px;height:<%= t_height %>px;border-left: 1px solid #c0c0c0;overflow:hidden;" class="gantt_hdr"></div>
<%
top = headers_height + 8
@gantt.events.each do |i| %>
<div style="position: absolute;line-height:1.2em;height:16px;top:<%= top %>px;"><small>
<span id="<%=i.id%>_start_date_str" style="font-size: 7pt;"><%= format_date(i.start_date) %></span>
<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 %>
<%= observe_field "#{i.id}_start_date",
:url => { :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 },
:frequency => 0.25,
:with => 'start_date',
:success=>"change_date('#{i.id}', request.responseText)",
:failure=>"alert('Error! See the log')"
%>
<% if i.is_a? Issue %>
<span id="<%=i.id%>_due_date_str" style="font-size: 7pt;"><%= format_date(i.due_date) %></span>
<input type="hidden" size="12" id="<%=i.id%>_due_date" value="<%= i.due_date %>"><%= calendar_for("#{i.id}_due_date") %>
<%= observe_field "#{i.id}_due_date",
:url => { :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 },
:frequency => 0.25,
:with => 'due_date',
:success=>"change_date('#{i.id}', request.responseText)",
:failure=>"alert('Error! See the log')"
%>
<% end %>
</small></div>
<% top = top + 20
end %>
</div>
</td>
<td>
<div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;">
<div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;" id="gantt-container">
<div style="width:<%= g_width-1 %>px;height:<%= headers_height %>px;background: #eee;" class="gantt_hdr">&nbsp;</div>
<%
#
......
left = 0
height = g_height + header_heigth - 1
wday = @gantt.date_from.cwday
dt = @gantt.date_from
(@gantt.date_to - @gantt.date_from + 1).to_i.times do
width = zoom - 1
%>
<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">
<%= day_name(wday).first %>
<%= "#{dt.day}<br>"if @gantt.zoom == 4 %><%= day_name(wday).first %>
</div>
<%
left = left + width+1
wday = wday + 1
dt = dt + 1
wday = 1 if wday > 7
end
end %>
......
top = headers_height + 10
@gantt.events.each do |i|
if i.is_a? Issue
i_start_date = (i.start_date >= @gantt.date_from ? i.start_date : @gantt.date_from )
i_end_date = (i.due_before <= @gantt.date_to ? i.due_before : @gantt.date_to )
i_done_date = i.start_date + ((i.due_before - i.start_date+1)*i.done_ratio/100).floor
i_done_date = (i_done_date <= @gantt.date_from ? @gantt.date_from : i_done_date )
i_done_date = (i_done_date >= @gantt.date_to ? @gantt.date_to : i_done_date )
i_late_date = [i_end_date, Date.today].min if i_start_date < Date.today
i_left = ((i_start_date - @gantt.date_from)*zoom).floor
i_width = ((i_end_date - i_start_date + 1)*zoom).floor - 2 # total width of the issue (- 2 for left and right borders)
d_width = ((i_done_date - i_start_date)*zoom).floor - 2 # done width
l_width = i_late_date ? ((i_late_date - i_start_date+1)*zoom).floor - 2 : 0 # delay width
i_left, i_width, l_width, d_width = get_position(i, @gantt.date_from, @gantt.date_to, zoom)
%>
<div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;" class="task task_todo">&nbsp;</div>
<% if l_width > 0 %>
<div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= l_width %>px;" class="task task_late">&nbsp;</div>
<% end %>
<% if d_width > 0 %>
<div style="top:<%= top %>px;left:<%= i_left %>px;width:<%= d_width %>px;" class="task task_done">&nbsp;</div>
<% end %>
<div style="top:<%= top %>px;left:<%= i_left + i_width + 5 %>px;background:#fff;" class="task">
<%= i.status.name %>
<%= (i.done_ratio).to_i %>%
</div>
<div class="tooltip" style="position: absolute;top:<%= top %>px;left:<%= i_left %>px;width:<%= i_width %>px;height:12px;">
<span class="tip">
<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">
<div id="task_todo_<%=i.id%>" style="float:left; width:<%= i_width %>px;" class="task task_todo">&nbsp;</div>
<% if l_width > 0 %>
<div id="task_late_<%=i.id%>" style="float:left; width:<%= l_width %>px;" class="task task_late">&nbsp;</div>
<% end %>
<% if d_width > 0 %>
<div id="task_done_<%=i.id%>" style="float:left; width:<%= d_width %>px;" class="task task_done">&nbsp;</div>
<% end %>
<div id="task_task_<%=i.id%>" style="position:absolute;left:<%= (i_width + 5) %>px;background:#fff;" class="task">
<%= i.status.name %>
<%= (i.done_ratio).to_i %>%
</div>
</div>
<% # === tooltip === %>
<div id="tt_<%=i.id%>" class="tooltip" style="position: absolute;top:<%= top+14 %>px;left:<%= i_left %>px;width:<%= i_width %>px;height:8px;">
<span class="tip" style="position: relative;top:-2px;">
<%= render_issue_tooltip i %>
</span></div>
<%= draggable_element("ev_#{i.id}",
:revert =>false, :scroll=>"'gantt-container'", :constraint => "'horizontal'", :snap=>zoom,
:onEnd=>"function( draggable, event ) {issue_moved(draggable.element);}"
) %>
<% else
i_left = ((i.start_date - @gantt.date_from)*zoom).floor
%>
<div style="top:<%= top %>px;left:<%= i_left %>px;width:15px;" class="task milestone">&nbsp;</div>
<div style="top:<%= top %>px;left:<%= i_left %>px;width:15px;" class="task milestone">&nbsp;</div>
<div style="top:<%= top %>px;left:<%= i_left + 12 %>px;background:#fff;" class="task">
<%= h("#{i.project} -") unless @project && @project == i.project %>
<strong><%=h i %></strong>
(1-1/35)