Index: app/controllers/gantts_controller.rb =================================================================== --- app/controllers/gantts_controller.rb (revision 4883) +++ app/controllers/gantts_controller.rb (working copy) @@ -33,4 +33,34 @@ show end + def edit_gantt + date_from = Date.parse(params[:date_from]) + date_to = Date.parse(params[:date_to]) + months = date_to.month - date_from.month + 1 + params[:year] = date_from.year + params[:month] = date_from.month + params[:months] = months + @gantt = Redmine::Helpers::Gantt.new(params) + @gantt.project = @project + text, status = @gantt.edit(params) + render :text=>text, :status=>status + end + + def find_optional_project + begin + if params[:action] && params[:action].to_s == "edit_gantt" + @project = Project.find(params[:project_id]) unless params[:project_id].blank? + allowed = User.current.allowed_to?(:edit_issues, @project, :global => true) + if allowed + return true + else + render :text=>"lack of permission to edit issues", :status=>403 + end + else + super + end + rescue => e + return e.to_s + "\n===\n" + [$!,$@.join("\n")].join("\n") + end + end end Index: app/helpers/application_helper.rb =================================================================== --- app/helpers/application_helper.rb (revision 4883) +++ app/helpers/application_helper.rb (working copy) @@ -828,6 +828,12 @@ javascript_tag("Calendar.setup({inputField : '#{field_id}', ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });") end + def g_calendar_for(field_id) + include_calendar_headers_tags + image_tag("calendar.png", {:id => "#{field_id}_trigger",:class => "calendar-trigger"}) + + javascript_tag("Calendar.setup({inputField : '#{field_id}', electric : false, ifFormat : '%Y-%m-%d', button : '#{field_id}_trigger' });") + end + def include_calendar_headers_tags unless @calendar_headers_tags_included @calendar_headers_tags_included = true Index: app/helpers/issues_helper.rb =================================================================== --- app/helpers/issues_helper.rb (revision 4883) +++ app/helpers/issues_helper.rb (working copy) @@ -49,8 +49,8 @@ link_to_issue(issue) + "

" + "#{@cached_label_project}: #{link_to_project(issue.project)}
" + "#{@cached_label_status}: #{issue.status.name}
" + - "#{@cached_label_start_date}: #{format_date(issue.start_date)}
" + - "#{@cached_label_due_date}: #{format_date(issue.due_date)}
" + + "#{@cached_label_start_date}: #{format_date(issue.start_date)}
" + + "#{@cached_label_due_date}: #{format_date(issue.due_date)}
" + "#{@cached_label_assigned_to}: #{issue.assigned_to}
" + "#{@cached_label_priority}: #{issue.priority.name}" end Index: app/models/issue.rb =================================================================== --- app/models/issue.rb (revision 4883) +++ app/models/issue.rb (working copy) @@ -465,6 +465,16 @@ 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 relations_to.select {|r| r.relation_type == IssueRelation::TYPE_DUPLICATES}.collect {|r| r.issue_from} Index: app/views/gantts/show.html.erb =================================================================== --- app/views/gantts/show.html.erb (revision 4883) +++ app/views/gantts/show.html.erb (working copy) @@ -1,3 +1,4 @@ +<% include_calendar_headers_tags %> <% @gantt.view = self %>

<%= l(:label_gantt) %>

@@ -41,7 +42,7 @@ <% zoom = 1 @gantt.zoom.times { zoom = zoom * 2 } -subject_width = 330 +subject_width = 280 header_heigth = 18 headers_height = header_heigth @@ -67,7 +68,151 @@ %> + + + + + + <% if @gantt.truncated %>

<%= l(:notice_gantt_chart_truncated, :max => @gantt.max_rows) %>

<% end %> @@ -86,9 +231,20 @@ + +
+
+
+ +
+<%= @gantt.calendars %> +
+ +
+ -
+
 
