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
pdf report engine: show long text custom fields by parameter setting
as-op52c4a8cbdd5f
diff --git a/app/components/work_packages/exports/pdf/report/export_settings_component.html.erb b/app/components/work_packages/exports/pdf/report/export_settings_component.html.erbindex 64befb83807..77ce4bcd863 100644--- a/app/components/work_packages/exports/pdf/report/export_settings_component.html.erb+++ b/app/components/work_packages/exports/pdf/report/export_settings_component.html.erb@@ -10,18 +10,18 @@<hr class="mt-2 mb-4"/><%= helpers.angular_component_tag "opce-draggable-autocompleter",inputs: {- id: "cfs-select-export-pdf-report",- name: 'cfs',- dragAreaName: "cfs-select-export-pdf-report_dragarea",- formControlId: "cfs-select-export-pdf-report_autocompleter",+ id: "ltf-select-export-pdf-report",+ name: 'long_text_fields',+ dragAreaName: "ltf-select-export-pdf-report_dragarea",+ formControlId: "ltf-select-export-pdf-report_autocompleter",appendToComponent: true,- options: available_cfs,- selected: selected_cfs,- protected: protected_cfs,- inputLabel: I18n.t(:"export.dialog.pdf.custom_fields.input_label"),- inputCaption: I18n.t(:"export.dialog.pdf.custom_fields.input_caption"),- inputPlaceholder: I18n.t(:"export.dialog.pdf.custom_fields.input_placeholder"),- dragAreaLabel: I18n.t(:"export.dialog.pdf.custom_fields.drag_area_label"),+ options: available_long_text_fields,+ selected: selected_long_text_fields,+ protected: protected_long_text_fields,+ inputLabel: I18n.t(:"export.dialog.pdf.long_text_fields.input_label"),+ inputCaption: I18n.t(:"export.dialog.pdf.long_text_fields.input_caption"),+ inputPlaceholder: I18n.t(:"export.dialog.pdf.long_text_fields.input_placeholder"),+ dragAreaLabel: I18n.t(:"export.dialog.pdf.long_text_fields.drag_area_label"),}%><% end %>diff --git a/app/components/work_packages/exports/pdf/report/export_settings_component.rb b/app/components/work_packages/exports/pdf/report/export_settings_component.rbindex 59c3c680ded..b540b3fd3ce 100644--- a/app/components/work_packages/exports/pdf/report/export_settings_component.rb+++ b/app/components/work_packages/exports/pdf/report/export_settings_component.rb@@ -35,16 +35,16 @@ module WorkPackagesclass ExportSettingsComponent < BaseExportSettingsComponentDESCRIPTION_CF = { id: "description", name: WorkPackage.human_attribute_name("description") }.freeze- def available_cfs+ def available_long_text_fields[DESCRIPTION_CF] + WorkPackageCustomField.where(field_format: "text").map { |cf| { id: cf.id, name: cf.name } }end- def selected_cfs- available_cfs+ def selected_long_text_fields+ available_long_text_fieldsend- def protected_cfs+ def protected_long_text_fields[]endenddiff --git a/app/models/work_package/pdf_export/work_package_detail.rb b/app/models/work_package/pdf_export/work_package_detail.rbindex faf82aef1ba..80876e03f6c 100644--- a/app/models/work_package/pdf_export/work_package_detail.rb+++ b/app/models/work_package/pdf_export/work_package_detail.rb@@ -46,8 +46,7 @@ module WorkPackage::PDFExport::WorkPackageDetaildef write_work_package_detail_content!(work_package)write_attributes_table! work_package- write_description! work_package- write_custom_fields! work_package+ write_long_text_fields! work_packageendprivate@@ -178,14 +177,28 @@ module WorkPackage::PDFExport::WorkPackageDetail]end+ def write_long_text_fields!(work_package)+ selected_long_text_fields.each do |field_id_or_desc|+ if field_id_or_desc == "description"+ write_description!(work_package)+ else+ write_long_text_field!(work_package, field_id_or_desc.to_i)+ end+ end+ end++ def selected_long_text_fields+ @selected_long_text_fields ||= (options[:long_text_fields] || "").split+ end+def write_description!(work_package)write_markdown_field!(work_package, work_package.description, WorkPackage.human_attribute_name(:description))end- def write_custom_fields!(work_package)- work_package.custom_field_values- .select { |cv| cv.custom_field.formattable? }- .each do |custom_value|+ def write_long_text_field!(work_package, field_id)+ custom_value = work_package.custom_field_values+ .find { |cv| cv.custom_field.id == field_id && cv.custom_field.formattable? }+ if custom_value&.valuewrite_markdown_field!(work_package, custom_value.value, custom_value.custom_field.name)endenddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 1b11e7d555b..3a9997aa909 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1797,7 +1797,7 @@ en:paper_size:label: "Paper size"caption: "Depending on the chart size more than one page might be exported."- custom_fields:+ long_text_fields:input_caption: "By default all long text fields are selected."input_label: "Add long text fields"input_placeholder: "Search for long text fields"diff --git a/spec/features/work_packages/export_spec.rb b/spec/features/work_packages/export_spec.rbindex 13a5f328e57..abd3c957340 100644--- a/spec/features/work_packages/export_spec.rb+++ b/spec/features/work_packages/export_spec.rb@@ -235,8 +235,8 @@ RSpec.describe "work package export" dolet(:export_sub_type) { I18n.t("export.dialog.pdf.export_type.options.report.label") }let(:default_params_report) { default_params.merge({ pdf_export_type: "report" }) }- context "with custom fields" do- let(:expected_params) { default_params_report.merge({ cfs: "description 42 43" }) }+ context "with long text fields" do+ let(:expected_params) { default_params_report.merge({ long_text_fields: "description 42 43" }) }it "exports a pdf report with all long text custom fields by default" dochoose export_sub_type@@ -244,8 +244,8 @@ RSpec.describe "work package export" doendend- context "with custom fields selection" do- let(:expected_params) { default_params_report.merge({ cfs: "description 43" }) }+ context "with long text fields selection" do+ let(:expected_params) { default_params_report.merge({ long_text_fields: "description 43" }) }it "exports a pdf report with all remaining custom fields" dochoose export_sub_typediff --git a/spec/models/work_packages/pdf_export/work_package_list_to_pdf_spec.rb b/spec/models/work_packages/pdf_export/work_package_list_to_pdf_spec.rbindex d28f0c7be78..f160bb2cd49 100644--- a/spec/models/work_packages/pdf_export/work_package_list_to_pdf_spec.rb+++ b/spec/models/work_packages/pdf_export/work_package_list_to_pdf_spec.rb@@ -116,16 +116,6 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf doendlet(:column_names) { %w[id subject status story_points done_ratio] }- def custom_values_for(*names)- custom_field- .custom_options- .where(value: names)- .pluck(:id)- .map do |value|- CustomValue.new(custom_field_id: custom_field.id, value:)- end- end-def work_packages_sumwork_package_parent.story_points + work_package_child.story_pointsend@@ -144,17 +134,29 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf dowork_package.done_ratio == 25 ? "25% · Σ 50%" : "50%"end- def work_package_details(work_package, index)- [+ def work_package_details(work_package, index, ltfs = [])+ result = ["#{index}.", work_package.subject,column_title(:id), work_package.id.to_s,column_title(:status), work_package.status.name,column_title(:story_points), work_package.story_points.to_s,- column_title(:done_ratio), work_package_done_ratio(work_package),- label_title(:description), work_package.description,- text_custom_field_a.name, work_package.custom_field_values.find { |cf| cf.custom_field == text_custom_field_a }.value,- text_custom_field_b.name, work_package.custom_field_values.find { |cf| cf.custom_field == text_custom_field_b }.value+ column_title(:done_ratio), work_package_done_ratio(work_package)]+ ltfs.each do |ltf|+ case ltf+ when "description"+ result.push(label_title(:description), work_package.description)+ when text_custom_field_a.id+ result.push(*work_package_details_long_text(text_custom_field_a, work_package))+ when text_custom_field_b.id+ result.push(*work_package_details_long_text(text_custom_field_b, work_package))+ end+ end+ result+ end++ def work_package_details_long_text(field, work_package)+ [field.name, work_package.custom_field_values.find { |cf| cf.custom_field == field }.value]enddef cover_page_content@@ -175,174 +177,215 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf doexpect(pdf.strings.join(" ")).to eq(strings.join(" "))end- describe "with a request for a PDF table" do- it "contains correct data" do- expect(pdf_strings).to eq [- query.name,- *column_titles,- *work_package_columns(work_package_parent),- *work_package_columns(work_package_child),- "1/1", export_time_formatted, query.name- ].join(" ")+ context "with a request for a PDF Table" do+ let(:options) { { pdf_export_type: "table" } }++ describe "with default settings" do+ it "contains correct data" do+ expect(pdf_strings).to eq [+ query.name,+ *column_titles,+ *work_package_columns(work_package_parent),+ *work_package_columns(work_package_child),+ "1/1", export_time_formatted, query.name+ ].join(" ")+ endend- end- describe "with a request for a PDF table grouped" do- let(:query_attributes) { { group_by: "type" } }-- it "contains correct data" do- expect(pdf_strings).to eq [- query.name,- work_package_parent.type.name,- *column_titles,- *work_package_columns(work_package_parent),- work_package_child.type.name,- *column_titles,- *work_package_columns(work_package_child),- "1/1", export_time_formatted, query.name- ].join(" ")+ describe "grouped" do+ let(:query_attributes) { { group_by: "type" } }++ it "contains correct data" do+ expect(pdf_strings).to eq [+ query.name,+ work_package_parent.type.name,+ *column_titles,+ *work_package_columns(work_package_parent),+ work_package_child.type.name,+ *column_titles,+ *work_package_columns(work_package_child),+ "1/1", export_time_formatted, query.name+ ].join(" ")+ endend- end- describe "with a request for a PDF table grouped with sums" do- let(:query_attributes) { { group_by: "type", display_sums: true } }-- it "contains correct data" do- expect(pdf_strings).to eq [- query.name,- work_package_parent.type.name,- *column_titles,- *work_package_columns(work_package_parent),- I18n.t("js.label_sum"), work_package_parent.story_points.to_s,- work_package_child.type.name,- *column_titles,- *work_package_columns(work_package_child),- I18n.t("js.label_sum"), work_package_child.story_points.to_s,- "1/1", export_time_formatted, query.name- ].join(" ")+ describe "grouped with sums" do+ let(:query_attributes) { { group_by: "type", display_sums: true } }++ it "contains correct data" do+ expect(pdf_strings).to eq [+ query.name,+ work_package_parent.type.name,+ *column_titles,+ *work_package_columns(work_package_parent),+ I18n.t("js.label_sum"), work_package_parent.story_points.to_s,+ work_package_child.type.name,+ *column_titles,+ *work_package_columns(work_package_child),+ I18n.t("js.label_sum"), work_package_child.story_points.to_s,+ "1/1", export_time_formatted, query.name+ ].join(" ")+ endend- end- describe "with a request for a PDF table grouped by a custom field with sums" do- let(:query_attributes) { { group_by: list_custom_field.column_name, display_sums: true } }-- it "contains correct data" do- expect(pdf_strings).to eq [- query.name,- "Foo",- *column_titles,- *work_package_columns(work_package_child),- I18n.t("js.label_sum"), work_package_child.story_points.to_s,- "Foo, Bar",- *column_titles,- *work_package_columns(work_package_parent),- I18n.t("js.label_sum"), work_package_parent.story_points.to_s,- "1/1", export_time_formatted, query.name- ].join(" ")+ describe "grouped by a custom field with sums" do+ let(:query_attributes) { { group_by: list_custom_field.column_name, display_sums: true } }++ it "contains correct data" do+ expect(pdf_strings).to eq [+ query.name,+ "Foo",+ *column_titles,+ *work_package_columns(work_package_child),+ I18n.t("js.label_sum"), work_package_child.story_points.to_s,+ "Foo, Bar",+ *column_titles,+ *work_package_columns(work_package_parent),+ I18n.t("js.label_sum"), work_package_parent.story_points.to_s,+ "1/1", export_time_formatted, query.name+ ].join(" ")+ endendend- describe "with a request for a PDF Report default" do- let(:options) { { pdf_export_type: "report" } }-- it "contains correct data" do- expect(pdf_strings).to eq [- *cover_page_content,- query.name,- "1.", "2", work_package_parent.subject,- "2.", "2", work_package_child.subject,- "1/2", export_time_formatted, query.name,- *work_package_details(work_package_parent, "1"),- *work_package_details(work_package_child, "2"),- "2/2", export_time_formatted, query.name- ].join(" ")+ context "with a request for a PDF Report" do+ let(:options) do+ { pdf_export_type: "report", long_text_fields: "description #{text_custom_field_a.id} #{text_custom_field_b.id}" }end- end+ let(:long_text_fields) { ["description", text_custom_field_a.id, text_custom_field_b.id] }- describe "with a request for a PDF Report with hierarchies" do- let(:options) { { pdf_export_type: "report" } }- let(:query_attributes) { { show_hierarchies: true } }-- it "contains correct data" do- expect(pdf_strings).to eq [- *cover_page_content,- query.name,- "1.", "2", work_package_parent.subject,- "1.1.", "2", work_package_child.subject,- "1/2", export_time_formatted, query.name,- *work_package_details(work_package_parent, "1"),- *work_package_details(work_package_child, "1.1"),- "2/2", export_time_formatted, query.name- ].join(" ")+ describe "with default settings" do+ it "contains correct data" do+ expect(pdf_strings).to eq [+ *cover_page_content,+ query.name,+ "1.", "2", work_package_parent.subject,+ "2.", "2", work_package_child.subject,+ "1/2", export_time_formatted, query.name,+ *work_package_details(work_package_parent, "1", long_text_fields),+ *work_package_details(work_package_child, "2", long_text_fields),+ "2/2", export_time_formatted, query.name+ ].join(" ")+ endend- end- describe "with a request for a PDF Report with sums" do- let(:options) { { pdf_export_type: "report" } }- let(:query_attributes) { { display_sums: true } }-- it "contains correct data" do- expect(pdf_strings).to eq [- *cover_page_content,- query.name,- "1.", "2", work_package_parent.subject,- "2.", "2", work_package_child.subject,- "1/2", export_time_formatted, query.name,- I18n.t("js.work_packages.tabs.overview"),- column_title(:story_points),- I18n.t("js.label_sum"), work_packages_sum.to_s,- *work_package_details(work_package_parent, "1"),- *work_package_details(work_package_child, "2"),- "2/2", export_time_formatted, query.name- ].join(" ")+ describe "with no long text fields" do+ let(:options) { { pdf_export_type: "report" } }+ let(:long_text_fields) { [] }++ it "contains correct data" do+ expect(pdf_strings).to eq [+ *cover_page_content,+ query.name,+ "1.", "2", work_package_parent.subject,+ "2.", "2", work_package_child.subject,+ "1/2", export_time_formatted, query.name,+ *work_package_details(work_package_parent, "1", long_text_fields),+ *work_package_details(work_package_child, "2", long_text_fields),+ "2/2", export_time_formatted, query.name+ ].join(" ")+ endend- end- describe "with a request for a PDF Report grouped with sums" do- let(:options) { { pdf_export_type: "report" } }- let(:query_attributes) { { display_sums: true, group_by: "type" } }-- it "contains correct data" do- expect(pdf_strings).to eq [- *cover_page_content,- query.name,- "1.", "2", work_package_parent.subject,- "2.", "2", work_package_child.subject,- "1/2", export_time_formatted, query.name,- I18n.t("js.work_packages.tabs.overview"),- column_title(:type), column_title(:story_points),- work_package_parent.type.name, work_package_parent.story_points.to_s,- work_package_child.type.name, work_package_child.story_points.to_s,- I18n.t("js.label_sum"), work_packages_sum.to_s,- *work_package_details(work_package_parent, "1"),- *work_package_details(work_package_child, "2"),- "2/2", export_time_formatted, query.name- ].join(" ")+ describe "with reordered long text fields" do+ let(:options) { { pdf_export_type: "report", long_text_fields: "#{text_custom_field_a.id} description" } }+ let(:long_text_fields) { [text_custom_field_a.id, "description"] }++ it "contains correct data" do+ expect(pdf_strings).to eq [+ *cover_page_content,+ query.name,+ "1.", "2", work_package_parent.subject,+ "2.", "2", work_package_child.subject,+ "1/2", export_time_formatted, query.name,+ *work_package_details(work_package_parent, "1", long_text_fields),+ *work_package_details(work_package_child, "2", long_text_fields),+ "2/2", export_time_formatted, query.name+ ].join(" ")+ endend- end- describe "with a request for a PDF Report grouped by a custom field with sums" do- let(:options) { { pdf_export_type: "report" } }- let(:query_attributes) { { display_sums: true, group_by: list_custom_field.column_name } }-- it "contains correct data" do- expect(pdf_strings).to eq [- *cover_page_content,- query.name,- "1.", "2", work_package_child.subject,- "2.", "2", work_package_parent.subject,- "1/2", export_time_formatted, query.name,- I18n.t("js.work_packages.tabs.overview"),- list_custom_field.name.upcase, column_title(:story_points),-- "Foo", work_package_child.story_points.to_s,- "Foo, Bar", work_package_parent.story_points.to_s,- I18n.t("js.label_sum"), work_packages_sum.to_s,-- *work_package_details(work_package_child, "1"),- *work_package_details(work_package_parent, "2"),- "2/2", export_time_formatted, query.name- ].join(" ")+ describe "with hierarchies" do+ let(:query_attributes) { { show_hierarchies: true } }++ it "contains correct data" do+ expect(pdf_strings).to eq [+ *cover_page_content,+ query.name,+ "1.", "2", work_package_parent.subject,+ "1.1.", "2", work_package_child.subject,+ "1/2", export_time_formatted, query.name,+ *work_package_details(work_package_parent, "1", long_text_fields),+ *work_package_details(work_package_child, "1.1", long_text_fields),+ "2/2", export_time_formatted, query.name+ ].join(" ")+ end+ end++ describe "with sums" do+ let(:query_attributes) { { display_sums: true } }++ it "contains correct data" do+ expect(pdf_strings).to eq [+ *cover_page_content,+ query.name,+ "1.", "2", work_package_parent.subject,+ "2.", "2", work_package_child.subject,+ "1/2", export_time_formatted, query.name,+ I18n.t("js.work_packages.tabs.overview"),+ column_title(:story_points),+ I18n.t("js.label_sum"), work_packages_sum.to_s,+ *work_package_details(work_package_parent, "1", long_text_fields),+ *work_package_details(work_package_child, "2", long_text_fields),+ "2/2", export_time_formatted, query.name+ ].join(" ")+ end+ end++ describe "grouped with sums" do+ let(:query_attributes) { { display_sums: true, group_by: "type" } }++ it "contains correct data" do+ expect(pdf_strings).to eq [+ *cover_page_content,+ query.name,+ "1.", "2", work_package_parent.subject,+ "2.", "2", work_package_child.subject,+ "1/2", export_time_formatted, query.name,+ I18n.t("js.work_packages.tabs.overview"),+ column_title(:type), column_title(:story_points),+ work_package_parent.type.name, work_package_parent.story_points.to_s,+ work_package_child.type.name, work_package_child.story_points.to_s,+ I18n.t("js.label_sum"), work_packages_sum.to_s,+ *work_package_details(work_package_parent, "1", long_text_fields),+ *work_package_details(work_package_child, "2", long_text_fields),+ "2/2", export_time_formatted, query.name+ ].join(" ")+ end+ end++ describe "grouped by a custom field with sums" do+ let(:query_attributes) { { display_sums: true, group_by: list_custom_field.column_name } }++ it "contains correct data" do+ expect(pdf_strings).to eq [+ *cover_page_content,+ query.name,+ "1.", "2", work_package_child.subject,+ "2.", "2", work_package_parent.subject,+ "1/2", export_time_formatted, query.name,+ I18n.t("js.work_packages.tabs.overview"),+ list_custom_field.name.upcase, column_title(:story_points),++ "Foo", work_package_child.story_points.to_s,+ "Foo, Bar", work_package_parent.story_points.to_s,+ I18n.t("js.label_sum"), work_packages_sum.to_s,++ *work_package_details(work_package_child, "1", long_text_fields),+ *work_package_details(work_package_parent, "2", long_text_fields),+ "2/2", export_time_formatted, query.name+ ].join(" ")+ endendendend