Project

General

Profile

Feature #2024 » gantt-editting-r2671-2.patch

Hiroyuki Yoshioka, 2009-04-19 11:39

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]
before_filter :find_issue, :only => [:show, :edit, :reply, :edit_gantt]
before_filter :find_issues, :only => [:bulk_edit, :move, :destroy]
before_filter :find_project, :only => [:new, :update_form, :preview]
before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :update_form, :context_menu]
before_filter :authorize, :except => [:index, :changes, :gantt, :calendar, :preview, :update_form, :context_menu, :edit_gantt]
before_filter :find_optional_project, :only => [:index, :changes, :gantt, :calendar]
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
if !@issue.start_date || !@issue.due_before
render :text=>l(:notice_locking_conflict), :status=>400
return
end
@issue.init_journal(User.current)
date_from = Date.parse(params[:date_from])
old_start_date = @issue.start_date
o = get_position(@issue, date_from, Date.parse(params[:date_to]), params[:zoom])
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]}"
if params[:day]
#bar moved
day = params[:day].to_i
duration = @issue.due_before - @issue.start_date
@issue.start_date = date_from + day
@issue.due_date = @issue.start_date + duration.to_i if @issue.due_date
elsif params[:start_date]
#start date changed
start_date = Date.parse(params[:start_date])
if @issue.start_date == start_date
render :text=>""
return #nothing has changed
end
@issue.start_date = start_date
@issue.due_date = start_date if @issue.due_date && start_date > @issue.due_date
elsif params[:due_date]
#due date changed
due_date = Date.parse(params[:due_date])
if @issue.due_date == due_date
render :text=>""
return #nothing has changed
end
@issue.due_date = due_date
@issue.start_date = due_date if due_date < @issue.start_date
end
fv = @issue.fixed_version
if fv && fv.effective_date && !@issue.due_date && fv.effective_date < @issue.start_date
@issue.start_date = old_start_date
end
begin
@issue.save!
o = get_position(@issue, date_from, Date.parse(params[:date_to]), params[:zoom])
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]}"
#check dependencies
issues = @issue.all_precedes_issues
issues.each do |i|
o = get_position(i, date_from, Date.parse(params[:date_to]), params[:zoom])
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]}"
end
render :text=>text
rescue
render :text=>@issue.errors.full_messages.join("\n") + "|" + text_for_revert , :status=>400
end
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_before <= date_to ? event.due_before : date_to )
i_done_date = event.start_date + ((event.due_before - 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/models/issue.rb (working copy)
end
dependencies
end
def all_precedes_issues
dependencies = []
relations_from.each do |relation|
next unless relation.relation_type == IssueRelation::TYPE_PRECEDES
dependencies << relation.issue_to
dependencies += relation.issue_to.all_dependent_issues
end
dependencies
end
# Returns an array of issues that duplicate this one
def duplicates
app/views/issues/gantt.rhtml (working copy)
<% include_calendar_headers_tags %>
<% form_tag(params.merge(:month => nil, :year => nil, :months => nil), :id => 'query_form') do %>
<% if @query.new_record? %>
<h2><%=l(:label_gantt)%></h2>
......
</p>
<p class="buttons">
<%= link_to_remote l(:button_apply),
<%= link_to_remote l(:button_apply),
{ :url => { :set_filter => (@query.new_record? ? 1 : nil) },
:update => "content",
:with => "Form.serialize('query_form')"
}, :class => 'icon icon-checked' %>
<%= link_to_remote l(:button_clear),
{ :url => { :set_filter => (@query.new_record? ? 1 : nil) },
{ :url => { :set_filter => (@query.new_record? ? 1 : nil) },
:update => "content",
}, :class => 'icon icon-reload' if @query.new_record? %>
</p>
......
<% zoom = 1
@gantt.zoom.times { zoom = zoom * 2 }
subject_width = 330
subject_width = 280
header_heigth = 18
headers_height = header_heigth
......
g_height = [(20 * @gantt.events.length + 6)+150, 206].max
t_height = g_height + headers_height
%>
<input type="hidden" name="_date_from" id="i_date_from" value="<%=h(@gantt.date_from)%>" />
<input type="hidden" name="_date_to" id="i_date_to" value="<%=h(@gantt.date_to)%>" />
<input type="hidden" name="zm" id="i_zm" value="<%=h(zoom)%>" />
<script type='text/javascript'>
function issue_moved(elem) {
var id_str = elem.id.substring(3, elem.id.length);
var v_date_from = document.getElementById('i_date_from').getAttribute("value");
var v_date_to = document.getElementById('i_date_to').getAttribute("value");
var v_zm = document.getElementById('i_zm').getAttribute("value");
var url_str = '/issues/edit_gantt/' + id_str;
var day = parseInt(elem.style.left)/parseInt(v_zm);
new Ajax.Request(url_str, {asynchronous:true, evalScripts:true,
parameters: 'day='+day+'&date_from='+v_date_from+'&date_to='+v_date_to+'&zoom='+v_zm,
onSuccess:function(obj) {
change_dates(obj.responseText);
},
onFailure:function(obj) {
handle_failure(obj.responseText);
}
});
}
function handle_failure(res_text) {
var text = res_text.split('|');
alert(text[0]);
if (text.length == 1) {
return;
}
change_dates(text[1]);//revert
}
function change_dates(issue_infos) {
if (!issue_infos) {
return;
}
var issue_list = issue_infos.split("|");
for (i = 0; i < issue_list.length; i++) {
change_date(issue_list[i]);
}
}
function change_date(text) {
if (!text) {
return;
}
var issue_info = text.split("=");
var elem_id = issue_info[0];
var vals = issue_info[1].split(',');
var start_date_elem = document.getElementById(elem_id + '_start_date_str');
if (!start_date_elem) {
//target not exists
return;
}
start_date_elem.innerHTML = vals[0];
var tooltip_start_date_elem = document.getElementById('tooltip_start_date_' + elem_id);
tooltip_start_date_elem.innerHTML = vals[0];
var due_date_elem = document.getElementById(elem_id + '_due_date_str');
due_date_elem.innerHTML = vals[2];
var tooltip_due_date_elem = document.getElementById('tooltip_due_date_' + elem_id);
tooltip_due_date_elem.innerHTML = vals[2];
var ev_elem = document.getElementById('ev_' + elem_id);
ev_elem.style.left = vals[4] + 'px';
ev_elem.style.width = (parseInt(vals[5])+100)+'px';
var todo_elem = document.getElementById('task_todo_' + elem_id);
todo_elem.style.width = vals[5] + 'px';
var late_elem = document.getElementById('task_late_' + elem_id);
if (late_elem) {
late_elem.style.width = vals[6] + 'px';
if (vals[6] == '0') {
late_elem.className = 'task task_none';
} else {
late_elem.className = 'task task_late';
}
}
var done_elem = document.getElementById('task_done_' + elem_id);
if (done_elem) {
done_elem.style.width = vals[7] + 'px';
if (vals[7] == '0') {
done_elem.className = 'task task_none';
} else {
done_elem.className = 'task task_done';
}
}
var task_elem = document.getElementById('task_task_' + elem_id);
if (task_elem) {
task_elem.style.left = (parseInt(vals[5])+5) + 'px';
}
var tooltip = document.getElementById("tt_" + elem_id);
tooltip.style.left = ev_elem.style.left;
//change calendar date
document.getElementById(elem_id+"_hidden_start_date").value = vals[1];
document.getElementById(elem_id+"_start_date").value = vals[1];
document.getElementById(elem_id+"_hidden_due_date").value = vals[3];
document.getElementById(elem_id+"_due_date").value = vals[3];
}
</script>
<table width="100%" style="border:0; border-collapse: collapse;">
<tr>
<td style="width:<%= subject_width %>px; padding:0px;">
......
#
top = headers_height + 8
@gantt.events.each do |i| %>
<div style="position: absolute;line-height:1.2em;height:16px;top:<%= top %>px;left:4px;overflow:hidden;"><small>
<div style="position: absolute;line-height:1.2em;height:16px;top:<%= top %>px;left:4px;overflow:hidden;"><small>
<% if i.is_a? Issue %>
<%= h("#{i.project} -") unless @project && @project == i.project %>
<%= link_to_issue i %>: <%=h i.subject %>
......
<%= h("#{i.project} -") unless @project && @project == i.project %>
<%= link_to_version i %>
</span>
<% end %>
<% end %>
</small></div>
<% top = top + 20
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>
<% if i.is_a? Issue %>
<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%>_hidden_start_date" value="<%= i.start_date %>">
<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 %>
<script type="text/javascript">
//<![CDATA[
new Form.Element.Observer('<%=i.id%>_start_date', 0.25,
function(element, value) {
if (value == document.getElementById('<%=i.id%>_hidden_start_date').value) {
return ;
}
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)});
})
//]]>
</script>
<span id="<%=i.id%>_due_date_str" style="font-size: 7pt;<%= "color: blue;" unless i.due_date%>">
<%= format_date(i.due_before) %>
</span>
<input type="hidden" size="12" id="<%=i.id%>_hidden_due_date" value="<%= i.due_date %>">
<input type="hidden" size="12" id="<%=i.id%>_due_date" value="<%= i.due_date %>"><%= calendar_for("#{i.id}_due_date") if i.due_date%>
<script type="text/javascript">
//<![CDATA[
new Form.Element.Observer('<%=i.id%>_due_date', 0.25,
function(element, value) {
if (value == document.getElementById('<%=i.id%>_hidden_due_date').value) {
return ;
}
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)});
})
//]]>
</script>
<% else %>
<span style="font-size: 7pt;"><%= format_date(i.start_date) %></span>
<% 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>
<%
<%
#
# Months headers
#
month_f = @gantt.date_from
left = 0
height = (show_weeks ? header_heigth : header_heigth + g_height)
@gantt.months.times do
@gantt.months.times do
width = ((month_f >> 1) - month_f) * zoom - 1
%>
<div style="left:<%= left %>px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">
<%= 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}"%>
</div>
<%
<%
left = left + width + 1
month_f = month_f >> 1
end %>
<%
<%
#
# Weeks headers
#
......
width = (7 - @gantt.date_from.cwday + 1) * zoom-1
%>
<div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">&nbsp;</div>
<%
<%
left = left + width+1
end %>
<%
......
<div style="left:<%= left %>px;top:19px;width:<%= width %>px;height:<%= height %>px;" class="gantt_hdr">
<small><%= week_f.cweek if width >= 16 %></small>
</div>
<%
<%
left = left + width+1
week_f = week_f+7
end
end %>
<%
<%
#
# Days headers
#
......
left = 0
height = g_height + header_heigth - 1
wday = @gantt.date_from.cwday
(@gantt.date_to - @gantt.date_from + 1).to_i.times do
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 %>
......
# Tasks
#
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
@gantt.events.each do |i|
if i.is_a? Issue
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:0px; width:<%= i_width %>px;" class="task task_todo">&nbsp;</div>
<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>
<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>
<div id="task_task_<%=i.id%>" style="position:absolute;left:<%= (i_width + 5) %>px;background:#fff;" class="task">
<%= h(i.status.name) %>
<%= (i.done_ratio).to_i %>%
<% if !i.due_date && i.fixed_version %>
-&nbsp;<strong><%= h(i.fixed_version.name) %></strong>
<% end %>
</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>
<% else
<%= 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>
public/stylesheets/application.css (working copy)
.task_late { background:#f66 url(../images/task_late.png); border: 1px solid #f66; }
.task_done { background:#66f url(../images/task_done.png); border: 1px solid #66f; }
.task_todo { background:#aaa url(../images/task_todo.png); border: 1px solid #aaa; }
.task_none { background:transparent; border-style: none; }
.task_none { background:transparent; border-style: none; }
.milestone { background-image:url(../images/milestone.png); background-repeat: no-repeat; border: 0; }
/***** Icons *****/
(5-5/35)