<% # @@ -148,19 +304,20 @@ 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 %>
5 %>" class="gantt_hdr"> - <%= day_name(wday).first %> + <%= "#{dt.day}
"if @gantt.zoom == 4 %><%= day_name(wday).first %>
<% left = left + width+1 wday = wday + 1 + dt = dt + 1 wday = 1 if wday > 7 end end %> - <%= @gantt.lines %> <% Index: config/routes.rb =================================================================== --- config/routes.rb (revision 4883) +++ config/routes.rb (working copy) @@ -80,8 +80,8 @@ map.quoted_issue '/issues/:id/quoted', :controller => 'journals', :action => 'new', :id => /\d+/, :conditions => { :method => :post } map.connect '/issues/:id/destroy', :controller => 'issues', :action => 'destroy', :conditions => { :method => :post } # legacy - map.resource :gantt, :path_prefix => '/issues', :controller => 'gantts', :only => [:show, :update] - map.resource :gantt, :path_prefix => '/projects/:project_id/issues', :controller => 'gantts', :only => [:show, :update] + map.resource :gantt, :path_prefix => '/issues', :controller => 'gantts', :only => [:show, :update, :edit_gantt] + map.resource :gantt, :path_prefix => '/projects/:project_id/issues', :controller => 'gantts', :only => [:show, :update, :edit_gantt] map.resource :calendar, :path_prefix => '/issues', :controller => 'calendars', :only => [:show, :update] map.resource :calendar, :path_prefix => '/projects/:project_id/issues', :controller => 'calendars', :only => [:show, :update] Index: lib/redmine/helpers/gantt.rb =================================================================== --- lib/redmine/helpers/gantt.rb (revision 4883) +++ lib/redmine/helpers/gantt.rb (working copy) @@ -5,7 +5,7 @@ # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -38,10 +38,10 @@ attr_accessor :query attr_accessor :project attr_accessor :view - + def initialize(options={}) options = options.dup - + if options[:year] && options[:year].to_i >0 @year_from = options[:year].to_i if options[:month] && options[:month].to_i >=1 && options[:month].to_i <= 12 @@ -53,27 +53,28 @@ @month_from ||= Date.today.month @year_from ||= Date.today.year end - + zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i - @zoom = (zoom > 0 && zoom < 5) ? zoom : 2 + @zoom = (zoom > 0 && zoom < 5) ? zoom : 2 months = (options[:months] || User.current.pref[:gantt_months]).to_i @months = (months > 0 && months < 25) ? months : 6 - + # Save gantt parameters as user preference (zoom and months count) if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || @months != User.current.pref[:gantt_months])) User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months User.current.preference.save end - + @date_from = Date.civil(@year_from, @month_from, 1) @date_to = (@date_from >> @months) - 1 - + @subjects = '' @lines = '' + @calendars = '' @number_of_rows = nil - + @issue_ancestors = [] - + @truncated = false if options.has_key?(:max_rows) @max_rows = options[:max_rows] @@ -85,15 +86,15 @@ def common_params { :controller => 'gantts', :action => 'show', :project_id => @project } end - + def params common_params.merge({ :zoom => zoom, :year => year_from, :month => month_from, :months => months }) end - + def params_previous common_params.merge({:year => (date_from << months).year, :month => (date_from << months).month, :zoom => zoom, :months => months }) end - + def params_next common_params.merge({:year => (date_from >> months).year, :month => (date_from >> months).month, :zoom => zoom, :months => months }) end @@ -102,7 +103,7 @@ # Returns the number of rows that will be rendered on the Gantt chart def number_of_rows return @number_of_rows if @number_of_rows - + rows = if @project number_of_rows_on_project(@project) else @@ -110,7 +111,7 @@ total += number_of_rows_on_project(project) end end - + rows > @max_rows ? @max_rows : rows end @@ -154,14 +155,26 @@ render(options.merge(:only => :lines)) unless @lines_rendered @lines end - + + # Renders the calendars of the Gantt chart, the right side + def calendars(options={}) + render(options.merge(:only => :calendars)) unless @calendars_rendered + @calendars + end + def render(options={}) options = {:indent => 4, :render => :subject, :format => :html}.merge(options) - - @subjects = '' unless options[:only] == :lines - @lines = '' unless options[:only] == :subjects + + if options[:format] == :html + @subjects = '' unless options[:only] == :lines && options[:only] == :calendars + @lines = '' unless options[:only] == :subjects && options[:only] == :calendars + @calendars = '' unless options[:only] == :lines && options[:only] == :subjects + else + @subjects = '' unless options[:only] == :lines + @lines = '' unless options[:only] == :subjects + end @number_of_rows = 0 - + if @project render_project(@project, options) else @@ -170,10 +183,16 @@ break if abort? end end + + if options[:format] == :html + @subjects_rendered = true unless options[:only] == :lines && options[:only] == :calendars + @lines_rendered = true unless options[:only] == :subjects && options[:only] == :calendars + @calendars_rendered = true unless options[:only] == :lines && options[:only] == :subjects + else + @subjects_rendered = true unless options[:only] == :lines + @lines_rendered = true unless options[:only] == :subjects + end - @subjects_rendered = true unless options[:only] == :lines - @lines_rendered = true unless options[:only] == :subjects - render_end(options) end @@ -182,14 +201,20 @@ options[:indent_increment] = 20 unless options.key? :indent_increment options[:top_increment] = 20 unless options.key? :top_increment - subject_for_project(project, options) unless options[:only] == :lines - line_for_project(project, options) unless options[:only] == :subjects - + if options[:format] == :html + subject_for_project(project, options) unless options[:only] == :lines && options[:only] == :calendars + line_for_project(project, options) unless options[:only] == :subjects && options[:only] == :calendars + calendar_for_project(project, options) unless options[:only] == :lines && options[:only] == :subjects + else + subject_for_project(project, options) unless options[:only] == :lines + line_for_project(project, options) unless options[:only] == :subjects + end + options[:top] += options[:top_increment] options[:indent] += options[:indent_increment] @number_of_rows += 1 return if abort? - + # Second, Issues without a version issues = project.issues.for_gantt.without_version.with_query(@query).all(:limit => current_limit) sort_issues!(issues) @@ -216,33 +241,45 @@ def render_issues(issues, options={}) @issue_ancestors = [] - + issues.each do |i| - subject_for_issue(i, options) unless options[:only] == :lines - line_for_issue(i, options) unless options[:only] == :subjects - + if options[:format] == :html + subject_for_issue(i, options) unless options[:only] == :lines && options[:only] == :calendars + line_for_issue(i, options) unless options[:only] == :subjects && options[:only] == :calendars + calendar_for_issue(i, options) unless options[:only] == :lines && options[:only] == :subjects + else + subject_for_issue(i, options) unless options[:only] == :lines + line_for_issue(i, options) unless options[:only] == :subjects + end + options[:top] += options[:top_increment] @number_of_rows += 1 break if abort? end - + options[:indent] -= (options[:indent_increment] * @issue_ancestors.size) end def render_version(version, options={}) # Version header - subject_for_version(version, options) unless options[:only] == :lines - line_for_version(version, options) unless options[:only] == :subjects - + if options[:format] == :html + subject_for_version(version, options) unless options[:only] == :lines && options[:only] == :calendars + line_for_version(version, options) unless options[:only] == :subjects && options[:only] == :calendars + calendar_for_version(version, options) unless options[:only] == :lines && options[:only] == :subjects + else + subject_for_version(version, options) unless options[:only] == :lines + line_for_version(version, options) unless options[:only] == :subjects + end + options[:top] += options[:top_increment] @number_of_rows += 1 return if abort? - + # Remove the project requirement for Versions because it will # restrict issues to only be on the current project. This # ends up missing issues which are assigned to shared versions. @query.project = nil if @query.project - + issues = version.fixed_issues.for_gantt.with_query(@query).all(:limit => current_limit) if issues sort_issues!(issues) @@ -252,10 +289,10 @@ options[:indent] -= options[:indent_increment] end end - + def render_end(options={}) case options[:format] - when :pdf + when :pdf options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top]) end end @@ -280,13 +317,13 @@ if project.is_a?(Project) && project.start_date && project.due_date options[:zoom] ||= 1 options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom] - + coords = coordinates(project.start_date, project.due_date, nil, options[:zoom]) label = h(project) - + case options[:format] when :html - html_task(options, coords, :css => "project task", :label => label, :markers => true) + html_task(options, coords, :css => "project task", :label => label, :markers => true, :id => project.id, :kind => "p") when :image image_task(options, coords, :label => label, :markers => true, :height => 3) when :pdf @@ -318,14 +355,14 @@ if version.is_a?(Version) && version.start_date && version.due_date options[:zoom] ||= 1 options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom] - + coords = coordinates(version.start_date, version.due_date, version.completed_pourcent, options[:zoom]) label = "#{h version } #{h version.completed_pourcent.to_i.to_s}%" label = h("#{version.project} -") + label unless @project && @project == version.project case options[:format] when :html - html_task(options, coords, :css => "version task", :label => label, :markers => true) + html_task(options, coords, :css => "version task", :label => label, :markers => true, :id => version.id, :kind => "v") when :image image_task(options, coords, :label => label, :markers => true, :height => 3) when :pdf @@ -342,14 +379,14 @@ @issue_ancestors.pop options[:indent] -= options[:indent_increment] end - + output = case options[:format] when :html css_classes = '' css_classes << ' issue-overdue' if issue.overdue? css_classes << ' issue-behind-schedule' if issue.behind_schedule? css_classes << ' icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to - + subject = "" if issue.assigned_to.present? assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name @@ -369,7 +406,7 @@ @issue_ancestors << issue options[:indent] += options[:indent_increment] end - + output end @@ -378,10 +415,17 @@ if issue.is_a?(Issue) && issue.due_before coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom]) label = "#{ issue.status.name } #{ issue.done_ratio }%" - + if !issue.due_date && issue.fixed_version + if options[:format] == :html + label += "- #{h(issue.fixed_version.name)}" + else + label += "-#{h(issue.fixed_version.name)}" + end + end + case options[:format] when :html - html_task(options, coords, :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), :label => label, :issue => issue, :markers => !issue.leaf?) + html_task(options, coords, :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), :label => label, :issue => issue, :markers => !issue.leaf?, :id => issue.id, :kind => "i") when :image image_task(options, coords, :label => label) when :pdf @@ -393,13 +437,13 @@ end end - # Generates a gantt image + # Generates a gantt image # Only defined if RMagick is avalaible def to_image(format='PNG') - date_to = (@date_from >> @months)-1 + date_to = (@date_from >> @months)-1 show_weeks = @zoom > 1 show_days = @zoom > 2 - + subject_width = 400 header_heigth = 18 # width of one day in pixels @@ -408,19 +452,19 @@ g_height = 20 * number_of_rows + 30 headers_heigth = (show_weeks ? 2*header_heigth : header_heigth) height = g_height + headers_heigth - + imgl = Magick::ImageList.new imgl.new_image(subject_width+g_width+1, height) gc = Magick::Draw.new - + # Subjects gc.stroke('transparent') subjects(:image => gc, :top => (headers_heigth + 20), :indent => 4, :format => :image) - + # Months headers month_f = @date_from left = subject_width - @months.times do + @months.times do width = ((month_f >> 1) - month_f) * zoom gc.fill('white') gc.stroke('grey') @@ -433,7 +477,7 @@ left = left + width month_f = month_f >> 1 end - + # Weeks headers if show_weeks left = subject_width @@ -465,13 +509,13 @@ week_f = week_f+7 end end - + # Days details (week-end in grey) if show_days left = subject_width height = g_height + header_heigth - 1 wday = @date_from.cwday - (date_to - @date_from + 1).to_i.times do + (date_to - @date_from + 1).to_i.times do width = zoom gc.fill(wday == 6 || wday == 7 ? '#eee' : 'white') gc.stroke('#ddd') @@ -482,7 +526,7 @@ wday = 1 if wday > 7 end end - + # border gc.fill('transparent') gc.stroke('grey') @@ -490,20 +534,20 @@ gc.rectangle(0, 0, subject_width+g_width, headers_heigth) gc.stroke('black') gc.rectangle(0, 0, subject_width+g_width, g_height+ headers_heigth-1) - + # content top = headers_heigth + 20 gc.stroke('transparent') lines(:image => gc, :top => top, :zoom => zoom, :subject_width => subject_width, :format => :image) - + # today red line if Date.today >= @date_from and Date.today <= date_to gc.stroke('red') x = (Date.today-@date_from+1)*zoom + subject_width - gc.line(x, headers_heigth, x, headers_heigth + g_height-1) - end - + gc.line(x, headers_heigth, x, headers_heigth + g_height-1) + end + gc.draw(imgl) imgl.format = format imgl.to_blob @@ -520,14 +564,14 @@ pdf.Cell(PDF::LeftPaneWidth, 20, project.to_s) pdf.Ln pdf.SetFontStyle('B',9) - + subject_width = PDF::LeftPaneWidth header_heigth = 5 - + headers_heigth = header_heigth show_weeks = false show_days = false - + if self.months < 7 show_weeks = true headers_heigth = 2*header_heigth @@ -536,27 +580,27 @@ headers_heigth = 3*header_heigth end end - + g_width = PDF.right_pane_width zoom = (g_width) / (self.date_to - self.date_from + 1) g_height = 120 t_height = g_height + headers_heigth - + y_start = pdf.GetY - + # Months headers month_f = self.date_from left = subject_width height = header_heigth - self.months.times do - width = ((month_f >> 1) - month_f) * zoom + self.months.times do + width = ((month_f >> 1) - month_f) * zoom pdf.SetY(y_start) pdf.SetX(left) pdf.Cell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C") left = left + width month_f = month_f >> 1 - end - + end + # Weeks headers if show_weeks left = subject_width @@ -582,14 +626,14 @@ week_f = week_f+7 end end - + # Days headers if show_days left = subject_width height = header_heigth wday = self.date_from.cwday pdf.SetFontStyle('B',7) - (self.date_to - self.date_from + 1).to_i.times do + (self.date_to - self.date_from + 1).to_i.times do width = zoom pdf.SetY(y_start + 2 * header_heigth) pdf.SetX(left) @@ -599,11 +643,11 @@ wday = 1 if wday > 7 end end - + pdf.SetY(y_start) pdf.SetX(15) pdf.Cell(subject_width+g_width-15, headers_heigth, "", 1) - + # Tasks top = headers_heigth + y_start options = { @@ -620,12 +664,111 @@ render(options) pdf.Output end - + + def edit(pms) + id = pms[:id] + kind = id.slice!(0).chr + begin + case kind + when 'i' + @issue = Issue.find(pms[:id], :include => [:project, :tracker, :status, :author, :priority, :category]) + when 'p' + @issue = Project.find(pms[:id]) + when 'v' + @issue = Version.find(pms[:id], :include => [:project]) + end + rescue ActiveRecord::RecordNotFound + return "issue not found : #{pms[:id]}", 400 + end + + if !@issue.start_date || !@issue.due_before + #render :text=>l(:notice_locking_conflict), :status=>400 + return l(:notice_locking_conflict), 400 + end + @issue.init_journal(User.current) + date_from = Date.parse(pms[:date_from]) + old_start_date = @issue.start_date + o = get_issue_position(@issue, pms[:zoom]) + 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]}" + + if pms[:day] + #bar moved + day = pms[: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 pms[:start_date] + #start date changed + start_date = Date.parse(pms[:start_date]) + if @issue.start_date == start_date + #render :text=>"" + return "", 200 #nothing has changed + end + @issue.start_date = start_date + @issue.due_date = start_date if @issue.due_date && start_date > @issue.due_date + elsif pms[:due_date] + #due date changed + due_date = Date.parse(pms[:due_date]) + if @issue.due_date == due_date + #render :text=>"" + return "", 200 #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_issue_position(@issue, pms[:zoom]) + 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]}" + + prj_map = {} + text = set_project_data(@issue.project, pms[:zoom], text, prj_map) + version_map = {} + text = set_version_data(@issue.fixed_version, pms[:zoom], text, version_map) + + #check dependencies + issues = @issue.all_precedes_issues + issues.each do |i| + o = get_issue_position(i, pms[:zoom]) + 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]}" + text = set_project_data(i.project, pms[:zoom], text, prj_map) + text = set_version_data(i.fixed_version, pms[:zoom], text, version_map) + end + + #check parent + is = @issue + while + pid = is.parent_issue_id + break if !pid + i = Issue.find(pid) + o = get_issue_position(i, pms[:zoom]) + 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]}" + text = set_project_data(i.project, pms[:zoom], text, prj_map) + text = set_version_data(i.fixed_version, pms[:zoom], text, version_map) + is = i + end + #render :text=>text + return text, 200 + rescue => e + #render :text=>@issue.errors.full_messages.join("\n") + "|" + text_for_revert , :status=>400 + if @issue.errors.full_messages.to_s == "" + return e.to_s + "\n" + [$!,$@.join("\n")].join("\n") + "\n" + @issue.errors.full_messages.join("\n") + "|" + text_for_revert, 400 + else + return @issue.errors.full_messages.join("\n") + "|" + text_for_revert, 400 + end + end + end + private - + def coordinates(start_date, end_date, progress, zoom=nil) zoom ||= @zoom - + coords = {} if start_date && end_date && start_date < self.date_to && end_date > self.date_from if start_date > self.date_from @@ -640,7 +783,7 @@ else coords[:bar_end] = self.date_to - self.date_from + 1 end - + if progress progress_date = start_date + (end_date - start_date) * (progress / 100.0) if progress_date > self.date_from && progress_date > start_date @@ -650,7 +793,7 @@ coords[:bar_progress_end] = self.date_to - self.date_from + 1 end end - + if progress_date < Date.today late_date = [Date.today, end_date].min if late_date > self.date_from && late_date > start_date @@ -663,7 +806,7 @@ end end end - + # Transforms dates into pixels witdh coords.keys.each do |key| coords[key] = (coords[key] * zoom).floor @@ -675,7 +818,7 @@ def sort_issues!(issues) issues.sort! { |a, b| gantt_issue_compare(a, b, issues) } end - + # TODO: top level issues should be sorted by start date def gantt_issue_compare(x, y, issues) if x.root_id == y.root_id @@ -684,7 +827,7 @@ x.root_id <=> y.root_id end end - + def current_limit if @max_rows @max_rows - @number_of_rows @@ -692,13 +835,13 @@ nil end end - + def abort? if @max_rows && @number_of_rows >= @max_rows @truncated = true end end - + def pdf_new_page?(options) if options[:top] > 180 options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top]) @@ -707,7 +850,7 @@ options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1) end end - + def html_subject(params, subject, options={}) output = "
" output << subject @@ -715,57 +858,74 @@ @subjects << output output end - + def pdf_subject(params, subject, options={}) params[:pdf].SetY(params[:top]) params[:pdf].SetX(15) - + char_limit = PDF::MaxCharactorsForSubject - params[:indent] params[:pdf].Cell(params[:subject_width]-15, 5, (" " * params[:indent]) + subject.to_s.sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR") - + params[:pdf].SetY(params[:top]) params[:pdf].SetX(params[:subject_width]) params[:pdf].Cell(params[:g_width], 5, "", "LR") end - + def image_subject(params, subject, options={}) params[:image].fill('black') params[:image].stroke('transparent') params[:image].stroke_width(1) params[:image].text(params[:indent], params[:top] + 2, subject) end - + def html_task(params, coords, options={}) output = '' # Renders the task bar, with progress and late if coords[:bar_start] && coords[:bar_end] - output << "
 
