remove trailing white-spaces lib/redmine/helpers/gantt.rb.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5662 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
773b248669
commit
2711f4c745
|
@ -5,12 +5,12 @@
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
# as published by the Free Software Foundation; either version 2
|
# as published by the Free Software Foundation; either version 2
|
||||||
# of the License, or (at your option) any later version.
|
# of the License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
@ -38,10 +38,10 @@ module Redmine
|
||||||
attr_accessor :query
|
attr_accessor :query
|
||||||
attr_accessor :project
|
attr_accessor :project
|
||||||
attr_accessor :view
|
attr_accessor :view
|
||||||
|
|
||||||
def initialize(options={})
|
def initialize(options={})
|
||||||
options = options.dup
|
options = options.dup
|
||||||
|
|
||||||
if options[:year] && options[:year].to_i >0
|
if options[:year] && options[:year].to_i >0
|
||||||
@year_from = options[:year].to_i
|
@year_from = options[:year].to_i
|
||||||
if options[:month] && options[:month].to_i >=1 && options[:month].to_i <= 12
|
if options[:month] && options[:month].to_i >=1 && options[:month].to_i <= 12
|
||||||
|
@ -53,27 +53,27 @@ module Redmine
|
||||||
@month_from ||= Date.today.month
|
@month_from ||= Date.today.month
|
||||||
@year_from ||= Date.today.year
|
@year_from ||= Date.today.year
|
||||||
end
|
end
|
||||||
|
|
||||||
zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i
|
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 = (options[:months] || User.current.pref[:gantt_months]).to_i
|
||||||
@months = (months > 0 && months < 25) ? months : 6
|
@months = (months > 0 && months < 25) ? months : 6
|
||||||
|
|
||||||
# Save gantt parameters as user preference (zoom and months count)
|
# 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]))
|
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.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months
|
||||||
User.current.preference.save
|
User.current.preference.save
|
||||||
end
|
end
|
||||||
|
|
||||||
@date_from = Date.civil(@year_from, @month_from, 1)
|
@date_from = Date.civil(@year_from, @month_from, 1)
|
||||||
@date_to = (@date_from >> @months) - 1
|
@date_to = (@date_from >> @months) - 1
|
||||||
|
|
||||||
@subjects = ''
|
@subjects = ''
|
||||||
@lines = ''
|
@lines = ''
|
||||||
@number_of_rows = nil
|
@number_of_rows = nil
|
||||||
|
|
||||||
@issue_ancestors = []
|
@issue_ancestors = []
|
||||||
|
|
||||||
@truncated = false
|
@truncated = false
|
||||||
if options.has_key?(:max_rows)
|
if options.has_key?(:max_rows)
|
||||||
@max_rows = options[:max_rows]
|
@max_rows = options[:max_rows]
|
||||||
|
@ -85,15 +85,15 @@ module Redmine
|
||||||
def common_params
|
def common_params
|
||||||
{ :controller => 'gantts', :action => 'show', :project_id => @project }
|
{ :controller => 'gantts', :action => 'show', :project_id => @project }
|
||||||
end
|
end
|
||||||
|
|
||||||
def params
|
def params
|
||||||
common_params.merge({ :zoom => zoom, :year => year_from, :month => month_from, :months => months })
|
common_params.merge({ :zoom => zoom, :year => year_from, :month => month_from, :months => months })
|
||||||
end
|
end
|
||||||
|
|
||||||
def params_previous
|
def params_previous
|
||||||
common_params.merge({:year => (date_from << months).year, :month => (date_from << months).month, :zoom => zoom, :months => months })
|
common_params.merge({:year => (date_from << months).year, :month => (date_from << months).month, :zoom => zoom, :months => months })
|
||||||
end
|
end
|
||||||
|
|
||||||
def params_next
|
def params_next
|
||||||
common_params.merge({:year => (date_from >> months).year, :month => (date_from >> months).month, :zoom => zoom, :months => months })
|
common_params.merge({:year => (date_from >> months).year, :month => (date_from >> months).month, :zoom => zoom, :months => months })
|
||||||
end
|
end
|
||||||
|
@ -101,22 +101,22 @@ module Redmine
|
||||||
# Returns the number of rows that will be rendered on the Gantt chart
|
# Returns the number of rows that will be rendered on the Gantt chart
|
||||||
def number_of_rows
|
def number_of_rows
|
||||||
return @number_of_rows if @number_of_rows
|
return @number_of_rows if @number_of_rows
|
||||||
|
|
||||||
rows = projects.inject(0) {|total, p| total += number_of_rows_on_project(p)}
|
rows = projects.inject(0) {|total, p| total += number_of_rows_on_project(p)}
|
||||||
rows > @max_rows ? @max_rows : rows
|
rows > @max_rows ? @max_rows : rows
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the number of rows that will be used to list a project on
|
# Returns the number of rows that will be used to list a project on
|
||||||
# the Gantt chart. This will recurse for each subproject.
|
# the Gantt chart. This will recurse for each subproject.
|
||||||
def number_of_rows_on_project(project)
|
def number_of_rows_on_project(project)
|
||||||
return 0 unless projects.include?(project)
|
return 0 unless projects.include?(project)
|
||||||
|
|
||||||
count = 1
|
count = 1
|
||||||
count += project_issues(project).size
|
count += project_issues(project).size
|
||||||
count += project_versions(project).size
|
count += project_versions(project).size
|
||||||
count
|
count
|
||||||
end
|
end
|
||||||
|
|
||||||
# Renders the subjects of the Gantt chart, the left side.
|
# Renders the subjects of the Gantt chart, the left side.
|
||||||
def subjects(options={})
|
def subjects(options={})
|
||||||
render(options.merge(:only => :subjects)) unless @subjects_rendered
|
render(options.merge(:only => :subjects)) unless @subjects_rendered
|
||||||
|
@ -128,20 +128,20 @@ module Redmine
|
||||||
render(options.merge(:only => :lines)) unless @lines_rendered
|
render(options.merge(:only => :lines)) unless @lines_rendered
|
||||||
@lines
|
@lines
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns issues that will be rendered
|
# Returns issues that will be rendered
|
||||||
def issues
|
def issues
|
||||||
@issues ||= @query.issues(
|
@issues ||= @query.issues(
|
||||||
:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
|
:include => [:assigned_to, :tracker, :priority, :category, :fixed_version],
|
||||||
:order => "#{Project.table_name}.lft ASC, #{Issue.table_name}.id ASC",
|
:order => "#{Project.table_name}.lft ASC, #{Issue.table_name}.id ASC",
|
||||||
:limit => @max_rows
|
:limit => @max_rows
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return all the project nodes that will be displayed
|
# Return all the project nodes that will be displayed
|
||||||
def projects
|
def projects
|
||||||
return @projects if @projects
|
return @projects if @projects
|
||||||
|
|
||||||
ids = issues.collect(&:project).uniq.collect(&:id)
|
ids = issues.collect(&:project).uniq.collect(&:id)
|
||||||
if ids.any?
|
if ids.any?
|
||||||
# All issues projects and their visible ancestors
|
# All issues projects and their visible ancestors
|
||||||
|
@ -154,59 +154,59 @@ module Redmine
|
||||||
@projects = []
|
@projects = []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the issues that belong to +project+
|
# Returns the issues that belong to +project+
|
||||||
def project_issues(project)
|
def project_issues(project)
|
||||||
@issues_by_project ||= issues.group_by(&:project)
|
@issues_by_project ||= issues.group_by(&:project)
|
||||||
@issues_by_project[project] || []
|
@issues_by_project[project] || []
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the distinct versions of the issues that belong to +project+
|
# Returns the distinct versions of the issues that belong to +project+
|
||||||
def project_versions(project)
|
def project_versions(project)
|
||||||
project_issues(project).collect(&:fixed_version).compact.uniq
|
project_issues(project).collect(&:fixed_version).compact.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the issues that belong to +project+ and are assigned to +version+
|
# Returns the issues that belong to +project+ and are assigned to +version+
|
||||||
def version_issues(project, version)
|
def version_issues(project, version)
|
||||||
project_issues(project).select {|issue| issue.fixed_version == version}
|
project_issues(project).select {|issue| issue.fixed_version == version}
|
||||||
end
|
end
|
||||||
|
|
||||||
def render(options={})
|
def render(options={})
|
||||||
options = {:top => 0, :top_increment => 20, :indent_increment => 20, :render => :subject, :format => :html}.merge(options)
|
options = {:top => 0, :top_increment => 20, :indent_increment => 20, :render => :subject, :format => :html}.merge(options)
|
||||||
indent = options[:indent] || 4
|
indent = options[:indent] || 4
|
||||||
|
|
||||||
@subjects = '' unless options[:only] == :lines
|
@subjects = '' unless options[:only] == :lines
|
||||||
@lines = '' unless options[:only] == :subjects
|
@lines = '' unless options[:only] == :subjects
|
||||||
@number_of_rows = 0
|
@number_of_rows = 0
|
||||||
|
|
||||||
Project.project_tree(projects) do |project, level|
|
Project.project_tree(projects) do |project, level|
|
||||||
options[:indent] = indent + level * options[:indent_increment]
|
options[:indent] = indent + level * options[:indent_increment]
|
||||||
render_project(project, options)
|
render_project(project, options)
|
||||||
break if abort?
|
break if abort?
|
||||||
end
|
end
|
||||||
|
|
||||||
@subjects_rendered = true unless options[:only] == :lines
|
@subjects_rendered = true unless options[:only] == :lines
|
||||||
@lines_rendered = true unless options[:only] == :subjects
|
@lines_rendered = true unless options[:only] == :subjects
|
||||||
|
|
||||||
render_end(options)
|
render_end(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_project(project, options={})
|
def render_project(project, options={})
|
||||||
subject_for_project(project, options) unless options[:only] == :lines
|
subject_for_project(project, options) unless options[:only] == :lines
|
||||||
line_for_project(project, options) unless options[:only] == :subjects
|
line_for_project(project, options) unless options[:only] == :subjects
|
||||||
|
|
||||||
options[:top] += options[:top_increment]
|
options[:top] += options[:top_increment]
|
||||||
options[:indent] += options[:indent_increment]
|
options[:indent] += options[:indent_increment]
|
||||||
@number_of_rows += 1
|
@number_of_rows += 1
|
||||||
return if abort?
|
return if abort?
|
||||||
|
|
||||||
issues = project_issues(project).select {|i| i.fixed_version.nil?}
|
issues = project_issues(project).select {|i| i.fixed_version.nil?}
|
||||||
sort_issues!(issues)
|
sort_issues!(issues)
|
||||||
if issues
|
if issues
|
||||||
render_issues(issues, options)
|
render_issues(issues, options)
|
||||||
return if abort?
|
return if abort?
|
||||||
end
|
end
|
||||||
|
|
||||||
versions = project_versions(project)
|
versions = project_versions(project)
|
||||||
versions.each do |version|
|
versions.each do |version|
|
||||||
render_version(project, version, options)
|
render_version(project, version, options)
|
||||||
|
@ -218,16 +218,16 @@ module Redmine
|
||||||
|
|
||||||
def render_issues(issues, options={})
|
def render_issues(issues, options={})
|
||||||
@issue_ancestors = []
|
@issue_ancestors = []
|
||||||
|
|
||||||
issues.each do |i|
|
issues.each do |i|
|
||||||
subject_for_issue(i, options) unless options[:only] == :lines
|
subject_for_issue(i, options) unless options[:only] == :lines
|
||||||
line_for_issue(i, options) unless options[:only] == :subjects
|
line_for_issue(i, options) unless options[:only] == :subjects
|
||||||
|
|
||||||
options[:top] += options[:top_increment]
|
options[:top] += options[:top_increment]
|
||||||
@number_of_rows += 1
|
@number_of_rows += 1
|
||||||
break if abort?
|
break if abort?
|
||||||
end
|
end
|
||||||
|
|
||||||
options[:indent] -= (options[:indent_increment] * @issue_ancestors.size)
|
options[:indent] -= (options[:indent_increment] * @issue_ancestors.size)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -235,11 +235,11 @@ module Redmine
|
||||||
# Version header
|
# Version header
|
||||||
subject_for_version(version, options) unless options[:only] == :lines
|
subject_for_version(version, options) unless options[:only] == :lines
|
||||||
line_for_version(version, options) unless options[:only] == :subjects
|
line_for_version(version, options) unless options[:only] == :subjects
|
||||||
|
|
||||||
options[:top] += options[:top_increment]
|
options[:top] += options[:top_increment]
|
||||||
@number_of_rows += 1
|
@number_of_rows += 1
|
||||||
return if abort?
|
return if abort?
|
||||||
|
|
||||||
issues = version_issues(project, version)
|
issues = version_issues(project, version)
|
||||||
if issues
|
if issues
|
||||||
sort_issues!(issues)
|
sort_issues!(issues)
|
||||||
|
@ -249,10 +249,10 @@ module Redmine
|
||||||
options[:indent] -= options[:indent_increment]
|
options[:indent] -= options[:indent_increment]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_end(options={})
|
def render_end(options={})
|
||||||
case options[:format]
|
case options[:format]
|
||||||
when :pdf
|
when :pdf
|
||||||
options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
|
options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -277,10 +277,10 @@ module Redmine
|
||||||
if project.is_a?(Project) && project.start_date && project.due_date
|
if project.is_a?(Project) && project.start_date && project.due_date
|
||||||
options[:zoom] ||= 1
|
options[:zoom] ||= 1
|
||||||
options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
|
options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
|
||||||
|
|
||||||
coords = coordinates(project.start_date, project.due_date, nil, options[:zoom])
|
coords = coordinates(project.start_date, project.due_date, nil, options[:zoom])
|
||||||
label = h(project)
|
label = h(project)
|
||||||
|
|
||||||
case options[:format]
|
case options[:format]
|
||||||
when :html
|
when :html
|
||||||
html_task(options, coords, :css => "project task", :label => label, :markers => true)
|
html_task(options, coords, :css => "project task", :label => label, :markers => true)
|
||||||
|
@ -315,7 +315,7 @@ module Redmine
|
||||||
if version.is_a?(Version) && version.start_date && version.due_date
|
if version.is_a?(Version) && version.start_date && version.due_date
|
||||||
options[:zoom] ||= 1
|
options[:zoom] ||= 1
|
||||||
options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom]
|
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])
|
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 } #{h version.completed_pourcent.to_i.to_s}%"
|
||||||
label = h("#{version.project} -") + label unless @project && @project == version.project
|
label = h("#{version.project} -") + label unless @project && @project == version.project
|
||||||
|
@ -339,14 +339,14 @@ module Redmine
|
||||||
@issue_ancestors.pop
|
@issue_ancestors.pop
|
||||||
options[:indent] -= options[:indent_increment]
|
options[:indent] -= options[:indent_increment]
|
||||||
end
|
end
|
||||||
|
|
||||||
output = case options[:format]
|
output = case options[:format]
|
||||||
when :html
|
when :html
|
||||||
css_classes = ''
|
css_classes = ''
|
||||||
css_classes << ' issue-overdue' if issue.overdue?
|
css_classes << ' issue-overdue' if issue.overdue?
|
||||||
css_classes << ' issue-behind-schedule' if issue.behind_schedule?
|
css_classes << ' issue-behind-schedule' if issue.behind_schedule?
|
||||||
css_classes << ' icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to
|
css_classes << ' icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to
|
||||||
|
|
||||||
subject = "<span class='#{css_classes}'>"
|
subject = "<span class='#{css_classes}'>"
|
||||||
if issue.assigned_to.present?
|
if issue.assigned_to.present?
|
||||||
assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name
|
assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name
|
||||||
|
@ -366,7 +366,7 @@ module Redmine
|
||||||
@issue_ancestors << issue
|
@issue_ancestors << issue
|
||||||
options[:indent] += options[:indent_increment]
|
options[:indent] += options[:indent_increment]
|
||||||
end
|
end
|
||||||
|
|
||||||
output
|
output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ module Redmine
|
||||||
if issue.is_a?(Issue) && issue.due_before
|
if issue.is_a?(Issue) && issue.due_before
|
||||||
coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom])
|
coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom])
|
||||||
label = "#{ issue.status.name } #{ issue.done_ratio }%"
|
label = "#{ issue.status.name } #{ issue.done_ratio }%"
|
||||||
|
|
||||||
case options[:format]
|
case options[:format]
|
||||||
when :html
|
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?)
|
||||||
|
@ -393,10 +393,10 @@ module Redmine
|
||||||
# Generates a gantt image
|
# Generates a gantt image
|
||||||
# Only defined if RMagick is avalaible
|
# Only defined if RMagick is avalaible
|
||||||
def to_image(format='PNG')
|
def to_image(format='PNG')
|
||||||
date_to = (@date_from >> @months)-1
|
date_to = (@date_from >> @months)-1
|
||||||
show_weeks = @zoom > 1
|
show_weeks = @zoom > 1
|
||||||
show_days = @zoom > 2
|
show_days = @zoom > 2
|
||||||
|
|
||||||
subject_width = 400
|
subject_width = 400
|
||||||
header_heigth = 18
|
header_heigth = 18
|
||||||
# width of one day in pixels
|
# width of one day in pixels
|
||||||
|
@ -405,19 +405,19 @@ module Redmine
|
||||||
g_height = 20 * number_of_rows + 30
|
g_height = 20 * number_of_rows + 30
|
||||||
headers_heigth = (show_weeks ? 2*header_heigth : header_heigth)
|
headers_heigth = (show_weeks ? 2*header_heigth : header_heigth)
|
||||||
height = g_height + headers_heigth
|
height = g_height + headers_heigth
|
||||||
|
|
||||||
imgl = Magick::ImageList.new
|
imgl = Magick::ImageList.new
|
||||||
imgl.new_image(subject_width+g_width+1, height)
|
imgl.new_image(subject_width+g_width+1, height)
|
||||||
gc = Magick::Draw.new
|
gc = Magick::Draw.new
|
||||||
|
|
||||||
# Subjects
|
# Subjects
|
||||||
gc.stroke('transparent')
|
gc.stroke('transparent')
|
||||||
subjects(:image => gc, :top => (headers_heigth + 20), :indent => 4, :format => :image)
|
subjects(:image => gc, :top => (headers_heigth + 20), :indent => 4, :format => :image)
|
||||||
|
|
||||||
# Months headers
|
# Months headers
|
||||||
month_f = @date_from
|
month_f = @date_from
|
||||||
left = subject_width
|
left = subject_width
|
||||||
@months.times do
|
@months.times do
|
||||||
width = ((month_f >> 1) - month_f) * zoom
|
width = ((month_f >> 1) - month_f) * zoom
|
||||||
gc.fill('white')
|
gc.fill('white')
|
||||||
gc.stroke('grey')
|
gc.stroke('grey')
|
||||||
|
@ -430,7 +430,7 @@ module Redmine
|
||||||
left = left + width
|
left = left + width
|
||||||
month_f = month_f >> 1
|
month_f = month_f >> 1
|
||||||
end
|
end
|
||||||
|
|
||||||
# Weeks headers
|
# Weeks headers
|
||||||
if show_weeks
|
if show_weeks
|
||||||
left = subject_width
|
left = subject_width
|
||||||
|
@ -462,13 +462,13 @@ module Redmine
|
||||||
week_f = week_f+7
|
week_f = week_f+7
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Days details (week-end in grey)
|
# Days details (week-end in grey)
|
||||||
if show_days
|
if show_days
|
||||||
left = subject_width
|
left = subject_width
|
||||||
height = g_height + header_heigth - 1
|
height = g_height + header_heigth - 1
|
||||||
wday = @date_from.cwday
|
wday = @date_from.cwday
|
||||||
(date_to - @date_from + 1).to_i.times do
|
(date_to - @date_from + 1).to_i.times do
|
||||||
width = zoom
|
width = zoom
|
||||||
gc.fill(wday == 6 || wday == 7 ? '#eee' : 'white')
|
gc.fill(wday == 6 || wday == 7 ? '#eee' : 'white')
|
||||||
gc.stroke('#ddd')
|
gc.stroke('#ddd')
|
||||||
|
@ -479,7 +479,7 @@ module Redmine
|
||||||
wday = 1 if wday > 7
|
wday = 1 if wday > 7
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# border
|
# border
|
||||||
gc.fill('transparent')
|
gc.fill('transparent')
|
||||||
gc.stroke('grey')
|
gc.stroke('grey')
|
||||||
|
@ -487,20 +487,20 @@ module Redmine
|
||||||
gc.rectangle(0, 0, subject_width+g_width, headers_heigth)
|
gc.rectangle(0, 0, subject_width+g_width, headers_heigth)
|
||||||
gc.stroke('black')
|
gc.stroke('black')
|
||||||
gc.rectangle(0, 0, subject_width+g_width, g_height+ headers_heigth-1)
|
gc.rectangle(0, 0, subject_width+g_width, g_height+ headers_heigth-1)
|
||||||
|
|
||||||
# content
|
# content
|
||||||
top = headers_heigth + 20
|
top = headers_heigth + 20
|
||||||
|
|
||||||
gc.stroke('transparent')
|
gc.stroke('transparent')
|
||||||
lines(:image => gc, :top => top, :zoom => zoom, :subject_width => subject_width, :format => :image)
|
lines(:image => gc, :top => top, :zoom => zoom, :subject_width => subject_width, :format => :image)
|
||||||
|
|
||||||
# today red line
|
# today red line
|
||||||
if Date.today >= @date_from and Date.today <= date_to
|
if Date.today >= @date_from and Date.today <= date_to
|
||||||
gc.stroke('red')
|
gc.stroke('red')
|
||||||
x = (Date.today-@date_from+1)*zoom + subject_width
|
x = (Date.today-@date_from+1)*zoom + subject_width
|
||||||
gc.line(x, headers_heigth, x, headers_heigth + g_height-1)
|
gc.line(x, headers_heigth, x, headers_heigth + g_height-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
gc.draw(imgl)
|
gc.draw(imgl)
|
||||||
imgl.format = format
|
imgl.format = format
|
||||||
imgl.to_blob
|
imgl.to_blob
|
||||||
|
@ -521,14 +521,14 @@ module Redmine
|
||||||
pdf.RDMCell(PDF::LeftPaneWidth, 20, project.to_s)
|
pdf.RDMCell(PDF::LeftPaneWidth, 20, project.to_s)
|
||||||
pdf.Ln
|
pdf.Ln
|
||||||
pdf.SetFontStyle('B',9)
|
pdf.SetFontStyle('B',9)
|
||||||
|
|
||||||
subject_width = PDF::LeftPaneWidth
|
subject_width = PDF::LeftPaneWidth
|
||||||
header_heigth = 5
|
header_heigth = 5
|
||||||
|
|
||||||
headers_heigth = header_heigth
|
headers_heigth = header_heigth
|
||||||
show_weeks = false
|
show_weeks = false
|
||||||
show_days = false
|
show_days = false
|
||||||
|
|
||||||
if self.months < 7
|
if self.months < 7
|
||||||
show_weeks = true
|
show_weeks = true
|
||||||
headers_heigth = 2*header_heigth
|
headers_heigth = 2*header_heigth
|
||||||
|
@ -537,27 +537,27 @@ module Redmine
|
||||||
headers_heigth = 3*header_heigth
|
headers_heigth = 3*header_heigth
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
g_width = PDF.right_pane_width
|
g_width = PDF.right_pane_width
|
||||||
zoom = (g_width) / (self.date_to - self.date_from + 1)
|
zoom = (g_width) / (self.date_to - self.date_from + 1)
|
||||||
g_height = 120
|
g_height = 120
|
||||||
t_height = g_height + headers_heigth
|
t_height = g_height + headers_heigth
|
||||||
|
|
||||||
y_start = pdf.GetY
|
y_start = pdf.GetY
|
||||||
|
|
||||||
# Months headers
|
# Months headers
|
||||||
month_f = self.date_from
|
month_f = self.date_from
|
||||||
left = subject_width
|
left = subject_width
|
||||||
height = header_heigth
|
height = header_heigth
|
||||||
self.months.times do
|
self.months.times do
|
||||||
width = ((month_f >> 1) - month_f) * zoom
|
width = ((month_f >> 1) - month_f) * zoom
|
||||||
pdf.SetY(y_start)
|
pdf.SetY(y_start)
|
||||||
pdf.SetX(left)
|
pdf.SetX(left)
|
||||||
pdf.RDMCell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C")
|
pdf.RDMCell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C")
|
||||||
left = left + width
|
left = left + width
|
||||||
month_f = month_f >> 1
|
month_f = month_f >> 1
|
||||||
end
|
end
|
||||||
|
|
||||||
# Weeks headers
|
# Weeks headers
|
||||||
if show_weeks
|
if show_weeks
|
||||||
left = subject_width
|
left = subject_width
|
||||||
|
@ -583,14 +583,14 @@ module Redmine
|
||||||
week_f = week_f+7
|
week_f = week_f+7
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Days headers
|
# Days headers
|
||||||
if show_days
|
if show_days
|
||||||
left = subject_width
|
left = subject_width
|
||||||
height = header_heigth
|
height = header_heigth
|
||||||
wday = self.date_from.cwday
|
wday = self.date_from.cwday
|
||||||
pdf.SetFontStyle('B',7)
|
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
|
width = zoom
|
||||||
pdf.SetY(y_start + 2 * header_heigth)
|
pdf.SetY(y_start + 2 * header_heigth)
|
||||||
pdf.SetX(left)
|
pdf.SetX(left)
|
||||||
|
@ -600,11 +600,11 @@ module Redmine
|
||||||
wday = 1 if wday > 7
|
wday = 1 if wday > 7
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
pdf.SetY(y_start)
|
pdf.SetY(y_start)
|
||||||
pdf.SetX(15)
|
pdf.SetX(15)
|
||||||
pdf.RDMCell(subject_width+g_width-15, headers_heigth, "", 1)
|
pdf.RDMCell(subject_width+g_width-15, headers_heigth, "", 1)
|
||||||
|
|
||||||
# Tasks
|
# Tasks
|
||||||
top = headers_heigth + y_start
|
top = headers_heigth + y_start
|
||||||
options = {
|
options = {
|
||||||
|
@ -621,12 +621,12 @@ module Redmine
|
||||||
render(options)
|
render(options)
|
||||||
pdf.Output
|
pdf.Output
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def coordinates(start_date, end_date, progress, zoom=nil)
|
def coordinates(start_date, end_date, progress, zoom=nil)
|
||||||
zoom ||= @zoom
|
zoom ||= @zoom
|
||||||
|
|
||||||
coords = {}
|
coords = {}
|
||||||
if start_date && end_date && start_date < self.date_to && end_date > self.date_from
|
if start_date && end_date && start_date < self.date_to && end_date > self.date_from
|
||||||
if start_date > self.date_from
|
if start_date > self.date_from
|
||||||
|
@ -641,7 +641,7 @@ module Redmine
|
||||||
else
|
else
|
||||||
coords[:bar_end] = self.date_to - self.date_from + 1
|
coords[:bar_end] = self.date_to - self.date_from + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if progress
|
if progress
|
||||||
progress_date = start_date + (end_date - start_date + 1) * (progress / 100.0)
|
progress_date = start_date + (end_date - start_date + 1) * (progress / 100.0)
|
||||||
if progress_date > self.date_from && progress_date > start_date
|
if progress_date > self.date_from && progress_date > start_date
|
||||||
|
@ -651,7 +651,7 @@ module Redmine
|
||||||
coords[:bar_progress_end] = self.date_to - self.date_from + 1
|
coords[:bar_progress_end] = self.date_to - self.date_from + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if progress_date < Date.today
|
if progress_date < Date.today
|
||||||
late_date = [Date.today, end_date].min
|
late_date = [Date.today, end_date].min
|
||||||
if late_date > self.date_from && late_date > start_date
|
if late_date > self.date_from && late_date > start_date
|
||||||
|
@ -664,7 +664,7 @@ module Redmine
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Transforms dates into pixels witdh
|
# Transforms dates into pixels witdh
|
||||||
coords.keys.each do |key|
|
coords.keys.each do |key|
|
||||||
coords[key] = (coords[key] * zoom).floor
|
coords[key] = (coords[key] * zoom).floor
|
||||||
|
@ -676,7 +676,7 @@ module Redmine
|
||||||
def sort_issues!(issues)
|
def sort_issues!(issues)
|
||||||
issues.sort! { |a, b| gantt_issue_compare(a, b, issues) }
|
issues.sort! { |a, b| gantt_issue_compare(a, b, issues) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: top level issues should be sorted by start date
|
# TODO: top level issues should be sorted by start date
|
||||||
def gantt_issue_compare(x, y, issues)
|
def gantt_issue_compare(x, y, issues)
|
||||||
if x.root_id == y.root_id
|
if x.root_id == y.root_id
|
||||||
|
@ -685,7 +685,7 @@ module Redmine
|
||||||
x.root_id <=> y.root_id
|
x.root_id <=> y.root_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_limit
|
def current_limit
|
||||||
if @max_rows
|
if @max_rows
|
||||||
@max_rows - @number_of_rows
|
@max_rows - @number_of_rows
|
||||||
|
@ -693,13 +693,13 @@ module Redmine
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def abort?
|
def abort?
|
||||||
if @max_rows && @number_of_rows >= @max_rows
|
if @max_rows && @number_of_rows >= @max_rows
|
||||||
@truncated = true
|
@truncated = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def pdf_new_page?(options)
|
def pdf_new_page?(options)
|
||||||
if options[:top] > 180
|
if options[:top] > 180
|
||||||
options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
|
options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top])
|
||||||
|
@ -708,41 +708,41 @@ module Redmine
|
||||||
options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1)
|
options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def html_subject(params, subject, options={})
|
def html_subject(params, subject, options={})
|
||||||
style = "position: absolute;top:#{params[:top]}px;left:#{params[:indent]}px;"
|
style = "position: absolute;top:#{params[:top]}px;left:#{params[:indent]}px;"
|
||||||
style << "width:#{params[:subject_width] - params[:indent]}px;" if params[:subject_width]
|
style << "width:#{params[:subject_width] - params[:indent]}px;" if params[:subject_width]
|
||||||
|
|
||||||
output = view.content_tag 'div', subject, :class => options[:css], :style => style, :title => options[:title]
|
output = view.content_tag 'div', subject, :class => options[:css], :style => style, :title => options[:title]
|
||||||
@subjects << output
|
@subjects << output
|
||||||
output
|
output
|
||||||
end
|
end
|
||||||
|
|
||||||
def pdf_subject(params, subject, options={})
|
def pdf_subject(params, subject, options={})
|
||||||
params[:pdf].SetY(params[:top])
|
params[:pdf].SetY(params[:top])
|
||||||
params[:pdf].SetX(15)
|
params[:pdf].SetX(15)
|
||||||
|
|
||||||
char_limit = PDF::MaxCharactorsForSubject - params[:indent]
|
char_limit = PDF::MaxCharactorsForSubject - params[:indent]
|
||||||
params[:pdf].RDMCell(params[:subject_width]-15, 5, (" " * params[:indent]) + subject.to_s.sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR")
|
params[:pdf].RDMCell(params[:subject_width]-15, 5, (" " * params[:indent]) + subject.to_s.sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR")
|
||||||
|
|
||||||
params[:pdf].SetY(params[:top])
|
params[:pdf].SetY(params[:top])
|
||||||
params[:pdf].SetX(params[:subject_width])
|
params[:pdf].SetX(params[:subject_width])
|
||||||
params[:pdf].RDMCell(params[:g_width], 5, "", "LR")
|
params[:pdf].RDMCell(params[:g_width], 5, "", "LR")
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_subject(params, subject, options={})
|
def image_subject(params, subject, options={})
|
||||||
params[:image].fill('black')
|
params[:image].fill('black')
|
||||||
params[:image].stroke('transparent')
|
params[:image].stroke('transparent')
|
||||||
params[:image].stroke_width(1)
|
params[:image].stroke_width(1)
|
||||||
params[:image].text(params[:indent], params[:top] + 2, subject)
|
params[:image].text(params[:indent], params[:top] + 2, subject)
|
||||||
end
|
end
|
||||||
|
|
||||||
def html_task(params, coords, options={})
|
def html_task(params, coords, options={})
|
||||||
output = ''
|
output = ''
|
||||||
# Renders the task bar, with progress and late
|
# Renders the task bar, with progress and late
|
||||||
if coords[:bar_start] && coords[:bar_end]
|
if coords[:bar_start] && coords[:bar_end]
|
||||||
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>"
|
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>"
|
||||||
|
|
||||||
if coords[:bar_late_end]
|
if coords[:bar_late_end]
|
||||||
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>"
|
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>"
|
||||||
end
|
end
|
||||||
|
@ -775,17 +775,17 @@ module Redmine
|
||||||
@lines << output
|
@lines << output
|
||||||
output
|
output
|
||||||
end
|
end
|
||||||
|
|
||||||
def pdf_task(params, coords, options={})
|
def pdf_task(params, coords, options={})
|
||||||
height = options[:height] || 2
|
height = options[:height] || 2
|
||||||
|
|
||||||
# Renders the task bar, with progress and late
|
# Renders the task bar, with progress and late
|
||||||
if coords[:bar_start] && coords[:bar_end]
|
if coords[:bar_start] && coords[:bar_end]
|
||||||
params[:pdf].SetY(params[:top]+1.5)
|
params[:pdf].SetY(params[:top]+1.5)
|
||||||
params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
|
params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
|
||||||
params[:pdf].SetFillColor(200,200,200)
|
params[:pdf].SetFillColor(200,200,200)
|
||||||
params[:pdf].RDMCell(coords[:bar_end] - coords[:bar_start], height, "", 0, 0, "", 1)
|
params[:pdf].RDMCell(coords[:bar_end] - coords[:bar_start], height, "", 0, 0, "", 1)
|
||||||
|
|
||||||
if coords[:bar_late_end]
|
if coords[:bar_late_end]
|
||||||
params[:pdf].SetY(params[:top]+1.5)
|
params[:pdf].SetY(params[:top]+1.5)
|
||||||
params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
|
params[:pdf].SetX(params[:subject_width] + coords[:bar_start])
|
||||||
|
@ -805,13 +805,13 @@ module Redmine
|
||||||
params[:pdf].SetY(params[:top] + 1)
|
params[:pdf].SetY(params[:top] + 1)
|
||||||
params[:pdf].SetX(params[:subject_width] + coords[:start] - 1)
|
params[:pdf].SetX(params[:subject_width] + coords[:start] - 1)
|
||||||
params[:pdf].SetFillColor(50,50,200)
|
params[:pdf].SetFillColor(50,50,200)
|
||||||
params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1)
|
params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1)
|
||||||
end
|
end
|
||||||
if coords[:end]
|
if coords[:end]
|
||||||
params[:pdf].SetY(params[:top] + 1)
|
params[:pdf].SetY(params[:top] + 1)
|
||||||
params[:pdf].SetX(params[:subject_width] + coords[:end] - 1)
|
params[:pdf].SetX(params[:subject_width] + coords[:end] - 1)
|
||||||
params[:pdf].SetFillColor(50,50,200)
|
params[:pdf].SetFillColor(50,50,200)
|
||||||
params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1)
|
params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# Renders the label on the right
|
# Renders the label on the right
|
||||||
|
@ -823,12 +823,12 @@ module Redmine
|
||||||
|
|
||||||
def image_task(params, coords, options={})
|
def image_task(params, coords, options={})
|
||||||
height = options[:height] || 6
|
height = options[:height] || 6
|
||||||
|
|
||||||
# Renders the task bar, with progress and late
|
# Renders the task bar, with progress and late
|
||||||
if coords[:bar_start] && coords[:bar_end]
|
if coords[:bar_start] && coords[:bar_end]
|
||||||
params[:image].fill('#aaa')
|
params[:image].fill('#aaa')
|
||||||
params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_end], params[:top] - height)
|
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]
|
if coords[:bar_late_end]
|
||||||
params[:image].fill('#f66')
|
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)
|
params[:image].rectangle(params[:subject_width] + coords[:bar_start], params[:top], params[:subject_width] + coords[:bar_late_end], params[:top] - height)
|
||||||
|
|
Loading…
Reference in New Issue