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

DRY code, refactor overview PDF table code to more generic wp_table PDF

as-opb985d1ce9458
diff --git a/app/models/work_package/pdf_export/common/styles.rb b/app/models/work_package/pdf_export/common/styles.rb
index 1ea20eab8a6..d62a564146b 100644
--- a/app/models/work_package/pdf_export/common/styles.rb
+++ b/app/models/work_package/pdf_export/common/styles.rb
@@ -29,72 +29,13 @@
#++
module WorkPackage::PDFExport::Common::Styles
- def initialize(yml)
- @styles = yml.deep_symbolize_keys
- end
+ include MarkdownToPDF::StyleValidation
- def page_size
- @styles[:page_size] || "A4"
- end
-
- def page_header_offset
- resolve_pt(@styles.dig(:page_header, :offset), 20)
- end
-
- def page_footer_offset
- resolve_pt(@styles.dig(:page_footer, :offset), -30)
- end
-
- def page_footer_horizontal_spacing
- resolve_pt(@styles.dig(:page_footer, :spacing), 6)
- end
-
- def page_logo_height
- resolve_pt(@styles.dig(:page_logo, :height), 20)
- end
-
- def page_logo_align
- @styles.dig(:page_logo, :align) || :right
- end
-
- def page_margin_top
- resolve_pt(@styles.dig(:page, :margin_top), 60)
- end
-
- def page_margin_left
- resolve_pt(@styles.dig(:page, :margin_left), 50)
- end
-
- def page_margin_right
- resolve_pt(@styles.dig(:page, :margin_right), 50)
- end
-
- def page_margin_bottom
- resolve_pt(@styles.dig(:page, :margin_bottom), 60)
- end
-
- def page_heading
- resolve_font(@styles[:page_heading])
- end
-
- def page_heading_margins
- resolve_margin(@styles[:page_heading])
- end
-
- def page_header
- resolve_font(@styles[:page_header])
- end
-
- def page_footer
- resolve_font(@styles[:page_footer])
- end
-
- def page_break_threshold
- resolve_pt(@styles.dig(:page, :page_break_threshold), 200)
- end
-
- def link_color
- @styles.dig(:page, :link_color) || "000000"
+ def initialize(styles_asset_path, style_yml_file = "standard.yml", schema_json_file = "schema.json")
+ yml = YAML::load_file(File.join(styles_asset_path, style_yml_file))
+ schema = JSON::load_file(File.join(styles_asset_path, schema_json_file))
+ validate_schema!(yml, schema)
+ @styles = yml.deep_symbolize_keys
end
protected
diff --git a/app/models/work_package/pdf_export/common/styles_attributes_table.rb b/app/models/work_package/pdf_export/common/styles_attributes_table.rb
new file mode 100644
index 00000000000..cfe9e29677d
--- /dev/null
+++ b/app/models/work_package/pdf_export/common/styles_attributes_table.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module WorkPackage::PDFExport::Common::StylesAttributesTable
+ def wp_attributes_table_margins
+ resolve_margin(@styles.dig(:work_package, :attributes_table))
+ end
+
+ def wp_attributes_table_cell
+ resolve_table_cell(@styles.dig(:work_package, :attributes_table, :cell))
+ end
+
+ def wp_attributes_table_label_cell
+ wp_attributes_table_cell.merge(
+ resolve_table_cell(@styles.dig(:work_package, :attributes_table, :cell_label))
+ )
+ end
+end
diff --git a/app/models/work_package/pdf_export/common/styles_cover.rb b/app/models/work_package/pdf_export/common/styles_cover.rb
new file mode 100644
index 00000000000..99e2b792602
--- /dev/null
+++ b/app/models/work_package/pdf_export/common/styles_cover.rb
@@ -0,0 +1,97 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module WorkPackage::PDFExport::Common::StylesCover
+ def cover_header
+ resolve_font(@styles.dig(:cover, :header))
+ end
+
+ def cover_header_logo_height
+ resolve_pt(@styles.dig(:cover, :header, :logo_height), 25)
+ end
+
+ def cover_header_border
+ { color: @styles.dig(:cover, :header, :border, :color),
+ height: resolve_pt(@styles.dig(:cover, :header, :border, :height), 1),
+ offset: resolve_pt(@styles.dig(:cover, :header, :border, :offset), 0) }
+ end
+
+ def cover_footer
+ resolve_font(@styles.dig(:cover, :footer))
+ end
+
+ def cover_footer_offset
+ resolve_pt(@styles.dig(:cover, :footer, :offset), 0)
+ end
+
+ def cover_hero_padding
+ resolve_padding(@styles.dig(:cover, :hero))
+ end
+
+ def cover_hero_title
+ resolve_font(@styles.dig(:cover, :hero, :title))
+ end
+
+ def cover_hero_title_spacing
+ resolve_pt(@styles.dig(:cover, :hero, :title, :spacing), 0)
+ end
+
+ def cover_hero_title_max_height
+ resolve_pt(@styles.dig(:cover, :hero, :title, :max_height), 30)
+ end
+
+ def cover_hero_heading
+ resolve_font(@styles.dig(:cover, :hero, :heading))
+ end
+
+ def cover_hero_heading_spacing
+ resolve_pt(@styles.dig(:cover, :hero, :heading, :spacing), 0)
+ end
+
+ def cover_hero_dates
+ resolve_font(@styles.dig(:cover, :hero, :dates))
+ end
+
+ def cover_hero_dates_spacing
+ resolve_pt(@styles.dig(:cover, :hero, :dates, :spacing), 0)
+ end
+
+ def cover_hero_dates_max_height
+ resolve_pt(@styles.dig(:cover, :hero, :dates, :max_height), 0)
+ end
+
+ def cover_hero_subheading
+ resolve_font(@styles.dig(:cover, :hero, :subheading))
+ end
+
+ def cover_hero_subheading_max_height
+ resolve_pt(@styles.dig(:cover, :hero, :subheading, :max_height), 30)
+ end
+end
diff --git a/app/models/work_package/pdf_export/common/styles_markdown.rb b/app/models/work_package/pdf_export/common/styles_markdown.rb
new file mode 100644
index 00000000000..c8298f10b9a
--- /dev/null
+++ b/app/models/work_package/pdf_export/common/styles_markdown.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module WorkPackage::PDFExport::Common::StylesMarkdown
+ def wp_markdown_label
+ resolve_font(@styles.dig(:work_package, :markdown_label))
+ end
+
+ def wp_markdown_label_margins
+ resolve_margin(@styles.dig(:work_package, :markdown_label))
+ end
+
+ def wp_markdown_margins
+ resolve_margin(@styles.dig(:work_package, :markdown_margin))
+ end
+
+ def wp_markdown_styling_yml
+ resolve_markdown_styling(@styles.dig(:work_package, :markdown) || {})
+ end
+end
diff --git a/app/models/work_package/pdf_export/common/styles_page.rb b/app/models/work_package/pdf_export/common/styles_page.rb
new file mode 100644
index 00000000000..ff42416c8a4
--- /dev/null
+++ b/app/models/work_package/pdf_export/common/styles_page.rb
@@ -0,0 +1,95 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module WorkPackage::PDFExport::Common::StylesPage
+ def page_size
+ @styles[:page_size] || "A4"
+ end
+
+ def page_header_offset
+ resolve_pt(@styles.dig(:page_header, :offset), 20)
+ end
+
+ def page_footer_offset
+ resolve_pt(@styles.dig(:page_footer, :offset), -30)
+ end
+
+ def page_footer_horizontal_spacing
+ resolve_pt(@styles.dig(:page_footer, :spacing), 6)
+ end
+
+ def page_logo_height
+ resolve_pt(@styles.dig(:page_logo, :height), 20)
+ end
+
+ def page_logo_align
+ @styles.dig(:page_logo, :align) || :right
+ end
+
+ def page_margin_top
+ resolve_pt(@styles.dig(:page, :margin_top), 60)
+ end
+
+ def page_margin_left
+ resolve_pt(@styles.dig(:page, :margin_left), 50)
+ end
+
+ def page_margin_right
+ resolve_pt(@styles.dig(:page, :margin_right), 50)
+ end
+
+ def page_margin_bottom
+ resolve_pt(@styles.dig(:page, :margin_bottom), 60)
+ end
+
+ def page_heading
+ resolve_font(@styles[:page_heading])
+ end
+
+ def page_heading_margins
+ resolve_margin(@styles[:page_heading])
+ end
+
+ def page_header
+ resolve_font(@styles[:page_header])
+ end
+
+ def page_footer
+ resolve_font(@styles[:page_footer])
+ end
+
+ def page_break_threshold
+ resolve_pt(@styles.dig(:page, :page_break_threshold), 200)
+ end
+
+ def link_color
+ @styles.dig(:page, :link_color) || "000000"
+ end
+end
diff --git a/app/models/work_package/pdf_export/common/styles_wp_table.rb b/app/models/work_package/pdf_export/common/styles_wp_table.rb
new file mode 100644
index 00000000000..95974dc9a4c
--- /dev/null
+++ b/app/models/work_package/pdf_export/common/styles_wp_table.rb
@@ -0,0 +1,63 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module WorkPackage::PDFExport::Common::StylesWpTable
+ def wp_table_group_header
+ resolve_font(@styles.dig(:wp_table, :group_heading))
+ end
+
+ def wp_table_group_header_margins
+ resolve_margin(@styles.dig(:wp_table, :group_heading))
+ end
+
+ def wp_table_margins
+ resolve_margin(@styles.dig(:wp_table, :table))
+ end
+
+ def wp_table_cell
+ resolve_table_cell(@styles.dig(:wp_table, :table, :cell))
+ end
+
+ def wp_table_header_cell
+ wp_table_cell.merge(
+ resolve_table_cell(@styles.dig(:wp_table, :table, :cell_header))
+ )
+ end
+
+ def wp_table_sums_cell
+ wp_table_cell.merge(
+ resolve_table_cell(@styles.dig(:wp_table, :table, :cell_sums))
+ )
+ end
+
+ def wp_table_subject_indent
+ resolve_pt(@styles.dig(:wp_table, :table, :subject_indent), 0)
+ end
+end
diff --git a/app/models/work_package/pdf_export/export/report/schema.json b/app/models/work_package/pdf_export/export/report/schema.json
index 8cc799976c9..583a73c7f6f 100644
--- a/app/models/work_package/pdf_export/export/report/schema.json
+++ b/app/models/work_package/pdf_export/export/report/schema.json
@@ -27,8 +27,8 @@
"cover" : {
"$ref" : "#/$defs/cover"
},
- "overview" : {
- "$ref" : "#/$defs/overview"
+ "wp_table" : {
+ "$ref" : "#/$defs/wp_table"
}
},
"required" : [],
@@ -414,7 +414,7 @@
}
]
},
- "overview" : {
+ "wp_table" : {
"title" : "Overview",
"description" : "Styling for the PDF table export",
"x-example" : {
diff --git a/app/models/work_package/pdf_export/export/report/standard.yml b/app/models/work_package/pdf_export/export/report/standard.yml
index 04152364426..5ac0ee60d24 100644
--- a/app/models/work_package/pdf_export/export/report/standard.yml
+++ b/app/models/work_package/pdf_export/export/report/standard.yml
@@ -25,7 +25,7 @@ page_heading:
styles: [ "bold" ]
margin_bottom: 10
-overview:
+wp_table:
group_heading:
size: 11
styles: [ "bold" ]
diff --git a/app/models/work_package/pdf_export/export/report/styles.rb b/app/models/work_package/pdf_export/export/report/styles.rb
index ed789a2f196..2d07a22342b 100644
--- a/app/models/work_package/pdf_export/export/report/styles.rb
+++ b/app/models/work_package/pdf_export/export/report/styles.rb
@@ -29,44 +29,15 @@
#++
module WorkPackage::PDFExport::Export::Report::Styles
- include MarkdownToPDF::StyleValidation
-
class PDFStyles
include MarkdownToPDF::Common
include MarkdownToPDF::StyleHelper
include WorkPackage::PDFExport::Common::Styles
-
- def overview_group_header
- resolve_font(@styles.dig(:overview, :group_heading))
- end
-
- def overview_group_header_margins
- resolve_margin(@styles.dig(:overview, :group_heading))
- end
-
- def overview_table_margins
- resolve_margin(@styles.dig(:overview, :table))
- end
-
- def overview_table_cell
- resolve_table_cell(@styles.dig(:overview, :table, :cell))
- end
-
- def overview_table_header_cell
- overview_table_cell.merge(
- resolve_table_cell(@styles.dig(:overview, :table, :cell_header))
- )
- end
-
- def overview_table_sums_cell
- overview_table_cell.merge(
- resolve_table_cell(@styles.dig(:overview, :table, :cell_sums))
- )
- end
-
- def overview_table_subject_indent
- resolve_pt(@styles.dig(:overview, :table, :subject_indent), 0)
- end
+ include WorkPackage::PDFExport::Common::StylesPage
+ include WorkPackage::PDFExport::Common::StylesCover
+ include WorkPackage::PDFExport::Common::StylesMarkdown
+ include WorkPackage::PDFExport::Common::StylesWpTable
+ include WorkPackage::PDFExport::Common::StylesAttributesTable
def toc_max_depth
@styles.dig(:toc, :max_depth) || 4
@@ -109,116 +80,14 @@ module WorkPackage::PDFExport::Export::Report::Styles
def wp_detail_subject_margins
resolve_margin(@styles.dig(:work_package, :subject))
end
-
- def wp_attributes_table_margins
- resolve_margin(@styles.dig(:work_package, :attributes_table))
- end
-
- def wp_attributes_table_cell
- resolve_table_cell(@styles.dig(:work_package, :attributes_table, :cell))
- end
-
- def wp_attributes_table_label_cell
- wp_attributes_table_cell.merge(
- resolve_table_cell(@styles.dig(:work_package, :attributes_table, :cell_label))
- )
- end
-
- def wp_markdown_label
- resolve_font(@styles.dig(:work_package, :markdown_label))
- end
-
- def wp_markdown_label_margins
- resolve_margin(@styles.dig(:work_package, :markdown_label))
- end
-
- def wp_markdown_margins
- resolve_margin(@styles.dig(:work_package, :markdown_margin))
- end
-
- def wp_markdown_styling_yml
- resolve_markdown_styling(@styles.dig(:work_package, :markdown) || {})
- end
-
- def cover_header
- resolve_font(@styles.dig(:cover, :header))
- end
-
- def cover_header_logo_height
- resolve_pt(@styles.dig(:cover, :header, :logo_height), 25)
- end
-
- def cover_header_border
- { color: @styles.dig(:cover, :header, :border, :color),
- height: resolve_pt(@styles.dig(:cover, :header, :border, :height), 1),
- offset: resolve_pt(@styles.dig(:cover, :header, :border, :offset), 0) }
- end
-
- def cover_footer
- resolve_font(@styles.dig(:cover, :footer))
- end
-
- def cover_footer_offset
- resolve_pt(@styles.dig(:cover, :footer, :offset), 0)
- end
-
- def cover_hero_padding
- resolve_padding(@styles.dig(:cover, :hero))
- end
-
- def cover_hero_title
- resolve_font(@styles.dig(:cover, :hero, :title))
- end
-
- def cover_hero_title_spacing
- resolve_pt(@styles.dig(:cover, :hero, :title, :spacing), 0)
- end
-
- def cover_hero_title_max_height
- resolve_pt(@styles.dig(:cover, :hero, :title, :max_height), 30)
- end
-
- def cover_hero_heading
- resolve_font(@styles.dig(:cover, :hero, :heading))
- end
-
- def cover_hero_heading_spacing
- resolve_pt(@styles.dig(:cover, :hero, :heading, :spacing), 0)
- end
-
- def cover_hero_dates
- resolve_font(@styles.dig(:cover, :hero, :dates))
- end
-
- def cover_hero_dates_spacing
- resolve_pt(@styles.dig(:cover, :hero, :dates, :spacing), 0)
- end
-
- def cover_hero_dates_max_height
- resolve_pt(@styles.dig(:cover, :hero, :dates, :max_height), 0)
- end
-
- def cover_hero_subheading
- resolve_font(@styles.dig(:cover, :hero, :subheading))
- end
-
- def cover_hero_subheading_max_height
- resolve_pt(@styles.dig(:cover, :hero, :subheading, :max_height), 30)
- end
end
def styles
- @styles ||= PDFStyles.new(load_style)
+ @styles ||= PDFStyles.new(styles_asset_path)
end
private
- def load_style
- yml = YAML::load_file(File.join(styles_asset_path, "standard.yml"))
- schema = JSON::load_file(File.join(styles_asset_path, "schema.json"))
- validate_schema!(yml, schema)
- end
-
def styles_asset_path
File.dirname(File.expand_path(__FILE__))
end
diff --git a/app/models/work_package/pdf_export/export/report/sums_table.rb b/app/models/work_package/pdf_export/export/report/sums_table.rb
index 595eebe3cdf..b2ad1fe8c9b 100644
--- a/app/models/work_package/pdf_export/export/report/sums_table.rb
+++ b/app/models/work_package/pdf_export/export/report/sums_table.rb
@@ -34,7 +34,7 @@ module WorkPackage::PDFExport::Export::Report::SumsTable
write_optional_page_break
write_sums_title
- with_margin(styles.overview_table_margins) do
+ with_margin(styles.wp_table_margins) do
write_sums_table
end
end
@@ -76,11 +76,11 @@ module WorkPackage::PDFExport::Export::Report::SumsTable
end
def sums_table_options
- { header: true, cell_style: styles.overview_table_cell.merge({ inline_format: true }) }
+ { header: true, cell_style: styles.wp_table_cell.merge({ inline_format: true }) }
end
def build_sums_header_row
- header_style = styles.overview_table_header_cell
+ header_style = styles.wp_table_header_cell
row = sums_columns_objects.map do |col|
pdf.make_cell(sums_column_name(col), header_style)
end
@@ -94,7 +94,7 @@ module WorkPackage::PDFExport::Export::Report::SumsTable
end
def build_sums_group_row(group)
- build_sums_row(get_group_sums(group), make_group_label(group), styles.overview_table_cell)
+ build_sums_row(get_group_sums(group), make_group_label(group), styles.wp_table_cell)
end
def get_group_sums(group)
@@ -109,7 +109,7 @@ module WorkPackage::PDFExport::Export::Report::SumsTable
end
def build_sums_total_row
- build_sums_row(get_total_sums || {}, I18n.t("js.label_sum"), styles.overview_table_sums_cell)
+ build_sums_row(get_total_sums || {}, I18n.t("js.label_sum"), styles.wp_table_sums_cell)
end
def build_sums_row(sums, label, sums_style)
diff --git a/app/models/work_package/pdf_export/export/timesheet/styles.rb b/app/models/work_package/pdf_export/export/timesheet/styles.rb
index 34faa48773f..81b44ea6ad5 100644
--- a/app/models/work_package/pdf_export/export/timesheet/styles.rb
+++ b/app/models/work_package/pdf_export/export/timesheet/styles.rb
@@ -29,92 +29,20 @@
#++
module WorkPackage::PDFExport::Export::Timesheet::Styles
- include MarkdownToPDF::StyleValidation
-
class PDFStyles
include MarkdownToPDF::Common
include MarkdownToPDF::StyleHelper
include WorkPackage::PDFExport::Common::Styles
-
- def cover_header
- resolve_font(@styles.dig(:cover, :header))
- end
-
- def cover_header_logo_height
- resolve_pt(@styles.dig(:cover, :header, :logo_height), 25)
- end
-
- def cover_header_border
- { color: @styles.dig(:cover, :header, :border, :color),
- height: resolve_pt(@styles.dig(:cover, :header, :border, :height), 1),
- offset: resolve_pt(@styles.dig(:cover, :header, :border, :offset), 0) }
- end
-
- def cover_footer
- resolve_font(@styles.dig(:cover, :footer))
- end
-
- def cover_footer_offset
- resolve_pt(@styles.dig(:cover, :footer, :offset), 0)
- end
-
- def cover_hero_padding
- resolve_padding(@styles.dig(:cover, :hero))
- end
-
- def cover_hero_title
- resolve_font(@styles.dig(:cover, :hero, :title))
- end
-
- def cover_hero_title_spacing
- resolve_pt(@styles.dig(:cover, :hero, :title, :spacing), 0)
- end
-
- def cover_hero_title_max_height
- resolve_pt(@styles.dig(:cover, :hero, :title, :max_height), 30)
- end
-
- def cover_hero_heading
- resolve_font(@styles.dig(:cover, :hero, :heading))
- end
-
- def cover_hero_heading_spacing
- resolve_pt(@styles.dig(:cover, :hero, :heading, :spacing), 0)
- end
-
- def cover_hero_dates
- resolve_font(@styles.dig(:cover, :hero, :dates))
- end
-
- def cover_hero_dates_spacing
- resolve_pt(@styles.dig(:cover, :hero, :dates, :spacing), 0)
- end
-
- def cover_hero_dates_max_height
- resolve_pt(@styles.dig(:cover, :hero, :dates, :max_height), 0)
- end
-
- def cover_hero_subheading
- resolve_font(@styles.dig(:cover, :hero, :subheading))
- end
-
- def cover_hero_subheading_max_height
- resolve_pt(@styles.dig(:cover, :hero, :subheading, :max_height), 30)
- end
+ include WorkPackage::PDFExport::Common::StylesPage
+ include WorkPackage::PDFExport::Common::StylesCover
end
def styles
- @styles ||= PDFStyles.new(load_style)
+ @styles ||= PDFStyles.new(styles_asset_path)
end
private
- def load_style
- yml = YAML::load_file(File.join(styles_asset_path, "standard.yml"))
- schema = JSON::load_file(File.join(styles_asset_path, "schema.json"))
- validate_schema!(yml, schema)
- end
-
def styles_asset_path
File.dirname(File.expand_path(__FILE__))
end
diff --git a/app/models/work_package/pdf_export/export/wp/attributes.rb b/app/models/work_package/pdf_export/export/wp/attributes.rb
index 78eaeadb5a7..191c68a7b39 100644
--- a/app/models/work_package/pdf_export/export/wp/attributes.rb
+++ b/app/models/work_package/pdf_export/export/wp/attributes.rb
@@ -32,9 +32,12 @@ module WorkPackage::PDFExport::Export::Wp::Attributes
def write_attributes_tables!(work_package)
work_package
.type.attribute_groups
- .filter { |group| group.is_a?(Type::AttributeGroup) }
- .map do |group|
- write_attributes_group(group, work_package)
+ .each do |group|
+ if group.is_a?(Type::AttributeGroup)
+ write_attributes_group(group, work_package)
+ elsif group.is_a?(Type::QueryGroup)
+ write_query_group(group)
+ end
end
end
@@ -48,12 +51,18 @@ module WorkPackage::PDFExport::Export::Wp::Attributes
escape_tags(value)
end
+ def write_query_group(group)
+ write_group_title(group)
+ related_work_packages = group.query.results.work_packages
+ write_work_packages_table!(related_work_packages, group.query)
+ end
+
def write_attributes_group(group, work_package)
- write_attributes_group_table_title(group)
+ write_group_title(group)
write_attributes_group_table(group, work_package)
end
- def write_attributes_group_table_title(group)
+ def write_group_title(group)
with_margin(styles.wp_markdown_label_margins) do
pdf.formatted_text([styles.wp_markdown_label
.merge({ text: group.translated_key })])
diff --git a/app/models/work_package/pdf_export/export/wp/schema.json b/app/models/work_package/pdf_export/export/wp/schema.json
index 42dfad04851..9d5bb410ba6 100644
--- a/app/models/work_package/pdf_export/export/wp/schema.json
+++ b/app/models/work_package/pdf_export/export/wp/schema.json
@@ -20,6 +20,9 @@
},
"work_package" : {
"$ref" : "#/$defs/work_package"
+ },
+ "wp_table" : {
+ "$ref" : "#/$defs/wp_table"
}
},
"required" : [],
@@ -193,6 +196,95 @@
}
]
},
+ "wp_table" : {
+ "title" : "Work package table",
+ "description" : "Styling for the related tables (Form configuration)",
+ "x-example" : {
+ "overview" : {
+ "group_heading" : {},
+ "table" : {}
+ }
+ },
+ "type" : "object",
+ "properties" : {
+ "group_heading" : {
+ "type" : "object",
+ "title" : "Overview group heading",
+ "description" : "Styling for the group label if grouping is activated",
+ "x-example" : {
+ "group_heading" : {
+ "size" : 11,
+ "styles" : [
+ "bold"
+ ],
+ "margin_bottom" : 10
+ }
+ },
+ "allOf" : [
+ {
+ "$ref" : "#/$defs/font"
+ },
+ {
+ "$ref" : "#/$defs/margin"
+ }
+ ]
+ },
+ "table" : {
+ "type" : "object",
+ "title" : "Overview table",
+ "x-example" : {
+ "table" : {
+ "subject_indent" : 0,
+ "margin_bottom" : 20,
+ "cell" : {
+ "size" : 9,
+ "color" : "000000",
+ "padding" : 5
+ },
+ "cell_header" : {
+ "size" : 9,
+ "styles" : [
+ "bold"
+ ]
+ },
+ "cell_sums" : {
+ "size" : 8,
+ "styles" : [
+ "bold"
+ ]
+ }
+ }
+ },
+ "properties" : {
+ "subject_indent" : {
+ "title" : "Indent subject",
+ "description" : "Indent by work package level in the subject cell",
+ "$ref" : "#/$defs/measurement"
+ },
+ "cell" : {
+ "title" : "Table cell",
+ "description" : "Styling for a table value cell",
+ "$ref" : "#/$defs/table_cell"
+ },
+ "cell_header" : {
+ "title" : "Table header cell",
+ "description" : "Styling for a table header cell",
+ "$ref" : "#/$defs/table_cell"
+ },
+ "cell_sums" : {
+ "title" : "Table sum cell",
+ "description" : "Styling for a table sum cell",
+ "$ref" : "#/$defs/table_cell"
+ }
+ },
+ "allOf" : [
+ {
+ "$ref" : "#/$defs/margin"
+ }
+ ]
+ }
+ }
+ },
"markdown" : {
"type" : "object",
"title" : "Markdown Styling",
diff --git a/app/models/work_package/pdf_export/export/wp/standard.yml b/app/models/work_package/pdf_export/export/wp/standard.yml
index 761590b573a..953de089f0f 100644
--- a/app/models/work_package/pdf_export/export/wp/standard.yml
+++ b/app/models/work_package/pdf_export/export/wp/standard.yml
@@ -25,6 +25,29 @@ page_heading:
styles: [ "bold" ]
margin_bottom: 10
+wp_table:
+ group_heading:
+ size: 11
+ styles: [ "bold" ]
+ margin_bottom: 10
+ table:
+ subject_indent: 8
+ margin_bottom: 20
+ cell:
+ size: 9
+ color: "000000"
+ padding_left: 5
+ padding_right: 5
+ padding_top: 0
+ padding_bottom: 5
+ border_width: 0.25
+ cell_header:
+ size: 9
+ styles: [ "bold" ]
+ cell_sums:
+ size: 8
+ styles: [ "bold" ]
+
work_package:
margin_bottom: 14
subject:
diff --git a/app/models/work_package/pdf_export/export/wp/styles.rb b/app/models/work_package/pdf_export/export/wp/styles.rb
index 6b8dcbe85eb..8507f781c34 100644
--- a/app/models/work_package/pdf_export/export/wp/styles.rb
+++ b/app/models/work_package/pdf_export/export/wp/styles.rb
@@ -29,12 +29,14 @@
#++
module WorkPackage::PDFExport::Export::Wp::Styles
- include MarkdownToPDF::StyleValidation
-
class PDFStyles
include MarkdownToPDF::Common
include MarkdownToPDF::StyleHelper
include WorkPackage::PDFExport::Common::Styles
+ include WorkPackage::PDFExport::Common::StylesPage
+ include WorkPackage::PDFExport::Common::StylesMarkdown
+ include WorkPackage::PDFExport::Common::StylesWpTable
+ include WorkPackage::PDFExport::Common::StylesAttributesTable
def wp_margins
resolve_margin(@styles[:work_package])
@@ -49,50 +51,14 @@ module WorkPackage::PDFExport::Export::Wp::Styles
def wp_detail_subject_margins
resolve_margin(@styles.dig(:work_package, :subject))
end
-
- def wp_attributes_table_margins
- resolve_margin(@styles.dig(:work_package, :attributes_table))
- end
-
- def wp_attributes_table_cell
- resolve_table_cell(@styles.dig(:work_package, :attributes_table, :cell))
- end
-
- def wp_attributes_table_label_cell
- wp_attributes_table_cell.merge(
- resolve_table_cell(@styles.dig(:work_package, :attributes_table, :cell_label))
- )
- end
-
- def wp_markdown_label
- resolve_font(@styles.dig(:work_package, :markdown_label))
- end
-
- def wp_markdown_label_margins
- resolve_margin(@styles.dig(:work_package, :markdown_label))
- end
-
- def wp_markdown_margins
- resolve_margin(@styles.dig(:work_package, :markdown_margin))
- end
-
- def wp_markdown_styling_yml
- resolve_markdown_styling(@styles.dig(:work_package, :markdown) || {})
- end
end
def styles
- @styles ||= PDFStyles.new(load_style)
+ @styles ||= PDFStyles.new(styles_asset_path)
end
private
- def load_style
- yml = YAML::load_file(File.join(styles_asset_path, "standard.yml"))
- schema = JSON::load_file(File.join(styles_asset_path, "schema.json"))
- validate_schema!(yml, schema)
- end
-
def styles_asset_path
File.dirname(File.expand_path(__FILE__))
end
diff --git a/app/models/work_package/pdf_export/export/report/overview_table.rb b/app/models/work_package/pdf_export/export/wp_table.rb
similarity index 67%
rename from app/models/work_package/pdf_export/export/report/overview_table.rb
rename to app/models/work_package/pdf_export/export/wp_table.rb
index 75f6585a6c3..f8294a6403c 100644
--- a/app/models/work_package/pdf_export/export/report/overview_table.rb
+++ b/app/models/work_package/pdf_export/export/wp_table.rb
@@ -28,26 +28,31 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module WorkPackage::PDFExport::Export::Report::OverviewTable
- def write_work_packages_overview!(work_packages)
+module WorkPackage::PDFExport::Export::WpTable
+ def write_work_packages_table!(work_packages, query)
+ columns = limit_table_columns_objects(query)
if query.grouped?
- write_grouped!(work_packages)
+ write_grouped!(work_packages, query, columns)
else
- with_margin(styles.overview_table_margins) do
- write_table!(work_packages, get_total_sums)
+ with_margin(styles.wp_table_margins) do
+ write_table!(work_packages, query, columns, get_sums(query))
end
end
end
private
- def write_grouped!(work_packages)
+ def get_sums(query)
+ query.display_sums? ? (query.results.all_total_sums || {}) : {}
+ end
+
+ def write_grouped!(work_packages, query, columns)
groups_with_work_packages = work_packages.group_by do |work_package|
query.group_by_column.value(work_package)
end
- sums = transformed_sum_group
+ sums = transformed_sum_group(query)
groups_with_work_packages.each do |group, grouped_work_packages|
- write_group!(group, grouped_work_packages, sums[group] || {})
+ write_group!(group, grouped_work_packages, query, columns, sums[group] || {})
end
end
@@ -77,16 +82,16 @@ module WorkPackage::PDFExport::Export::Report::OverviewTable
#
# we therefor transform the keys of sums from b) to a)
- def transformed_sum_group
+ def transformed_sum_group(query)
sums = query.results.all_group_sums
if query.group_by_column.is_a?(Queries::WorkPackages::Selects::CustomFieldSelect)
- transform_custom_field_keys(sums)
+ transform_custom_field_keys(sums, query)
else
sums
end
end
- def transform_custom_field_keys(groups)
+ def transform_custom_field_keys(groups, query)
custom_field = query.group_by_column.custom_field
if custom_field.list?
transform_list_custom_field_keys(custom_field, groups)
@@ -122,56 +127,53 @@ module WorkPackage::PDFExport::Export::Report::OverviewTable
# -- end workaround
- def overview_columns_objects
- @overview_columns_objects ||= limit_table_columns_objects
- end
-
- def limit_table_columns_objects
- list = column_objects
+ def limit_table_columns_objects(query)
+ list = query
+ .columns
+ .reject { |c| c.is_a?(Queries::WorkPackages::Selects::RelationSelect) }
list = list.reject { |c| c == query.group_by_column } if query.grouped?
list
end
- def table_column_widths
- widths = overview_columns_objects.map do |col|
+ def table_column_widths(columns)
+ widths = columns.map do |col|
col.name == :subject || text_column?(col) ? 4.0 : 1.0
end
ratio = pdf.bounds.width / widths.sum
widths.map { |w| w * ratio }
end
- def write_group!(group, work_packages, sums)
+ def write_group!(group, work_packages, query, columns, sums)
write_optional_page_break
- with_margin(styles.overview_table_margins) do
- label = make_group_label(group)
- with_margin(styles.overview_group_header_margins) do
- pdf.formatted_text([styles.overview_group_header.merge({ text: label })])
+ with_margin(styles.wp_table_margins) do
+ with_margin(styles.wp_table_group_header_margins) do
+ pdf.formatted_text([styles.wp_table_group_header.merge({ text: make_group_label(group) })])
end
- write_table!(work_packages, sums)
+ write_table!(work_packages, query, columns, sums)
end
end
- def write_table!(work_packages, sums)
- rows = build_table_rows(work_packages, sums)
- pdf_table_auto_widths(rows, table_column_widths, overview_table_options)
+ def write_table!(work_packages, query, columns, sums)
+ rows = build_table_rows(work_packages, query, columns, sums)
+ pdf_table_auto_widths(rows, table_column_widths(columns), wp_table_options)
end
- def overview_table_options
- { header: true, cell_style: styles.overview_table_cell.merge({ inline_format: true }) }
+ def wp_table_options
+ { header: true, cell_style: styles.wp_table_cell.merge({ inline_format: true }) }
end
- def build_table_rows(work_packages, sums)
+ def build_table_rows(work_packages, query, columns, sums)
rows = work_packages.map do |work_package|
- build_table_row(work_package)
+ build_table_row(work_package, columns)
end
- rows.unshift build_header_row
- rows.push build_overview_sum_row(sums) if query.display_sums?
+ rows.unshift build_header_row(columns)
+ rows.push build_sum_row(columns, sums) if query.display_sums?
rows
end
- def build_table_row(work_package)
- cell_style = styles.overview_table_cell
- overview_columns_objects.map do |col|
+ def build_table_row(work_package, columns)
+ cell_style = styles.wp_table_cell
+ columns.map do |col|
content = get_column_value_cell work_package, col.name
if col.name == :subject
build_subject_cell(content)
@@ -182,22 +184,22 @@ module WorkPackage::PDFExport::Export::Report::OverviewTable
end
def build_subject_cell(content)
- cell_style = styles.overview_table_cell
+ cell_style = styles.wp_table_cell
padding_left = cell_style.fetch(:padding_left, 0)
pdf.make_cell(content, cell_style.merge({ padding_left: }))
end
- def build_header_row
- header_style = styles.overview_table_header_cell
- overview_columns_objects.map do |col|
+ def build_header_row(columns)
+ header_style = styles.wp_table_header_cell
+ columns.map do |col|
content = (col.caption || "").upcase
pdf.make_cell(content, header_style)
end
end
- def build_overview_sum_row(sums)
- sums_style = styles.overview_table_sums_cell
- sum_row = overview_columns_objects.map do |col|
+ def build_sum_row(columns, sums)
+ sums_style = styles.wp_table_sums_cell
+ sum_row = columns.map do |col|
content = get_formatted_value(sums[col], col.name)
pdf.make_cell(content, sums_style)
end
diff --git a/app/models/work_package/pdf_export/work_package_list_to_pdf.rb b/app/models/work_package/pdf_export/work_package_list_to_pdf.rb
index cb873be99ad..ce8d2feb368 100644
--- a/app/models/work_package/pdf_export/work_package_list_to_pdf.rb
+++ b/app/models/work_package/pdf_export/work_package_list_to_pdf.rb
@@ -49,10 +49,10 @@ class WorkPackage::PDFExport::WorkPackageListToPdf < WorkPackage::Exports::Query
include WorkPackage::PDFExport::Export::MarkdownField
include WorkPackage::PDFExport::Export::WorkPackageDetail
include WorkPackage::PDFExport::Export::Report::Styles
- include WorkPackage::PDFExport::Export::Report::OverviewTable
include WorkPackage::PDFExport::Export::Report::SumsTable
include WorkPackage::PDFExport::Export::Report::TableOfContents
include WorkPackage::PDFExport::Export::Report::Attributes
+ include WorkPackage::PDFExport::Export::WpTable
include WorkPackage::PDFExport::Export::Cover
include WorkPackage::PDFExport::Export::Gantt
@@ -151,7 +151,7 @@ class WorkPackage::PDFExport::WorkPackageListToPdf < WorkPackage::Exports::Query
else
write_title!
write_work_packages_toc! work_packages, @id_wp_meta_map if wants_report?
- write_work_packages_overview! work_packages unless wants_report?
+ write_work_packages_table!(work_packages, query) unless wants_report?
write_work_packages_sums! work_packages if with_sums_table? && wants_report?
end
if should_be_batched?(work_packages)
diff --git a/app/models/work_package/pdf_export/work_package_to_pdf.rb b/app/models/work_package/pdf_export/work_package_to_pdf.rb
index 892efb9251f..63fbcd1a3f5 100644
--- a/app/models/work_package/pdf_export/work_package_to_pdf.rb
+++ b/app/models/work_package/pdf_export/work_package_to_pdf.rb
@@ -37,6 +37,7 @@ class WorkPackage::PDFExport::WorkPackageToPdf < Exports::Exporter
include WorkPackage::PDFExport::Export::Page
include WorkPackage::PDFExport::Export::Wp::Styles
include WorkPackage::PDFExport::Export::Wp::Attributes
+ include WorkPackage::PDFExport::Export::WpTable
attr_accessor :pdf, :columns
diff --git a/docs/system-admin-guide/design/pdf-export-styles/attributes-and-description/README.md b/docs/system-admin-guide/design/pdf-export-styles/attributes-and-description/README.md
index 58d154c6956..197e0a99f4c 100644
--- a/docs/system-admin-guide/design/pdf-export-styles/attributes-and-description/README.md
+++ b/docs/system-admin-guide/design/pdf-export-styles/attributes-and-description/README.md
@@ -11,6 +11,7 @@ This document describes the style settings format for the [PDF Export styling fi
| `page_footer` | **Page footers**<br/>See [Page footers](#page-footers) | object |
| `page_heading` | **Page heading**<br/>The main page title heading<br/>See [Page heading](#page-heading) | object |
| `work_package` | **Work package**<br/>Styling for the Work package section<br/>See [Work package](#work-package) | object |
+| `wp_table` | **Work package table**<br/>Styling for the related tables (Form configuration)<br/>See [Work package table](#work-package-table) | object |
## Alert
@@ -529,6 +530,57 @@ unordered_list_point:
| `spacing` | **Spacing**<br/>Space between point and list item content<br/>Examples: `10mm`, `10` | number or string<br/>See [Units](#units) |
| … | See [Font properties](#font-properties) | |
+## Overview group heading
+
+Styling for the group label if grouping is activated
+
+Key: `group_heading`
+
+Example:
+```yml
+group_heading:
+ size: 11
+ styles:
+ - bold
+ margin_bottom: 10
+```
+
+| Key | Description | Data type |
+| - | - | - |
+| … | See [Font properties](#font-properties) | |
+| … | See [Margin properties](#margin-properties) | |
+
+## Overview table
+
+Key: `table`
+
+Example:
+```yml
+table:
+ subject_indent: 0
+ margin_bottom: 20
+ cell:
+ size: 9
+ color: '000000'
+ padding: 5
+ cell_header:
+ size: 9
+ styles:
+ - bold
+ cell_sums:
+ size: 8
+ styles:
+ - bold
+```
+
+| Key | Description | Data type |
+| - | - | - |
+| `subject_indent` | **Indent subject**<br/>Indent by work package level in the subject cell<br/>Examples: `10mm`, `10` | number or string<br/>See [Units](#units) |
+| `cell` | **Table cell**<br/>Styling for a table value cell<br/>See [Table cell](#table-cell) | object |
+| `cell_header` | **Table header cell**<br/>Styling for a table header cell<br/>See [Table cell](#table-cell) | object |
+| `cell_sums` | **Table sum cell**<br/>Styling for a table sum cell<br/>See [Table cell](#table-cell) | object |
+| … | See [Margin properties](#margin-properties) | |
+
## Padding Properties
Properties to set paddings
@@ -835,6 +887,24 @@ subject_level_3:
| … | See [Font properties](#font-properties) | |
| … | See [Margin properties](#margin-properties) | |
+## Work package table
+
+Styling for the related tables (Form configuration)
+
+Key: `wp_table`
+
+Example:
+```yml
+overview:
+ group_heading: {}
+ table: {}
+```
+
+| Key | Description | Data type |
+| - | - | - |
+| `group_heading` | **Overview group heading**<br/>Styling for the group label if grouping is activated<br/>See [Overview group heading](#overview-group-heading) | object |
+| `table` | **Overview table**<br/>See [Overview table](#overview-table) | object |
+
## alert boxes (styled blockquotes)
Key: `alerts`
diff --git a/docs/system-admin-guide/design/pdf-export-styles/report/README.md b/docs/system-admin-guide/design/pdf-export-styles/report/README.md
index 678e8f8b390..2e4c192d16c 100644
--- a/docs/system-admin-guide/design/pdf-export-styles/report/README.md
+++ b/docs/system-admin-guide/design/pdf-export-styles/report/README.md
@@ -13,7 +13,7 @@ This document describes the style settings format for the [PDF Export styling fi
| `work_package` | **Work package**<br/>Styling for the Work package section<br/>See [Work package](#work-package) | object |
| `toc` | **Table of content**<br/>Styling for the table of content of the PDF report export<br/>See [Table of content](#table-of-content) | object |
| `cover` | **Cover page**<br/>Styling for the cover page of the PDF report export<br/>See [Cover page](#cover-page) | object |
-| `overview` | **Overview**<br/>Styling for the PDF table export<br/>See [Overview](#overview) | object |
+| `wp_table` | **Overview**<br/>Styling for the PDF table export<br/>See [Overview](#overview) | object |
## Alert
@@ -643,7 +643,7 @@ unordered_list_point:
Styling for the PDF table export
-Key: `overview`
+Key: `wp_table`
Example:
```yml