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
task(pdf): change the default paper size; fix drawing bug and add missing test
as-op997b1e24054b
diff --git a/app/models/work_package/pdf_export/gantt/gantt_builder.rb b/app/models/work_package/pdf_export/gantt/gantt_builder.rbindex 7e34eedab15..4024c536b64 100644--- a/app/models/work_package/pdf_export/gantt/gantt_builder.rb+++ b/app/models/work_package/pdf_export/gantt/gantt_builder.rb@@ -511,20 +511,45 @@ module WorkPackage::PDFExport::Gantt)end- # Builds the dependency line between two work packages on different horizontal and vertical pages+ # Builds the dependency line between two work packages on different vertical (and maybe horizontal) pages# @param [GanttDataLineInfo] source# @param [GanttDataLineInfo] target# @param [Array<GanttDataPageGroup>] page_groupsdef build_multi_group_dep_line(source, target, page_groups)start_page_index = source.page_group.pages.index(source.finish_row.page)finish_page_index = target.page_group.pages.index(target.start_row.page)- if start_page_index > finish_page_index+ if start_page_index == finish_page_index+ build_multi_group_same_page_dep_line(source, target, start_page_index, page_groups)+ elsif start_page_index > finish_page_indexbuild_multi_group_dep_line_backward(source, target, start_page_index, finish_page_index, page_groups)elsebuild_multi_group_dep_line_forward(source, target, start_page_index, finish_page_index, page_groups)endend+ # Builds the dependency line between two work packages on different vertical but not horizontal pages+ # @param [GanttDataLineInfo] source+ # @param [GanttDataLineInfo] target+ # @param [Integer] page_index+ # @param [Array<GanttDataPageGroup>] page_groups+ def build_multi_group_same_page_dep_line(source, target, page_index, page_groups)+ build_multi_group_same_page_dep_lines_forward_start(source, target)+ build_multi_group_dep_line_middle(source, target, page_index, page_groups)+ build_multi_group_dep_line_group_end_end(target, target.start_left - LINE_STEP)+ end++ # Builds the dependency line between two work packages on different vertical but not horizontal pages (start)+ # @param [GanttDataLineInfo] source+ # @param [GanttDataLineInfo] target+ def build_multi_group_same_page_dep_lines_forward_start(source, target)+ source_top = source.finish_top+ target_left = target.start_left - LINE_STEP+ source.finish_row.page.add_lines([+ [source.finish_left, target_left, source_top, source_top],+ [target_left, target_left, source_top, source.finish_row.page.height]+ ])+ end+# Builds the dependency line between two work packages on different horizontal and vertical pages# and the source work package page is before the target work package page# @param [GanttDataLineInfo] source@@ -596,13 +621,13 @@ module WorkPackage::PDFExport::Gantt# draw line between the source and target work package pages# @param [GanttDataLineInfo] source# @param [GanttDataLineInfo] target- def build_multi_group_dep_line_middle(source, target, finish_page_index, page_groups)+ def build_multi_group_dep_line_middle(source, target, page_index, page_groups)start_group_index = page_groups.index(source.finish_row.page.group)finish_group_index = page_groups.index(target.start_row.page.group)start = [start_group_index, finish_group_index].minfinish = [start_group_index, finish_group_index].max((start + 1)..(finish - 1)).each do |index|- build_multi_group_dep_line_middle_for_group(page_groups[index], target, finish_page_index)+ build_multi_group_dep_line_middle_for_group(page_groups[index], target, page_index)endend@@ -702,9 +727,7 @@ module WorkPackage::PDFExport::Gantt# @param [WorkPackage] work_package# @return [String]def work_package_info_line(work_package)- level_path = @id_wp_meta_map[work_package.id][:level_path]- level_string = "#{level_path.join('.')}."- "#{level_string} #{work_package.type} ##{work_package.id}"+ "#{work_package.type} ##{work_package.id}"end# Builds the shape for the given work packagediff --git a/app/models/work_package/pdf_export/standard.yml b/app/models/work_package/pdf_export/standard.ymlindex ca9d808cf07..9a514dbceba 100644--- a/app/models/work_package/pdf_export/standard.yml+++ b/app/models/work_package/pdf_export/standard.yml@@ -1,5 +1,5 @@page:- page_size: "EXECUTIVE"+ page_size: "A4"margin_top: 60margin_bottom: 60margin_left: 36diff --git a/app/models/work_package/pdf_export/style.rb b/app/models/work_package/pdf_export/style.rbindex c1efef8f07b..f507fb344ad 100644--- a/app/models/work_package/pdf_export/style.rb+++ b/app/models/work_package/pdf_export/style.rb@@ -38,7 +38,7 @@ module WorkPackage::PDFExport::Styleenddef page_size- @styles[:page_size] || "EXECUTIVE"+ @styles[:page_size] || "A4"enddef page_header_offsetdiff --git a/frontend/src/app/shared/components/modals/export-modal/wp-table-export.modal.ts b/frontend/src/app/shared/components/modals/export-modal/wp-table-export.modal.tsindex 665a33382a0..d1a894e2fe7 100644--- a/frontend/src/app/shared/components/modals/export-modal/wp-table-export.modal.ts+++ b/frontend/src/app/shared/components/modals/export-modal/wp-table-export.modal.ts@@ -74,18 +74,18 @@ export class WpTableExportModalComponent extends OpModalComponent implements OnIid: 'pdf-option-paper-size',label: this.I18n.t('js.gantt_chart.export.options.paper_size'),paramName: 'paper_size',- value: 'EXECUTIVE',+ value: 'A4',// supported page sizes: https://github.com/prawnpdf/pdf-core/blob/6017800c46ce6cb43e0c8c8904e5e08d8e90b259/lib/pdf/core/page_geometry.rboptions: [- { label: 'Executive', value: 'EXECUTIVE' },- { label: 'Folio', value: 'FOLIO' },- { label: 'Letter', value: 'LETTER' },- { label: 'Tabloid', value: 'TABLOID' },{ label: 'A4', value: 'A4' },{ label: 'A3', value: 'A3' },{ label: 'A2', value: 'A2' },{ label: 'A1', value: 'A1' },{ label: 'A0', value: 'A0' },+ { label: 'Executive', value: 'EXECUTIVE' },+ { label: 'Folio', value: 'FOLIO' },+ { label: 'Letter', value: 'LETTER' },+ { label: 'Tabloid', value: 'TABLOID' },],},};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.rbindex 3e25d0769ab..7b9518fbd85 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@@ -67,7 +67,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf docreate(:user,member_with_permissions: { project => %w[view_work_packages export_work_packages] })end- let(:options) { { gantt: true, gantt_mode: "day", gantt_width: "wide" } }+ let(:options) { { gantt: true, gantt_mode: "day", gantt_width: "wide", paper_size: "EXECUTIVE" } }let(:query_attributes) { {} }let(:column_names) { %w[id subject status] }let!(:query) do@@ -138,7 +138,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do[work_package_task, work_package_milestone]end- def show+ def show_pdfcmd = "open -a Preview #{export_pdf.content.path}"`#{cmd}`end@@ -147,8 +147,8 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf dopp pdf[:calls]end- def wp_title_column(level, work_package)- "#{level} #{work_package.type} ##{work_package.id} #{work_package.subject}"+ def wp_title_column(work_package)+ "#{work_package.type} ##{work_package.id} #{work_package.subject}"endsubject(:pdf) do@@ -171,8 +171,8 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf dodescribe "with a request for a PDF gantt" doit "contains correct data" doexpect(pdf[:strings]).to eq [query.name, "2024 Apr 21 22 23", # header columns- wp_title_column("1.", work_package_task),- wp_title_column("2.", work_package_milestone),+ wp_title_column(work_package_task),+ wp_title_column(work_package_milestone),"1/1", export_time_formatted, query.name].join(" ")# if one of these expect fails you can output the actual pdf calls uncommenting the following line@@ -203,8 +203,8 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf doit "contains correct data" doexpect(pdf[:strings]).to eq [query.name, "2024 Apr May 21 22 23 24 25 26 27 28 29 30 1 2 3 4 5", # header columns- wp_title_column("1.", work_package_task),- wp_title_column("2.", work_package_milestone),+ wp_title_column(work_package_task),+ 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(" ")@@ -237,27 +237,26 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf dolet(:work_package_milestone_due) doDate.new(2024, 5, 8)end-let(:large_example_content) do[query.name, "2024 Apr May 21 22 23 24 25 26 27 28 29 30 1 2 3 4 5", # header columns- wp_title_column("1.", work_package_task),- filler_work_packages.slice(0, 17).map.with_index { |wp, index| wp_title_column("#{index + 2}.", wp) },+ wp_title_column(work_package_task),+ filler_work_packages.slice(0, 17).map.with_index { |wp, index| wp_title_column(wp) },"1/6", export_time_formatted, query.name,"2024 May 6 7 8", # header columns"2/6", export_time_formatted, query.name,query.name, "2024 Apr May 21 22 23 24 25 26 27 28 29 30 1 2 3 4 5", # header columns- filler_work_packages.slice(17, 18).map.with_index { |wp, index| wp_title_column("#{index + 19}.", wp) },+ filler_work_packages.slice(17, 18).map.with_index { |wp, index| wp_title_column(wp) },"3/6", export_time_formatted, query.name,"2024 May 6 7 8", # header columns"4/6", export_time_formatted, query.name,query.name, "2024 Apr May 21 22 23 24 25 26 27 28 29 30 1 2 3 4 5", # header columns- filler_work_packages.slice(35, 15).map.with_index { |wp, index| wp_title_column("#{index + 37}.", wp) },- wp_title_column("52.", work_package_milestone),+ filler_work_packages.slice(35, 15).map.with_index { |wp, index| wp_title_column(wp) },+ wp_title_column(work_package_milestone),"5/6", export_time_formatted, query.name,"2024 May 6 7 8", # header columns@@ -292,15 +291,67 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf doendend+ describe "with a request for a PDF gantt split on multiple vertical pages" do+ let(:work_packages) do+ [work_package_task] + filler_work_packages + [work_package_milestone]+ end+ let(:work_package_milestone_due) do+ Date.new(2024, 5, 1)+ end+ let(:large_example_content) do+ [+ query.name, "2024 Apr May 21 22 23 24 25 26 27 28 29 30 1", # header columns+ wp_title_column(work_package_task),+ filler_work_packages.slice(0, 17).map.with_index { |wp, index| wp_title_column(wp) },+ "1/3", export_time_formatted, query.name,++ query.name, "2024 Apr May 21 22 23 24 25 26 27 28 29 30 1", # header columns+ filler_work_packages.slice(17, 18).map.with_index { |wp, index| wp_title_column(wp) },+ "2/3", export_time_formatted, query.name,++ query.name, "2024 Apr May 21 22 23 24 25 26 27 28 29 30 1", # header columns+ filler_work_packages.slice(35, 15).map.with_index { |wp, index| wp_title_column(wp) },+ wp_title_column(work_package_milestone),+ "3/3", export_time_formatted, query.name+ ].flatten.join(" ")+ end++ it "contains correct data" do+ expect(pdf[:strings]).to eq large_example_content++ # if one of these expect fails you can output the actual pdf calls uncommenting the following line+ # show_calls+ milestone = [+ [:set_color_for_nonstroking_and_special, 1.0, 0.0, 0.0], # red milestone polygon+ [:begin_new_subpath, 690.01515, 121.86],+ [:append_line, 696.68182, 128.52667],+ [:append_line, 703.34848, 121.86],+ [:append_line, 696.68182, 115.19333],+ [:append_line, 690.01515, 121.86],+ [:close_subpath]+ ]+ expect(include_calls?(milestone, pdf[:calls])).to be true+ task = [+ [:set_color_for_nonstroking_and_special, 1.0, 1.0, 0.0], # yellow rectangle+ [:append_rectangle, 207.0, 416.86, 46.63636, 10.0],+ [:fill_path_with_nonzero]+ ]+ expect(include_calls?(task, pdf[:calls])).to be true+ expect(+ pdf[:calls].count { |call| call == [:set_color_for_nonstroking_and_special, 0.0, 1.0, 1.0] } # aqua color rectangles+ ).to be filler_work_packages.length+ end+ end+describe "with a request for a PDF gantt with grouped work packages" dolet(:query_attributes) { { group_by: "type" } }it "contains correct data" doexpect(pdf[:strings]).to eq [query.name, "2024 Apr 21 22 23", # header columnstype_milestone.name,- wp_title_column("1.", work_package_milestone),+ wp_title_column(work_package_milestone),type_standard.name,- wp_title_column("2.", work_package_task),+ wp_title_column(work_package_task),"1/1", export_time_formatted, query.name].join(" ")# if one of these expect fails you can output the actual pdf calls uncommenting the following line