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

refactor common code

as-opa777d021e5ce
diff --git a/modules/meeting/app/workers/meetings/pdf/common/agenda.rb b/modules/meeting/app/workers/meetings/pdf/common/agenda.rb
new file mode 100644
index 00000000000..ddca6815070
--- /dev/null
+++ b/modules/meeting/app/workers/meetings/pdf/common/agenda.rb
@@ -0,0 +1,115 @@
+# 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 Meetings::PDF::Common::Agenda
+ def write_agenda
+ return if meeting.sections.empty?
+
+ write_optional_page_break
+ write_agenda_sections
+ end
+
+ def write_agenda_sections
+ meeting.sections.each_with_index { |section, index| write_section(section, index) }
+ end
+
+ def format_duration(duration)
+ OpenProject::Common::DurationComponent.new(duration, :minutes, abbreviated: true).text
+ end
+
+ def section_title(section)
+ section.title.presence || I18n.t("meeting_section.untitled_title")
+ end
+
+ def format_agenda_item_title(title)
+ prawn_table_cell_inline_formatting_data(title, styles.agenda_item_title)
+ end
+
+ def format_agenda_item_subtitle(text)
+ prawn_table_cell_inline_formatting_data(text, styles.agenda_item_subtitle)
+ end
+
+ def agenda_title_wp(work_package)
+ href = url_helpers.work_package_url(work_package)
+ make_link_href(
+ href,
+ prawn_table_cell_inline_formatting_data(
+ "#{work_package.type.name} ##{work_package.id} #{work_package.subject}",
+ { styles: [:underline] }
+ )
+ )
+ end
+
+ def agenda_wp_title_row(agenda_item)
+ if agenda_item.visible_work_package?
+ work_package = agenda_item.work_package
+ [agenda_title_wp(work_package), "(#{work_package.status.name})"].join(" ")
+ elsif agenda_item.linked_work_package?
+ I18n.t(:label_agenda_item_undisclosed_wp, id: agenda_item.work_package_id)
+ elsif agenda_item.deleted_work_package?
+ I18n.t(:label_agenda_item_deleted_wp)
+ else
+ agenda_item.title
+ end
+ end
+
+ def write_outcome(agenda_item)
+ return unless agenda_item.outcomes.exists?
+
+ outcome = agenda_item.outcomes.information_kind.last
+ return if outcome.notes.blank?
+
+ pdf.indent(styles.outcome_indent) do
+ write_optional_page_break
+ write_outcome_title
+ write_outcome_notes(outcome.notes)
+ end
+ end
+
+ def write_outcome_title
+ with_vertical_margin(styles.outcome_title_margins) do
+ style = styles.outcome_title
+ pdf.formatted_text([
+ styles.outcome_symbol.merge({ text: "✓ " }),
+ style.merge({ text: I18n.t("label_agenda_outcome") })
+ ], style)
+ end
+ end
+
+ def write_outcome_notes(notes)
+ with_vertical_margin(styles.outcome_markdown_margins) do
+ write_markdown!(
+ apply_markdown_field_macros(notes, { project: meeting.project, user: User.current }),
+ styles.outcome_markdown_styling_yml
+ )
+ end
+ end
+end
diff --git a/modules/meeting/app/workers/meetings/pdf/common/exporter.rb b/modules/meeting/app/workers/meetings/pdf/common/exporter.rb
new file mode 100644
index 00000000000..384401a957f
--- /dev/null
+++ b/modules/meeting/app/workers/meetings/pdf/common/exporter.rb
@@ -0,0 +1,129 @@
+# 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 Meetings::PDF::Common
+ class Exporter < ::Exports::Exporter
+ include Exports::PDF::Common::Common
+ include Exports::PDF::Common::Logo
+ include Exports::PDF::Common::Markdown
+ include Exports::PDF::Common::Attachments
+ include Exports::PDF::Common::Macro
+ include Exports::PDF::Components::Page
+
+ self.model = Meeting
+
+ alias :meeting :object
+
+ attr_accessor :pdf
+
+ def self.key
+ :pdf
+ end
+
+ def initialize(meeting, options)
+ super(meeting, options[:options] || options)
+ @total_page_nr = nil
+ @page_count = 0
+
+ setup_page!
+ end
+
+ def export!
+ render_doc
+ success(pdf.render)
+ rescue StandardError => e
+ Rails.logger.error "Failed to generate PDF export: #{e.message}:\n#{e.backtrace.join("\n")}"
+ error(I18n.t(:error_pdf_failed_to_export, error: e.message))
+ end
+
+ def setup_page!
+ self.pdf = get_pdf
+ pdf.title = heading
+ configure_page_size!(:portrait)
+ end
+
+ def write_heading(text)
+ style = styles.heading
+ with_vertical_margin(styles.heading_margins) do
+ pdf.formatted_text([style.merge({ text: })], style)
+ end
+ end
+
+ def cover_page_title
+ project_title
+ end
+
+ def cover_page_heading
+ meeting.title
+ end
+
+ def cover_page_dates
+ [
+ "#{meeting_mode},",
+ "#{format_date(meeting.start_time)},",
+ format_time(meeting.start_time, include_date: false),
+ "–",
+ format_time(meeting.end_time, include_date: false)
+ ].join(" ")
+ end
+
+ def meeting_mode
+ meeting.state == "open" ? I18n.t("label_meeting_agenda") : I18n.t("label_meeting_minutes")
+ end
+
+ def cover_page_subheading
+ meeting.location
+ end
+
+ def heading
+ meeting.title
+ end
+
+ def project_title
+ meeting.project&.name || ""
+ end
+
+ def title_datetime
+ meeting.start_time.strftime("%Y-%m-%d")
+ end
+
+ def title
+ build_pdf_filename(meeting.title)
+ end
+
+ def with_outcomes?
+ ActiveModel::Type::Boolean.new.cast(options[:outcomes])
+ end
+
+ def with_images?
+ true
+ end
+ end
+end
diff --git a/modules/meeting/app/workers/meetings/pdf/common/styles.rb b/modules/meeting/app/workers/meetings/pdf/common/styles.rb
new file mode 100644
index 00000000000..4874bd5934e
--- /dev/null
+++ b/modules/meeting/app/workers/meetings/pdf/common/styles.rb
@@ -0,0 +1,143 @@
+# 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 Meetings::PDF::Common::Styles
+ class Base
+ include MarkdownToPDF::Common
+ include MarkdownToPDF::StyleHelper
+ include Exports::PDF::Common::Styles
+ include Exports::PDF::Components::PageStyles
+ include Exports::PDF::Components::CoverStyles
+
+ def page_subtitle
+ resolve_font(@styles[:page_subtitle])
+ end
+
+ def page_subtitle_margins
+ resolve_margin(@styles[:page_subtitle])
+ end
+
+ def notes_markdown_margins
+ resolve_margin(@styles.dig(:notes, :markdown_margin))
+ end
+
+ def notes_markdown_styling_yml
+ resolve_markdown_styling(@styles.dig(:notes, :markdown) || {})
+ end
+
+ def outcome_markdown_styling_yml
+ resolve_markdown_styling(@styles.dig(:outcome, :markdown) || {})
+ end
+
+ def heading
+ resolve_font(@styles[:heading])
+ end
+
+ def heading_margins
+ resolve_margin(@styles[:heading])
+ end
+
+ def agenda_item_title_margins
+ resolve_margin(@styles.dig(:agenda_item, :title_margin))
+ end
+
+ def agenda_item_indent
+ @styles.dig(:agenda_item, :indent).presence || 5
+ end
+
+ def outcome_title
+ resolve_font(@styles.dig(:outcome, :title))
+ end
+
+ def outcome_symbol
+ resolve_font(@styles.dig(:outcome, :symbol))
+ end
+
+ def outcome_title_margins
+ resolve_margin(@styles.dig(:outcome, :title))
+ end
+
+ def outcome_markdown_margins
+ resolve_margin(@styles.dig(:outcome, :markdown_margin))
+ end
+
+ def outcome_indent
+ @styles.dig(:outcome, :indent).presence || 15
+ end
+
+ def agenda_item_title
+ resolve_font(@styles.dig(:agenda_item, :title))
+ end
+
+ def agenda_item_title_cell
+ resolve_table_cell(@styles.dig(:agenda_item, :title_cell))
+ end
+
+ def agenda_item_subtitle
+ resolve_font(@styles.dig(:agenda_item, :subtitle))
+ end
+
+ def participants_table_cell
+ resolve_table_cell(@styles.dig(:participants, :cell))
+ end
+
+ def participants_status
+ resolve_font(@styles.dig(:participants, :status))
+ end
+
+ def participants_margins
+ resolve_margin(@styles[:participants])
+ end
+
+ def attachments_table_cell
+ resolve_table_cell(@styles.dig(:attachments, :cell))
+ end
+
+ def attachments_margins
+ resolve_margin(@styles[:attachments])
+ end
+
+ def agenda_section_title
+ resolve_font(@styles.dig(:agenda_section, :title))
+ end
+
+ def agenda_section_title_table_margins
+ resolve_margin(@styles.dig(:agenda_section, :title_margins))
+ end
+
+ def agenda_section_subtitle
+ resolve_font(@styles.dig(:agenda_section, :subtitle))
+ end
+
+ def agenda_section_title_cell
+ resolve_table_cell(@styles.dig(:agenda_section, :title_cell))
+ end
+ end
+end
diff --git a/modules/meeting/app/workers/meetings/pdf/default/agenda.rb b/modules/meeting/app/workers/meetings/pdf/default/agenda.rb
index 16861db8a11..dd916bea655 100644
--- a/modules/meeting/app/workers/meetings/pdf/default/agenda.rb
+++ b/modules/meeting/app/workers/meetings/pdf/default/agenda.rb
@@ -28,201 +28,118 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Meetings::PDF::Default
- module Agenda
- def write_agenda
- return if meeting.sections.empty?
+module Meetings::PDF::Default::Agenda
+ include Meetings::PDF::Common::Agenda
- write_optional_page_break
- write_agenda_sections
- end
-
- def write_backlog
- return if meeting.backlog.blank? || meeting.backlog.agenda_items.empty?
-
- write_hr
- write_heading(meeting.recurring? ? I18n.t("label_series_backlog") : I18n.t("label_agenda_backlog"))
- write_agenda_items(meeting.backlog)
- end
-
- def write_agenda_sections
- meeting.sections.each_with_index { |section, index| write_section(section, index) }
- end
-
- def write_section(section, section_index)
- write_optional_page_break
- unless section.title.blank? && section_index == 0 && meeting.sections.count == 1
- write_section_title(section, section_index)
- end
- write_agenda_items(section)
- end
-
- def write_section_title(section, section_index)
- margins = styles.agenda_section_title_table_margins
- margins = margins.merge({ top_margin: 0 }) if section_index == 0
- with_vertical_margin(margins) do
- pdf.table(
- [[{ content: format_agenda_section_title_cell(section) }]],
- width: pdf.bounds.width,
- cell_style: { inline_format: true }.merge(styles.agenda_section_title_cell)
- )
- end
- end
-
- def format_agenda_section_title_cell(section)
- content = [prawn_table_cell_inline_formatting_data(section_title(section), styles.agenda_section_title)]
- if section.agenda_items_sum_duration_in_minutes > 0
- content.push(
- prawn_table_cell_inline_formatting_data(
- format_duration(section.agenda_items_sum_duration_in_minutes),
- styles.agenda_section_subtitle
- )
- )
- end
- content.join(" ")
- end
-
- def format_duration(duration)
- OpenProject::Common::DurationComponent.new(duration, :minutes, abbreviated: true).text
- end
-
- def section_title(section)
- section.title.presence || I18n.t("meeting_section.untitled_title")
- end
-
- def write_agenda_items(section)
- section.agenda_items.each_with_index do |item, index|
- write_agenda_item_hr if index > 0
- write_optional_page_break
- write_agenda_item(item)
- end
- end
-
- def write_agenda_item_hr
- hr_style = styles.agenda_item_hr
- with_vertical_margin(styles.agenda_item_hr_margins) do
- write_horizontal_line(
- pdf.cursor,
- hr_style[:height],
- hr_style[:color],
- left_padding: styles.agenda_item_indent
- )
- end
- end
-
- def write_agenda_item(agenda_item)
- case agenda_item.item_type.to_sym
- when :simple
- write_agenda_title_item_simple(agenda_item)
- when :work_package
- write_agenda_title_item_wp(agenda_item)
- end
- write_notes(agenda_item)
- write_outcome(agenda_item) if with_outcomes?
- end
+ def write_backlog
+ return if meeting.backlog.blank? || meeting.backlog.agenda_items.empty?
- def write_agenda_item_title(title, duration, user)
- with_vertical_margin(styles.agenda_item_title_margins) do
- pdf.table(
- [[{ content: format_agenda_item_cell(title, duration, user) }]],
- width: pdf.bounds.width,
- cell_style: { inline_format: true }.merge(styles.agenda_item_title_cell)
- )
- end
- end
-
- def format_agenda_item_cell(text, duration, user)
- content = [format_agenda_item_title(text)]
- content.push(format_agenda_item_subtitle(format_duration(duration))) if duration > 0
- content.push(format_agenda_item_subtitle(user.name)) unless user.nil?
- content.join(" ")
- end
+ write_hr
+ write_heading(meeting.recurring? ? I18n.t("label_series_backlog") : I18n.t("label_agenda_backlog"))
+ write_agenda_items(meeting.backlog)
+ end
- def format_agenda_item_subtitle(text)
- prawn_table_cell_inline_formatting_data(text, styles.agenda_item_subtitle)
+ def write_section(section, section_index)
+ write_optional_page_break
+ unless section.title.blank? && section_index == 0 && meeting.sections.count == 1
+ write_section_title(section, section_index)
end
+ write_agenda_items(section)
+ end
- def format_agenda_item_title(title)
- prawn_table_cell_inline_formatting_data(title, styles.agenda_item_title)
+ def write_section_title(section, section_index)
+ margins = styles.agenda_section_title_table_margins
+ margins = margins.merge({ top_margin: 0 }) if section_index == 0
+ with_vertical_margin(margins) do
+ pdf.table(
+ [[{ content: format_agenda_section_title_cell(section) }]],
+ width: pdf.bounds.width,
+ cell_style: { inline_format: true }.merge(styles.agenda_section_title_cell)
+ )
end
+ end
- def agenda_title_wp(work_package)
- href = url_helpers.work_package_url(work_package)
- make_link_href(
- href,
+ def format_agenda_section_title_cell(section)
+ content = [prawn_table_cell_inline_formatting_data(section_title(section), styles.agenda_section_title)]
+ if section.agenda_items_sum_duration_in_minutes > 0
+ content.push(
prawn_table_cell_inline_formatting_data(
- "#{work_package.type.name} ##{work_package.id} #{work_package.subject}",
- { styles: [:underline] }
+ format_duration(section.agenda_items_sum_duration_in_minutes),
+ styles.agenda_section_subtitle
)
)
end
+ content.join(" ")
+ end
- def write_agenda_title_item_wp(agenda_item)
- write_agenda_item_title(
- agenda_wp_title_row(agenda_item),
- agenda_item.duration_in_minutes || 0,
- agenda_item.presenter
- )
+ def write_agenda_items(section)
+ section.agenda_items.each_with_index do |item, index|
+ write_agenda_item_hr if index > 0
+ write_optional_page_break
+ write_agenda_item(item)
end
+ end
- def agenda_wp_title_row(agenda_item)
- if agenda_item.visible_work_package?
- work_package = agenda_item.work_package
- [agenda_title_wp(work_package), "(#{work_package.status.name})"].join(" ")
- elsif agenda_item.linked_work_package?
- I18n.t(:label_agenda_item_undisclosed_wp, id: agenda_item.work_package_id)
- elsif agenda_item.deleted_work_package?
- I18n.t(:label_agenda_item_deleted_wp)
- else
- agenda_item.title
- end
+ def write_agenda_item_hr
+ hr_style = styles.agenda_item_hr
+ with_vertical_margin(styles.agenda_item_hr_margins) do
+ write_horizontal_line(
+ pdf.cursor,
+ hr_style[:height],
+ hr_style[:color],
+ left_padding: styles.agenda_item_indent
+ )
end
+ end
- def write_agenda_title_item_simple(agenda_item)
- write_agenda_item_title(agenda_item.title, agenda_item.duration_in_minutes || 0, agenda_item.presenter)
+ def write_agenda_item(agenda_item)
+ case agenda_item.item_type.to_sym
+ when :simple
+ write_agenda_title_item_simple(agenda_item)
+ when :work_package
+ write_agenda_title_item_wp(agenda_item)
end
+ write_notes(agenda_item)
+ write_outcome(agenda_item) if with_outcomes?
+ end
- def write_notes(agenda_item)
- return if agenda_item.notes.blank?
-
- pdf.indent(styles.agenda_item_indent) do
- write_markdown!(
- apply_markdown_field_macros(agenda_item.notes, { project: meeting.project, user: User.current }),
- styles.notes_markdown_styling_yml
- )
- end
+ def write_agenda_item_title(title, duration, user)
+ with_vertical_margin(styles.agenda_item_title_margins) do
+ pdf.table(
+ [[{ content: format_agenda_item_cell(title, duration, user) }]],
+ width: pdf.bounds.width,
+ cell_style: { inline_format: true }.merge(styles.agenda_item_title_cell)
+ )
end
+ end
- def write_outcome(agenda_item)
- return unless agenda_item.outcomes.exists?
+ def format_agenda_item_cell(text, duration, user)
+ content = [format_agenda_item_title(text)]
+ content.push(format_agenda_item_subtitle(format_duration(duration))) if duration > 0
+ content.push(format_agenda_item_subtitle(user.name)) unless user.nil?
+ content.join(" ")
+ end
- outcome = agenda_item.outcomes.information_kind.last
- return if outcome.notes.blank?
+ def write_agenda_title_item_wp(agenda_item)
+ write_agenda_item_title(
+ agenda_wp_title_row(agenda_item),
+ agenda_item.duration_in_minutes || 0,
+ agenda_item.presenter
+ )
+ end
- pdf.indent(styles.outcome_indent) do
- write_optional_page_break
- write_outcome_title
- write_outcome_notes(outcome.notes)
- end
- end
+ def write_agenda_title_item_simple(agenda_item)
+ write_agenda_item_title(agenda_item.title, agenda_item.duration_in_minutes || 0, agenda_item.presenter)
+ end
- def write_outcome_title
- style = styles.outcome_title
- with_vertical_margin(styles.outcome_title_margins) do
- pdf.formatted_text([
- { text: "✓ " }.merge(styles.outcome_symbol),
- { text: I18n.t("label_agenda_outcome") }.merge(style)
- ])
- end
- end
+ def write_notes(agenda_item)
+ return if agenda_item.notes.blank?
- def write_outcome_notes(notes)
- with_vertical_margin(styles.outcome_markdown_margins) do
- write_markdown!(
- apply_markdown_field_macros(notes, { project: meeting.project, user: User.current }),
- styles.outcome_markdown_styling_yml
- )
- end
+ pdf.indent(styles.agenda_item_indent) do
+ write_markdown!(
+ apply_markdown_field_macros(agenda_item.notes, { project: meeting.project, user: User.current }),
+ styles.notes_markdown_styling_yml
+ )
end
end
end
diff --git a/modules/meeting/app/workers/meetings/pdf/default/attachments.rb b/modules/meeting/app/workers/meetings/pdf/default/attachments.rb
index f2fa6e03c0a..9787edf45d6 100644
--- a/modules/meeting/app/workers/meetings/pdf/default/attachments.rb
+++ b/modules/meeting/app/workers/meetings/pdf/default/attachments.rb
@@ -28,60 +28,58 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Meetings::PDF::Default
- module Attachments
- def write_attachments_list
- return if meeting.attachments.empty?
+module Meetings::PDF::Default::Attachments
+ def write_attachments_list
+ return if meeting.attachments.empty?
- columns_count = [meeting.attachments.size, 3].min
- rows = meeting_attachments_table_rows(columns_count)
- return if rows.empty?
+ columns_count = [meeting.attachments.size, 3].min
+ rows = meeting_attachments_table_rows(columns_count)
+ return if rows.empty?
- write_hr
- write_heading(attachments_list_title)
- write_attachments_list_table(rows, columns_count)
- end
+ write_hr
+ write_heading(attachments_list_title)
+ write_attachments_list_table(rows, columns_count)
+ end
- def write_attachments_list_table(rows, columns_count)
- with_vertical_margin(styles.attachments_margins) do
- pdf.table(
- rows,
- column_widths: attachments_list_table_column_widths(columns_count),
- cell_style: styles.attachments_table_cell
- )
- end
+ def write_attachments_list_table(rows, columns_count)
+ with_vertical_margin(styles.attachments_margins) do
+ pdf.table(
+ rows,
+ column_widths: attachments_list_table_column_widths(columns_count),
+ cell_style: styles.attachments_table_cell
+ )
end
+ end
- def attachments_list_table_column_widths(columns_count)
- width = pdf.bounds.width / columns_count
- [width] * columns_count
- end
+ def attachments_list_table_column_widths(columns_count)
+ width = pdf.bounds.width / columns_count
+ [width] * columns_count
+ end
- def meeting_attachments_table_rows(columns_count)
- groups = meeting.attachments.in_groups(columns_count)
- return [] if groups.empty?
+ def meeting_attachments_table_rows(columns_count)
+ groups = meeting.attachments.in_groups(columns_count)
+ return [] if groups.empty?
- Array.new(groups[0].size) do |row_index|
- (0..(columns_count - 1)).map do |group_nr|
- { content: attachment_name(groups.dig(group_nr, row_index)), inline_format: true }
- end
+ Array.new(groups[0].size) do |row_index|
+ (0..(columns_count - 1)).map do |group_nr|
+ { content: attachment_name(groups.dig(group_nr, row_index)), inline_format: true }
end
end
+ end
- def attachment_name(attachment)
- return "" if attachment.nil?
+ def attachment_name(attachment)
+ return "" if attachment.nil?
- make_link_href(attachment_link_href(attachment), "<u>#{attachment.filename}</u>")
- end
+ make_link_href(attachment_link_href(attachment), "<u>#{attachment.filename}</u>")
+ end
- def attachment_link_href(attachment)
- "#{Setting.protocol}://#{Setting.host_name}#{
- API::V3::Utilities::PathHelper::ApiV3Path.attachment_content(attachment.id)
- }"
- end
+ def attachment_link_href(attachment)
+ "#{Setting.protocol}://#{Setting.host_name}#{
+ API::V3::Utilities::PathHelper::ApiV3Path.attachment_content(attachment.id)
+ }"
+ end
- def attachments_list_title
- I18n.t(:label_attachment_plural)
- end
+ def attachments_list_title
+ I18n.t(:label_attachment_plural)
end
end
diff --git a/modules/meeting/app/workers/meetings/pdf/default/exporter.rb b/modules/meeting/app/workers/meetings/pdf/default/exporter.rb
index 9a35bccd29d..6f5a0fa8046 100644
--- a/modules/meeting/app/workers/meetings/pdf/default/exporter.rb
+++ b/modules/meeting/app/workers/meetings/pdf/default/exporter.rb
@@ -29,14 +29,8 @@
#++
module Meetings::PDF::Default
- class Exporter < ::Exports::Exporter
- include Exports::PDF::Common::Common
- include Exports::PDF::Common::Logo
- include Exports::PDF::Common::Markdown
- include Exports::PDF::Common::Attachments
+ class Exporter < ::Meetings::PDF::Common::Exporter
include Exports::PDF::Common::Badge
- include Exports::PDF::Common::Macro
- include Exports::PDF::Components::Page
include Exports::PDF::Components::Cover
include Meetings::PDF::Default::Styles
include Meetings::PDF::Default::PageHead
@@ -44,38 +38,6 @@ module Meetings::PDF::Default
include Meetings::PDF::Default::Agenda
include Meetings::PDF::Default::Attachments
- attr_accessor :pdf
-
- self.model = Meeting
-
- alias :meeting :object
-
- def self.key
- :pdf
- end
-
- def initialize(meeting, options)
- super(meeting, options[:options] || options)
- @total_page_nr = nil
- @page_count = 0
-
- setup_page!
- end
-
- def setup_page!
- self.pdf = get_pdf
- pdf.title = heading
- configure_page_size!(:portrait)
- end
-
- def export!
- render_doc
- success(pdf.render)
- rescue StandardError => e
- Rails.logger.error "Failed to generate PDF export: #{e.message}:\n#{e.backtrace.join("\n")}"
- error(I18n.t(:error_pdf_failed_to_export, error: e.message))
- end
-
def render_doc
write_cover_page! if with_cover?
render_meeting!
@@ -91,13 +53,6 @@ module Meetings::PDF::Default
write_footers!
end
- def write_heading(text)
- style = styles.heading
- with_vertical_margin(styles.heading_margins) do
- pdf.formatted_text([style.merge({ text: })], style)
- end
- end
-
def write_hr
hr_style = styles.heading_hr
with_vertical_margin(styles.heading_hr_margins) do
@@ -105,52 +60,10 @@ module Meetings::PDF::Default
end
end
- def cover_page_title
- project_title
- end
-
- def cover_page_heading
- meeting.title
- end
-
- def cover_page_dates
- [
- "#{meeting_mode},",
- "#{format_date(meeting.start_time)},",
- format_time(meeting.start_time, include_date: false),
- "–",
- format_time(meeting.end_time, include_date: false)
- ].join(" ")
- end
-
- def meeting_mode
- meeting.state == "open" ? I18n.t("label_meeting_agenda") : I18n.t("label_meeting_minutes")
- end
-
- def cover_page_subheading
- meeting.location
- end
-
- def heading
- meeting.title
- end
-
- def project_title
- meeting.project&.name || ""
- end
-
def footer_title
options[:footer_text] || project_title
end
- def title_datetime
- meeting.start_time.strftime("%Y-%m-%d")
- end
-
- def title
- build_pdf_filename(meeting.title)
- end
-
def with_participants?
ActiveModel::Type::Boolean.new.cast(options[:participants])
end
@@ -163,16 +76,8 @@ module Meetings::PDF::Default
ActiveModel::Type::Boolean.new.cast(options[:backlog])
end
- def with_outcomes?
- ActiveModel::Type::Boolean.new.cast(options[:outcomes])
- end
-
def with_cover?
true
end
-
- def with_images?
- true
- end
end
end
diff --git a/modules/meeting/app/workers/meetings/pdf/default/page_head.rb b/modules/meeting/app/workers/meetings/pdf/default/page_head.rb
index 970ab043c58..ce47fed3b4e 100644
--- a/modules/meeting/app/workers/meetings/pdf/default/page_head.rb
+++ b/modules/meeting/app/workers/meetings/pdf/default/page_head.rb
@@ -28,38 +28,36 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Meetings::PDF::Default
- module PageHead
- def write_page_head
- with_vertical_margin(styles.page_heading_margins) do
- write_page_title
- end
- with_vertical_margin(styles.page_subtitle_margins) do
- write_meeting_subtitle
- end
- write_hr
+module Meetings::PDF::Default::PageHead
+ def write_page_head
+ with_vertical_margin(styles.page_heading_margins) do
+ write_page_title
end
-
- def write_page_title
- style = styles.page_heading
- pdf.formatted_text([style.merge(
- { text: meeting.title, link: url_helpers.meeting_url(meeting) }
- )], style)
+ with_vertical_margin(styles.page_subtitle_margins) do
+ write_meeting_subtitle
end
+ write_hr
+ end
- def write_meeting_subtitle
- style = styles.page_subtitle
- pdf.formatted_text([style.merge({ text: meeting_subtitle })], style)
- end
+ def write_page_title
+ style = styles.page_heading
+ pdf.formatted_text([style.merge(
+ { text: meeting.title, link: url_helpers.meeting_url(meeting) }
+ )], style)
+ end
- def meeting_subtitle
- [
- "#{meeting_mode} (#{I18n.t("label_meeting_state_#{meeting.state}")}),",
- "#{format_date(meeting.start_time)},",
- format_time(meeting.start_time, include_date: false),
- "–",
- format_time(meeting.end_time, include_date: false)
- ].join(" ")
- end
+ def write_meeting_subtitle
+ style = styles.page_subtitle
+ pdf.formatted_text([style.merge({ text: meeting_subtitle })], style)
+ end
+
+ def meeting_subtitle
+ [
+ "#{meeting_mode} (#{I18n.t("label_meeting_state_#{meeting.state}")}),",
+ "#{format_date(meeting.start_time)},",
+ format_time(meeting.start_time, include_date: false),
+ "–",
+ format_time(meeting.end_time, include_date: false)
+ ].join(" ")
end
end
diff --git a/modules/meeting/app/workers/meetings/pdf/default/participants.rb b/modules/meeting/app/workers/meetings/pdf/default/participants.rb
index 881a9974f48..918a70479fb 100644
--- a/modules/meeting/app/workers/meetings/pdf/default/participants.rb
+++ b/modules/meeting/app/workers/meetings/pdf/default/participants.rb
@@ -28,83 +28,81 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Meetings::PDF::Default
- module Participants
- def write_participants
- return if participants.empty?
+module Meetings::PDF::Default::Participants
+ def write_participants
+ return if participants.empty?
- write_heading(participants_title)
- write_participants_table
- end
+ write_heading(participants_title)
+ write_participants_table
+ end
- def write_participants_table
- columns_count = [participants.size, 3].min
+ def write_participants_table
+ columns_count = [participants.size, 3].min
- rows = participants_table_rows(columns_count)
- with_vertical_margin(styles.participants_margins) do
- pdf.table(
- rows,
- column_widths: participants_table_column_widths(columns_count),
- cell_style: { inline_format: true }.merge(styles.participants_table_cell)
- )
- end
+ rows = participants_table_rows(columns_count)
+ with_vertical_margin(styles.participants_margins) do
+ pdf.table(
+ rows,
+ column_widths: participants_table_column_widths(columns_count),
+ cell_style: { inline_format: true }.merge(styles.participants_table_cell)
+ )
end
+ end
- def participants_table_column_widths(columns_count)
- width = pdf.bounds.width / columns_count
- [width] * columns_count
- end
+ def participants_table_column_widths(columns_count)
+ width = pdf.bounds.width / columns_count
+ [width] * columns_count
+ end
- def participants
- meeting.invited_or_attended_participants.sort_by(&:name)
- end
+ def participants
+ meeting.invited_or_attended_participants.sort_by(&:name)
+ end
- def participants_groups(columns_count)
- # note participants.in_groups does not work with the alphabetically sorted requirement
- # should be left to right and then the next row
- array = Array.new(columns_count) { [] }
- chunks = participants.in_groups_of(columns_count)
- chunks.each do |chunk|
- chunk.each_with_index do |participant, participant_index|
- array[participant_index] << participant
- end
+ def participants_groups(columns_count)
+ # note participants.in_groups does not work with the alphabetically sorted requirement
+ # should be left to right and then the next row
+ array = Array.new(columns_count) { [] }
+ chunks = participants.in_groups_of(columns_count)
+ chunks.each do |chunk|
+ chunk.each_with_index do |participant, participant_index|
+ array[participant_index] << participant
end
- array
end
+ array
+ end
- def participants_table_rows(columns_count)
- groups = participants_groups(columns_count)
- return [] if groups.empty?
+ def participants_table_rows(columns_count)
+ groups = participants_groups(columns_count)
+ return [] if groups.empty?
- Array.new(groups[0].size) do |row_index|
- (0..(columns_count - 1)).map do |group_nr|
- participant = groups.dig(group_nr, row_index)
- { content: "#{participant_name(participant)} #{participants_status(participant)}".strip }
- end
+ Array.new(groups[0].size) do |row_index|
+ (0..(columns_count - 1)).map do |group_nr|
+ participant = groups.dig(group_nr, row_index)
+ { content: "#{participant_name(participant)} #{participants_status(participant)}".strip }
end
end
+ end
- def participants_status(participant)
- return "" if participant.nil?
+ def participants_status(participant)
+ return "" if participant.nil?
- content = if participant.attended?
- I18n.t("description_attended")
- elsif participant.invited?
- I18n.t("description_invite")
- else
- ""
- end
- prawn_table_cell_inline_formatting_data(content.capitalize, styles.participants_status)
- end
+ content = if participant.attended?
+ I18n.t("description_attended")
+ elsif participant.invited?
+ I18n.t("description_invite")
+ else
+ ""
+ end
+ prawn_table_cell_inline_formatting_data(content.capitalize, styles.participants_status)
+ end
- def participant_name(participant)
- return "" if participant.nil?
+ def participant_name(participant)
+ return "" if participant.nil?
- participant.name
- end
+ participant.name
+ end
- def participants_title
- "#{Meeting.human_attribute_name(:participants)} (#{meeting.invited_or_attended_participants.count})"
- end
+ def participants_title
+ "#{Meeting.human_attribute_name(:participants)} (#{meeting.invited_or_attended_participants.count})"
end
end
diff --git a/modules/meeting/app/workers/meetings/pdf/default/styles.rb b/modules/meeting/app/workers/meetings/pdf/default/styles.rb
index 7a31f13da37..2d10085624a 100644
--- a/modules/meeting/app/workers/meetings/pdf/default/styles.rb
+++ b/modules/meeting/app/workers/meetings/pdf/default/styles.rb
@@ -29,41 +29,7 @@
#++
module Meetings::PDF::Default::Styles
- class PDFStyles
- include MarkdownToPDF::Common
- include MarkdownToPDF::StyleHelper
- include Exports::PDF::Common::Styles
- include Exports::PDF::Components::PageStyles
- include Exports::PDF::Components::CoverStyles
-
- def page_subtitle
- resolve_font(@styles[:page_subtitle])
- end
-
- def page_subtitle_margins
- resolve_margin(@styles[:page_subtitle])
- end
-
- def notes_markdown_margins
- resolve_margin(@styles.dig(:notes, :markdown_margin))
- end
-
- def notes_markdown_styling_yml
- resolve_markdown_styling(@styles.dig(:notes, :markdown) || {})
- end
-
- def outcome_markdown_styling_yml
- resolve_markdown_styling(@styles.dig(:outcome, :markdown) || {})
- end
-
- def heading
- resolve_font(@styles[:heading])
- end
-
- def heading_margins
- resolve_margin(@styles[:heading])
- end
-
+ class PDFStyles < Meetings::PDF::Common::Styles::Base
def heading_hr
{
color: @styles.dig(:heading, :hr, :color),
@@ -75,46 +41,6 @@ module Meetings::PDF::Default::Styles
resolve_margin(@styles.dig(:heading, :hr))
end
- def agenda_item_title_margins
- resolve_margin(@styles.dig(:agenda_item, :title_margin))
- end
-
- def agenda_item_indent
- @styles.dig(:agenda_item, :indent).presence || 5
- end
-
- def outcome_title
- resolve_font(@styles.dig(:outcome, :title))
- end
-
- def outcome_symbol
- resolve_font(@styles.dig(:outcome, :symbol))
- end
-
- def outcome_title_margins
- resolve_margin(@styles.dig(:outcome, :title))
- end
-
- def outcome_markdown_margins
- resolve_margin(@styles.dig(:outcome, :markdown_margin))
- end
-
- def outcome_indent
- @styles.dig(:outcome, :indent).presence || 15
- end
-
- def agenda_item_title
- resolve_font(@styles.dig(:agenda_item, :title))
- end
-
- def agenda_item_title_cell
- resolve_table_cell(@styles.dig(:agenda_item, :title_cell))
- end
-
- def agenda_item_subtitle
- resolve_font(@styles.dig(:agenda_item, :subtitle))
- end
-
def agenda_item_hr
{
color: @styles.dig(:agenda_item, :hr, :color),
@@ -125,42 +51,6 @@ module Meetings::PDF::Default::Styles
def agenda_item_hr_margins
resolve_margin(@styles.dig(:agenda_item, :margins))
end
-
- def participants_table_cell
- resolve_table_cell(@styles.dig(:participants, :cell))
- end
-
- def participants_status
- resolve_font(@styles.dig(:participants, :status))
- end
-
- def participants_margins
- resolve_margin(@styles[:participants])
- end
-
- def attachments_table_cell
- resolve_table_cell(@styles.dig(:attachments, :cell))
- end
-
- def attachments_margins
- resolve_margin(@styles[:attachments])
- end
-
- def agenda_section_title
- resolve_font(@styles.dig(:agenda_section, :title))
- end
-
- def agenda_section_title_table_margins
- resolve_margin(@styles.dig(:agenda_section, :title_margins))
- end
-
- def agenda_section_subtitle
- resolve_font(@styles.dig(:agenda_section, :subtitle))
- end
-
- def agenda_section_title_cell
- resolve_table_cell(@styles.dig(:agenda_section, :title_cell))
- end
end
def styles
diff --git a/modules/meeting/app/workers/meetings/pdf/minutes/agenda.rb b/modules/meeting/app/workers/meetings/pdf/minutes/agenda.rb
index bb5dcd226d1..773577b554d 100644
--- a/modules/meeting/app/workers/meetings/pdf/minutes/agenda.rb
+++ b/modules/meeting/app/workers/meetings/pdf/minutes/agenda.rb
@@ -28,194 +28,111 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Meetings::PDF::Minutes
- module Agenda
- def write_agenda
- return if meeting.sections.empty?
+module Meetings::PDF::Minutes::Agenda
+ include Meetings::PDF::Common::Agenda
- write_optional_page_break
- write_agenda_sections
- end
+ def write_backlog
+ return if meeting.backlog.blank? || meeting.backlog.agenda_items.empty?
- def write_backlog
- return if meeting.backlog.blank? || meeting.backlog.agenda_items.empty?
+ write_heading(meeting.recurring? ? I18n.t("label_series_backlog") : I18n.t("label_agenda_backlog"))
+ write_agenda_items(meeting.backlog)
+ end
+
+ def write_section(section, index)
+ write_optional_page_break
+ write_section_title(section, index)
+ write_agenda_items(section, index)
+ end
- write_heading(meeting.recurring? ? I18n.t("label_series_backlog") : I18n.t("label_agenda_backlog"))
- write_agenda_items(meeting.backlog)
+ def write_section_title(section, index)
+ margins = styles.agenda_section_title_table_margins
+ with_vertical_margin(margins) do
+ write_section_title_table(section, index)
end
+ end
+
+ def write_section_title_table(section, index)
+ pdf.table(
+ [[
+ { content: "#{index + 1}." },
+ { content: format_agenda_section_title_cell(section) }
+ ]],
+ width: pdf.bounds.width,
+ column_widths: [40, pdf.bounds.width - 40],
+ cell_style: { inline_format: true }.merge(styles.agenda_section_title_cell)
+ )
+ end
- def write_agenda_sections
- meeting.sections.each_with_index { |section, index| write_section(section, index) }
+ def format_agenda_section_title_cell(section)
+ content = [prawn_table_cell_inline_formatting_data(section_title(section), styles.agenda_section_title)]
+ if section.agenda_items_sum_duration_in_minutes > 0
+ content.push(
+ prawn_table_cell_inline_formatting_data(
+ format_duration(section.agenda_items_sum_duration_in_minutes),
+ styles.agenda_section_subtitle
+ )
+ )
end
+ content.join(" ")
+ end
- def write_section(section, index)
+ def write_agenda_items(section, section_index)
+ section.agenda_items.each_with_index do |item, index|
write_optional_page_break
- write_section_title(section, index)
- write_agenda_items(section, index)
+ with_vertical_margin(styles.agenda_item_margins) do
+ write_agenda_item(item, section_index, index)
+ end
end
+ end
- def write_section_title(section, index)
- margins = styles.agenda_section_title_table_margins
- with_vertical_margin(margins) do
- write_section_title_table(section, index)
- end
+ def write_agenda_item(agenda_item, section_index, index)
+ case agenda_item.item_type.to_sym
+ when :simple
+ write_agenda_title_item_simple(agenda_item, section_index, index)
+ when :work_package
+ write_agenda_title_item_wp(agenda_item, section_index, index)
end
+ write_notes(agenda_item)
+ write_outcome(agenda_item) if with_outcomes?
+ end
- def write_section_title_table(section, index)
+ def write_agenda_item_title(title, section_index, index)
+ with_vertical_margin(styles.agenda_item_title_margins) do
pdf.table(
[[
- { content: "#{index + 1}." },
- { content: format_agenda_section_title_cell(section) }
- ]],
+ { content: "#{section_index + 1}.#{index + 1}." },
+ { content: title }
+ ]],
width: pdf.bounds.width,
column_widths: [40, pdf.bounds.width - 40],
- cell_style: { inline_format: true }.merge(styles.agenda_section_title_cell)
+ cell_style: { inline_format: true }.merge(styles.agenda_item_title_cell)
)
end
+ end
- def format_agenda_section_title_cell(section)
- content = [prawn_table_cell_inline_formatting_data(section_title(section), styles.agenda_section_title)]
- if section.agenda_items_sum_duration_in_minutes > 0
- content.push(
- prawn_table_cell_inline_formatting_data(
- format_duration(section.agenda_items_sum_duration_in_minutes),
- styles.agenda_section_subtitle
- )
- )
- end
- content.join(" ")
- end
-
- def format_duration(duration)
- OpenProject::Common::DurationComponent.new(duration, :minutes, abbreviated: true).text
- end
-
- def section_title(section)
- section.title.presence || I18n.t("meeting_section.untitled_title")
- end
-
- def write_agenda_items(section, section_index)
- section.agenda_items.each_with_index do |item, index|
- write_optional_page_break
- with_vertical_margin(styles.agenda_item_margins) do
- write_agenda_item(item, section_index, index)
- end
- end
- end
-
- def write_agenda_item(agenda_item, section_index, index)
- case agenda_item.item_type.to_sym
- when :simple
- write_agenda_title_item_simple(agenda_item, section_index, index)
- when :work_package
- write_agenda_title_item_wp(agenda_item, section_index, index)
- end
- write_notes(agenda_item)
- write_outcome(agenda_item) if with_outcomes?
- end
-
- def write_agenda_item_title(title, section_index, index)
- with_vertical_margin(styles.agenda_item_title_margins) do
- pdf.table(
- [[
- { content: "#{section_index + 1}.#{index + 1}." },
- { content: title }
- ]],
- width: pdf.bounds.width,
- column_widths: [40, pdf.bounds.width - 40],
- cell_style: { inline_format: true }.merge(styles.agenda_item_title_cell)
- )
- end
- end
+ def format_agenda_item_cell(text, duration, user)
+ content = [format_agenda_item_title(text)]
+ content.push(format_agenda_item_subtitle(format_duration(duration))) if duration > 0
+ content.push(format_agenda_item_subtitle(user.name)) unless user.nil?
+ content.join(" ")
+ end
- def format_agenda_item_cell(text, duration, user)
- content = [format_agenda_item_title(text)]
- content.push(format_agenda_item_subtitle(format_duration(duration))) if duration > 0
- content.push(format_agenda_item_subtitle(user.name)) unless user.nil?
- content.join(" ")
- end
+ def write_agenda_title_item_wp(agenda_item, section_index, index)
+ write_agenda_item_title(agenda_wp_title_row(agenda_item), section_index, index)
+ end
- def format_agenda_item_subtitle(text)
- prawn_table_cell_inline_formatting_data(text, styles.agenda_item_subtitle)
- end
+ def write_agenda_title_item_simple(agenda_item, section_index, index)
+ write_agenda_item_title(agenda_item.title, section_index, index)
+ end
- def format_agenda_item_title(title)
- prawn_table_cell_inline_formatting_data(title, styles.agenda_item_title)
- end
+ def write_notes(agenda_item)
+ return if agenda_item.notes.blank?
- def agenda_title_wp(work_package)
- href = url_helpers.work_package_url(work_package)
- make_link_href(
- href,
- prawn_table_cell_inline_formatting_data(
- "#{work_package.type.name} ##{work_package.id} #{work_package.subject}",
- { styles: [:underline] }
- )
+ with_vertical_margin(styles.notes_markdown_margins) do
+ write_markdown!(
+ apply_markdown_field_macros(agenda_item.notes, { project: meeting.project, user: User.current }),
+ styles.notes_markdown_styling_yml
)
end
-
- def write_agenda_title_item_wp(agenda_item, section_index, index)
- write_agenda_item_title(agenda_wp_title_row(agenda_item), section_index, index)
- end
-
- def agenda_wp_title_row(agenda_item)
- if agenda_item.visible_work_package?
- work_package = agenda_item.work_package
- [agenda_title_wp(work_package), "(#{work_package.status.name})"].join(" ")
- elsif agenda_item.linked_work_package?
- I18n.t(:label_agenda_item_undisclosed_wp, id: agenda_item.work_package_id)
- elsif agenda_item.deleted_work_package?
- I18n.t(:label_agenda_item_deleted_wp)
- else
- agenda_item.title
- end
- end
-
- def write_agenda_title_item_simple(agenda_item, section_index, index)
- write_agenda_item_title(agenda_item.title, section_index, index)
- end
-
- def write_notes(agenda_item)
- return if agenda_item.notes.blank?
-
- with_vertical_margin(styles.notes_markdown_margins) do
- write_markdown!(
- apply_markdown_field_macros(agenda_item.notes, { project: meeting.project, user: User.current }),
- styles.notes_markdown_styling_yml
- )
- end
- end
-
- def write_outcome(agenda_item)
- return unless agenda_item.outcomes.exists?
-
- outcome = agenda_item.outcomes.information_kind.last
- return if outcome.notes.blank?
-
- pdf.indent(styles.outcome_indent) do
- write_optional_page_break
- write_outcome_title
- write_outcome_notes(outcome.notes)
- end
- end
-
- def write_outcome_title
- with_vertical_margin(styles.outcome_title_margins) do
- style = styles.outcome_title
- pdf.formatted_text([
- styles.outcome_symbol.merge({ text: "✓ " }),
- style.merge({ text: I18n.t("label_agenda_outcome") })
- ], style)
- end
- end
-
- def write_outcome_notes(notes)
- with_vertical_margin(styles.outcome_markdown_margins) do
- write_markdown!(
- apply_markdown_field_macros(notes, { project: meeting.project, user: User.current }),
- styles.outcome_markdown_styling_yml
- )
- end
- end
end
end
diff --git a/modules/meeting/app/workers/meetings/pdf/minutes/exporter.rb b/modules/meeting/app/workers/meetings/pdf/minutes/exporter.rb
index 5693bbedd3b..468e92dd3e9 100644
--- a/modules/meeting/app/workers/meetings/pdf/minutes/exporter.rb
+++ b/modules/meeting/app/workers/meetings/pdf/minutes/exporter.rb
@@ -29,63 +29,25 @@
#++
module Meetings::PDF::Minutes
- class Exporter < ::Exports::Exporter
- include Exports::PDF::Common::Common
- include Exports::PDF::Common::Logo
- include Exports::PDF::Common::Markdown
- include Exports::PDF::Common::Attachments
- include Exports::PDF::Common::Macro
- include Exports::PDF::Components::Page
+ class Exporter < ::Meetings::PDF::Common::Exporter
include Meetings::PDF::Minutes::Styles
include Meetings::PDF::Minutes::PageHead
include Meetings::PDF::Minutes::Agenda
- attr_accessor :pdf
-
- self.model = Meeting
-
- alias :meeting :object
-
- def self.key
- :pdf
- end
-
def self.active?(template)
(template == "minutes") && OpenProject::FeatureDecisions.minutes_styling_meeting_pdf_active?
end
- def initialize(meeting, options)
- super(meeting, options[:options] || options)
- @total_page_nr = nil
- @page_count = 0
-
- setup_page!
- end
-
- def setup_page!
- self.pdf = get_pdf
- pdf.title = heading
- configure_page_size!(:portrait)
- end
-
- def export!
- render_doc
- render_doc_again_with_total_page_nrs if wants_total_page_nrs?
- success(pdf.render)
- rescue StandardError => e
- Rails.logger.error "Failed to generate PDF export: #{e.message}:\n#{e.backtrace.join("\n")}"
- error(I18n.t(:error_pdf_failed_to_export, error: e.message))
- end
-
def render_doc
render_meeting
+ render_again_with_total_page_nrs if wants_total_page_nrs?
end
- def render_doc_again_with_total_page_nrs
+ def render_again_with_total_page_nrs
@total_page_nr = pdf.page_count + @page_count
@page_count = 0
setup_page! # clear current pdf
- render_doc
+ render_meeting
end
def render_meeting
@@ -95,47 +57,6 @@ module Meetings::PDF::Minutes
write_minutes_footers
end
- def write_heading(text)
- style = styles.heading
- with_vertical_margin(styles.heading_margins) do
- pdf.formatted_text([style.merge({ text: })], style)
- end
- end
-
- def cover_page_title
- project_title
- end
-
- def cover_page_heading
- meeting.title
- end
-
- def cover_page_dates
- [
- "#{meeting_mode},",
- "#{format_date(meeting.start_time)},",
- format_time(meeting.start_time, include_date: false),
- "–",
- format_time(meeting.end_time, include_date: false)
- ].join(" ")
- end
-
- def meeting_mode
- meeting.state == "open" ? I18n.t("label_meeting_agenda") : I18n.t("label_meeting_minutes")
- end
-
- def cover_page_subheading
- meeting.location
- end
-
- def heading
- meeting.title
- end
-
- def project_title
- meeting.project&.name || ""
- end
-
def page_header_text
options[:first_page_header_left] || ""
end
@@ -194,18 +115,6 @@ module Meetings::PDF::Minutes
end
end
- def title_datetime
- meeting.start_time.strftime("%Y-%m-%d")
- end
-
- def title
- build_pdf_filename(meeting.title)
- end
-
- def with_outcomes?
- ActiveModel::Type::Boolean.new.cast(options[:outcomes])
- end
-
def with_cover?
false
end
@@ -213,9 +122,5 @@ module Meetings::PDF::Minutes
def wants_total_page_nrs?
true
end
-
- def with_images?
- true
- end
end
end
diff --git a/modules/meeting/app/workers/meetings/pdf/minutes/page_head.rb b/modules/meeting/app/workers/meetings/pdf/minutes/page_head.rb
index 7715b86ccdb..bf567beb70e 100644
--- a/modules/meeting/app/workers/meetings/pdf/minutes/page_head.rb
+++ b/modules/meeting/app/workers/meetings/pdf/minutes/page_head.rb
@@ -28,60 +28,58 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Meetings::PDF::Minutes
- module PageHead
- def write_page_head
- write_page_title
- write_page_subheading
- write_meeting_subtitle
- end
+module Meetings::PDF::Minutes::PageHead
+ def write_page_head
+ write_page_title
+ write_page_subheading
+ write_meeting_subtitle
+ end
- def write_page_title
- style = styles.page_heading
- with_vertical_margin(styles.page_heading_margins) do
- pdf.formatted_text([style.merge({ text: meeting.title })], style)
- end
+ def write_page_title
+ style = styles.page_heading
+ with_vertical_margin(styles.page_heading_margins) do
+ pdf.formatted_text([style.merge({ text: meeting.title })], style)
end
+ end
- def write_page_subheading
- style = styles.page_subheading
- with_vertical_margin(styles.page_subheading_margins) do
- pdf.formatted_text([style.merge({ text: I18n.t("meeting.export.minutes.title") })], style)
- end
+ def write_page_subheading
+ style = styles.page_subheading
+ with_vertical_margin(styles.page_subheading_margins) do
+ pdf.formatted_text([style.merge({ text: I18n.t("meeting.export.minutes.title") })], style)
end
+ end
- def write_meeting_subtitle
- style = styles.page_subtitle
- with_vertical_margin(styles.page_subtitle_margins) do
- pdf.formatted_text([style.merge({ text: meeting_subtitle })], style)
- end
+ def write_meeting_subtitle
+ style = styles.page_subtitle
+ with_vertical_margin(styles.page_subtitle_margins) do
+ pdf.formatted_text([style.merge({ text: meeting_subtitle })], style)
end
+ end
- def meeting_subtitle_date
- format_date(meeting.start_time)
- end
+ def meeting_subtitle_date
+ format_date(meeting.start_time)
+ end
- def meeting_subtitle_time
- "#{format_time(meeting.start_time, include_date: false)} – #{format_time(meeting.end_time, include_date: false)}"
- end
+ def meeting_subtitle_time
+ "#{format_time(meeting.start_time, include_date: false)} – #{format_time(meeting.end_time, include_date: false)}"
+ end
- def meeting_subtitle_first_line
- list = [
- "#{I18n.t('meeting.export.minutes.date')}:", meeting_subtitle_date, "|",
- "#{I18n.t('meeting.export.minutes.time')}:", meeting_subtitle_time
- ]
- if meeting.location.present?
- list += ["|", "#{I18n.t('meeting.export.minutes.location')}:", meeting.location]
- end
- list.join(" ")
+ def meeting_subtitle_first_line
+ list = [
+ "#{I18n.t('meeting.export.minutes.date')}:", meeting_subtitle_date, "|",
+ "#{I18n.t('meeting.export.minutes.time')}:", meeting_subtitle_time
+ ]
+ if meeting.location.present?
+ list += ["|", "#{I18n.t('meeting.export.minutes.location')}:", meeting.location]
end
+ list.join(" ")
+ end
- def meeting_subtitle
- result = meeting_subtitle_first_line
- if minutes_author.present?
- result += "\n#{I18n.t('meeting.export.minutes.author')}: #{minutes_author}"
- end
- result
+ def meeting_subtitle
+ result = meeting_subtitle_first_line
+ if minutes_author.present?
+ result += "\n#{I18n.t('meeting.export.minutes.author')}: #{minutes_author}"
end
+ result
end
end
diff --git a/modules/meeting/app/workers/meetings/pdf/minutes/styles.rb b/modules/meeting/app/workers/meetings/pdf/minutes/styles.rb
index 180fcf65d2c..db98db264fa 100644
--- a/modules/meeting/app/workers/meetings/pdf/minutes/styles.rb
+++ b/modules/meeting/app/workers/meetings/pdf/minutes/styles.rb
@@ -29,13 +29,7 @@
#++
module Meetings::PDF::Minutes::Styles
- class PDFStyles
- include MarkdownToPDF::Common
- include MarkdownToPDF::StyleHelper
- include Exports::PDF::Common::Styles
- include Exports::PDF::Components::PageStyles
- include Exports::PDF::Components::CoverStyles
-
+ class PDFStyles < Meetings::PDF::Common::Styles::Base
def page_subheading
resolve_font(@styles[:page_subheading])
end
@@ -44,113 +38,9 @@ module Meetings::PDF::Minutes::Styles
resolve_margin(@styles[:page_subheading])
end
- def page_subtitle
- resolve_font(@styles[:page_subtitle])
- end
-
- def page_subtitle_margins
- resolve_margin(@styles[:page_subtitle])
- end
-
- def notes_markdown_margins
- resolve_margin(@styles.dig(:notes, :markdown_margin))
- end
-
- def notes_markdown_styling_yml
- resolve_markdown_styling(@styles.dig(:notes, :markdown) || {})
- end
-
- def outcome_markdown_styling_yml
- resolve_markdown_styling(@styles.dig(:outcome, :markdown) || {})
- end
-
- def heading
- resolve_font(@styles[:heading])
- end
-
- def agenda_item_title_margins
- resolve_margin(@styles.dig(:agenda_item, :title_margin))
- end
-
- def agenda_item_indent
- @styles.dig(:agenda_item, :indent).presence || 5
- end
-
- def outcome_title
- resolve_font(@styles.dig(:outcome, :title))
- end
-
- def outcome_symbol
- resolve_font(@styles.dig(:outcome, :symbol))
- end
-
- def outcome_title_margins
- resolve_margin(@styles.dig(:outcome, :title))
- end
-
- def outcome_markdown_margins
- resolve_margin(@styles.dig(:outcome, :markdown_margin))
- end
-
- def outcome_indent
- @styles.dig(:outcome, :indent).presence || 15
- end
-
- def agenda_item_title
- resolve_font(@styles.dig(:agenda_item, :title))
- end
-
- def agenda_item_title_cell
- resolve_table_cell(@styles.dig(:agenda_item, :title_cell))
- end
-
- def agenda_item_subtitle
- resolve_font(@styles.dig(:agenda_item, :subtitle))
- end
-
def agenda_item_margins
resolve_margin(@styles.dig(:agenda_item, :margin))
end
-
- def heading_margins
- resolve_margin(@styles[:heading])
- end
-
- def participants_table_cell
- resolve_table_cell(@styles.dig(:participants, :cell))
- end
-
- def participants_status
- resolve_font(@styles.dig(:participants, :status))
- end
-
- def participants_margins
- resolve_margin(@styles[:participants])
- end
-
- def attachments_table_cell
- resolve_table_cell(@styles.dig(:attachments, :cell))
- end
-
- def attachments_margins
- resolve_margin(@styles[:attachments])
- end
-
- def agenda_section_title
- resolve_font(@styles.dig(:agenda_section, :title))
- end
-
- def agenda_section_title_table_margins
- resolve_margin(@styles.dig(:agenda_section, :title_margins))
- end
-
- def agenda_section_subtitle
- resolve_font(@styles.dig(:agenda_section, :subtitle))
- end
-
- def agenda_section_title_cell
- resolve_table_cell(@styles.dig(:agenda_section, :title_cell))
- end
end
def styles