" - + i_width = coords[:bar_end] - coords[:bar_start] - 2 + output << "
" + output << "
 
" + if coords[:bar_late_end] - output << "
 
" + l_width = coords[:bar_late_end] - coords[:bar_start] - 2 + output << "
 
" + else + output << "
 
" end if coords[:bar_progress_end] - output << "
 
" + d_width = coords[:bar_progress_end] - coords[:bar_start] - 2 + output << "
 
" + else + output << "
 
" end + output << "
" + else + output << "
" + output << "
 
" + output << "
 
" + output << "
 
" + output << "
" end # Renders the markers if options[:markers] if coords[:start] - output << "
 
" + output << "
 
" end if coords[:end] - output << "
 
" + output << "
 
" end + else + 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);}') end # Renders the label on the right if options[:label] - output << "
" + output << "
" output << options[:label] output << "
" end # Renders the tooltip if options[:issue] && coords[:bar_start] && coords[:bar_end] - output << "
" + output << "
" output << '' output << view.render_issue_tooltip(options[:issue]) output << "
" @@ -773,17 +933,17 @@ @lines << output output end - + def pdf_task(params, coords, options={}) height = options[:height] || 2 - + # Renders the task bar, with progress and late if coords[:bar_start] && coords[:bar_end] params[:pdf].SetY(params[:top]+1.5) params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) params[:pdf].SetFillColor(200,200,200) params[:pdf].Cell(coords[:bar_end] - coords[:bar_start], height, "", 0, 0, "", 1) - + if coords[:bar_late_end] params[:pdf].SetY(params[:top]+1.5) params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) @@ -803,13 +963,13 @@ params[:pdf].SetY(params[:top] + 1) params[:pdf].SetX(params[:subject_width] + coords[:start] - 1) params[:pdf].SetFillColor(50,50,200) - params[:pdf].Cell(2, 2, "", 0, 0, "", 1) + params[:pdf].Cell(2, 2, "", 0, 0, "", 1) end if coords[:end] params[:pdf].SetY(params[:top] + 1) params[:pdf].SetX(params[:subject_width] + coords[:end] - 1) params[:pdf].SetFillColor(50,50,200) - params[:pdf].Cell(2, 2, "", 0, 0, "", 1) + params[:pdf].Cell(2, 2, "", 0, 0, "", 1) end end # Renders the label on the right @@ -821,12 +981,12 @@ def image_task(params, coords, options={}) height = options[:height] || 6 - + # Renders the task bar, with progress and late if coords[:bar_start] && coords[:bar_end] params[:image].fill('#aaa') params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_end], params[:top] - height) - + if coords[:bar_late_end] params[:image].fill('#f66') params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_late_end], params[:top] - height) @@ -857,6 +1017,209 @@ params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5,params[:top] + 1, options[:label]) end end + + ## + ## for edit gantt + ## + def set_project_data(prj, zoom, text, prj_map = {}) + if !prj + return text + end + if !prj_map[prj.id] + o = get_project_position(prj, zoom) + 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]}" + prj_map[prj.id] = prj + end + text = set_project_data(prj.parent, zoom, text, prj_map) + end + + def set_version_data(version, zoom, text, version_map = {}) + if !version + return text + end + if !version_map[version.id] + o = get_version_position(version, zoom) + 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]}" + version_map[version.id] = version + end + return text + end + + def get_pos(coords) + i_left = 0 + i_width = 0 + l_width = 0 + d_width = 0 + if coords[:bar_start] + i_left = coords[:bar_start] + if coords[:bar_end] + i_width = coords[:bar_end] - coords[:bar_start] - 2 + i_width = 0 if i_width < 0 + end + if coords[:bar_late_end] + l_width = coords[:bar_late_end] - coords[:bar_start] - 2 + end + if coords[:bar_progress_end] + d_width = coords[:bar_progress_end] - coords[:bar_start] - 2 + end + end + return i_left, i_width, l_width, d_width + end + + def get_issue_position(issue, zoom_str) + z = zoom_str.to_i + zoom = 1 + z.times { zoom = zoom * 2} + id = issue.due_before + if id && @date_to < id + id = @date_to + end + coords = coordinates(issue.start_date, id, issue.done_ratio, zoom) + + i_left, i_width, l_width, d_width = get_pos(coords) + if coords[:end] + return i_left, i_width, l_width, d_width, coords[:start], coords[:end] + zoom + else + return i_left, i_width, l_width, d_width, coords[:start], nil + end + end + + def get_project_position(project, zoom_str) + z = zoom_str.to_i + zoom = 1 + z.times { zoom = zoom * 2} + pd = project.due_date + if pd && @date_to < pd + pd = @date_to + end + coords = coordinates(project.start_date, pd, nil, zoom) + i_left, i_width, l_width, d_width = get_pos(coords) + if coords[:end] + return i_left, i_width, l_width, d_width, coords[:start], coords[:end] + zoom + else + return i_left, i_width, l_width, d_width, coords[:start], nil + end + end + + def get_version_position(version, zoom_str) + z = zoom_str.to_i + zoom = 1 + z.times { zoom = zoom * 2} + vd = version.due_date + if vd && @date_to < vd + vd = @date_to + end + coords = coordinates(version.start_date, vd, version.completed_pourcent, zoom) + i_left, i_width, l_width, d_width = get_pos(coords) + if coords[:end] + return i_left, i_width, l_width, d_width, coords[:start], coords[:end] + zoom + else + return i_left, i_width, l_width, d_width, coords[:start], nil + end + end + + def calendar_for_issue(issue, options) + # Skip issues that don't have a due_before (due_date or version's due_date) + if issue.is_a?(Issue) && issue.due_before + + case options[:format] + when :html + @calendars << "
" + start_date = issue.start_date + if start_date + @calendars << "" + @calendars << format_date(start_date) + @calendars << "" + @calendars << "" + if issue.leaf? + @calendars << "#{view.g_calendar_for('i' + issue.id.to_s + '_start_date')}" + else + @calendars << "   " + end + @calendars << observe_date_field("i#{issue.id}", 'start') + end + due_date = issue.due_date + if due_date + @calendars << "" + @calendars << format_date(due_date) + @calendars << "" + @calendars << "" + if issue.leaf? + @calendars << "#{view.g_calendar_for('i' + issue.id.to_s + '_due_date')}" + else + @calendars << "" + end + @calendars << observe_date_field("i#{issue.id}", 'due') + end + @calendars << "
" + when :image + #nop + when :pdf + #nop + end + else + ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before" + '' + end + end + + def calendar_for_version(version, options) + # Skip version that don't have a due_before (due_date or version's due_date) + if version.is_a?(Version) && version.start_date && version.due_date + + case options[:format] + when :html + @calendars << "
" + @calendars << "" + @calendars << format_date(version.effective_date) + @calendars << "" + @calendars << "
" + when :image + #nop + when :pdf + #nop + end + else + ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before" + '' + end + end + + def calendar_for_project(project, options) + case options[:format] + when :html + @calendars << "
" + @calendars << "" + @calendars << format_date(project.start_date) if project.start_date + @calendars << "" + @calendars << "   " + @calendars << "" + @calendars << format_date(project.due_date) if project.due_date + @calendars << "" + @calendars << "
" + when :image + # nop + when :pdf + # nop + end + end + + def observe_date_field(id, type) + output = '' + prj_id = '' + prj_id = @project.to_param if @project + output << "" + end end end end Index: public/stylesheets/application.css =================================================================== --- public/stylesheets/application.css (revision 4883) +++ public/stylesheets/application.css (working copy) @@ -801,6 +801,7 @@ .task_late { background:#f66 url(../images/task_late.png); border: 1px solid #f66; } .task_done { background:#00c600 url(../images/task_done.png); border: 1px solid #00c600; } .task_todo { background:#aaa url(../images/task_todo.png); border: 1px solid #aaa; } +.task_none { background:transparent; border-style: none; } .task_todo.parent { background: #888; border: 1px solid #888; height: 3px;} .task_late.parent, .task_done.parent { height: 3px;}