2011-10-29 16:19:11 +04:00
|
|
|
#-- encoding: UTF-8
|
2011-05-30 00:11:52 +04:00
|
|
|
#-- copyright
|
|
|
|
# ChiliProject is a project management system.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# Copyright (C) 2010-2011 the ChiliProject Team
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# 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.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
|
|
#++
|
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
module Redmine
|
|
|
|
module Helpers
|
|
|
|
# Simple class to handle gantt chart data
|
|
|
|
class Gantt
|
2010-09-10 07:09:02 +04:00
|
|
|
include ERB::Util
|
|
|
|
include Redmine::I18n
|
|
|
|
|
|
|
|
# :nodoc:
|
|
|
|
# Some utility methods for the PDF export
|
|
|
|
class PDF
|
|
|
|
MaxCharactorsForSubject = 45
|
|
|
|
TotalWidth = 280
|
|
|
|
LeftPaneWidth = 100
|
|
|
|
|
|
|
|
def self.right_pane_width
|
|
|
|
TotalWidth - LeftPaneWidth
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-12-16 00:18:06 +03:00
|
|
|
attr_reader :year_from, :month_from, :date_from, :date_to, :zoom, :months, :truncated, :max_rows
|
2010-09-10 07:09:02 +04:00
|
|
|
attr_accessor :query
|
|
|
|
attr_accessor :project
|
|
|
|
attr_accessor :view
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
def initialize(options={})
|
|
|
|
options = options.dup
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
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
|
|
|
|
@month_from = options[:month].to_i
|
|
|
|
else
|
|
|
|
@month_from = 1
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@month_from ||= Date.today.month
|
|
|
|
@year_from ||= Date.today.year
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i
|
2011-05-30 22:52:25 +04:00
|
|
|
@zoom = (zoom > 0 && zoom < 5) ? zoom : 2
|
2008-09-10 22:26:13 +04:00
|
|
|
months = (options[:months] || User.current.pref[:gantt_months]).to_i
|
|
|
|
@months = (months > 0 && months < 25) ? months : 6
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
# 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
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
@date_from = Date.civil(@year_from, @month_from, 1)
|
|
|
|
@date_to = (@date_from >> @months) - 1
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-07 21:40:34 +03:00
|
|
|
@subjects = ''
|
|
|
|
@lines = ''
|
2010-12-07 22:29:47 +03:00
|
|
|
@number_of_rows = nil
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-18 19:06:20 +03:00
|
|
|
@issue_ancestors = []
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-16 00:18:06 +03:00
|
|
|
@truncated = false
|
|
|
|
if options.has_key?(:max_rows)
|
|
|
|
@max_rows = options[:max_rows]
|
|
|
|
else
|
|
|
|
@max_rows = Setting.gantt_items_limit.blank? ? nil : Setting.gantt_items_limit.to_i
|
|
|
|
end
|
2008-09-10 22:26:13 +04:00
|
|
|
end
|
2010-09-10 07:09:18 +04:00
|
|
|
|
|
|
|
def common_params
|
|
|
|
{ :controller => 'gantts', :action => 'show', :project_id => @project }
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
def params
|
2010-09-10 07:09:18 +04:00
|
|
|
common_params.merge({ :zoom => zoom, :year => year_from, :month => month_from, :months => months })
|
2008-09-10 22:26:13 +04:00
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
def params_previous
|
2010-09-10 07:09:18 +04:00
|
|
|
common_params.merge({:year => (date_from << months).year, :month => (date_from << months).month, :zoom => zoom, :months => months })
|
2008-09-10 22:26:13 +04:00
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
def params_next
|
2010-09-10 07:09:18 +04:00
|
|
|
common_params.merge({:year => (date_from >> months).year, :month => (date_from >> months).month, :zoom => zoom, :months => months })
|
2008-09-10 22:26:13 +04:00
|
|
|
end
|
2010-09-10 07:09:02 +04:00
|
|
|
|
|
|
|
# Returns the number of rows that will be rendered on the Gantt chart
|
|
|
|
def number_of_rows
|
2010-12-07 22:29:47 +03:00
|
|
|
return @number_of_rows if @number_of_rows
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2011-03-10 21:07:09 +03:00
|
|
|
rows = projects.inject(0) {|total, p| total += number_of_rows_on_project(p)}
|
2011-02-20 07:58:12 +03:00
|
|
|
|
|
|
|
if @max_rows.present?
|
|
|
|
rows > @max_rows ? @max_rows : rows
|
|
|
|
else
|
|
|
|
rows
|
|
|
|
end
|
2010-09-10 07:09:02 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Returns the number of rows that will be used to list a project on
|
|
|
|
# the Gantt chart. This will recurse for each subproject.
|
|
|
|
def number_of_rows_on_project(project)
|
2011-03-10 21:07:09 +03:00
|
|
|
return 0 unless projects.include?(project)
|
2010-09-10 07:09:02 +04:00
|
|
|
count = 1
|
2011-03-10 21:07:09 +03:00
|
|
|
count += project_issues(project).size
|
|
|
|
count += project_versions(project).size
|
2010-09-10 07:09:02 +04:00
|
|
|
count
|
|
|
|
end
|
|
|
|
|
|
|
|
# Renders the subjects of the Gantt chart, the left side.
|
|
|
|
def subjects(options={})
|
2010-12-07 21:40:34 +03:00
|
|
|
render(options.merge(:only => :subjects)) unless @subjects_rendered
|
|
|
|
@subjects
|
2010-09-10 07:09:02 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Renders the lines of the Gantt chart, the right side
|
|
|
|
def lines(options={})
|
2010-12-07 21:40:34 +03:00
|
|
|
render(options.merge(:only => :lines)) unless @lines_rendered
|
|
|
|
@lines
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2011-03-10 21:07:09 +03:00
|
|
|
# Returns issues that will be rendered
|
|
|
|
def issues
|
|
|
|
@issues ||= @query.issues(
|
|
|
|
:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
|
2011-05-30 22:52:25 +04:00
|
|
|
:order => "#{Project.table_name}.lft ASC, #{Issue.table_name}.id ASC",
|
2011-03-10 21:07:09 +03:00
|
|
|
:limit => @max_rows
|
|
|
|
)
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2011-03-10 21:07:09 +03:00
|
|
|
# Return all the project nodes that will be displayed
|
|
|
|
def projects
|
|
|
|
return @projects if @projects
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2011-03-10 21:07:09 +03:00
|
|
|
ids = issues.collect(&:project).uniq.collect(&:id)
|
|
|
|
if ids.any?
|
|
|
|
# All issues projects and their visible ancestors
|
|
|
|
@projects = Project.visible.all(
|
|
|
|
:joins => "LEFT JOIN #{Project.table_name} child ON #{Project.table_name}.lft <= child.lft AND #{Project.table_name}.rgt >= child.rgt",
|
|
|
|
:conditions => ["child.id IN (?)", ids],
|
|
|
|
:order => "#{Project.table_name}.lft ASC"
|
|
|
|
).uniq
|
|
|
|
else
|
|
|
|
@projects = []
|
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2011-03-10 21:07:09 +03:00
|
|
|
# Returns the issues that belong to +project+
|
|
|
|
def project_issues(project)
|
|
|
|
@issues_by_project ||= issues.group_by(&:project)
|
|
|
|
@issues_by_project[project] || []
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2011-03-10 21:07:09 +03:00
|
|
|
# Returns the distinct versions of the issues that belong to +project+
|
|
|
|
def project_versions(project)
|
|
|
|
project_issues(project).collect(&:fixed_version).compact.uniq
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2011-03-10 21:07:09 +03:00
|
|
|
# Returns the issues that belong to +project+ and are assigned to +version+
|
|
|
|
def version_issues(project, version)
|
|
|
|
project_issues(project).select {|issue| issue.fixed_version == version}
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-07 21:40:34 +03:00
|
|
|
def render(options={})
|
2011-03-10 21:07:09 +03:00
|
|
|
options = {:top => 0, :top_increment => 20, :indent_increment => 20, :render => :subject, :format => :html}.merge(options)
|
|
|
|
indent = options[:indent] || 4
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-07 21:40:34 +03:00
|
|
|
@subjects = '' unless options[:only] == :lines
|
|
|
|
@lines = '' unless options[:only] == :subjects
|
2010-12-07 22:29:47 +03:00
|
|
|
@number_of_rows = 0
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2011-03-10 21:07:09 +03:00
|
|
|
Project.project_tree(projects) do |project, level|
|
|
|
|
options[:indent] = indent + level * options[:indent_increment]
|
|
|
|
render_project(project, options)
|
|
|
|
break if abort?
|
2010-09-10 07:09:02 +04:00
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-07 21:40:34 +03:00
|
|
|
@subjects_rendered = true unless options[:only] == :lines
|
|
|
|
@lines_rendered = true unless options[:only] == :subjects
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-07 21:57:46 +03:00
|
|
|
render_end(options)
|
2010-09-10 07:09:02 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def render_project(project, options={})
|
2010-12-07 21:40:34 +03:00
|
|
|
subject_for_project(project, options) unless options[:only] == :lines
|
|
|
|
line_for_project(project, options) unless options[:only] == :subjects
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-10 07:09:02 +04:00
|
|
|
options[:top] += options[:top_increment]
|
|
|
|
options[:indent] += options[:indent_increment]
|
2010-12-07 22:29:47 +03:00
|
|
|
@number_of_rows += 1
|
2010-12-16 00:18:06 +03:00
|
|
|
return if abort?
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2011-03-10 21:07:09 +03:00
|
|
|
issues = project_issues(project).select {|i| i.fixed_version.nil?}
|
2010-11-21 16:54:26 +03:00
|
|
|
sort_issues!(issues)
|
2010-09-10 07:09:02 +04:00
|
|
|
if issues
|
2010-12-07 21:40:34 +03:00
|
|
|
render_issues(issues, options)
|
2010-12-16 00:18:06 +03:00
|
|
|
return if abort?
|
2010-09-10 07:09:02 +04:00
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2011-03-10 21:07:09 +03:00
|
|
|
versions = project_versions(project)
|
|
|
|
versions.each do |version|
|
|
|
|
render_version(project, version, options)
|
2010-09-10 07:09:02 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Remove indent to hit the next sibling
|
|
|
|
options[:indent] -= options[:indent_increment]
|
|
|
|
end
|
|
|
|
|
|
|
|
def render_issues(issues, options={})
|
2010-12-18 19:06:20 +03:00
|
|
|
@issue_ancestors = []
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-10 07:09:02 +04:00
|
|
|
issues.each do |i|
|
2010-12-07 21:40:34 +03:00
|
|
|
subject_for_issue(i, options) unless options[:only] == :lines
|
|
|
|
line_for_issue(i, options) unless options[:only] == :subjects
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-10 07:09:02 +04:00
|
|
|
options[:top] += options[:top_increment]
|
2010-12-07 22:29:47 +03:00
|
|
|
@number_of_rows += 1
|
2010-12-18 19:06:20 +03:00
|
|
|
break if abort?
|
2010-09-10 07:09:02 +04:00
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-18 19:06:20 +03:00
|
|
|
options[:indent] -= (options[:indent_increment] * @issue_ancestors.size)
|
2010-09-10 07:09:02 +04:00
|
|
|
end
|
|
|
|
|
2011-03-10 21:07:09 +03:00
|
|
|
def render_version(project, version, options={})
|
2010-09-10 07:09:02 +04:00
|
|
|
# Version header
|
2010-12-07 21:40:34 +03:00
|
|
|
subject_for_version(version, options) unless options[:only] == :lines
|
|
|
|
line_for_version(version, options) unless options[:only] == :subjects
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-10 07:09:02 +04:00
|
|
|
options[:top] += options[:top_increment]
|
2010-12-07 22:29:47 +03:00
|
|
|
@number_of_rows += 1
|
2010-12-16 00:18:06 +03:00
|
|
|
return if abort?
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2011-03-10 21:07:09 +03:00
|
|
|
issues = version_issues(project, version)
|
2010-09-10 07:09:02 +04:00
|
|
|
if issues
|
2010-11-21 16:54:26 +03:00
|
|
|
sort_issues!(issues)
|
2010-09-10 07:09:02 +04:00
|
|
|
# Indent issues
|
|
|
|
options[:indent] += options[:indent_increment]
|
2010-12-07 21:40:34 +03:00
|
|
|
render_issues(issues, options)
|
2010-09-10 07:09:02 +04:00
|
|
|
options[:indent] -= options[:indent_increment]
|
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-07 21:57:46 +03:00
|
|
|
def render_end(options={})
|
|
|
|
case options[:format]
|
2011-05-30 22:52:25 +04:00
|
|
|
when :pdf
|
2010-12-07 21:57:46 +03:00
|
|
|
options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
|
|
|
|
end
|
|
|
|
end
|
2010-09-10 07:09:02 +04:00
|
|
|
|
|
|
|
def subject_for_project(project, options)
|
|
|
|
case options[:format]
|
|
|
|
when :html
|
2010-12-17 18:21:38 +03:00
|
|
|
subject = "<span class='icon icon-projects #{project.overdue? ? 'project-overdue' : ''}'>"
|
|
|
|
subject << view.link_to_project(project)
|
|
|
|
subject << '</span>'
|
|
|
|
html_subject(options, subject, :css => "project-name")
|
2010-09-10 07:09:02 +04:00
|
|
|
when :image
|
2010-12-17 18:21:38 +03:00
|
|
|
image_subject(options, project.name)
|
2010-09-10 07:09:02 +04:00
|
|
|
when :pdf
|
2010-12-07 21:53:15 +03:00
|
|
|
pdf_new_page?(options)
|
2010-12-17 18:21:38 +03:00
|
|
|
pdf_subject(options, project.name)
|
2010-09-10 07:09:02 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def line_for_project(project, options)
|
2010-10-23 02:13:39 +04:00
|
|
|
# Skip versions that don't have a start_date or due date
|
|
|
|
if project.is_a?(Project) && project.start_date && project.due_date
|
2010-09-10 07:09:02 +04:00
|
|
|
options[:zoom] ||= 1
|
|
|
|
options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-29 23:29:42 +03:00
|
|
|
coords = coordinates(project.start_date, project.due_date, nil, options[:zoom])
|
|
|
|
label = h(project)
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-10 07:09:02 +04:00
|
|
|
case options[:format]
|
|
|
|
when :html
|
2010-12-17 17:59:32 +03:00
|
|
|
html_task(options, coords, :css => "project task", :label => label, :markers => true)
|
2010-09-10 07:09:02 +04:00
|
|
|
when :image
|
2010-12-17 17:53:30 +03:00
|
|
|
image_task(options, coords, :label => label, :markers => true, :height => 3)
|
2010-09-10 07:09:02 +04:00
|
|
|
when :pdf
|
2010-12-17 17:37:51 +03:00
|
|
|
pdf_task(options, coords, :label => label, :markers => true, :height => 0.8)
|
2010-09-10 07:09:02 +04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
ActiveRecord::Base.logger.debug "Gantt#line_for_project was not given a project with a start_date"
|
|
|
|
''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def subject_for_version(version, options)
|
|
|
|
case options[:format]
|
|
|
|
when :html
|
2010-12-17 18:21:38 +03:00
|
|
|
subject = "<span class='icon icon-package #{version.behind_schedule? ? 'version-behind-schedule' : ''} #{version.overdue? ? 'version-overdue' : ''}'>"
|
|
|
|
subject << view.link_to_version(version)
|
|
|
|
subject << '</span>'
|
|
|
|
html_subject(options, subject, :css => "version-name")
|
2010-09-10 07:09:02 +04:00
|
|
|
when :image
|
2010-12-17 18:21:38 +03:00
|
|
|
image_subject(options, version.to_s_with_project)
|
2010-09-10 07:09:02 +04:00
|
|
|
when :pdf
|
2010-12-07 21:53:15 +03:00
|
|
|
pdf_new_page?(options)
|
2010-12-17 18:21:38 +03:00
|
|
|
pdf_subject(options, version.to_s_with_project)
|
2010-09-10 07:09:02 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def line_for_version(version, options)
|
|
|
|
# Skip versions that don't have a start_date
|
2010-10-23 02:13:39 +04:00
|
|
|
if version.is_a?(Version) && version.start_date && version.due_date
|
2010-09-10 07:09:02 +04:00
|
|
|
options[:zoom] ||= 1
|
|
|
|
options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-23 17:58:52 +03:00
|
|
|
coords = coordinates(version.start_date, version.due_date, version.completed_pourcent, options[:zoom])
|
2010-12-17 17:59:32 +03:00
|
|
|
label = "#{h version } #{h version.completed_pourcent.to_i.to_s}%"
|
|
|
|
label = h("#{version.project} -") + label unless @project && @project == version.project
|
2010-09-10 07:09:02 +04:00
|
|
|
|
|
|
|
case options[:format]
|
|
|
|
when :html
|
2010-12-17 17:59:32 +03:00
|
|
|
html_task(options, coords, :css => "version task", :label => label, :markers => true)
|
2010-09-10 07:09:02 +04:00
|
|
|
when :image
|
2010-12-17 17:53:30 +03:00
|
|
|
image_task(options, coords, :label => label, :markers => true, :height => 3)
|
2010-09-10 07:09:02 +04:00
|
|
|
when :pdf
|
2010-12-17 17:37:51 +03:00
|
|
|
pdf_task(options, coords, :label => label, :markers => true, :height => 0.8)
|
2010-09-10 07:09:02 +04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
ActiveRecord::Base.logger.debug "Gantt#line_for_version was not given a version with a start_date"
|
|
|
|
''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def subject_for_issue(issue, options)
|
2010-12-18 19:06:20 +03:00
|
|
|
while @issue_ancestors.any? && !issue.is_descendant_of?(@issue_ancestors.last)
|
|
|
|
@issue_ancestors.pop
|
|
|
|
options[:indent] -= options[:indent_increment]
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-18 19:06:20 +03:00
|
|
|
output = case options[:format]
|
2010-09-10 07:09:02 +04:00
|
|
|
when :html
|
2010-12-17 18:21:38 +03:00
|
|
|
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
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 18:21:38 +03:00
|
|
|
subject = "<span class='#{css_classes}'>"
|
|
|
|
if issue.assigned_to.present?
|
|
|
|
assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name
|
2011-02-28 23:23:28 +03:00
|
|
|
subject << view.avatar(issue.assigned_to, :class => 'gravatar icon-gravatar', :size => 10, :title => assigned_string).to_s
|
2010-09-10 07:09:02 +04:00
|
|
|
end
|
2010-12-17 18:21:38 +03:00
|
|
|
subject << view.link_to_issue(issue)
|
|
|
|
subject << '</span>'
|
2011-02-21 18:17:52 +03:00
|
|
|
html_subject(options, subject, :css => "issue-subject", :title => issue.subject) + "\n"
|
2010-09-10 07:09:02 +04:00
|
|
|
when :image
|
2010-12-17 18:21:38 +03:00
|
|
|
image_subject(options, issue.subject)
|
2010-09-10 07:09:02 +04:00
|
|
|
when :pdf
|
2010-12-07 21:53:15 +03:00
|
|
|
pdf_new_page?(options)
|
2010-12-17 18:21:38 +03:00
|
|
|
pdf_subject(options, issue.subject)
|
2010-09-10 07:09:02 +04:00
|
|
|
end
|
2010-12-18 19:06:20 +03:00
|
|
|
|
|
|
|
unless issue.leaf?
|
|
|
|
@issue_ancestors << issue
|
|
|
|
options[:indent] += options[:indent_increment]
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-18 19:06:20 +03:00
|
|
|
output
|
2010-09-10 07:09:02 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def line_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
|
2010-12-17 17:59:32 +03:00
|
|
|
coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom])
|
|
|
|
label = "#{ issue.status.name } #{ issue.done_ratio }%"
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-10 07:09:02 +04:00
|
|
|
case options[:format]
|
|
|
|
when :html
|
2010-12-18 19:06:20 +03:00
|
|
|
html_task(options, coords, :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), :label => label, :issue => issue, :markers => !issue.leaf?)
|
2010-09-10 07:09:02 +04:00
|
|
|
when :image
|
2010-12-17 17:59:32 +03:00
|
|
|
image_task(options, coords, :label => label)
|
2010-09-10 07:09:02 +04:00
|
|
|
when :pdf
|
2010-12-17 17:59:32 +03:00
|
|
|
pdf_task(options, coords, :label => label)
|
2010-12-17 17:37:51 +03:00
|
|
|
end
|
2010-09-10 07:09:02 +04:00
|
|
|
else
|
|
|
|
ActiveRecord::Base.logger.debug "GanttHelper#line_for_issue was not given an issue with a due_before"
|
|
|
|
''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
# Generates a gantt image
|
|
|
|
# Only defined if RMagick is avalaible
|
2010-09-10 07:09:02 +04:00
|
|
|
def to_image(format='PNG')
|
2011-05-30 22:52:25 +04:00
|
|
|
date_to = (@date_from >> @months)-1
|
2008-09-10 22:26:13 +04:00
|
|
|
show_weeks = @zoom > 1
|
|
|
|
show_days = @zoom > 2
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-07-25 15:43:19 +04:00
|
|
|
subject_width = 400
|
2008-09-10 22:26:13 +04:00
|
|
|
header_heigth = 18
|
|
|
|
# width of one day in pixels
|
|
|
|
zoom = @zoom*2
|
|
|
|
g_width = (@date_to - @date_from + 1)*zoom
|
2010-09-10 07:09:02 +04:00
|
|
|
g_height = 20 * number_of_rows + 30
|
2008-09-10 22:26:13 +04:00
|
|
|
headers_heigth = (show_weeks ? 2*header_heigth : header_heigth)
|
|
|
|
height = g_height + headers_heigth
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
imgl = Magick::ImageList.new
|
|
|
|
imgl.new_image(subject_width+g_width+1, height)
|
|
|
|
gc = Magick::Draw.new
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
# Subjects
|
2010-12-17 17:53:30 +03:00
|
|
|
gc.stroke('transparent')
|
2010-09-10 07:09:02 +04:00
|
|
|
subjects(:image => gc, :top => (headers_heigth + 20), :indent => 4, :format => :image)
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
# Months headers
|
|
|
|
month_f = @date_from
|
|
|
|
left = subject_width
|
2011-05-30 22:52:25 +04:00
|
|
|
@months.times do
|
2008-09-10 22:26:13 +04:00
|
|
|
width = ((month_f >> 1) - month_f) * zoom
|
|
|
|
gc.fill('white')
|
|
|
|
gc.stroke('grey')
|
|
|
|
gc.stroke_width(1)
|
|
|
|
gc.rectangle(left, 0, left + width, height)
|
|
|
|
gc.fill('black')
|
|
|
|
gc.stroke('transparent')
|
|
|
|
gc.stroke_width(1)
|
|
|
|
gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}")
|
|
|
|
left = left + width
|
|
|
|
month_f = month_f >> 1
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
# Weeks headers
|
|
|
|
if show_weeks
|
|
|
|
left = subject_width
|
|
|
|
height = header_heigth
|
|
|
|
if @date_from.cwday == 1
|
|
|
|
# date_from is monday
|
|
|
|
week_f = date_from
|
|
|
|
else
|
|
|
|
# find next monday after date_from
|
|
|
|
week_f = @date_from + (7 - @date_from.cwday + 1)
|
|
|
|
width = (7 - @date_from.cwday + 1) * zoom
|
|
|
|
gc.fill('white')
|
|
|
|
gc.stroke('grey')
|
|
|
|
gc.stroke_width(1)
|
|
|
|
gc.rectangle(left, header_heigth, left + width, 2*header_heigth + g_height-1)
|
|
|
|
left = left + width
|
|
|
|
end
|
|
|
|
while week_f <= date_to
|
|
|
|
width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom
|
|
|
|
gc.fill('white')
|
|
|
|
gc.stroke('grey')
|
|
|
|
gc.stroke_width(1)
|
|
|
|
gc.rectangle(left.round, header_heigth, left.round + width, 2*header_heigth + g_height-1)
|
|
|
|
gc.fill('black')
|
|
|
|
gc.stroke('transparent')
|
|
|
|
gc.stroke_width(1)
|
|
|
|
gc.text(left.round + 2, header_heigth + 14, week_f.cweek.to_s)
|
|
|
|
left = left + width
|
|
|
|
week_f = week_f+7
|
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
# Days details (week-end in grey)
|
|
|
|
if show_days
|
|
|
|
left = subject_width
|
|
|
|
height = g_height + header_heigth - 1
|
|
|
|
wday = @date_from.cwday
|
2011-05-30 22:52:25 +04:00
|
|
|
(date_to - @date_from + 1).to_i.times do
|
2008-09-10 22:26:13 +04:00
|
|
|
width = zoom
|
|
|
|
gc.fill(wday == 6 || wday == 7 ? '#eee' : 'white')
|
2010-12-30 18:04:08 +03:00
|
|
|
gc.stroke('#ddd')
|
2008-09-10 22:26:13 +04:00
|
|
|
gc.stroke_width(1)
|
|
|
|
gc.rectangle(left, 2*header_heigth, left + width, 2*header_heigth + g_height-1)
|
|
|
|
left = left + width
|
|
|
|
wday = wday + 1
|
|
|
|
wday = 1 if wday > 7
|
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
# border
|
|
|
|
gc.fill('transparent')
|
|
|
|
gc.stroke('grey')
|
|
|
|
gc.stroke_width(1)
|
|
|
|
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)
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
# content
|
|
|
|
top = headers_heigth + 20
|
2010-12-17 17:53:30 +03:00
|
|
|
|
|
|
|
gc.stroke('transparent')
|
2010-09-10 07:09:02 +04:00
|
|
|
lines(:image => gc, :top => top, :zoom => zoom, :subject_width => subject_width, :format => :image)
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
# 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
|
2011-05-30 22:52:25 +04:00
|
|
|
gc.line(x, headers_heigth, x, headers_heigth + g_height-1)
|
|
|
|
end
|
|
|
|
|
2008-09-10 22:26:13 +04:00
|
|
|
gc.draw(imgl)
|
|
|
|
imgl.format = format
|
|
|
|
imgl.to_blob
|
|
|
|
end if Object.const_defined?(:Magick)
|
2010-09-10 07:09:02 +04:00
|
|
|
|
|
|
|
def to_pdf
|
2011-04-02 12:01:47 +04:00
|
|
|
if ( current_language.to_s.downcase == 'ko' ||
|
2011-03-30 15:32:35 +04:00
|
|
|
current_language.to_s.downcase == 'ja' ||
|
|
|
|
current_language.to_s.downcase == 'zh' ||
|
|
|
|
current_language.to_s.downcase == 'zh-tw' ||
|
|
|
|
current_language.to_s.downcase == 'th' )
|
|
|
|
pdf = ::Redmine::Export::PDF::IFPDF.new(current_language)
|
|
|
|
else
|
|
|
|
pdf = ::Redmine::Export::PDF::ITCPDF.new(current_language)
|
|
|
|
end
|
2010-09-10 07:09:02 +04:00
|
|
|
pdf.SetTitle("#{l(:label_gantt)} #{project}")
|
2011-03-30 11:32:08 +04:00
|
|
|
pdf.alias_nb_pages
|
2010-09-10 07:09:02 +04:00
|
|
|
pdf.footer_date = format_date(Date.today)
|
|
|
|
pdf.AddPage("L")
|
|
|
|
pdf.SetFontStyle('B',12)
|
|
|
|
pdf.SetX(15)
|
2011-03-30 11:32:08 +04:00
|
|
|
pdf.RDMCell(PDF::LeftPaneWidth, 20, project.to_s)
|
2010-09-10 07:09:02 +04:00
|
|
|
pdf.Ln
|
|
|
|
pdf.SetFontStyle('B',9)
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-10 07:09:02 +04:00
|
|
|
subject_width = PDF::LeftPaneWidth
|
|
|
|
header_heigth = 5
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-10 07:09:02 +04:00
|
|
|
headers_heigth = header_heigth
|
|
|
|
show_weeks = false
|
|
|
|
show_days = false
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-10 07:09:02 +04:00
|
|
|
if self.months < 7
|
|
|
|
show_weeks = true
|
|
|
|
headers_heigth = 2*header_heigth
|
|
|
|
if self.months < 3
|
|
|
|
show_days = true
|
|
|
|
headers_heigth = 3*header_heigth
|
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-10 07:09:02 +04:00
|
|
|
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
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-10 07:09:02 +04:00
|
|
|
y_start = pdf.GetY
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-10 07:09:02 +04:00
|
|
|
# Months headers
|
|
|
|
month_f = self.date_from
|
|
|
|
left = subject_width
|
|
|
|
height = header_heigth
|
2011-05-30 22:52:25 +04:00
|
|
|
self.months.times do
|
|
|
|
width = ((month_f >> 1) - month_f) * zoom
|
2010-09-10 07:09:02 +04:00
|
|
|
pdf.SetY(y_start)
|
|
|
|
pdf.SetX(left)
|
2011-03-30 11:32:08 +04:00
|
|
|
pdf.RDMCell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C")
|
2010-09-10 07:09:02 +04:00
|
|
|
left = left + width
|
|
|
|
month_f = month_f >> 1
|
2011-05-30 22:52:25 +04:00
|
|
|
end
|
|
|
|
|
2010-09-10 07:09:02 +04:00
|
|
|
# Weeks headers
|
|
|
|
if show_weeks
|
|
|
|
left = subject_width
|
|
|
|
height = header_heigth
|
|
|
|
if self.date_from.cwday == 1
|
|
|
|
# self.date_from is monday
|
|
|
|
week_f = self.date_from
|
2010-03-13 17:56:49 +03:00
|
|
|
else
|
2010-09-10 07:09:02 +04:00
|
|
|
# find next monday after self.date_from
|
|
|
|
week_f = self.date_from + (7 - self.date_from.cwday + 1)
|
|
|
|
width = (7 - self.date_from.cwday + 1) * zoom-1
|
|
|
|
pdf.SetY(y_start + header_heigth)
|
|
|
|
pdf.SetX(left)
|
2011-03-30 11:32:08 +04:00
|
|
|
pdf.RDMCell(width + 1, height, "", "LTR")
|
2010-09-10 07:09:02 +04:00
|
|
|
left = left + width+1
|
|
|
|
end
|
|
|
|
while week_f <= self.date_to
|
|
|
|
width = (week_f + 6 <= self.date_to) ? 7 * zoom : (self.date_to - week_f + 1) * zoom
|
|
|
|
pdf.SetY(y_start + header_heigth)
|
|
|
|
pdf.SetX(left)
|
2011-03-30 11:32:08 +04:00
|
|
|
pdf.RDMCell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C")
|
2010-09-10 07:09:02 +04:00
|
|
|
left = left + width
|
|
|
|
week_f = week_f+7
|
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-10 07:09:02 +04:00
|
|
|
# Days headers
|
|
|
|
if show_days
|
|
|
|
left = subject_width
|
|
|
|
height = header_heigth
|
|
|
|
wday = self.date_from.cwday
|
|
|
|
pdf.SetFontStyle('B',7)
|
2011-05-30 22:52:25 +04:00
|
|
|
(self.date_to - self.date_from + 1).to_i.times do
|
2010-09-10 07:09:02 +04:00
|
|
|
width = zoom
|
|
|
|
pdf.SetY(y_start + 2 * header_heigth)
|
|
|
|
pdf.SetX(left)
|
2011-03-30 11:32:08 +04:00
|
|
|
pdf.RDMCell(width, height, day_name(wday).first, "LTR", 0, "C")
|
2010-09-10 07:09:02 +04:00
|
|
|
left = left + width
|
|
|
|
wday = wday + 1
|
|
|
|
wday = 1 if wday > 7
|
2010-03-13 17:56:49 +03:00
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-10 07:09:02 +04:00
|
|
|
pdf.SetY(y_start)
|
|
|
|
pdf.SetX(15)
|
2011-03-30 11:32:08 +04:00
|
|
|
pdf.RDMCell(subject_width+g_width-15, headers_heigth, "", 1)
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-10 07:09:02 +04:00
|
|
|
# Tasks
|
|
|
|
top = headers_heigth + y_start
|
2010-12-07 21:40:34 +03:00
|
|
|
options = {
|
|
|
|
:top => top,
|
|
|
|
:zoom => zoom,
|
|
|
|
:subject_width => subject_width,
|
|
|
|
:g_width => g_width,
|
|
|
|
:indent => 0,
|
|
|
|
:indent_increment => 5,
|
2010-12-07 21:53:15 +03:00
|
|
|
:top_increment => 5,
|
2010-12-07 21:40:34 +03:00
|
|
|
:format => :pdf,
|
|
|
|
:pdf => pdf
|
|
|
|
}
|
|
|
|
render(options)
|
2010-09-10 07:09:02 +04:00
|
|
|
pdf.Output
|
2010-03-13 17:56:49 +03:00
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-10 07:09:02 +04:00
|
|
|
private
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 15:24:11 +03:00
|
|
|
def coordinates(start_date, end_date, progress, zoom=nil)
|
|
|
|
zoom ||= @zoom
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 15:24:11 +03:00
|
|
|
coords = {}
|
|
|
|
if start_date && end_date && start_date < self.date_to && end_date > self.date_from
|
|
|
|
if start_date > self.date_from
|
|
|
|
coords[:start] = start_date - self.date_from
|
|
|
|
coords[:bar_start] = start_date - self.date_from
|
|
|
|
else
|
|
|
|
coords[:bar_start] = 0
|
|
|
|
end
|
|
|
|
if end_date < self.date_to
|
|
|
|
coords[:end] = end_date - self.date_from
|
|
|
|
coords[:bar_end] = end_date - self.date_from + 1
|
|
|
|
else
|
|
|
|
coords[:bar_end] = self.date_to - self.date_from + 1
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 15:24:11 +03:00
|
|
|
if progress
|
2011-03-28 21:35:20 +04:00
|
|
|
progress_date = start_date + (end_date - start_date + 1) * (progress / 100.0)
|
2010-12-17 15:24:11 +03:00
|
|
|
if progress_date > self.date_from && progress_date > start_date
|
|
|
|
if progress_date < self.date_to
|
2011-03-28 21:35:20 +04:00
|
|
|
coords[:bar_progress_end] = progress_date - self.date_from
|
2010-12-17 15:24:11 +03:00
|
|
|
else
|
|
|
|
coords[:bar_progress_end] = self.date_to - self.date_from + 1
|
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 15:24:11 +03:00
|
|
|
if progress_date < Date.today
|
|
|
|
late_date = [Date.today, end_date].min
|
|
|
|
if late_date > self.date_from && late_date > start_date
|
|
|
|
if late_date < self.date_to
|
|
|
|
coords[:bar_late_end] = late_date - self.date_from + 1
|
|
|
|
else
|
|
|
|
coords[:bar_late_end] = self.date_to - self.date_from + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 15:24:11 +03:00
|
|
|
# Transforms dates into pixels witdh
|
|
|
|
coords.keys.each do |key|
|
|
|
|
coords[key] = (coords[key] * zoom).floor
|
|
|
|
end
|
|
|
|
coords
|
|
|
|
end
|
2010-09-10 07:09:02 +04:00
|
|
|
|
2010-11-21 16:54:26 +03:00
|
|
|
# Sorts a collection of issues by start_date, due_date, id for gantt rendering
|
|
|
|
def sort_issues!(issues)
|
2010-12-18 19:06:20 +03:00
|
|
|
issues.sort! { |a, b| gantt_issue_compare(a, b, issues) }
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-29 23:21:39 +03:00
|
|
|
# TODO: top level issues should be sorted by start date
|
2010-12-18 19:06:20 +03:00
|
|
|
def gantt_issue_compare(x, y, issues)
|
2010-12-29 23:21:39 +03:00
|
|
|
if x.root_id == y.root_id
|
|
|
|
x.lft <=> y.lft
|
2010-12-18 19:06:20 +03:00
|
|
|
else
|
2010-12-29 23:21:39 +03:00
|
|
|
x.root_id <=> y.root_id
|
2010-11-21 16:54:26 +03:00
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-16 00:18:06 +03:00
|
|
|
def current_limit
|
|
|
|
if @max_rows
|
|
|
|
@max_rows - @number_of_rows
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-16 00:18:06 +03:00
|
|
|
def abort?
|
|
|
|
if @max_rows && @number_of_rows >= @max_rows
|
|
|
|
@truncated = true
|
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-07 21:53:15 +03:00
|
|
|
def pdf_new_page?(options)
|
|
|
|
if options[:top] > 180
|
|
|
|
options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
|
|
|
|
options[:pdf].AddPage("L")
|
|
|
|
options[:top] = 15
|
|
|
|
options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1)
|
|
|
|
end
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 18:21:38 +03:00
|
|
|
def html_subject(params, subject, options={})
|
2011-02-21 20:10:15 +03:00
|
|
|
style = "position: absolute;top:#{params[:top]}px;left:#{params[:indent]}px;"
|
2011-02-21 18:06:11 +03:00
|
|
|
style << "width:#{params[:subject_width] - params[:indent]}px;" if params[:subject_width]
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2011-02-21 18:17:52 +03:00
|
|
|
output = view.content_tag 'div', subject, :class => options[:css], :style => style, :title => options[:title]
|
2010-12-17 18:21:38 +03:00
|
|
|
@subjects << output
|
|
|
|
output
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 18:21:38 +03:00
|
|
|
def pdf_subject(params, subject, options={})
|
|
|
|
params[:pdf].SetY(params[:top])
|
|
|
|
params[:pdf].SetX(15)
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 18:21:38 +03:00
|
|
|
char_limit = PDF::MaxCharactorsForSubject - params[:indent]
|
2011-03-30 11:32:08 +04:00
|
|
|
params[:pdf].RDMCell(params[:subject_width]-15, 5, (" " * params[:indent]) + subject.to_s.sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR")
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 18:21:38 +03:00
|
|
|
params[:pdf].SetY(params[:top])
|
|
|
|
params[:pdf].SetX(params[:subject_width])
|
2011-03-30 11:32:08 +04:00
|
|
|
params[:pdf].RDMCell(params[:g_width], 5, "", "LR")
|
2010-12-17 18:21:38 +03:00
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 18:21:38 +03:00
|
|
|
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
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 17:37:51 +03:00
|
|
|
def html_task(params, coords, options={})
|
2010-12-17 15:41:54 +03:00
|
|
|
output = ''
|
|
|
|
# Renders the task bar, with progress and late
|
|
|
|
if coords[:bar_start] && coords[:bar_end]
|
2010-12-17 17:37:51 +03:00
|
|
|
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>"
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 15:41:54 +03:00
|
|
|
if coords[:bar_late_end]
|
2010-12-17 17:37:51 +03:00
|
|
|
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>"
|
2010-12-17 15:41:54 +03:00
|
|
|
end
|
|
|
|
if coords[:bar_progress_end]
|
2010-12-17 17:37:51 +03:00
|
|
|
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>"
|
2010-12-17 15:41:54 +03:00
|
|
|
end
|
|
|
|
end
|
2010-12-17 16:40:25 +03:00
|
|
|
# Renders the markers
|
|
|
|
if options[:markers]
|
|
|
|
if coords[:start]
|
2010-12-17 17:37:51 +03:00
|
|
|
output << "<div style='top:#{ params[:top] }px;left:#{ coords[:start] }px;width:15px;' class='#{options[:css]} marker starting'> </div>"
|
2010-12-17 16:40:25 +03:00
|
|
|
end
|
|
|
|
if coords[:end]
|
2010-12-18 19:06:20 +03:00
|
|
|
output << "<div style='top:#{ params[:top] }px;left:#{ coords[:end] + params[:zoom] }px;width:15px;' class='#{options[:css]} marker ending'> </div>"
|
2010-12-17 16:40:25 +03:00
|
|
|
end
|
|
|
|
end
|
2010-12-17 15:41:54 +03:00
|
|
|
# Renders the label on the right
|
|
|
|
if options[:label]
|
2010-12-18 19:06:20 +03:00
|
|
|
output << "<div style='top:#{ params[:top] }px;left:#{ (coords[:bar_end] || 0) + 8 }px;' class='#{options[:css]} label'>"
|
2010-12-17 15:41:54 +03:00
|
|
|
output << options[:label]
|
|
|
|
output << "</div>"
|
2010-12-17 15:24:11 +03:00
|
|
|
end
|
2010-12-17 15:41:54 +03:00
|
|
|
# Renders the tooltip
|
|
|
|
if options[:issue] && coords[:bar_start] && coords[:bar_end]
|
2010-12-17 17:37:51 +03:00
|
|
|
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;'>"
|
2010-12-17 15:41:54 +03:00
|
|
|
output << '<span class="tip">'
|
|
|
|
output << view.render_issue_tooltip(options[:issue])
|
|
|
|
output << "</span></div>"
|
2010-12-17 15:24:11 +03:00
|
|
|
end
|
2010-12-17 17:59:32 +03:00
|
|
|
@lines << output
|
2010-12-17 15:24:11 +03:00
|
|
|
output
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 17:37:51 +03:00
|
|
|
def pdf_task(params, coords, options={})
|
|
|
|
height = options[:height] || 2
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 17:37:51 +03:00
|
|
|
# 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)
|
2011-03-30 11:32:08 +04:00
|
|
|
params[:pdf].RDMCell(coords[:bar_end] - coords[:bar_start], height, "", 0, 0, "", 1)
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 17:37:51 +03:00
|
|
|
if coords[:bar_late_end]
|
|
|
|
params[:pdf].SetY(params[:top]+1.5)
|
|
|
|
params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
|
|
|
|
params[:pdf].SetFillColor(255,100,100)
|
2011-03-30 11:32:08 +04:00
|
|
|
params[:pdf].RDMCell(coords[:bar_late_end] - coords[:bar_start], height, "", 0, 0, "", 1)
|
2010-12-17 17:37:51 +03:00
|
|
|
end
|
|
|
|
if coords[:bar_progress_end]
|
|
|
|
params[:pdf].SetY(params[:top]+1.5)
|
|
|
|
params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
|
|
|
|
params[:pdf].SetFillColor(90,200,90)
|
2011-03-30 11:32:08 +04:00
|
|
|
params[:pdf].RDMCell(coords[:bar_progress_end] - coords[:bar_start], height, "", 0, 0, "", 1)
|
2010-12-17 17:37:51 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
# Renders the markers
|
|
|
|
if options[:markers]
|
|
|
|
if coords[:start]
|
|
|
|
params[:pdf].SetY(params[:top] + 1)
|
|
|
|
params[:pdf].SetX(params[:subject_width] + coords[:start] - 1)
|
|
|
|
params[:pdf].SetFillColor(50,50,200)
|
2011-05-30 22:52:25 +04:00
|
|
|
params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1)
|
2010-12-17 17:37:51 +03:00
|
|
|
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)
|
2011-05-30 22:52:25 +04:00
|
|
|
params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1)
|
2010-12-17 17:37:51 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
# Renders the label on the right
|
|
|
|
if options[:label]
|
|
|
|
params[:pdf].SetX(params[:subject_width] + (coords[:bar_end] || 0) + 5)
|
2011-03-30 11:32:08 +04:00
|
|
|
params[:pdf].RDMCell(30, 2, options[:label])
|
2010-12-17 17:37:51 +03:00
|
|
|
end
|
|
|
|
end
|
2010-12-17 17:53:30 +03:00
|
|
|
|
|
|
|
def image_task(params, coords, options={})
|
|
|
|
height = options[:height] || 6
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 17:53:30 +03:00
|
|
|
# Renders the task bar, with progress and late
|
|
|
|
if coords[:bar_start] && coords[:bar_end]
|
2010-12-30 18:04:08 +03:00
|
|
|
params[:image].fill('#aaa')
|
2010-12-17 17:53:30 +03:00
|
|
|
params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_end], params[:top] - height)
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-12-17 17:53:30 +03:00
|
|
|
if coords[:bar_late_end]
|
2010-12-30 18:04:08 +03:00
|
|
|
params[:image].fill('#f66')
|
2010-12-17 17:53:30 +03:00
|
|
|
params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_late_end], params[:top] - height)
|
|
|
|
end
|
|
|
|
if coords[:bar_progress_end]
|
2010-12-30 18:04:08 +03:00
|
|
|
params[:image].fill('#00c600')
|
2010-12-17 17:53:30 +03:00
|
|
|
params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_progress_end], params[:top] - height)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# Renders the markers
|
|
|
|
if options[:markers]
|
|
|
|
if coords[:start]
|
2010-12-30 18:04:08 +03:00
|
|
|
x = params[:subject_width] + coords[:start]
|
|
|
|
y = params[:top] - height / 2
|
2010-12-17 17:53:30 +03:00
|
|
|
params[:image].fill('blue')
|
2010-12-30 18:04:08 +03:00
|
|
|
params[:image].polygon(x-4, y, x, y-4, x+4, y, x, y+4)
|
2010-12-17 17:53:30 +03:00
|
|
|
end
|
|
|
|
if coords[:end]
|
2010-12-30 18:04:08 +03:00
|
|
|
x = params[:subject_width] + coords[:end] + params[:zoom]
|
|
|
|
y = params[:top] - height / 2
|
2010-12-17 17:53:30 +03:00
|
|
|
params[:image].fill('blue')
|
2010-12-30 18:04:08 +03:00
|
|
|
params[:image].polygon(x-4, y, x, y-4, x+4, y, x, y+4)
|
2010-12-17 17:53:30 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
# Renders the label on the right
|
|
|
|
if options[:label]
|
|
|
|
params[:image].fill('black')
|
|
|
|
params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5,params[:top] + 1, options[:label])
|
|
|
|
end
|
|
|
|
end
|
2008-09-10 22:26:13 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|