From: Jean-Philippe Lang Date: Fri, 17 Dec 2010 15:21:38 +0000 (+0000) Subject: Gantt code cleaning. X-Git-Tag: 1.1.0~69 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8a86b2d2bc8b5bd954739d23b24adb850b94e074;p=redmine.git Gantt code cleaning. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4527 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/lib/redmine/helpers/gantt.rb b/lib/redmine/helpers/gantt.rb index ae10439c7..6ce98f775 100644 --- a/lib/redmine/helpers/gantt.rb +++ b/lib/redmine/helpers/gantt.rb @@ -257,37 +257,15 @@ module Redmine def subject_for_project(project, options) case options[:format] when :html - output = '' - - output << "
" - if project.is_a? Project - output << "" - output << view.link_to_project(project) - output << '' - else - ActiveRecord::Base.logger.debug "Gantt#subject_for_project was not given a project" - '' - end - output << "
" - @subjects << output - output + subject = "" + subject << view.link_to_project(project) + subject << '' + html_subject(options, subject, :css => "project-name") when :image - - options[:image].fill('black') - options[:image].stroke('transparent') - options[:image].stroke_width(1) - options[:image].text(options[:indent], options[:top] + 2, project.name) + image_subject(options, project.name) when :pdf pdf_new_page?(options) - options[:pdf].SetY(options[:top]) - options[:pdf].SetX(15) - - char_limit = PDF::MaxCharactorsForSubject - options[:indent] - options[:pdf].Cell(options[:subject_width]-15, 5, (" " * options[:indent]) +"#{project.name}".sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR") - - options[:pdf].SetY(options[:top]) - options[:pdf].SetX(options[:subject_width]) - options[:pdf].Cell(options[:g_width], 5, "", "LR") + pdf_subject(options, project.name) end end @@ -317,35 +295,15 @@ module Redmine def subject_for_version(version, options) case options[:format] when :html - output = '' - output << "
" - if version.is_a? Version - output << "" - output << view.link_to_version(version) - output << '' - else - ActiveRecord::Base.logger.debug "Gantt#subject_for_version was not given a version" - '' - end - output << "
" - @subjects << output - output + subject = "" + subject << view.link_to_version(version) + subject << '' + html_subject(options, subject, :css => "version-name") when :image - options[:image].fill('black') - options[:image].stroke('transparent') - options[:image].stroke_width(1) - options[:image].text(options[:indent], options[:top] + 2, version.to_s_with_project) + image_subject(options, version.to_s_with_project) when :pdf pdf_new_page?(options) - options[:pdf].SetY(options[:top]) - options[:pdf].SetX(15) - - char_limit = PDF::MaxCharactorsForSubject - options[:indent] - options[:pdf].Cell(options[:subject_width]-15, 5, (" " * options[:indent]) +"#{version.to_s_with_project}".sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR") - - options[:pdf].SetY(options[:top]) - options[:pdf].SetX(options[:subject_width]) - options[:pdf].Cell(options[:g_width], 5, "", "LR") + pdf_subject(options, version.to_s_with_project) end end @@ -376,54 +334,24 @@ module Redmine def subject_for_issue(issue, options) case options[:format] when :html - output = '' - output << "
" - output << "
" - if issue.is_a? Issue - 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 - - if issue.assigned_to.present? - assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name - output << view.avatar(issue.assigned_to, :class => 'gravatar icon-gravatar', :size => 10, :title => assigned_string) - end - output << "" - output << view.link_to_issue(issue) - output << '' - else - ActiveRecord::Base.logger.debug "Gantt#subject_for_issue was not given an issue" - '' - end - output << "
" - - # Tooltip - if issue.is_a? Issue - output << "" - output << view.render_issue_tooltip(issue) - output << "" + 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 + subject << view.avatar(issue.assigned_to, :class => 'gravatar icon-gravatar', :size => 10, :title => assigned_string) end - - output << "
" - @subjects << output - output + subject << view.link_to_issue(issue) + subject << '' + html_subject(options, subject, :css => "issue-subject") when :image - options[:image].fill('black') - options[:image].stroke('transparent') - options[:image].stroke_width(1) - options[:image].text(options[:indent], options[:top] + 2, issue.subject) + image_subject(options, issue.subject) when :pdf pdf_new_page?(options) - options[:pdf].SetY(options[:top]) - options[:pdf].SetX(15) - - char_limit = PDF::MaxCharactorsForSubject - options[:indent] - options[:pdf].Cell(options[:subject_width]-15, 5, (" " * options[:indent]) +"#{issue.tracker} #{issue.id}: #{issue.subject}".sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), "LR") - - options[:pdf].SetY(options[:top]) - options[:pdf].SetX(options[:subject_width]) - options[:pdf].Cell(options[:g_width], 5, "", "LR") + pdf_subject(options, issue.subject) end end @@ -759,6 +687,33 @@ module Redmine end end + def html_subject(params, subject, options={}) + output = "
" + output << subject + output << "
" + @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