To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / lib / redmine / helpers / gantt.rb @ 1298:4f746d8966dd
History | View | Annotate | Download (36.3 KB)
| 1 | 0:513646585e45 | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | 1295:622f24f53b42 | Chris | # Copyright (C) 2006-2013 Jean-Philippe Lang
|
| 3 | 0:513646585e45 | Chris | #
|
| 4 | # This program is free software; you can redistribute it and/or
|
||
| 5 | # modify it under the terms of the GNU General Public License
|
||
| 6 | # as published by the Free Software Foundation; either version 2
|
||
| 7 | # of the License, or (at your option) any later version.
|
||
| 8 | 441:cbce1fd3b1b7 | Chris | #
|
| 9 | 0:513646585e45 | Chris | # This program is distributed in the hope that it will be useful,
|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
| 12 | # GNU General Public License for more details.
|
||
| 13 | 441:cbce1fd3b1b7 | Chris | #
|
| 14 | 0:513646585e45 | Chris | # You should have received a copy of the GNU General Public License
|
| 15 | # along with this program; if not, write to the Free Software
|
||
| 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
| 17 | |||
| 18 | module Redmine |
||
| 19 | module Helpers |
||
| 20 | # Simple class to handle gantt chart data
|
||
| 21 | class Gantt |
||
| 22 | 22:40f7cfd4df19 | chris | include ERB::Util |
| 23 | include Redmine::I18n |
||
| 24 | 1115:433d4f72a19b | Chris | include Redmine::Utils::DateCalculation |
| 25 | 22:40f7cfd4df19 | chris | |
| 26 | 1295:622f24f53b42 | Chris | # Relation types that are rendered
|
| 27 | DRAW_TYPES = {
|
||
| 28 | IssueRelation::TYPE_BLOCKS => { :landscape_margin => 16, :color => '#F34F4F' }, |
||
| 29 | IssueRelation::TYPE_PRECEDES => { :landscape_margin => 20, :color => '#628FEA' } |
||
| 30 | }.freeze |
||
| 31 | |||
| 32 | 22:40f7cfd4df19 | chris | # :nodoc:
|
| 33 | # Some utility methods for the PDF export
|
||
| 34 | class PDF |
||
| 35 | MaxCharactorsForSubject = 45 |
||
| 36 | TotalWidth = 280 |
||
| 37 | LeftPaneWidth = 100 |
||
| 38 | |||
| 39 | def self.right_pane_width |
||
| 40 | TotalWidth - LeftPaneWidth |
||
| 41 | end
|
||
| 42 | end
|
||
| 43 | |||
| 44 | 119:8661b858af72 | Chris | attr_reader :year_from, :month_from, :date_from, :date_to, :zoom, :months, :truncated, :max_rows |
| 45 | 22:40f7cfd4df19 | chris | attr_accessor :query
|
| 46 | attr_accessor :project
|
||
| 47 | attr_accessor :view
|
||
| 48 | 441:cbce1fd3b1b7 | Chris | |
| 49 | 0:513646585e45 | Chris | def initialize(options={}) |
| 50 | options = options.dup |
||
| 51 | if options[:year] && options[:year].to_i >0 |
||
| 52 | @year_from = options[:year].to_i |
||
| 53 | if options[:month] && options[:month].to_i >=1 && options[:month].to_i <= 12 |
||
| 54 | @month_from = options[:month].to_i |
||
| 55 | else
|
||
| 56 | @month_from = 1 |
||
| 57 | end
|
||
| 58 | else
|
||
| 59 | @month_from ||= Date.today.month |
||
| 60 | @year_from ||= Date.today.year |
||
| 61 | end
|
||
| 62 | zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i |
||
| 63 | 441:cbce1fd3b1b7 | Chris | @zoom = (zoom > 0 && zoom < 5) ? zoom : 2 |
| 64 | 0:513646585e45 | Chris | months = (options[:months] || User.current.pref[:gantt_months]).to_i |
| 65 | @months = (months > 0 && months < 25) ? months : 6 |
||
| 66 | # Save gantt parameters as user preference (zoom and months count)
|
||
| 67 | 1115:433d4f72a19b | Chris | if (User.current.logged? && (@zoom != User.current.pref[:gantt_zoom] || |
| 68 | @months != User.current.pref[:gantt_months])) |
||
| 69 | 0:513646585e45 | Chris | User.current.pref[:gantt_zoom], User.current.pref[:gantt_months] = @zoom, @months |
| 70 | User.current.preference.save
|
||
| 71 | end
|
||
| 72 | @date_from = Date.civil(@year_from, @month_from, 1) |
||
| 73 | @date_to = (@date_from >> @months) - 1 |
||
| 74 | 119:8661b858af72 | Chris | @subjects = '' |
| 75 | @lines = '' |
||
| 76 | @number_of_rows = nil |
||
| 77 | @issue_ancestors = []
|
||
| 78 | @truncated = false |
||
| 79 | if options.has_key?(:max_rows) |
||
| 80 | @max_rows = options[:max_rows] |
||
| 81 | else
|
||
| 82 | @max_rows = Setting.gantt_items_limit.blank? ? nil : Setting.gantt_items_limit.to_i |
||
| 83 | end
|
||
| 84 | 0:513646585e45 | Chris | end
|
| 85 | 22:40f7cfd4df19 | chris | |
| 86 | def common_params |
||
| 87 | { :controller => 'gantts', :action => 'show', :project_id => @project }
|
||
| 88 | 0:513646585e45 | Chris | end
|
| 89 | 441:cbce1fd3b1b7 | Chris | |
| 90 | 0:513646585e45 | Chris | def params |
| 91 | 1115:433d4f72a19b | Chris | common_params.merge({:zoom => zoom, :year => year_from,
|
| 92 | :month => month_from, :months => months}) |
||
| 93 | 0:513646585e45 | Chris | end
|
| 94 | 441:cbce1fd3b1b7 | Chris | |
| 95 | 0:513646585e45 | Chris | def params_previous |
| 96 | 1115:433d4f72a19b | Chris | common_params.merge({:year => (date_from << months).year,
|
| 97 | :month => (date_from << months).month,
|
||
| 98 | :zoom => zoom, :months => months}) |
||
| 99 | 0:513646585e45 | Chris | end
|
| 100 | 441:cbce1fd3b1b7 | Chris | |
| 101 | 0:513646585e45 | Chris | def params_next |
| 102 | 1115:433d4f72a19b | Chris | common_params.merge({:year => (date_from >> months).year,
|
| 103 | :month => (date_from >> months).month,
|
||
| 104 | :zoom => zoom, :months => months}) |
||
| 105 | 0:513646585e45 | Chris | end
|
| 106 | 22:40f7cfd4df19 | chris | |
| 107 | # Returns the number of rows that will be rendered on the Gantt chart
|
||
| 108 | def number_of_rows |
||
| 109 | 119:8661b858af72 | Chris | return @number_of_rows if @number_of_rows |
| 110 | 441:cbce1fd3b1b7 | Chris | rows = projects.inject(0) {|total, p| total += number_of_rows_on_project(p)}
|
| 111 | 119:8661b858af72 | Chris | rows > @max_rows ? @max_rows : rows |
| 112 | 22:40f7cfd4df19 | chris | end
|
| 113 | |||
| 114 | # Returns the number of rows that will be used to list a project on
|
||
| 115 | # the Gantt chart. This will recurse for each subproject.
|
||
| 116 | def number_of_rows_on_project(project) |
||
| 117 | 441:cbce1fd3b1b7 | Chris | return 0 unless projects.include?(project) |
| 118 | 22:40f7cfd4df19 | chris | count = 1
|
| 119 | 441:cbce1fd3b1b7 | Chris | count += project_issues(project).size |
| 120 | count += project_versions(project).size |
||
| 121 | 22:40f7cfd4df19 | chris | count |
| 122 | end
|
||
| 123 | |||
| 124 | # Renders the subjects of the Gantt chart, the left side.
|
||
| 125 | def subjects(options={}) |
||
| 126 | 119:8661b858af72 | Chris | render(options.merge(:only => :subjects)) unless @subjects_rendered |
| 127 | @subjects
|
||
| 128 | 22:40f7cfd4df19 | chris | end
|
| 129 | |||
| 130 | # Renders the lines of the Gantt chart, the right side
|
||
| 131 | def lines(options={}) |
||
| 132 | 119:8661b858af72 | Chris | render(options.merge(:only => :lines)) unless @lines_rendered |
| 133 | @lines
|
||
| 134 | end
|
||
| 135 | 441:cbce1fd3b1b7 | Chris | |
| 136 | # Returns issues that will be rendered
|
||
| 137 | def issues |
||
| 138 | @issues ||= @query.issues( |
||
| 139 | :include => [:assigned_to, :tracker, :priority, :category, :fixed_version], |
||
| 140 | :order => "#{Project.table_name}.lft ASC, #{Issue.table_name}.id ASC", |
||
| 141 | :limit => @max_rows |
||
| 142 | ) |
||
| 143 | end
|
||
| 144 | |||
| 145 | 1295:622f24f53b42 | Chris | # Returns a hash of the relations between the issues that are present on the gantt
|
| 146 | # and that should be displayed, grouped by issue ids.
|
||
| 147 | def relations |
||
| 148 | return @relations if @relations |
||
| 149 | if issues.any?
|
||
| 150 | issue_ids = issues.map(&:id)
|
||
| 151 | @relations = IssueRelation. |
||
| 152 | where(:issue_from_id => issue_ids, :issue_to_id => issue_ids, :relation_type => DRAW_TYPES.keys). |
||
| 153 | group_by(&:issue_from_id)
|
||
| 154 | else
|
||
| 155 | @relations = {}
|
||
| 156 | end
|
||
| 157 | end
|
||
| 158 | |||
| 159 | 441:cbce1fd3b1b7 | Chris | # Return all the project nodes that will be displayed
|
| 160 | def projects |
||
| 161 | return @projects if @projects |
||
| 162 | ids = issues.collect(&:project).uniq.collect(&:id) |
||
| 163 | if ids.any?
|
||
| 164 | # All issues projects and their visible ancestors
|
||
| 165 | @projects = Project.visible.all( |
||
| 166 | :joins => "LEFT JOIN #{Project.table_name} child ON #{Project.table_name}.lft <= child.lft AND #{Project.table_name}.rgt >= child.rgt", |
||
| 167 | :conditions => ["child.id IN (?)", ids], |
||
| 168 | :order => "#{Project.table_name}.lft ASC" |
||
| 169 | ).uniq |
||
| 170 | else
|
||
| 171 | @projects = []
|
||
| 172 | end
|
||
| 173 | end
|
||
| 174 | |||
| 175 | # Returns the issues that belong to +project+
|
||
| 176 | def project_issues(project) |
||
| 177 | @issues_by_project ||= issues.group_by(&:project) |
||
| 178 | @issues_by_project[project] || []
|
||
| 179 | end
|
||
| 180 | |||
| 181 | # Returns the distinct versions of the issues that belong to +project+
|
||
| 182 | def project_versions(project) |
||
| 183 | project_issues(project).collect(&:fixed_version).compact.uniq
|
||
| 184 | end
|
||
| 185 | |||
| 186 | # Returns the issues that belong to +project+ and are assigned to +version+
|
||
| 187 | def version_issues(project, version) |
||
| 188 | project_issues(project).select {|issue| issue.fixed_version == version}
|
||
| 189 | end
|
||
| 190 | |||
| 191 | 119:8661b858af72 | Chris | def render(options={}) |
| 192 | 1115:433d4f72a19b | Chris | options = {:top => 0, :top_increment => 20,
|
| 193 | :indent_increment => 20, :render => :subject, |
||
| 194 | :format => :html}.merge(options) |
||
| 195 | 441:cbce1fd3b1b7 | Chris | indent = options[:indent] || 4 |
| 196 | 119:8661b858af72 | Chris | @subjects = '' unless options[:only] == :lines |
| 197 | @lines = '' unless options[:only] == :subjects |
||
| 198 | @number_of_rows = 0 |
||
| 199 | 441:cbce1fd3b1b7 | Chris | Project.project_tree(projects) do |project, level| |
| 200 | options[:indent] = indent + level * options[:indent_increment] |
||
| 201 | render_project(project, options) |
||
| 202 | break if abort? |
||
| 203 | 22:40f7cfd4df19 | chris | end
|
| 204 | 119:8661b858af72 | Chris | @subjects_rendered = true unless options[:only] == :lines |
| 205 | @lines_rendered = true unless options[:only] == :subjects |
||
| 206 | render_end(options) |
||
| 207 | 22:40f7cfd4df19 | chris | end
|
| 208 | |||
| 209 | def render_project(project, options={}) |
||
| 210 | 119:8661b858af72 | Chris | subject_for_project(project, options) unless options[:only] == :lines |
| 211 | line_for_project(project, options) unless options[:only] == :subjects |
||
| 212 | 22:40f7cfd4df19 | chris | options[:top] += options[:top_increment] |
| 213 | options[:indent] += options[:indent_increment] |
||
| 214 | 119:8661b858af72 | Chris | @number_of_rows += 1 |
| 215 | return if abort? |
||
| 216 | 441:cbce1fd3b1b7 | Chris | issues = project_issues(project).select {|i| i.fixed_version.nil?}
|
| 217 | 119:8661b858af72 | Chris | sort_issues!(issues) |
| 218 | 22:40f7cfd4df19 | chris | if issues
|
| 219 | 119:8661b858af72 | Chris | render_issues(issues, options) |
| 220 | return if abort? |
||
| 221 | 22:40f7cfd4df19 | chris | end
|
| 222 | 441:cbce1fd3b1b7 | Chris | versions = project_versions(project) |
| 223 | versions.each do |version|
|
||
| 224 | render_version(project, version, options) |
||
| 225 | 22:40f7cfd4df19 | chris | end
|
| 226 | # Remove indent to hit the next sibling
|
||
| 227 | options[:indent] -= options[:indent_increment] |
||
| 228 | end
|
||
| 229 | |||
| 230 | def render_issues(issues, options={}) |
||
| 231 | 119:8661b858af72 | Chris | @issue_ancestors = []
|
| 232 | 22:40f7cfd4df19 | chris | issues.each do |i|
|
| 233 | 119:8661b858af72 | Chris | subject_for_issue(i, options) unless options[:only] == :lines |
| 234 | line_for_issue(i, options) unless options[:only] == :subjects |
||
| 235 | 22:40f7cfd4df19 | chris | options[:top] += options[:top_increment] |
| 236 | 119:8661b858af72 | Chris | @number_of_rows += 1 |
| 237 | break if abort? |
||
| 238 | 22:40f7cfd4df19 | chris | end
|
| 239 | 119:8661b858af72 | Chris | options[:indent] -= (options[:indent_increment] * @issue_ancestors.size) |
| 240 | 22:40f7cfd4df19 | chris | end
|
| 241 | |||
| 242 | 441:cbce1fd3b1b7 | Chris | def render_version(project, version, options={}) |
| 243 | 22:40f7cfd4df19 | chris | # Version header
|
| 244 | 119:8661b858af72 | Chris | subject_for_version(version, options) unless options[:only] == :lines |
| 245 | line_for_version(version, options) unless options[:only] == :subjects |
||
| 246 | 22:40f7cfd4df19 | chris | options[:top] += options[:top_increment] |
| 247 | 119:8661b858af72 | Chris | @number_of_rows += 1 |
| 248 | return if abort? |
||
| 249 | 441:cbce1fd3b1b7 | Chris | issues = version_issues(project, version) |
| 250 | 22:40f7cfd4df19 | chris | if issues
|
| 251 | 119:8661b858af72 | Chris | sort_issues!(issues) |
| 252 | 22:40f7cfd4df19 | chris | # Indent issues
|
| 253 | options[:indent] += options[:indent_increment] |
||
| 254 | 119:8661b858af72 | Chris | render_issues(issues, options) |
| 255 | 22:40f7cfd4df19 | chris | options[:indent] -= options[:indent_increment] |
| 256 | end
|
||
| 257 | 119:8661b858af72 | Chris | end
|
| 258 | 441:cbce1fd3b1b7 | Chris | |
| 259 | 119:8661b858af72 | Chris | def render_end(options={}) |
| 260 | case options[:format] |
||
| 261 | 441:cbce1fd3b1b7 | Chris | when :pdf |
| 262 | 119:8661b858af72 | Chris | options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top]) |
| 263 | end
|
||
| 264 | 22:40f7cfd4df19 | chris | end
|
| 265 | |||
| 266 | def subject_for_project(project, options) |
||
| 267 | case options[:format] |
||
| 268 | when :html |
||
| 269 | 1115:433d4f72a19b | Chris | html_class = ""
|
| 270 | html_class << 'icon icon-projects '
|
||
| 271 | html_class << (project.overdue? ? 'project-overdue' : '') |
||
| 272 | s = view.link_to_project(project).html_safe |
||
| 273 | subject = view.content_tag(:span, s,
|
||
| 274 | :class => html_class).html_safe
|
||
| 275 | 119:8661b858af72 | Chris | html_subject(options, subject, :css => "project-name") |
| 276 | 22:40f7cfd4df19 | chris | when :image |
| 277 | 119:8661b858af72 | Chris | image_subject(options, project.name) |
| 278 | 22:40f7cfd4df19 | chris | when :pdf |
| 279 | 119:8661b858af72 | Chris | pdf_new_page?(options) |
| 280 | pdf_subject(options, project.name) |
||
| 281 | 22:40f7cfd4df19 | chris | end
|
| 282 | end
|
||
| 283 | |||
| 284 | def line_for_project(project, options) |
||
| 285 | 37:94944d00e43c | chris | # Skip versions that don't have a start_date or due date
|
| 286 | if project.is_a?(Project) && project.start_date && project.due_date |
||
| 287 | 22:40f7cfd4df19 | chris | options[:zoom] ||= 1 |
| 288 | options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom] |
||
| 289 | 119:8661b858af72 | Chris | coords = coordinates(project.start_date, project.due_date, nil, options[:zoom]) |
| 290 | label = h(project) |
||
| 291 | 22:40f7cfd4df19 | chris | case options[:format] |
| 292 | when :html |
||
| 293 | 119:8661b858af72 | Chris | html_task(options, coords, :css => "project task", :label => label, :markers => true) |
| 294 | 22:40f7cfd4df19 | chris | when :image |
| 295 | 119:8661b858af72 | Chris | image_task(options, coords, :label => label, :markers => true, :height => 3) |
| 296 | 22:40f7cfd4df19 | chris | when :pdf |
| 297 | 119:8661b858af72 | Chris | pdf_task(options, coords, :label => label, :markers => true, :height => 0.8) |
| 298 | 22:40f7cfd4df19 | chris | end
|
| 299 | else
|
||
| 300 | ''
|
||
| 301 | end
|
||
| 302 | end
|
||
| 303 | |||
| 304 | def subject_for_version(version, options) |
||
| 305 | case options[:format] |
||
| 306 | when :html |
||
| 307 | 1115:433d4f72a19b | Chris | html_class = ""
|
| 308 | html_class << 'icon icon-package '
|
||
| 309 | html_class << (version.behind_schedule? ? 'version-behind-schedule' : '') << " " |
||
| 310 | html_class << (version.overdue? ? 'version-overdue' : '') |
||
| 311 | 1295:622f24f53b42 | Chris | html_class << ' version-closed' unless version.open? |
| 312 | if version.start_date && version.due_date && version.completed_pourcent
|
||
| 313 | progress_date = calc_progress_date(version.start_date, |
||
| 314 | version.due_date, version.completed_pourcent) |
||
| 315 | html_class << ' behind-start-date' if progress_date < self.date_from |
||
| 316 | html_class << ' over-end-date' if progress_date > self.date_to |
||
| 317 | end
|
||
| 318 | 1115:433d4f72a19b | Chris | s = view.link_to_version(version).html_safe |
| 319 | subject = view.content_tag(:span, s,
|
||
| 320 | :class => html_class).html_safe
|
||
| 321 | 1295:622f24f53b42 | Chris | html_subject(options, subject, :css => "version-name", |
| 322 | :id => "version-#{version.id}") |
||
| 323 | 22:40f7cfd4df19 | chris | when :image |
| 324 | 119:8661b858af72 | Chris | image_subject(options, version.to_s_with_project) |
| 325 | 22:40f7cfd4df19 | chris | when :pdf |
| 326 | 119:8661b858af72 | Chris | pdf_new_page?(options) |
| 327 | pdf_subject(options, version.to_s_with_project) |
||
| 328 | 22:40f7cfd4df19 | chris | end
|
| 329 | end
|
||
| 330 | |||
| 331 | def line_for_version(version, options) |
||
| 332 | # Skip versions that don't have a start_date
|
||
| 333 | 1295:622f24f53b42 | Chris | if version.is_a?(Version) && version.due_date && version.start_date |
| 334 | 22:40f7cfd4df19 | chris | options[:zoom] ||= 1 |
| 335 | options[:g_width] ||= (self.date_to - self.date_from + 1) * options[:zoom] |
||
| 336 | 1115:433d4f72a19b | Chris | coords = coordinates(version.start_date, |
| 337 | 1295:622f24f53b42 | Chris | version.due_date, version.completed_percent, |
| 338 | 1115:433d4f72a19b | Chris | options[:zoom])
|
| 339 | 1295:622f24f53b42 | Chris | label = "#{h version} #{h version.completed_percent.to_i.to_s}%"
|
| 340 | 119:8661b858af72 | Chris | label = h("#{version.project} -") + label unless @project && @project == version.project |
| 341 | 22:40f7cfd4df19 | chris | case options[:format] |
| 342 | when :html |
||
| 343 | 1295:622f24f53b42 | Chris | html_task(options, coords, :css => "version task", |
| 344 | :label => label, :markers => true, :version => version) |
||
| 345 | 22:40f7cfd4df19 | chris | when :image |
| 346 | 119:8661b858af72 | Chris | image_task(options, coords, :label => label, :markers => true, :height => 3) |
| 347 | 22:40f7cfd4df19 | chris | when :pdf |
| 348 | 119:8661b858af72 | Chris | pdf_task(options, coords, :label => label, :markers => true, :height => 0.8) |
| 349 | 22:40f7cfd4df19 | chris | end
|
| 350 | else
|
||
| 351 | ''
|
||
| 352 | end
|
||
| 353 | end
|
||
| 354 | |||
| 355 | def subject_for_issue(issue, options) |
||
| 356 | 119:8661b858af72 | Chris | while @issue_ancestors.any? && !issue.is_descendant_of?(@issue_ancestors.last) |
| 357 | @issue_ancestors.pop
|
||
| 358 | options[:indent] -= options[:indent_increment] |
||
| 359 | end
|
||
| 360 | output = case options[:format] |
||
| 361 | 22:40f7cfd4df19 | chris | when :html |
| 362 | 119:8661b858af72 | Chris | css_classes = ''
|
| 363 | css_classes << ' issue-overdue' if issue.overdue? |
||
| 364 | css_classes << ' issue-behind-schedule' if issue.behind_schedule? |
||
| 365 | css_classes << ' icon icon-issue' unless Setting.gravatar_enabled? && issue.assigned_to |
||
| 366 | 1295:622f24f53b42 | Chris | css_classes << ' issue-closed' if issue.closed? |
| 367 | if issue.start_date && issue.due_before && issue.done_ratio
|
||
| 368 | progress_date = calc_progress_date(issue.start_date, |
||
| 369 | issue.due_before, issue.done_ratio) |
||
| 370 | css_classes << ' behind-start-date' if progress_date < self.date_from |
||
| 371 | css_classes << ' over-end-date' if progress_date > self.date_to |
||
| 372 | end
|
||
| 373 | 1115:433d4f72a19b | Chris | s = "".html_safe
|
| 374 | 119:8661b858af72 | Chris | if issue.assigned_to.present?
|
| 375 | assigned_string = l(:field_assigned_to) + ": " + issue.assigned_to.name |
||
| 376 | 1115:433d4f72a19b | Chris | s << view.avatar(issue.assigned_to, |
| 377 | :class => 'gravatar icon-gravatar', |
||
| 378 | :size => 10, |
||
| 379 | :title => assigned_string).to_s.html_safe
|
||
| 380 | 119:8661b858af72 | Chris | end
|
| 381 | 1115:433d4f72a19b | Chris | s << view.link_to_issue(issue).html_safe |
| 382 | subject = view.content_tag(:span, s, :class => css_classes).html_safe |
||
| 383 | html_subject(options, subject, :css => "issue-subject", |
||
| 384 | 1295:622f24f53b42 | Chris | :title => issue.subject, :id => "issue-#{issue.id}") + "\n" |
| 385 | 119:8661b858af72 | Chris | when :image |
| 386 | image_subject(options, issue.subject) |
||
| 387 | when :pdf |
||
| 388 | pdf_new_page?(options) |
||
| 389 | pdf_subject(options, issue.subject) |
||
| 390 | end
|
||
| 391 | unless issue.leaf?
|
||
| 392 | @issue_ancestors << issue
|
||
| 393 | options[:indent] += options[:indent_increment] |
||
| 394 | end
|
||
| 395 | output |
||
| 396 | 22:40f7cfd4df19 | chris | end
|
| 397 | |||
| 398 | def line_for_issue(issue, options) |
||
| 399 | # Skip issues that don't have a due_before (due_date or version's due_date)
|
||
| 400 | if issue.is_a?(Issue) && issue.due_before |
||
| 401 | 119:8661b858af72 | Chris | coords = coordinates(issue.start_date, issue.due_before, issue.done_ratio, options[:zoom])
|
| 402 | 1115:433d4f72a19b | Chris | label = "#{issue.status.name} #{issue.done_ratio}%"
|
| 403 | 22:40f7cfd4df19 | chris | case options[:format] |
| 404 | when :html |
||
| 405 | 1115:433d4f72a19b | Chris | html_task(options, coords, |
| 406 | :css => "task " + (issue.leaf? ? 'leaf' : 'parent'), |
||
| 407 | :label => label, :issue => issue, |
||
| 408 | :markers => !issue.leaf?)
|
||
| 409 | 22:40f7cfd4df19 | chris | when :image |
| 410 | 119:8661b858af72 | Chris | image_task(options, coords, :label => label)
|
| 411 | 22:40f7cfd4df19 | chris | when :pdf |
| 412 | 119:8661b858af72 | Chris | pdf_task(options, coords, :label => label)
|
| 413 | end
|
||
| 414 | 22:40f7cfd4df19 | chris | else
|
| 415 | ''
|
||
| 416 | end
|
||
| 417 | end
|
||
| 418 | |||
| 419 | 0:513646585e45 | Chris | # Generates a gantt image
|
| 420 | # Only defined if RMagick is avalaible
|
||
| 421 | 22:40f7cfd4df19 | chris | def to_image(format='PNG') |
| 422 | 1115:433d4f72a19b | Chris | date_to = (@date_from >> @months) - 1 |
| 423 | 0:513646585e45 | Chris | show_weeks = @zoom > 1 |
| 424 | show_days = @zoom > 2 |
||
| 425 | 1:cca12e1c1fd4 | Chris | subject_width = 400
|
| 426 | 441:cbce1fd3b1b7 | Chris | header_height = 18
|
| 427 | 0:513646585e45 | Chris | # width of one day in pixels
|
| 428 | 1115:433d4f72a19b | Chris | zoom = @zoom * 2 |
| 429 | g_width = (@date_to - @date_from + 1) * zoom |
||
| 430 | 22:40f7cfd4df19 | chris | g_height = 20 * number_of_rows + 30 |
| 431 | 1115:433d4f72a19b | Chris | headers_height = (show_weeks ? 2 * header_height : header_height)
|
| 432 | 441:cbce1fd3b1b7 | Chris | height = g_height + headers_height |
| 433 | 0:513646585e45 | Chris | imgl = Magick::ImageList.new |
| 434 | 1115:433d4f72a19b | Chris | imgl.new_image(subject_width + g_width + 1, height)
|
| 435 | 0:513646585e45 | Chris | gc = Magick::Draw.new |
| 436 | 1115:433d4f72a19b | Chris | gc.font = Redmine::Configuration['rmagick_font_path'] || "" |
| 437 | 0:513646585e45 | Chris | # Subjects
|
| 438 | 119:8661b858af72 | Chris | gc.stroke('transparent')
|
| 439 | 441:cbce1fd3b1b7 | Chris | subjects(:image => gc, :top => (headers_height + 20), :indent => 4, :format => :image) |
| 440 | 0:513646585e45 | Chris | # Months headers
|
| 441 | month_f = @date_from
|
||
| 442 | left = subject_width |
||
| 443 | 441:cbce1fd3b1b7 | Chris | @months.times do |
| 444 | 0:513646585e45 | Chris | width = ((month_f >> 1) - month_f) * zoom
|
| 445 | gc.fill('white')
|
||
| 446 | gc.stroke('grey')
|
||
| 447 | gc.stroke_width(1)
|
||
| 448 | gc.rectangle(left, 0, left + width, height)
|
||
| 449 | gc.fill('black')
|
||
| 450 | gc.stroke('transparent')
|
||
| 451 | gc.stroke_width(1)
|
||
| 452 | gc.text(left.round + 8, 14, "#{month_f.year}-#{month_f.month}") |
||
| 453 | left = left + width |
||
| 454 | month_f = month_f >> 1
|
||
| 455 | end
|
||
| 456 | # Weeks headers
|
||
| 457 | if show_weeks
|
||
| 458 | 1115:433d4f72a19b | Chris | left = subject_width |
| 459 | height = header_height |
||
| 460 | if @date_from.cwday == 1 |
||
| 461 | # date_from is monday
|
||
| 462 | week_f = date_from |
||
| 463 | else
|
||
| 464 | # find next monday after date_from
|
||
| 465 | week_f = @date_from + (7 - @date_from.cwday + 1) |
||
| 466 | width = (7 - @date_from.cwday + 1) * zoom |
||
| 467 | gc.fill('white')
|
||
| 468 | gc.stroke('grey')
|
||
| 469 | gc.stroke_width(1)
|
||
| 470 | gc.rectangle(left, header_height, left + width, 2 * header_height + g_height - 1) |
||
| 471 | left = left + width |
||
| 472 | end
|
||
| 473 | while week_f <= date_to
|
||
| 474 | width = (week_f + 6 <= date_to) ? 7 * zoom : (date_to - week_f + 1) * zoom |
||
| 475 | gc.fill('white')
|
||
| 476 | gc.stroke('grey')
|
||
| 477 | gc.stroke_width(1)
|
||
| 478 | gc.rectangle(left.round, header_height, left.round + width, 2 * header_height + g_height - 1) |
||
| 479 | gc.fill('black')
|
||
| 480 | gc.stroke('transparent')
|
||
| 481 | gc.stroke_width(1)
|
||
| 482 | gc.text(left.round + 2, header_height + 14, week_f.cweek.to_s) |
||
| 483 | left = left + width |
||
| 484 | week_f = week_f + 7
|
||
| 485 | end
|
||
| 486 | 0:513646585e45 | Chris | end
|
| 487 | # Days details (week-end in grey)
|
||
| 488 | if show_days
|
||
| 489 | 1115:433d4f72a19b | Chris | left = subject_width |
| 490 | height = g_height + header_height - 1
|
||
| 491 | wday = @date_from.cwday
|
||
| 492 | (date_to - @date_from + 1).to_i.times do |
||
| 493 | width = zoom |
||
| 494 | gc.fill(non_working_week_days.include?(wday) ? '#eee' : 'white') |
||
| 495 | gc.stroke('#ddd')
|
||
| 496 | gc.stroke_width(1)
|
||
| 497 | gc.rectangle(left, 2 * header_height, left + width, 2 * header_height + g_height - 1) |
||
| 498 | left = left + width |
||
| 499 | wday = wday + 1
|
||
| 500 | wday = 1 if wday > 7 |
||
| 501 | end
|
||
| 502 | 0:513646585e45 | Chris | end
|
| 503 | # border
|
||
| 504 | gc.fill('transparent')
|
||
| 505 | gc.stroke('grey')
|
||
| 506 | gc.stroke_width(1)
|
||
| 507 | 1115:433d4f72a19b | Chris | gc.rectangle(0, 0, subject_width + g_width, headers_height) |
| 508 | 0:513646585e45 | Chris | gc.stroke('black')
|
| 509 | 1115:433d4f72a19b | Chris | gc.rectangle(0, 0, subject_width + g_width, g_height + headers_height - 1) |
| 510 | 0:513646585e45 | Chris | # content
|
| 511 | 441:cbce1fd3b1b7 | Chris | top = headers_height + 20
|
| 512 | 119:8661b858af72 | Chris | gc.stroke('transparent')
|
| 513 | 1115:433d4f72a19b | Chris | lines(:image => gc, :top => top, :zoom => zoom, |
| 514 | :subject_width => subject_width, :format => :image) |
||
| 515 | 0:513646585e45 | Chris | # today red line
|
| 516 | if Date.today >= @date_from and Date.today <= date_to |
||
| 517 | gc.stroke('red')
|
||
| 518 | 1115:433d4f72a19b | Chris | x = (Date.today - @date_from + 1) * zoom + subject_width |
| 519 | gc.line(x, headers_height, x, headers_height + g_height - 1)
|
||
| 520 | 441:cbce1fd3b1b7 | Chris | end
|
| 521 | 0:513646585e45 | Chris | gc.draw(imgl) |
| 522 | imgl.format = format |
||
| 523 | imgl.to_blob |
||
| 524 | end if Object.const_defined?(:Magick) |
||
| 525 | 22:40f7cfd4df19 | chris | |
| 526 | def to_pdf |
||
| 527 | 441:cbce1fd3b1b7 | Chris | pdf = ::Redmine::Export::PDF::ITCPDF.new(current_language) |
| 528 | 22:40f7cfd4df19 | chris | pdf.SetTitle("#{l(:label_gantt)} #{project}")
|
| 529 | 441:cbce1fd3b1b7 | Chris | pdf.alias_nb_pages |
| 530 | 22:40f7cfd4df19 | chris | pdf.footer_date = format_date(Date.today)
|
| 531 | pdf.AddPage("L")
|
||
| 532 | 1115:433d4f72a19b | Chris | pdf.SetFontStyle('B', 12) |
| 533 | 22:40f7cfd4df19 | chris | pdf.SetX(15)
|
| 534 | 441:cbce1fd3b1b7 | Chris | pdf.RDMCell(PDF::LeftPaneWidth, 20, project.to_s) |
| 535 | 22:40f7cfd4df19 | chris | pdf.Ln |
| 536 | 1115:433d4f72a19b | Chris | pdf.SetFontStyle('B', 9) |
| 537 | 22:40f7cfd4df19 | chris | subject_width = PDF::LeftPaneWidth |
| 538 | 441:cbce1fd3b1b7 | Chris | header_height = 5
|
| 539 | headers_height = header_height |
||
| 540 | 22:40f7cfd4df19 | chris | show_weeks = false
|
| 541 | show_days = false
|
||
| 542 | if self.months < 7 |
||
| 543 | show_weeks = true
|
||
| 544 | 1115:433d4f72a19b | Chris | headers_height = 2 * header_height
|
| 545 | 22:40f7cfd4df19 | chris | if self.months < 3 |
| 546 | show_days = true
|
||
| 547 | 1115:433d4f72a19b | Chris | headers_height = 3 * header_height
|
| 548 | 22:40f7cfd4df19 | chris | end
|
| 549 | end
|
||
| 550 | g_width = PDF.right_pane_width
|
||
| 551 | zoom = (g_width) / (self.date_to - self.date_from + 1) |
||
| 552 | g_height = 120
|
||
| 553 | 441:cbce1fd3b1b7 | Chris | t_height = g_height + headers_height |
| 554 | 22:40f7cfd4df19 | chris | y_start = pdf.GetY |
| 555 | # Months headers
|
||
| 556 | month_f = self.date_from
|
||
| 557 | left = subject_width |
||
| 558 | 441:cbce1fd3b1b7 | Chris | height = header_height |
| 559 | self.months.times do |
||
| 560 | width = ((month_f >> 1) - month_f) * zoom
|
||
| 561 | 22:40f7cfd4df19 | chris | pdf.SetY(y_start) |
| 562 | pdf.SetX(left) |
||
| 563 | 441:cbce1fd3b1b7 | Chris | pdf.RDMCell(width, height, "#{month_f.year}-#{month_f.month}", "LTR", 0, "C") |
| 564 | 22:40f7cfd4df19 | chris | left = left + width |
| 565 | month_f = month_f >> 1
|
||
| 566 | 441:cbce1fd3b1b7 | Chris | end
|
| 567 | 22:40f7cfd4df19 | chris | # Weeks headers
|
| 568 | if show_weeks
|
||
| 569 | left = subject_width |
||
| 570 | 441:cbce1fd3b1b7 | Chris | height = header_height |
| 571 | 22:40f7cfd4df19 | chris | if self.date_from.cwday == 1 |
| 572 | # self.date_from is monday
|
||
| 573 | week_f = self.date_from
|
||
| 574 | else
|
||
| 575 | # find next monday after self.date_from
|
||
| 576 | week_f = self.date_from + (7 - self.date_from.cwday + 1) |
||
| 577 | width = (7 - self.date_from.cwday + 1) * zoom-1 |
||
| 578 | 441:cbce1fd3b1b7 | Chris | pdf.SetY(y_start + header_height) |
| 579 | 22:40f7cfd4df19 | chris | pdf.SetX(left) |
| 580 | 441:cbce1fd3b1b7 | Chris | pdf.RDMCell(width + 1, height, "", "LTR") |
| 581 | 1115:433d4f72a19b | Chris | left = left + width + 1
|
| 582 | 22:40f7cfd4df19 | chris | end
|
| 583 | while week_f <= self.date_to |
||
| 584 | width = (week_f + 6 <= self.date_to) ? 7 * zoom : (self.date_to - week_f + 1) * zoom |
||
| 585 | 441:cbce1fd3b1b7 | Chris | pdf.SetY(y_start + header_height) |
| 586 | 22:40f7cfd4df19 | chris | pdf.SetX(left) |
| 587 | 441:cbce1fd3b1b7 | Chris | pdf.RDMCell(width, height, (width >= 5 ? week_f.cweek.to_s : ""), "LTR", 0, "C") |
| 588 | 22:40f7cfd4df19 | chris | left = left + width |
| 589 | 1115:433d4f72a19b | Chris | week_f = week_f + 7
|
| 590 | 22:40f7cfd4df19 | chris | end
|
| 591 | end
|
||
| 592 | # Days headers
|
||
| 593 | if show_days
|
||
| 594 | left = subject_width |
||
| 595 | 441:cbce1fd3b1b7 | Chris | height = header_height |
| 596 | 22:40f7cfd4df19 | chris | wday = self.date_from.cwday
|
| 597 | 1115:433d4f72a19b | Chris | pdf.SetFontStyle('B', 7) |
| 598 | 441:cbce1fd3b1b7 | Chris | (self.date_to - self.date_from + 1).to_i.times do |
| 599 | 22:40f7cfd4df19 | chris | width = zoom |
| 600 | 441:cbce1fd3b1b7 | Chris | pdf.SetY(y_start + 2 * header_height)
|
| 601 | 22:40f7cfd4df19 | chris | pdf.SetX(left) |
| 602 | 441:cbce1fd3b1b7 | Chris | pdf.RDMCell(width, height, day_name(wday).first, "LTR", 0, "C") |
| 603 | 22:40f7cfd4df19 | chris | left = left + width |
| 604 | wday = wday + 1
|
||
| 605 | wday = 1 if wday > 7 |
||
| 606 | end
|
||
| 607 | end
|
||
| 608 | pdf.SetY(y_start) |
||
| 609 | pdf.SetX(15)
|
||
| 610 | 1115:433d4f72a19b | Chris | pdf.RDMCell(subject_width + g_width - 15, headers_height, "", 1) |
| 611 | 22:40f7cfd4df19 | chris | # Tasks
|
| 612 | 441:cbce1fd3b1b7 | Chris | top = headers_height + y_start |
| 613 | 119:8661b858af72 | Chris | options = {
|
| 614 | :top => top,
|
||
| 615 | :zoom => zoom,
|
||
| 616 | :subject_width => subject_width,
|
||
| 617 | :g_width => g_width,
|
||
| 618 | :indent => 0, |
||
| 619 | :indent_increment => 5, |
||
| 620 | :top_increment => 5, |
||
| 621 | :format => :pdf, |
||
| 622 | :pdf => pdf
|
||
| 623 | } |
||
| 624 | render(options) |
||
| 625 | 22:40f7cfd4df19 | chris | pdf.Output |
| 626 | end
|
||
| 627 | 441:cbce1fd3b1b7 | Chris | |
| 628 | 0:513646585e45 | Chris | private |
| 629 | 441:cbce1fd3b1b7 | Chris | |
| 630 | 119:8661b858af72 | Chris | def coordinates(start_date, end_date, progress, zoom=nil) |
| 631 | zoom ||= @zoom
|
||
| 632 | coords = {}
|
||
| 633 | if start_date && end_date && start_date < self.date_to && end_date > self.date_from |
||
| 634 | if start_date > self.date_from |
||
| 635 | coords[:start] = start_date - self.date_from |
||
| 636 | coords[:bar_start] = start_date - self.date_from |
||
| 637 | else
|
||
| 638 | coords[:bar_start] = 0 |
||
| 639 | end
|
||
| 640 | if end_date < self.date_to |
||
| 641 | coords[:end] = end_date - self.date_from |
||
| 642 | coords[:bar_end] = end_date - self.date_from + 1 |
||
| 643 | else
|
||
| 644 | coords[:bar_end] = self.date_to - self.date_from + 1 |
||
| 645 | end
|
||
| 646 | if progress
|
||
| 647 | 1295:622f24f53b42 | Chris | progress_date = calc_progress_date(start_date, end_date, progress) |
| 648 | 119:8661b858af72 | Chris | if progress_date > self.date_from && progress_date > start_date |
| 649 | if progress_date < self.date_to |
||
| 650 | 441:cbce1fd3b1b7 | Chris | coords[:bar_progress_end] = progress_date - self.date_from |
| 651 | 119:8661b858af72 | Chris | else
|
| 652 | coords[:bar_progress_end] = self.date_to - self.date_from + 1 |
||
| 653 | end
|
||
| 654 | end
|
||
| 655 | if progress_date < Date.today |
||
| 656 | late_date = [Date.today, end_date].min
|
||
| 657 | if late_date > self.date_from && late_date > start_date |
||
| 658 | if late_date < self.date_to |
||
| 659 | coords[:bar_late_end] = late_date - self.date_from + 1 |
||
| 660 | else
|
||
| 661 | coords[:bar_late_end] = self.date_to - self.date_from + 1 |
||
| 662 | end
|
||
| 663 | end
|
||
| 664 | end
|
||
| 665 | end
|
||
| 666 | end
|
||
| 667 | # Transforms dates into pixels witdh
|
||
| 668 | coords.keys.each do |key|
|
||
| 669 | coords[key] = (coords[key] * zoom).floor |
||
| 670 | end
|
||
| 671 | coords |
||
| 672 | end
|
||
| 673 | 22:40f7cfd4df19 | chris | |
| 674 | 1295:622f24f53b42 | Chris | def calc_progress_date(start_date, end_date, progress) |
| 675 | start_date + (end_date - start_date + 1) * (progress / 100.0) |
||
| 676 | end
|
||
| 677 | |||
| 678 | # TODO: Sorts a collection of issues by start_date, due_date, id for gantt rendering
|
||
| 679 | 119:8661b858af72 | Chris | def sort_issues!(issues) |
| 680 | 1115:433d4f72a19b | Chris | issues.sort! { |a, b| gantt_issue_compare(a, b) }
|
| 681 | 119:8661b858af72 | Chris | end
|
| 682 | 441:cbce1fd3b1b7 | Chris | |
| 683 | 119:8661b858af72 | Chris | # TODO: top level issues should be sorted by start date
|
| 684 | 1115:433d4f72a19b | Chris | def gantt_issue_compare(x, y) |
| 685 | 119:8661b858af72 | Chris | if x.root_id == y.root_id
|
| 686 | x.lft <=> y.lft |
||
| 687 | 0:513646585e45 | Chris | else
|
| 688 | 119:8661b858af72 | Chris | x.root_id <=> y.root_id |
| 689 | end
|
||
| 690 | end
|
||
| 691 | 441:cbce1fd3b1b7 | Chris | |
| 692 | 119:8661b858af72 | Chris | def current_limit |
| 693 | if @max_rows |
||
| 694 | @max_rows - @number_of_rows |
||
| 695 | else
|
||
| 696 | nil
|
||
| 697 | end
|
||
| 698 | end
|
||
| 699 | 441:cbce1fd3b1b7 | Chris | |
| 700 | 119:8661b858af72 | Chris | def abort? |
| 701 | if @max_rows && @number_of_rows >= @max_rows |
||
| 702 | @truncated = true |
||
| 703 | end
|
||
| 704 | end
|
||
| 705 | 441:cbce1fd3b1b7 | Chris | |
| 706 | 119:8661b858af72 | Chris | def pdf_new_page?(options) |
| 707 | if options[:top] > 180 |
||
| 708 | options[:pdf].Line(15, options[:top], PDF::TotalWidth, options[:top]) |
||
| 709 | options[:pdf].AddPage("L") |
||
| 710 | options[:top] = 15 |
||
| 711 | options[:pdf].Line(15, options[:top] - 0.1, PDF::TotalWidth, options[:top] - 0.1) |
||
| 712 | end
|
||
| 713 | end
|
||
| 714 | 441:cbce1fd3b1b7 | Chris | |
| 715 | 119:8661b858af72 | Chris | def html_subject(params, subject, options={}) |
| 716 | 245:051f544170fe | Chris | style = "position: absolute;top:#{params[:top]}px;left:#{params[:indent]}px;"
|
| 717 | style << "width:#{params[:subject_width] - params[:indent]}px;" if params[:subject_width] |
||
| 718 | 1295:622f24f53b42 | Chris | output = view.content_tag(:div, subject,
|
| 719 | 1115:433d4f72a19b | Chris | :class => options[:css], :style => style, |
| 720 | 1295:622f24f53b42 | Chris | :title => options[:title], |
| 721 | :id => options[:id]) |
||
| 722 | 119:8661b858af72 | Chris | @subjects << output
|
| 723 | output |
||
| 724 | end
|
||
| 725 | 441:cbce1fd3b1b7 | Chris | |
| 726 | 119:8661b858af72 | Chris | def pdf_subject(params, subject, options={}) |
| 727 | params[:pdf].SetY(params[:top]) |
||
| 728 | params[:pdf].SetX(15) |
||
| 729 | char_limit = PDF::MaxCharactorsForSubject - params[:indent] |
||
| 730 | 1115:433d4f72a19b | Chris | params[:pdf].RDMCell(params[:subject_width] - 15, 5, |
| 731 | (" " * params[:indent]) + |
||
| 732 | subject.to_s.sub(/^(.{#{char_limit}}[^\s]*\s).*$/, '\1 (...)'), |
||
| 733 | "LR")
|
||
| 734 | 119:8661b858af72 | Chris | params[:pdf].SetY(params[:top]) |
| 735 | params[:pdf].SetX(params[:subject_width]) |
||
| 736 | 441:cbce1fd3b1b7 | Chris | params[:pdf].RDMCell(params[:g_width], 5, "", "LR") |
| 737 | 119:8661b858af72 | Chris | end
|
| 738 | 441:cbce1fd3b1b7 | Chris | |
| 739 | 119:8661b858af72 | Chris | def image_subject(params, subject, options={}) |
| 740 | params[:image].fill('black') |
||
| 741 | params[:image].stroke('transparent') |
||
| 742 | params[:image].stroke_width(1) |
||
| 743 | params[:image].text(params[:indent], params[:top] + 2, subject) |
||
| 744 | end
|
||
| 745 | 441:cbce1fd3b1b7 | Chris | |
| 746 | 1295:622f24f53b42 | Chris | def issue_relations(issue) |
| 747 | rels = {}
|
||
| 748 | if relations[issue.id]
|
||
| 749 | relations[issue.id].each do |relation|
|
||
| 750 | (rels[relation.relation_type] ||= []) << relation.issue_to_id |
||
| 751 | end
|
||
| 752 | end
|
||
| 753 | rels |
||
| 754 | end
|
||
| 755 | |||
| 756 | 119:8661b858af72 | Chris | def html_task(params, coords, options={}) |
| 757 | output = ''
|
||
| 758 | # Renders the task bar, with progress and late
|
||
| 759 | if coords[:bar_start] && coords[:bar_end] |
||
| 760 | 1115:433d4f72a19b | Chris | width = coords[:bar_end] - coords[:bar_start] - 2 |
| 761 | style = ""
|
||
| 762 | style << "top:#{params[:top]}px;"
|
||
| 763 | style << "left:#{coords[:bar_start]}px;"
|
||
| 764 | style << "width:#{width}px;"
|
||
| 765 | 1295:622f24f53b42 | Chris | html_id = "task-todo-issue-#{options[:issue].id}" if options[:issue] |
| 766 | html_id = "task-todo-version-#{options[:version].id}" if options[:version] |
||
| 767 | content_opt = {:style => style,
|
||
| 768 | :class => "#{options[:css]} task_todo", |
||
| 769 | :id => html_id}
|
||
| 770 | if options[:issue] |
||
| 771 | rels = issue_relations(options[:issue])
|
||
| 772 | if rels.present?
|
||
| 773 | content_opt[:data] = {"rels" => rels.to_json} |
||
| 774 | end
|
||
| 775 | end
|
||
| 776 | output << view.content_tag(:div, ' '.html_safe, content_opt) |
||
| 777 | 119:8661b858af72 | Chris | if coords[:bar_late_end] |
| 778 | 1115:433d4f72a19b | Chris | width = coords[:bar_late_end] - coords[:bar_start] - 2 |
| 779 | style = ""
|
||
| 780 | style << "top:#{params[:top]}px;"
|
||
| 781 | style << "left:#{coords[:bar_start]}px;"
|
||
| 782 | style << "width:#{width}px;"
|
||
| 783 | output << view.content_tag(:div, ' '.html_safe, |
||
| 784 | :style => style,
|
||
| 785 | :class => "#{options[:css]} task_late") |
||
| 786 | 0:513646585e45 | Chris | end
|
| 787 | 119:8661b858af72 | Chris | if coords[:bar_progress_end] |
| 788 | 1115:433d4f72a19b | Chris | width = coords[:bar_progress_end] - coords[:bar_start] - 2 |
| 789 | style = ""
|
||
| 790 | style << "top:#{params[:top]}px;"
|
||
| 791 | style << "left:#{coords[:bar_start]}px;"
|
||
| 792 | style << "width:#{width}px;"
|
||
| 793 | 1295:622f24f53b42 | Chris | html_id = "task-done-issue-#{options[:issue].id}" if options[:issue] |
| 794 | html_id = "task-done-version-#{options[:version].id}" if options[:version] |
||
| 795 | 1115:433d4f72a19b | Chris | output << view.content_tag(:div, ' '.html_safe, |
| 796 | :style => style,
|
||
| 797 | 1295:622f24f53b42 | Chris | :class => "#{options[:css]} task_done", |
| 798 | :id => html_id)
|
||
| 799 | 119:8661b858af72 | Chris | end
|
| 800 | end
|
||
| 801 | # Renders the markers
|
||
| 802 | if options[:markers] |
||
| 803 | if coords[:start] |
||
| 804 | 1115:433d4f72a19b | Chris | style = ""
|
| 805 | style << "top:#{params[:top]}px;"
|
||
| 806 | style << "left:#{coords[:start]}px;"
|
||
| 807 | style << "width:15px;"
|
||
| 808 | output << view.content_tag(:div, ' '.html_safe, |
||
| 809 | :style => style,
|
||
| 810 | :class => "#{options[:css]} marker starting") |
||
| 811 | 119:8661b858af72 | Chris | end
|
| 812 | if coords[:end] |
||
| 813 | 1115:433d4f72a19b | Chris | style = ""
|
| 814 | style << "top:#{params[:top]}px;"
|
||
| 815 | style << "left:#{coords[:end] + params[:zoom]}px;"
|
||
| 816 | style << "width:15px;"
|
||
| 817 | output << view.content_tag(:div, ' '.html_safe, |
||
| 818 | :style => style,
|
||
| 819 | :class => "#{options[:css]} marker ending") |
||
| 820 | 119:8661b858af72 | Chris | end
|
| 821 | end
|
||
| 822 | # Renders the label on the right
|
||
| 823 | if options[:label] |
||
| 824 | 1115:433d4f72a19b | Chris | style = ""
|
| 825 | style << "top:#{params[:top]}px;"
|
||
| 826 | style << "left:#{(coords[:bar_end] || 0) + 8}px;"
|
||
| 827 | style << "width:15px;"
|
||
| 828 | output << view.content_tag(:div, options[:label], |
||
| 829 | :style => style,
|
||
| 830 | :class => "#{options[:css]} label") |
||
| 831 | 119:8661b858af72 | Chris | end
|
| 832 | # Renders the tooltip
|
||
| 833 | if options[:issue] && coords[:bar_start] && coords[:bar_end] |
||
| 834 | 1115:433d4f72a19b | Chris | s = view.content_tag(:span,
|
| 835 | view.render_issue_tooltip(options[:issue]).html_safe,
|
||
| 836 | :class => "tip") |
||
| 837 | style = ""
|
||
| 838 | style << "position: absolute;"
|
||
| 839 | style << "top:#{params[:top]}px;"
|
||
| 840 | style << "left:#{coords[:bar_start]}px;"
|
||
| 841 | style << "width:#{coords[:bar_end] - coords[:bar_start]}px;"
|
||
| 842 | style << "height:12px;"
|
||
| 843 | output << view.content_tag(:div, s.html_safe,
|
||
| 844 | :style => style,
|
||
| 845 | :class => "tooltip") |
||
| 846 | 119:8661b858af72 | Chris | end
|
| 847 | @lines << output
|
||
| 848 | output |
||
| 849 | end
|
||
| 850 | 441:cbce1fd3b1b7 | Chris | |
| 851 | 119:8661b858af72 | Chris | def pdf_task(params, coords, options={}) |
| 852 | height = options[:height] || 2 |
||
| 853 | # Renders the task bar, with progress and late
|
||
| 854 | if coords[:bar_start] && coords[:bar_end] |
||
| 855 | 1115:433d4f72a19b | Chris | params[:pdf].SetY(params[:top] + 1.5) |
| 856 | 119:8661b858af72 | Chris | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) |
| 857 | 1115:433d4f72a19b | Chris | params[:pdf].SetFillColor(200, 200, 200) |
| 858 | 441:cbce1fd3b1b7 | Chris | params[:pdf].RDMCell(coords[:bar_end] - coords[:bar_start], height, "", 0, 0, "", 1) |
| 859 | 119:8661b858af72 | Chris | if coords[:bar_late_end] |
| 860 | 1115:433d4f72a19b | Chris | params[:pdf].SetY(params[:top] + 1.5) |
| 861 | 119:8661b858af72 | Chris | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) |
| 862 | 1115:433d4f72a19b | Chris | params[:pdf].SetFillColor(255, 100, 100) |
| 863 | 441:cbce1fd3b1b7 | Chris | params[:pdf].RDMCell(coords[:bar_late_end] - coords[:bar_start], height, "", 0, 0, "", 1) |
| 864 | 119:8661b858af72 | Chris | end
|
| 865 | if coords[:bar_progress_end] |
||
| 866 | 1115:433d4f72a19b | Chris | params[:pdf].SetY(params[:top] + 1.5) |
| 867 | 119:8661b858af72 | Chris | params[:pdf].SetX(params[:subject_width] + coords[:bar_start]) |
| 868 | 1115:433d4f72a19b | Chris | params[:pdf].SetFillColor(90, 200, 90) |
| 869 | 441:cbce1fd3b1b7 | Chris | params[:pdf].RDMCell(coords[:bar_progress_end] - coords[:bar_start], height, "", 0, 0, "", 1) |
| 870 | 119:8661b858af72 | Chris | end
|
| 871 | end
|
||
| 872 | # Renders the markers
|
||
| 873 | if options[:markers] |
||
| 874 | if coords[:start] |
||
| 875 | params[:pdf].SetY(params[:top] + 1) |
||
| 876 | params[:pdf].SetX(params[:subject_width] + coords[:start] - 1) |
||
| 877 | 1115:433d4f72a19b | Chris | params[:pdf].SetFillColor(50, 50, 200) |
| 878 | 441:cbce1fd3b1b7 | Chris | params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1) |
| 879 | 119:8661b858af72 | Chris | end
|
| 880 | if coords[:end] |
||
| 881 | params[:pdf].SetY(params[:top] + 1) |
||
| 882 | params[:pdf].SetX(params[:subject_width] + coords[:end] - 1) |
||
| 883 | 1115:433d4f72a19b | Chris | params[:pdf].SetFillColor(50, 50, 200) |
| 884 | 441:cbce1fd3b1b7 | Chris | params[:pdf].RDMCell(2, 2, "", 0, 0, "", 1) |
| 885 | 119:8661b858af72 | Chris | end
|
| 886 | end
|
||
| 887 | # Renders the label on the right
|
||
| 888 | if options[:label] |
||
| 889 | params[:pdf].SetX(params[:subject_width] + (coords[:bar_end] || 0) + 5) |
||
| 890 | 441:cbce1fd3b1b7 | Chris | params[:pdf].RDMCell(30, 2, options[:label]) |
| 891 | 0:513646585e45 | Chris | end
|
| 892 | end
|
||
| 893 | 22:40f7cfd4df19 | chris | |
| 894 | 119:8661b858af72 | Chris | def image_task(params, coords, options={}) |
| 895 | height = options[:height] || 6 |
||
| 896 | # Renders the task bar, with progress and late
|
||
| 897 | if coords[:bar_start] && coords[:bar_end] |
||
| 898 | params[:image].fill('#aaa') |
||
| 899 | 1115:433d4f72a19b | Chris | params[:image].rectangle(params[:subject_width] + coords[:bar_start], |
| 900 | params[:top],
|
||
| 901 | params[:subject_width] + coords[:bar_end], |
||
| 902 | params[:top] - height)
|
||
| 903 | 119:8661b858af72 | Chris | if coords[:bar_late_end] |
| 904 | params[:image].fill('#f66') |
||
| 905 | 1115:433d4f72a19b | Chris | params[:image].rectangle(params[:subject_width] + coords[:bar_start], |
| 906 | params[:top],
|
||
| 907 | params[:subject_width] + coords[:bar_late_end], |
||
| 908 | params[:top] - height)
|
||
| 909 | 119:8661b858af72 | Chris | end
|
| 910 | if coords[:bar_progress_end] |
||
| 911 | params[:image].fill('#00c600') |
||
| 912 | 1115:433d4f72a19b | Chris | params[:image].rectangle(params[:subject_width] + coords[:bar_start], |
| 913 | params[:top],
|
||
| 914 | params[:subject_width] + coords[:bar_progress_end], |
||
| 915 | params[:top] - height)
|
||
| 916 | 119:8661b858af72 | Chris | end
|
| 917 | end
|
||
| 918 | # Renders the markers
|
||
| 919 | if options[:markers] |
||
| 920 | if coords[:start] |
||
| 921 | x = params[:subject_width] + coords[:start] |
||
| 922 | y = params[:top] - height / 2 |
||
| 923 | params[:image].fill('blue') |
||
| 924 | 1115:433d4f72a19b | Chris | params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4) |
| 925 | 119:8661b858af72 | Chris | end
|
| 926 | if coords[:end] |
||
| 927 | x = params[:subject_width] + coords[:end] + params[:zoom] |
||
| 928 | y = params[:top] - height / 2 |
||
| 929 | params[:image].fill('blue') |
||
| 930 | 1115:433d4f72a19b | Chris | params[:image].polygon(x - 4, y, x, y - 4, x + 4, y, x, y + 4) |
| 931 | 119:8661b858af72 | Chris | end
|
| 932 | end
|
||
| 933 | # Renders the label on the right
|
||
| 934 | if options[:label] |
||
| 935 | params[:image].fill('black') |
||
| 936 | 1115:433d4f72a19b | Chris | params[:image].text(params[:subject_width] + (coords[:bar_end] || 0) + 5, |
| 937 | params[:top] + 1, |
||
| 938 | options[:label])
|
||
| 939 | 119:8661b858af72 | Chris | end
|
| 940 | end
|
||
| 941 | 0:513646585e45 | Chris | end
|
| 942 | end
|
||
| 943 | end |