Skip to content

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

[#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.rb
index 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::Gantt
class GanttBuilder
+ include Redmine::I18n
BAR_CELL_PADDING = 5.to_f
TEXT_CELL_PADDING_H = 3.to_f
TEXT_CELL_PADDING_V = 1.to_f
@@ -89,6 +90,7 @@ module WorkPackage::PDFExport::Gantt
@nr_columns = (@pdf.bounds.width / @column_width).floor
end
+ # distribute empty spaces
def adjust_to_pages
# distribute empty space right to the default column widths
distribute_to_next_page_column
@@ -720,14 +722,27 @@ module WorkPackage::PDFExport::Gantt
def build_row_text_lines_wp_info(entry, left, right, top)
text_top = top + TEXT_CELL_PADDING_V
text_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 date
end
# Builds the shape for the given work package
diff --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.rb
index 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 @@ end
RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
include Redmine::I18n
include 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 do
let(:work_package_task) do
create(: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 do
create(: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 do
Array.new(50) do
create(: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 do
pp 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}"
end
subject(:pdf) do
@@ -173,7 +185,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
expect(pdf[:strings]).to eq [query.name, "2024 Apr 21 22 23", # header columns
wp_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 do
wp_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(" ")
end
it "contains correct data" do
@@ -313,7 +325,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
filler_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(" ")
end
it "contains correct data" do
@@ -352,7 +364,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
wp_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