65 |
65 |
@date_to = (@date_from >> @months) - 1
|
66 |
66 |
@subjects = ''
|
67 |
67 |
@lines = ''
|
|
68 |
@calendars = ''
|
68 |
69 |
@number_of_rows = nil
|
69 |
70 |
@issue_ancestors = []
|
70 |
71 |
@truncated = false
|
... | ... | |
121 |
122 |
@lines
|
122 |
123 |
end
|
123 |
124 |
|
|
125 |
# Renders the calendars of the Gantt chart, the right side
|
|
126 |
def calendars(options={})
|
|
127 |
render(options.merge(:only => :calendars)) unless @calendars_rendered
|
|
128 |
@calendars
|
|
129 |
end
|
|
130 |
|
124 |
131 |
# Returns issues that will be rendered
|
125 |
132 |
def issues
|
126 |
133 |
@issues ||= @query.issues(
|
... | ... | |
165 |
172 |
def render(options={})
|
166 |
173 |
options = {:top => 0, :top_increment => 20, :indent_increment => 20, :render => :subject, :format => :html}.merge(options)
|
167 |
174 |
indent = options[:indent] || 4
|
168 |
|
@subjects = '' unless options[:only] == :lines
|
169 |
|
@lines = '' unless options[:only] == :subjects
|
|
175 |
if options[:format] == :html
|
|
176 |
@subjects = '' unless options[:only] == :lines && options[:only] == :calendars
|
|
177 |
@lines = '' unless options[:only] == :subjects && options[:only] == :calendars
|
|
178 |
@calendars = '' unless options[:only] == :lines && options[:only] == :subjects
|
|
179 |
else
|
|
180 |
@subjects = '' unless options[:only] == :lines
|
|
181 |
@lines = '' unless options[:only] == :subjects
|
|
182 |
end
|
170 |
183 |
@number_of_rows = 0
|
171 |
184 |
Project.project_tree(projects) do |project, level|
|
172 |
185 |
options[:indent] = indent + level * options[:indent_increment]
|
173 |
186 |
render_project(project, options)
|
174 |
187 |
break if abort?
|
175 |
188 |
end
|
176 |
|
@subjects_rendered = true unless options[:only] == :lines
|
177 |
|
@lines_rendered = true unless options[:only] == :subjects
|
|
189 |
if options[:format] == :html
|
|
190 |
@subjects_rendered = true unless options[:only] == :lines && options[:only] == :calendars
|
|
191 |
@lines_rendered = true unless options[:only] == :subjects && options[:only] == :calendars
|
|
192 |
@calendars_rendered = true unless options[:only] == :lines && options[:only] == :subjects
|
|
193 |
else
|
|
194 |
@subjects_rendered = true unless options[:only] == :lines
|
|
195 |
@lines_rendered = true unless options[:only] == :subjects
|
|
196 |
end
|
178 |
197 |
render_end(options)
|
179 |
198 |
end
|
180 |
199 |
|
181 |
200 |
def render_project(project, options={})
|
182 |
|
subject_for_project(project, options) unless options[:only] == :lines
|
183 |
|
line_for_project(project, options) unless options[:only] == :subjects
|
|
201 |
if options[:format] == :html
|
|
202 |
subject_for_project(project, options) unless options[:only] == :lines && options[:only] == :calendars
|
|
203 |
line_for_project(project, options) unless options[:only] == :subjects && options[:only] == :calendars
|
|
204 |
calendar_for_project(project, options) unless options[:only] == :lines && options[:only] == :subjects
|
|
205 |
else
|
|
206 |
subject_for_project(project, options) unless options[:only] == :lines
|
|
207 |
line_for_project(project, options) unless options[:only] == :subjects
|
|
208 |
end
|
184 |
209 |
options[:top] += options[:top_increment]
|
185 |
210 |
options[:indent] += options[:indent_increment]
|
186 |
211 |
@number_of_rows += 1
|
... | ... | |
202 |
227 |
def render_issues(issues, options={})
|
203 |
228 |
@issue_ancestors = []
|
204 |
229 |
issues.each do |i|
|
205 |
|
subject_for_issue(i, options) unless options[:only] == :lines
|
206 |
|
line_for_issue(i, options) unless options[:only] == :subjects
|
|
230 |
if options[:format] == :html
|
|
231 |
subject_for_issue(i, options) unless options[:only] == :lines && options[:only] == :calendars
|
|
232 |
line_for_issue(i, options) unless options[:only] == :subjects && options[:only] == :calendars
|
|
233 |
calendar_for_issue(i, options) unless options[:only] == :lines && options[:only] == :subjects
|
|
234 |
else
|
|
235 |
subject_for_issue(i, options) unless options[:only] == :lines
|
|
236 |
line_for_issue(i, options) unless options[:only] == :subjects
|
|
237 |
end
|
207 |
238 |
options[:top] += options[:top_increment]
|
208 |
239 |
@number_of_rows += 1
|
209 |
240 |
break if abort?
|
... | ... | |
213 |
244 |
|
214 |
245 |
def render_version(project, version, options={})
|
215 |
246 |
# Version header
|
216 |
|
subject_for_version(version, options) unless options[:only] == :lines
|
217 |
|
line_for_version(version, options) unless options[:only] == :subjects
|
|
247 |
if options[:format] == :html
|
|
248 |
subject_for_version(version, options) unless options[:only] == :lines && options[:only] == :calendars
|
|
249 |
line_for_version(version, options) unless options[:only] == :subjects && options[:only] == :calendars
|
|
250 |
calendar_for_version(version, options) unless options[:only] == :lines && options[:only] == :subjects
|
|
251 |
else
|
|
252 |
subject_for_version(version, options) unless options[:only] == :lines
|
|
253 |
line_for_version(version, options) unless options[:only] == :subjects
|
|
254 |
end
|
218 |
255 |
options[:top] += options[:top_increment]
|
219 |
256 |
@number_of_rows += 1
|
220 |
257 |
return if abort?
|
... | ... | |
259 |
296 |
label = h(project)
|
260 |
297 |
case options[:format]
|
261 |
298 |
when :html
|
262 |
|
html_task(options, coords, :css => "project task", :label => label, :markers => true)
|
|
299 |
html_task(options, coords, :css => "project task", :label => label, :markers => true, :id => project.id, :kind => "p")
|
263 |
300 |
when :image
|
264 |
301 |
image_task(options, coords, :label => label, :markers => true, :height => 3)
|
265 |
302 |
when :pdf
|
... | ... | |
296 |
333 |
label = h("#{version.project} -") + label unless @project && @project == version.project
|
297 |
334 |
case options[:format]
|
298 |
335 |
when :html
|
299 |
|
html_task(options, coords, :css => "version task", :label => label, :markers => true)
|
|
336 |
html_task(options, coords, :css => "version task", :label => label, :markers => true, :id => version.id, :kind => "v")
|
300 |
337 |
when :image
|
301 |
338 |
image_task(options, coords, :label => label, :markers => true, :height => 3)
|
302 |
339 |
when :pdf
|
... | ... | |
346 |
383 |
if issue.is_a?(Issue) && issue.due_before
|
347 |
384 |
coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom])
|
348 |
385 |
label = "#{ issue.status.name } #{ issue.done_ratio }%"
|
|
386 |
if !issue.due_date && issue.fixed_version
|
|
387 |
if options[:format] == :html
|
|
388 |
label += "- <strong>#{h(issue.fixed_version.name)}</strong>"
|
|
389 |
else
|
|
390 |
label += "-#{h(issue.fixed_version.name)}"
|
|
391 |
end
|
|
392 |
end
|
349 |
393 |
case options[:format]
|
350 |
394 |
when :html
|
351 |
|
html_task(options, coords, :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), :label => label, :issue => issue, :markers => !issue.leaf?)
|
|
395 |
html_task(options, coords, :css => "task " + (issue.leaf? ? 'leaf' : 'parent'),
|
|
396 |
:label => label, :issue => issue, :markers => !issue.leaf?, :id => issue.id, :kind => "i")
|
352 |
397 |
when :image
|
353 |
398 |
image_task(options, coords, :label => label)
|
354 |
399 |
when :pdf
|
... | ... | |
568 |
613 |
pdf.Output
|
569 |
614 |
end
|
570 |
615 |
|
|
616 |
def edit(pms)
|
|
617 |
id = pms[:id]
|
|
618 |
kind = id.slice!(0).chr
|
|
619 |
begin
|
|
620 |
case kind
|
|
621 |
when 'i'
|
|
622 |
@issue = Issue.find(pms[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
|
|
623 |
when 'p'
|
|
624 |
@issue = Project.find(pms[:id])
|
|
625 |
when 'v'
|
|
626 |
@issue = Version.find(pms[:id], :include => [:project])
|
|
627 |
end
|
|
628 |
rescue ActiveRecord::RecordNotFound
|
|
629 |
return "issue not found : #{pms[:id]}", 400
|
|
630 |
end
|
|
631 |
|
|
632 |
if !@issue.start_date || !@issue.due_before
|
|
633 |
#render :text=>l(:notice_locking_conflict), :status=>400
|
|
634 |
return l(:notice_locking_conflict), 400
|
|
635 |
end
|
|
636 |
@issue.init_journal(User.current)
|
|
637 |
date_from = Date.parse(pms[:date_from])
|
|
638 |
old_start_date = @issue.start_date
|
|
639 |
o = get_issue_position(@issue, pms[:zoom])
|
|
640 |
text_for_revert = "#{kind}#{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]}".html_safe
|
|
641 |
|
|
642 |
if pms[:day]
|
|
643 |
#bar moved
|
|
644 |
day = pms[:day].to_i
|
|
645 |
duration = @issue.due_before - @issue.start_date
|
|
646 |
@issue.start_date = date_from + day
|
|
647 |
@issue.due_date = @issue.start_date + duration.to_i if @issue.due_date
|
|
648 |
elsif pms[:start_date]
|
|
649 |
#start date changed
|
|
650 |
start_date = Date.parse(pms[:start_date])
|
|
651 |
if @issue.start_date == start_date
|
|
652 |
#render :text=>""
|
|
653 |
return "", 200 #nothing has changed
|
|
654 |
end
|
|
655 |
@issue.start_date = start_date
|
|
656 |
@issue.due_date = start_date if @issue.due_date && start_date > @issue.due_date
|
|
657 |
elsif pms[:due_date]
|
|
658 |
#due date changed
|
|
659 |
due_date = Date.parse(pms[:due_date])
|
|
660 |
if @issue.due_date == due_date
|
|
661 |
#render :text=>""
|
|
662 |
return "", 200 #nothing has changed
|
|
663 |
end
|
|
664 |
@issue.due_date = due_date
|
|
665 |
@issue.start_date = due_date if due_date < @issue.start_date
|
|
666 |
end
|
|
667 |
fv = @issue.fixed_version
|
|
668 |
if fv && fv.effective_date && !@issue.due_date && fv.effective_date < @issue.start_date
|
|
669 |
@issue.start_date = old_start_date
|
|
670 |
end
|
|
671 |
|
|
672 |
begin
|
|
673 |
@issue.save!
|
|
674 |
o = get_issue_position(@issue, pms[:zoom])
|
|
675 |
text = "#{kind}#{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]}".html_safe
|
|
676 |
|
|
677 |
prj_map = {}
|
|
678 |
text = set_project_data(@issue.project, pms[:zoom], text, prj_map)
|
|
679 |
version_map = {}
|
|
680 |
text = set_version_data(@issue.fixed_version, pms[:zoom], text, version_map)
|
|
681 |
|
|
682 |
#check dependencies
|
|
683 |
issues = @issue.all_precedes_issues
|
|
684 |
issues.each do |i|
|
|
685 |
o = get_issue_position(i, pms[:zoom])
|
|
686 |
text += "|i#{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]}".html_safe
|
|
687 |
text = set_project_data(i.project, pms[:zoom], text, prj_map)
|
|
688 |
text = set_version_data(i.fixed_version, pms[:zoom], text, version_map)
|
|
689 |
end
|
|
690 |
|
|
691 |
#check parent
|
|
692 |
is = @issue
|
|
693 |
while
|
|
694 |
pid = is.parent_issue_id
|
|
695 |
break if !pid
|
|
696 |
i = Issue.find(pid)
|
|
697 |
o = get_issue_position(i, pms[:zoom])
|
|
698 |
text += "|i#{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]},#{o[4]},#{o[5]}".html_safe
|
|
699 |
text = set_project_data(i.project, pms[:zoom], text, prj_map)
|
|
700 |
text = set_version_data(i.fixed_version, pms[:zoom], text, version_map)
|
|
701 |
is = i
|
|
702 |
end
|
|
703 |
#render :text=>text
|
|
704 |
return text, 200
|
|
705 |
rescue => e
|
|
706 |
#render :text=>@issue.errors.full_messages.join("\n") + "|" + text_for_revert , :status=>400
|
|
707 |
if @issue.errors.full_messages.to_s == ""
|
|
708 |
return e.to_s + "\n" + [$!,$@.join("\n")].join("\n") + "\n" + @issue.errors.full_messages.join("\n") + "|" + text_for_revert, 400
|
|
709 |
else
|
|
710 |
return @issue.errors.full_messages.join("\n") + "|" + text_for_revert, 400
|
|
711 |
end
|
|
712 |
end
|
|
713 |
end
|
|
714 |
|
571 |
715 |
private
|
572 |
716 |
|
573 |
717 |
def coordinates(start_date, end_date, progress, zoom=nil)
|
... | ... | |
681 |
825 |
output = ''
|
682 |
826 |
# Renders the task bar, with progress and late
|
683 |
827 |
if coords[:bar_start] && coords[:bar_end]
|
684 |
|
output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_todo'> </div>".html_safe
|
|
828 |
i_width = coords[:bar_end] - coords[:bar_start] - 2
|
|
829 |
output << "<div id='ev_#{options[:kind]}#{options[:id]}' style='position:absolute;left:#{coords[:bar_start]}px;top:#{params[:top]}px;padding-top:3px;height:18px;width:#{ i_width + 100}px;' #{options[:kind] == 'i' ? "class='handle'" : ""}>".html_safe
|
|
830 |
output << "<div id='task_todo_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:#{ i_width}px;' class='#{options[:css]} task_todo'> </div>".html_safe
|
685 |
831 |
if coords[:bar_late_end]
|
686 |
|
output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_late_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_late'> </div>".html_safe
|
|
832 |
l_width = coords[:bar_late_end] - coords[:bar_start] - 2
|
|
833 |
output << "<div id='task_late_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:#{ l_width}px;' class='#{ l_width == 0 ? options[:css] + " task_none" : options[:css] + " task_late"}'> </div>".html_safe
|
|
834 |
else
|
|
835 |
output << "<div id='task_late_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'> </div>".html_safe
|
687 |
836 |
end
|
688 |
837 |
if coords[:bar_progress_end]
|
689 |
|
output << "<div style='top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_progress_end] - coords[:bar_start] - 2}px;' class='#{options[:css]} task_done'> </div>".html_safe
|
|
838 |
d_width = coords[:bar_progress_end] - coords[:bar_start] - 2
|
|
839 |
output << "<div id='task_done_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:#{ d_width}px;' class='#{ d_width == 0 ? options[:css] + " task_none" : options[:css] + " task_done"}'> </div>".html_safe
|
|
840 |
else
|
|
841 |
output << "<div id='task_done_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'> </div>".html_safe
|
690 |
842 |
end
|
|
843 |
output << "</div>".html_safe
|
|
844 |
else
|
|
845 |
output << "<div id='ev_#{options[:kind]}#{options[:id]}' style='position:absolute;left:0px;top:#{params[:top]}px;padding-top:3px;height:18px;width:0px;' #{options[:kind] == 'i' ? "class='handle'" : ""}>".html_safe
|
|
846 |
output << "<div id='task_todo_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css]} task_todo'> </div>".html_safe
|
|
847 |
output << "<div id='task_late_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'> </div>".html_safe
|
|
848 |
output << "<div id='task_done_#{options[:kind]}#{options[:id]}' style='float:left:0px; width:0px;' class='#{ options[:css] + " task_none"}'> </div>".html_safe
|
|
849 |
output << "</div>".html_safe
|
691 |
850 |
end
|
692 |
851 |
# Renders the markers
|
693 |
852 |
if options[:markers]
|
694 |
853 |
if coords[:start]
|
695 |
|
output << "<div style='top:#{ params[:top] }px;left:#{ coords[:start] }px;width:15px;' class='#{options[:css]} marker starting'> </div>".html_safe
|
|
854 |
output << "<div id='marker_start_#{options[:kind]}#{options[:id]}' style='top:#{ params[:top] }px;left:#{ coords[:start] }px;width:15px;' class='#{options[:css]} marker starting'> </div>".html_safe
|
696 |
855 |
end
|
697 |
856 |
if coords[:end]
|
698 |
|
output << "<div style='top:#{ params[:top] }px;left:#{ coords[:end] + params[:zoom] }px;width:15px;' class='#{options[:css]} marker ending'> </div>".html_safe
|
|
857 |
output << "<div id='marker_end_#{options[:kind]}#{options[:id]}' style='top:#{ params[:top] }px;left:#{ coords[:end] + params[:zoom] }px;width:15px;' class='#{options[:css]} marker ending'> </div>".html_safe
|
699 |
858 |
end
|
|
859 |
else
|
|
860 |
output << view.draggable_element("ev_#{options[:kind]}#{options[:id]}", :revert =>false, :scroll=>"'gantt-container'", :constraint => "'horizontal'", :snap=>params[:zoom],:onEnd=>'function( draggable, event ) {issue_moved(draggable.element);}') #pend
|
700 |
861 |
end
|
701 |
862 |
# Renders the label on the right
|
702 |
863 |
if options[:label]
|
703 |
|
output << "<div style='top:#{ params[:top] }px;left:#{ (coords[:bar_end] || 0) + 8 }px;' class='#{options[:css]} label'>".html_safe
|
|
864 |
output << "<div id='label_#{options[:kind]}#{options[:id]}' style='top:#{ params[:top] }px;left:#{ (coords[:bar_end] || 0) + 8 }px;' class='#{options[:css]} label'>".html_safe
|
704 |
865 |
output << options[:label]
|
705 |
866 |
output << "</div>".html_safe
|
706 |
867 |
end
|
707 |
868 |
# Renders the tooltip
|
708 |
869 |
if options[:issue] && coords[:bar_start] && coords[:bar_end]
|
709 |
|
output << "<div class='tooltip' style='position: absolute;top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_end] - coords[:bar_start] }px;height:12px;'>".html_safe
|
|
870 |
output << "<div id='tt_#{options[:kind]}#{options[:id]}' class='tooltip' style='position: absolute;top:#{ params[:top] }px;left:#{ coords[:bar_start] }px;width:#{ coords[:bar_end] - coords[:bar_start] }px;height:12px;'>".html_safe
|
710 |
871 |
output << '<span class="tip">'.html_safe
|
711 |
872 |
output << view.render_issue_tooltip(options[:issue]).html_safe
|
712 |
873 |
output << "</span></div>".html_safe
|
... | ... | |
794 |
955 |
params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5,params[:top] + 1, options[:label])
|
795 |
956 |
end
|
796 |
957 |
end
|
|
958 |
|
|
959 |
## for edit gantt
|
|
960 |
def set_project_data(prj, zoom, text, prj_map = {})
|
|
961 |
if !prj
|
|
962 |
return text
|
|
963 |
end
|
|
964 |
if !prj_map[prj.id]
|
|
965 |
o = get_project_position(prj, zoom)
|
|
966 |
text += "|p#{prj.id}=#{format_date(prj.start_date)},#{prj.start_date},#{format_date(prj.due_date)},#{prj.due_date},#{o[0]},#{o[1]},#{o[2]},#{o[3]},#{o[4]},#{o[5]}"
|
|
967 |
prj_map[prj.id] = prj
|
|
968 |
end
|
|
969 |
text = set_project_data(prj.parent, zoom, text, prj_map)
|
|
970 |
end
|
|
971 |
|
|
972 |
def set_version_data(version, zoom, text, version_map = {})
|
|
973 |
if !version
|
|
974 |
return text
|
|
975 |
end
|
|
976 |
if !version_map[version.id]
|
|
977 |
o = get_version_position(version, zoom)
|
|
978 |
text += "|v#{version.id}=#{format_date(version.start_date)},#{version.start_date},#{format_date(version.due_date)},#{version.due_date},#{o[0]},#{o[1]},#{o[2]},#{o[3]},#{o[4]},#{o[5]}"
|
|
979 |
version_map[version.id] = version
|
|
980 |
end
|
|
981 |
return text
|
|
982 |
end
|
|
983 |
|
|
984 |
def get_pos(coords)
|
|
985 |
i_left = 0
|
|
986 |
i_width = 0
|
|
987 |
l_width = 0
|
|
988 |
d_width = 0
|
|
989 |
if coords[:bar_start]
|
|
990 |
i_left = coords[:bar_start]
|
|
991 |
if coords[:bar_end]
|
|
992 |
i_width = coords[:bar_end] - coords[:bar_start] - 2
|
|
993 |
i_width = 0 if i_width < 0
|
|
994 |
end
|
|
995 |
if coords[:bar_late_end]
|
|
996 |
l_width = coords[:bar_late_end] - coords[:bar_start] - 2
|
|
997 |
end
|
|
998 |
if coords[:bar_progress_end]
|
|
999 |
d_width = coords[:bar_progress_end] - coords[:bar_start] - 2
|
|
1000 |
end
|
|
1001 |
end
|
|
1002 |
return i_left, i_width, l_width, d_width
|
|
1003 |
end
|
|
1004 |
|
|
1005 |
def get_issue_position(issue, zoom_str)
|
|
1006 |
z = zoom_str.to_i
|
|
1007 |
zoom = 1
|
|
1008 |
z.times { zoom = zoom * 2}
|
|
1009 |
id = issue.due_before
|
|
1010 |
if id && @date_to < id
|
|
1011 |
id = @date_to
|
|
1012 |
end
|
|
1013 |
coords = coordinates(issue.start_date, id, issue.done_ratio, zoom)
|
|
1014 |
|
|
1015 |
i_left, i_width, l_width, d_width = get_pos(coords)
|
|
1016 |
if coords[:end]
|
|
1017 |
return i_left, i_width, l_width, d_width, coords[:start], coords[:end] + zoom
|
|
1018 |
else
|
|
1019 |
return i_left, i_width, l_width, d_width, coords[:start], nil
|
|
1020 |
end
|
|
1021 |
end
|
|
1022 |
|
|
1023 |
def get_project_position(project, zoom_str)
|
|
1024 |
z = zoom_str.to_i
|
|
1025 |
zoom = 1
|
|
1026 |
z.times { zoom = zoom * 2}
|
|
1027 |
pd = project.due_date
|
|
1028 |
if pd && @date_to < pd
|
|
1029 |
pd = @date_to
|
|
1030 |
end
|
|
1031 |
coords = coordinates(project.start_date, pd, nil, zoom)
|
|
1032 |
i_left, i_width, l_width, d_width = get_pos(coords)
|
|
1033 |
if coords[:end]
|
|
1034 |
return i_left, i_width, l_width, d_width, coords[:start], coords[:end] + zoom
|
|
1035 |
else
|
|
1036 |
return i_left, i_width, l_width, d_width, coords[:start], nil
|
|
1037 |
end
|
|
1038 |
end
|
|
1039 |
|
|
1040 |
def get_version_position(version, zoom_str)
|
|
1041 |
z = zoom_str.to_i
|
|
1042 |
zoom = 1
|
|
1043 |
z.times { zoom = zoom * 2}
|
|
1044 |
vd = version.due_date
|
|
1045 |
if vd && @date_to < vd
|
|
1046 |
vd = @date_to
|
|
1047 |
end
|
|
1048 |
coords = coordinates(version.start_date, vd, version.completed_pourcent, zoom)
|
|
1049 |
i_left, i_width, l_width, d_width = get_pos(coords)
|
|
1050 |
if coords[:end]
|
|
1051 |
return i_left, i_width, l_width, d_width, coords[:start], coords[:end] + zoom
|
|
1052 |
else
|
|
1053 |
return i_left, i_width, l_width, d_width, coords[:start], nil
|
|
1054 |
end
|
|
1055 |
end
|
|
1056 |
|
|
1057 |
def calendar_for_issue(issue, options)
|
|
1058 |
# Skip issues that don't have a due_before (due_date or version's due_date)
|
|
1059 |
if issue.is_a?(Issue) && issue.due_before
|
|
1060 |
|
|
1061 |
case options[:format]
|
|
1062 |
when :html
|
|
1063 |
@calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;width:180px;'>"
|
|
1064 |
start_date = issue.start_date
|
|
1065 |
if start_date
|
|
1066 |
@calendars << "<div style='float: left; line-height: 1em; width: 90px;'>"
|
|
1067 |
@calendars << "<span id='i#{issue.id}_start_date_str'>"
|
|
1068 |
@calendars << format_date(start_date)
|
|
1069 |
@calendars << "</span>"
|
|
1070 |
@calendars << "<input type='hidden' size='12' id='i#{issue.id}_hidden_start_date' value='#{start_date}' />"
|
|
1071 |
if issue.leaf?
|
|
1072 |
@calendars << "<input type='hidden' size='12' id='i#{issue.id}_start_date' value='#{start_date}' />#{view.gantt_calendar_for('i' + issue.id.to_s + '_start_date')}"
|
|
1073 |
else
|
|
1074 |
@calendars << "<input type='hidden' size='12' id='i#{issue.id}_start_date' value='#{start_date}' /> "
|
|
1075 |
end
|
|
1076 |
@calendars << observe_date_field("i#{issue.id}", 'start')
|
|
1077 |
@calendars << "</div>"
|
|
1078 |
end
|
|
1079 |
due_date = issue.due_date
|
|
1080 |
if due_date
|
|
1081 |
@calendars << "<div style='float: right; line-height: 1em; width: 90px;'>"
|
|
1082 |
@calendars << "<span id='i#{issue.id}_due_date_str'>"
|
|
1083 |
@calendars << format_date(due_date)
|
|
1084 |
@calendars << "</span>"
|
|
1085 |
@calendars << "<input type='hidden' size='12' id='i#{issue.id}_hidden_due_date' value='#{due_date}' />"
|
|
1086 |
if issue.leaf?
|
|
1087 |
@calendars << "<input type='hidden' size='12' id='i#{issue.id}_due_date' value='#{due_date}' />#{view.gantt_calendar_for('i' + issue.id.to_s + '_due_date')}"
|
|
1088 |
else
|
|
1089 |
@calendars << "<input type='hidden' size='12' id='i#{issue.id}_due_date' value='#{due_date}' />"
|
|
1090 |
end
|
|
1091 |
@calendars << observe_date_field("i#{issue.id}", 'due')
|
|
1092 |
@calendars << "</div>"
|
|
1093 |
else
|
|
1094 |
@calendars << "<div style='float: right; line-height: 1em; width: 90px;'>"
|
|
1095 |
@calendars << "<span id='i#{issue.id}_due_date_str'>"
|
|
1096 |
@calendars << "Not set"
|
|
1097 |
@calendars << "</span>"
|
|
1098 |
@calendars << "<input type='hidden' size='12' id='i#{issue.id}_hidden_due_date' value='#{start_date}' />"
|
|
1099 |
if issue.leaf?
|
|
1100 |
@calendars << "<input type='hidden' size='12' id='i#{issue.id}_due_date' value='#{start_date}' />#{view.gantt_calendar_for('i' + issue.id.to_s + '_due_date')}"
|
|
1101 |
else
|
|
1102 |
@calendars << "<input type='hidden' size='12' id='i#{issue.id}_due_date' value='#{start_date}' />"
|
|
1103 |
end
|
|
1104 |
@calendars << observe_date_field("i#{issue.id}", 'due')
|
|
1105 |
@calendars << "</div>"
|
|
1106 |
end
|
|
1107 |
|
|
1108 |
@calendars << "</div>"
|
|
1109 |
when :image
|
|
1110 |
#nop
|
|
1111 |
when :pdf
|
|
1112 |
#nop
|
|
1113 |
end
|
|
1114 |
else
|
|
1115 |
ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before"
|
|
1116 |
''
|
|
1117 |
end
|
|
1118 |
end
|
|
1119 |
|
|
1120 |
def calendar_for_version(version, options)
|
|
1121 |
# Skip version that don't have a due_before (due_date or version's due_date)
|
|
1122 |
if version.is_a?(Version) && version.start_date && version.due_date
|
|
1123 |
|
|
1124 |
case options[:format]
|
|
1125 |
when :html
|
|
1126 |
@calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;'>"
|
|
1127 |
@calendars << "<span id='v#{version.id}_start_date_str'>"
|
|
1128 |
@calendars << format_date(version.effective_date)
|
|
1129 |
@calendars << "</span>"
|
|
1130 |
@calendars << "</div>"
|
|
1131 |
when :image
|
|
1132 |
#nop
|
|
1133 |
when :pdf
|
|
1134 |
#nop
|
|
1135 |
end
|
|
1136 |
else
|
|
1137 |
ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before"
|
|
1138 |
''
|
|
1139 |
end
|
|
1140 |
end
|
|
1141 |
|
|
1142 |
def calendar_for_project(project, options)
|
|
1143 |
case options[:format]
|
|
1144 |
when :html
|
|
1145 |
@calendars << "<div style='position: absolute;line-height:1.2em;height:16px;top:#{options[:top]}px;left:4px;overflow:hidden;width:180px;'>"
|
|
1146 |
@calendars << "<div style='float:left;width:90px;'>"
|
|
1147 |
@calendars << "<span id='p#{project.id}_start_date_str'>"
|
|
1148 |
@calendars << format_date(project.start_date) if project.start_date
|
|
1149 |
@calendars << "</span>"
|
|
1150 |
@calendars << "</div>"
|
|
1151 |
@calendars << "<div style='float:right;width:90px;'>"
|
|
1152 |
@calendars << "<span id='p#{project.id}_due_date_str'>"
|
|
1153 |
@calendars << format_date(project.due_date) if project.due_date
|
|
1154 |
@calendars << "</span>"
|
|
1155 |
@calendars << "</div>"
|
|
1156 |
@calendars << "</div>"
|
|
1157 |
when :image
|
|
1158 |
# nop
|
|
1159 |
when :pdf
|
|
1160 |
# nop
|
|
1161 |
end
|
|
1162 |
end
|
|
1163 |
|
|
1164 |
def observe_date_field(id, type)
|
|
1165 |
output = ''
|
|
1166 |
prj_id = ''
|
|
1167 |
prj_id = @project.to_param if @project
|
|
1168 |
output << "<script type='text/javascript'>\n"
|
|
1169 |
output << "//<![CDATA[\n"
|
|
1170 |
output << "new Form.Element.Observer('#{id}_#{type}_date', 0.25,\n"
|
|
1171 |
output << " function(element, value) {\n"
|
|
1172 |
output << " if (value == document.getElementById('#{id}_hidden_#{type}_date').value) {\n"
|
|
1173 |
output << " return ;\n"
|
|
1174 |
output << " }\n"
|
|
1175 |
output << " new Ajax.Request('#{view.url_for(:controller=>:gantts, :action => :edit_gantt, :id=>id, :date_from=>self.date_from.strftime("%Y-%m-%d"), :date_to=>self.date_to.strftime("%Y-%m-%d"), :zoom=>self.zoom, :escape => false, :project_id=>prj_id)}', {asynchronous:true, evalScripts:true, onFailure:function(request){handle_failure(request.responseText)}, onSuccess:function(request){change_dates(request.responseText)}, parameters:'#{type}_date=' + encodeURIComponent(value)});"
|
|
1176 |
output << " })\n"
|
|
1177 |
output << "//]]>\n"
|
|
1178 |
output << "</script>"
|
|
1179 |
end
|
797 |
1180 |
end
|
798 |
1181 |
end
|
799 |
1182 |
end
|