-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15850 from opf/feature/45896-generate-pdf-documen…
…t-from-a-work-package-description [#45896] Generate PDF document from a work package description
- Loading branch information
Showing
44 changed files
with
1,251 additions
and
135 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
app/components/work_packages/exports/generate/modal_dialog_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<%= render(Primer::Alpha::Dialog.new( | ||
title: I18n.t("pdf_generator.dialog.title"), | ||
id: MODAL_ID, | ||
size: :large | ||
)) do |dialog| | ||
dialog.with_header(variant: :large) | ||
dialog.with_body do | ||
primer_form_with( | ||
url: generate_pdf_work_package_path(work_package), | ||
data: { turbo: false }, | ||
id: GENERATE_PDF_FORM_ID | ||
) do |form| | ||
flex_layout do |modal_body| | ||
generate_selects.each_with_index do |entry, index| | ||
modal_body.with_row(mt: index == 0 ? 0 : 3) do | ||
render(Primer::Alpha::Select.new( | ||
name: entry[:name], | ||
label: entry[:label], | ||
caption: entry[:caption], | ||
size: :medium, | ||
input_width: :small, | ||
value: entry[:options].find { |e| e[:default] }[:value]) | ||
) do |component| | ||
entry[:options].each do |entry| | ||
component.option(label: entry[:label], value: entry[:value]) | ||
end | ||
end | ||
end | ||
end | ||
modal_body.with_row(mt: 3) do | ||
render Primer::Alpha::TextField.new( | ||
name: :header_text_right, | ||
label: I18n.t("pdf_generator.dialog.header_right.label"), | ||
caption: I18n.t("pdf_generator.dialog.header_right.caption"), | ||
visually_hide_label: false, | ||
value: default_header_text_right | ||
) | ||
end | ||
modal_body.with_row(mt: 3) do | ||
render Primer::Alpha::TextField.new( | ||
name: :footer_text_center, | ||
label: I18n.t("pdf_generator.dialog.footer_center.label"), | ||
caption: I18n.t("pdf_generator.dialog.footer_center.caption"), | ||
visually_hide_label: false, | ||
value: default_footer_text_center | ||
) | ||
end | ||
end | ||
end | ||
end | ||
dialog.with_footer do | ||
render(Primer::ButtonComponent.new(data: { "close-dialog-id": MODAL_ID })) { I18n.t(:button_cancel) } | ||
render(Primer::ButtonComponent.new( | ||
scheme: :primary, type: :submit, form: GENERATE_PDF_FORM_ID, | ||
data: { "close-dialog-id": MODAL_ID })) { I18n.t("pdf_generator.dialog.submit") } | ||
end | ||
end %> |
128 changes: 128 additions & 0 deletions
128
app/components/work_packages/exports/generate/modal_dialog_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# 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. | ||
# ++ | ||
require "text/hyphen" | ||
|
||
module WorkPackages | ||
module Exports | ||
module Generate | ||
class ModalDialogComponent < ApplicationComponent | ||
MODAL_ID = "op-work-package-generate-pdf-dialog" | ||
GENERATE_PDF_FORM_ID = "op-work-packages-generate-pdf-dialog-form" | ||
include OpTurbo::Streamable | ||
include OpPrimer::ComponentHelpers | ||
|
||
attr_reader :work_package, :params | ||
|
||
def initialize(work_package:, params:) | ||
super | ||
|
||
@work_package = work_package | ||
@params = params | ||
end | ||
|
||
def default_header_text_right | ||
"#{work_package.type} ##{work_package.id}" | ||
end | ||
|
||
def default_footer_text_center | ||
work_package.subject | ||
end | ||
|
||
def generate_selects | ||
[ | ||
{ | ||
name: "hyphenation", | ||
label: I18n.t("pdf_generator.dialog.hyphenation.label"), | ||
caption: I18n.t("pdf_generator.dialog.hyphenation.caption"), | ||
options: hyphenation_options | ||
}, | ||
{ | ||
name: "paper_size", | ||
label: I18n.t("pdf_generator.dialog.paper_size.label"), | ||
caption: I18n.t("pdf_generator.dialog.paper_size.caption"), | ||
options: paper_size_options | ||
} | ||
] | ||
end | ||
|
||
def hyphenation_options | ||
# This is a list of languages that are supported by the hyphenation library | ||
# https://rubygems.org/gems/text-hyphen | ||
# The labels are the language names in the language itself (NOT to be put I18n) | ||
supported_languages = [ | ||
{ label: "Català", value: "ca" }, | ||
{ label: "Dansk", value: "da" }, | ||
{ label: "Deutsch", value: "de" }, | ||
{ label: "Eesti", value: "et" }, | ||
{ label: "English (UK)", value: "en_uk" }, | ||
{ label: "English (USA)", value: "en_us" }, | ||
{ label: "Español", value: "es" }, | ||
{ label: "Euskara", value: "eu" }, | ||
{ label: "Français", value: "fr" }, | ||
{ label: "Gaeilge", value: "ga" }, | ||
{ label: "Hrvatski", value: "hr" }, | ||
{ label: "Indonesia", value: "id" }, | ||
{ label: "Interlingua", value: "ia" }, | ||
{ label: "Italiano", value: "it" }, | ||
{ label: "Magyar", value: "hu" }, | ||
{ label: "Melayu", value: "ms" }, | ||
{ label: "Nederlands", value: "nl" }, | ||
{ label: "Norsk", value: "no" }, | ||
{ label: "Polski", value: "pl" }, | ||
{ label: "Português", value: "pt" }, | ||
{ label: "Slovenčina", value: "sk" }, | ||
{ label: "Suomi", value: "fi" }, | ||
{ label: "Svenska", value: "sv" }, | ||
{ label: "Ísland", value: "is" }, | ||
{ label: "Čeština", value: "cs" }, | ||
{ label: "Монгол", value: "mn" }, | ||
{ label: "Русский", value: "ru" } | ||
] | ||
|
||
[{ value: "", label: "Off", default: true }].concat(supported_languages) | ||
end | ||
|
||
def paper_size_options | ||
[ | ||
{ label: "A4", value: "A4", default: true }, | ||
{ label: "A3", value: "A3" }, | ||
{ label: "A2", value: "A2" }, | ||
{ label: "A1", value: "A1" }, | ||
{ label: "A0", value: "A0" }, | ||
{ label: "Executive", value: "EXECUTIVE" }, | ||
{ label: "Folio", value: "FOLIO" }, | ||
{ label: "Letter", value: "LETTER" }, | ||
{ label: "Tabloid", value: "TABLOID" } | ||
] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# 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::Logo | ||
def logo_image | ||
image_obj, image_info = pdf.build_image_object(logo_image_filename) | ||
[image_obj, image_info] | ||
end | ||
|
||
def logo_image_filename | ||
custom_logo_image_filename || Rails.root.join("app/assets/images/logo_openproject.png") | ||
end | ||
|
||
def custom_logo_image_filename | ||
return unless CustomStyle.current.present? && | ||
CustomStyle.current.export_logo.present? && CustomStyle.current.export_logo.local_file.present? | ||
|
||
image_file = CustomStyle.current.export_logo.local_file.path | ||
content_type = OpenProject::ContentTypeDetector.new(image_file).detect | ||
return unless pdf_embeddable?(content_type) | ||
|
||
image_file | ||
end | ||
end |
Oops, something went wrong.