OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#55013] PDF Gantt Export: work package values in first column
as-opeae6b708ad3f
diff --git a/app/models/work_package/pdf_export/gantt/gantt_builder.rb b/app/models/work_package/pdf_export/gantt/gantt_builder.rbindex 4024c536b64..20104acc4c1 100644--- a/app/models/work_package/pdf_export/gantt/gantt_builder.rb+++ b/app/models/work_package/pdf_export/gantt/gantt_builder.rb@@ -28,6 +28,7 @@module WorkPackage::PDFExport::Ganttclass GanttBuilder+ include Redmine::I18nBAR_CELL_PADDING = 5.to_fTEXT_CELL_PADDING_H = 3.to_fTEXT_CELL_PADDING_V = 1.to_f@@ -89,6 +90,7 @@ module WorkPackage::PDFExport::Gantt@nr_columns = (@pdf.bounds.width / @column_width).floorend+ # distribute empty spacesdef adjust_to_pages# distribute empty space right to the default column widthsdistribute_to_next_page_column@@ -720,14 +722,27 @@ module WorkPackage::PDFExport::Ganttdef build_row_text_lines_wp_info(entry, left, right, top)text_top = top + TEXT_CELL_PADDING_Vtext_bottom = text_top + 8- GanttDataText.new(work_package_info_line(entry.work_package), left, right, text_top, text_bottom, 8)+ GanttDataText.new(work_package_info_line(entry.work_package), left, right, text_top, text_bottom, 6)end# Returns the info text line for the given work package# @param [WorkPackage] work_package# @return [String]def work_package_info_line(work_package)- "#{work_package.type} ##{work_package.id}"+ "#{work_package.type} ##{work_package.id} • #{work_package.status} • #{work_package_info_line_date work_package}"+ end++ def work_package_info_line_date(work_package)+ if work_package.start_date == work_package.due_date+ format_pdf_date(work_package.start_date)+ else+ "#{format_pdf_date(work_package.start_date)} - #{format_pdf_date(work_package.due_date)}"+ end+ end++ def format_pdf_date(date)+ return "" if date.nil?+ format_date dateend# Builds the shape for the given work packagediff --git a/spec/models/work_packages/pdf_export/work_package_list_to_pdf_gantt_spec.rb b/spec/models/work_packages/pdf_export/work_package_list_to_pdf_gantt_spec.rbindex 50f576f9394..6d714b3ad65 100644--- a/spec/models/work_packages/pdf_export/work_package_list_to_pdf_gantt_spec.rb+++ b/spec/models/work_packages/pdf_export/work_package_list_to_pdf_gantt_spec.rb@@ -56,6 +56,7 @@ endRSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf doinclude Redmine::I18ninclude PDFExportSpecUtils+ let!(:status_new) { create(:status, name: "New", is_default: true) }let(:type_standard) { create(:type_standard, name: "Standard", color: create(:color, hexcode: "#FFFF00")) }let(:type_bug) { create(:type_bug, name: "Bug", color: create(:color, hexcode: "#00FFFF")) }let!(:type_milestone) { create(:type, name: "Milestone", is_milestone: true, color: create(:color, hexcode: "#FF0000")) }@@ -110,6 +111,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf dolet(:work_package_task) docreate(:work_package,project:,+ status: status_new,type: type_standard,subject: "Work package 1",start_date: work_package_task_start,@@ -119,6 +121,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf docreate(:work_package,project:,type: type_milestone,+ status: status_new,subject: "Work package 2",start_date: work_package_milestone_start,due_date: work_package_milestone_due)@@ -127,6 +130,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf doArray.new(50) docreate(:work_package,project:,+ status: status_new,subject: "Work package Filler",start_date: work_package_task_start,due_date: work_package_task_due,@@ -147,8 +151,16 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf dopp pdf[:calls]end+ def wp_title_dates(work_package)+ if work_package.start_date == work_package.due_date+ format_date(work_package.start_date)+ else+ "#{format_date(work_package.start_date)} - #{format_date(work_package.due_date)}"+ end+ end+def wp_title_column(work_package)- "#{work_package.type} ##{work_package.id} #{work_package.subject}"+ "#{work_package.type} ##{work_package.id} • #{work_package.status} • #{wp_title_dates work_package} #{work_package.subject}"endsubject(:pdf) do@@ -173,7 +185,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf doexpect(pdf[:strings]).to eq [query.name, "2024 Apr 21 22 23", # header columnswp_title_column(work_package_task),wp_title_column(work_package_milestone),- "1/1", export_time_formatted, query.name].join(" ")+ "1/1", export_time_formatted, query.name].join(" ").squeeze(" ")# if one of these expect fails you can output the actual pdf calls uncommenting the following line# show_calls@@ -207,7 +219,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf dowp_title_column(work_package_milestone),"1/2", export_time_formatted, query.name,"2024 May 6 7 8", # header columns- "2/2", export_time_formatted, query.name].join(" ")+ "2/2", export_time_formatted, query.name].join(" ").squeeze(" ")# if one of these expect fails you can output the actual pdf calls uncommenting the following line# show_calls@@ -261,7 +273,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do"2024 May 6 7 8", # header columns"6/6", export_time_formatted, query.name- ].flatten.join(" ")+ ].flatten.join(" ").squeeze(" ")endit "contains correct data" do@@ -313,7 +325,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf dofiller_work_packages.slice(35, 15).map { |wp| wp_title_column(wp) },wp_title_column(work_package_milestone),"3/3", export_time_formatted, query.name- ].flatten.join(" ")+ ].flatten.join(" ").squeeze(" ")endit "contains correct data" do@@ -352,7 +364,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf dowp_title_column(work_package_milestone),type_standard.name,wp_title_column(work_package_task),- "1/1", export_time_formatted, query.name].join(" ")+ "1/1", export_time_formatted, query.name].join(" ").squeeze(" ")# if one of these expect fails you can output the actual pdf calls uncommenting the following line# show_calls