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
insert long text custom fields according to the work package form configuration
as-op67701625f57b
diff --git a/app/models/work_package/pdf_export/export/wp/attributes.rb b/app/models/work_package/pdf_export/export/wp/attributes.rbindex dfad56a0810..6ef87ac80ea 100644--- a/app/models/work_package/pdf_export/export/wp/attributes.rb+++ b/app/models/work_package/pdf_export/export/wp/attributes.rb@@ -75,19 +75,71 @@ module WorkPackage::PDFExport::Export::Wp::Attributesdef write_attributes_group(group, work_package)write_group_title(group)- write_attributes_group_table(group, work_package)- write_attributes_group_long_text_custom_fields(group, work_package)+ group_parts = group_attributes_group_parts(group, work_package)+ group_parts.each do |part|+ if part[:type] == :attribute+ write_attributes_group_table(part[:list], work_package)+ else+ part[:list].each do |cf|+ write_long_text_field!(work_package, cf.id)+ end+ end+ end+ end++ def write_attributes_group_table(list, work_package)+ rows = attributes_to_rows(list, work_package)+ return if rows.empty?++ with_margin(styles.wp_attributes_table_margins) do+ pdf.table(+ rows,+ column_widths: attributes_table_column_widths,+ cell_style: styles.wp_attributes_table_cell.merge({ inline_format: true })+ )+ endend- def write_attributes_group_long_text_custom_fields(group, work_package)- group.attributes.map do |form_key|- next unless CustomField.custom_field_attribute? form_key+ def attributes_to_rows(list, work_package)+ list = attributes_to_column_entries(list, work_package)+ .map { |entry| entry.merge({ value: get_column_value_cell(work_package, entry[:name]) }) }+ form_config_group_to_column_entries_rows(list)+ end- cf = form_key_to_custom_field(form_key)- next if cf.nil? || !cf.formattable? || !custom_field_allowed(cf, work_package)+ def attributes_to_column_entries(list, work_package)+ list.map do |form_key|+ form_key_to_column_entries(form_key.to_sym, work_package)+ end.flatten+ end- write_long_text_field!(work_package, cf.id)+ def group_attributes_group_parts(group, work_package)+ current_part = { type: :attribute, list: [] }+ parts = [current_part]+ group.attributes.each do |form_key|+ if allowed_long_text_custom_field?(form_key, work_package)+ if current_part[:type] == :long_text+ current_part[:list] << cf+ else+ current_part = { type: :long_text, list: [cf] }+ parts << current_part+ end+ elsif current_part[:type] != :attribute+ current_part = { type: :attribute, list: [form_key] }+ parts << current_part+ else+ current_part[:list] << form_key+ endend+ parts+ end++ def allowed_long_text_custom_field?(form_key, work_package)+ return false if CustomField.custom_field_attribute? form_key++ cf = form_key_to_custom_field(form_key)+ return false if cf.nil?++ cf.formattable? && custom_field_allowed(cf, work_package)enddef write_group_title(group)@@ -97,12 +149,6 @@ module WorkPackage::PDFExport::Export::Wp::Attributesendend- def form_config_group_to_column_entries(group, work_package)- group.attributes.map do |form_key|- form_key_to_column_entries(form_key.to_sym, work_package)- end.flatten- end-def form_config_group_to_column_entries_rows(list)0.step(list.length - 1, 2).map do |i|build_columns_table_cells(list[i]) +@@ -110,21 +156,6 @@ module WorkPackage::PDFExport::Export::Wp::Attributesendend- def write_attributes_group_table(group, work_package)- list = form_config_group_to_column_entries(group, work_package)- .map { |entry| entry.merge({ value: get_column_value_cell(work_package, entry[:name]) }) }- rows = form_config_group_to_column_entries_rows(list)- return if rows.empty?-- with_margin(styles.wp_attributes_table_margins) do- pdf.table(- rows,- column_widths: attributes_table_column_widths,- cell_style: styles.wp_attributes_table_cell.merge({ inline_format: true })- )- end- end-def attributes_table_column_widths# calculate fixed work package attribute table columns widthwidths = [1.5, 2.0, 1.5, 2.0] # label | value | label | valuediff --git a/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb b/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rbindex d9b9eb51fc7..0d5082b4e96 100644--- a/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb+++ b/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb@@ -199,21 +199,28 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf doendendlet(:expected_details) do- result = ["#{type.name} ##{work_package.id} - #{work_package.subject}"]- type.attribute_groups.each do |group|- result.push group.translated_key- group.attributes.each do |attribute|- columns = exporter.send(:form_key_to_column_entries, attribute.to_sym, work_package)- columns.each do |column|- result.push column[:label].upcase- value = get_column_value(column[:name])- result.push value if value.present?- end- end- if group.key == :other- result += [cf_long_text.name, "foo faa"]- end- end+ result = [+ "#{type.name} ##{work_package.id} - #{work_package.subject}",+ "People",+ "ASSIGNEE", user.name,+ "ACCOUNTABLE", user.name,+ "Estimates and progress",+ "WORK", "10h",+ "REMAINING WORK", "9h",+ "% COMPLETE", "25%",+ "SPENT TIME", "0h",+ "Details",+ "PRIORITY", "Normal",+ "VERSION", work_package.version,+ "CATEGORY", work_package.category,+ "START DATE", "05/30/2024",+ "FINISH DATE", "05/30/2024",+ "DURATION", "1 d",+ "Other",+ "WORK PACKAGE CUSTOM FIELD BOOLEAN", "Yes",+ "Costs",+ "SPENT", "UNITS", "LABOR", "COSTS UNIT", "COSTS OVERALL", "COSTS BUDGET"+ ]resultend@@ -432,11 +439,11 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf do"Custom field rich text", "[#{I18n.t('export.macro.rich_text_unsupported')}]","Custom field hidden","No replacement of:",+ "projectValue:1:status",+ "projectLabel:status","1", export_time_formatted, project.name,- "projectValue:1:status",- "projectLabel:status","projectValue:2:status projectLabel:status","projectValue:3:status", "projectLabel:status","Project by identifier:", " ", I18n.t(:general_text_Yes),