OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
pdf generator: use turbo+primer dialog
as-op968fda871fff
diff --git a/app/components/work_packages/exports/generate/modal_dialog_component.html.erb b/app/components/work_packages/exports/generate/modal_dialog_component.html.erbnew file mode 100644index 00000000000..90733873477--- /dev/null+++ b/app/components/work_packages/exports/generate/modal_dialog_component.html.erb@@ -0,0 +1,39 @@+<%= render(Primer::Alpha::Dialog.new(+ title: "Generate PDF",+ id: MODAL_ID+)) 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,+ method: :get+ ) do %>+ <% 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 %>+ <% 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 })) { "Generate" } %>+ <% end %>+<% end %>diff --git a/app/components/work_packages/exports/generate/modal_dialog_component.rb b/app/components/work_packages/exports/generate/modal_dialog_component.rbnew file mode 100644index 00000000000..bcd5c17e9f3--- /dev/null+++ b/app/components/work_packages/exports/generate/modal_dialog_component.rb@@ -0,0 +1,118 @@+# 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 generate_selects+ [+ {+ name: "hyphenation",+ label:'Hyphenation',+ caption: 'Break words between lines to improve text justification and readability.',+ options: hyphenation_options+ },+ {+ name: "paper_size",+ label: I18n.t("export.dialog.pdf.paper_size.label"),+ caption: 'The size of the paper to use for the PDF.',+ 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+ [+ { value: "", label: 'Off', default: true },+ { value: "ca", label: 'Catalan' },+ { value: "cs", label: 'Czech' },+ { value: "da", label: 'Danish' },+ { value: "de", label: 'German' },+ { value: "en_uk", label: 'English (UK)' },+ { value: "en_us", label: 'English (USA)' },+ { value: "es", label: 'Spanish' },+ { value: "et", label: 'Estonian' },+ { value: "eu", label: 'Basque' },+ { value: "fi", label: 'Finnish' },+ { value: "fr", label: 'French' },+ { value: "ga", label: 'Irish' },+ { value: "hr", label: 'Croatian' },+ { value: "hu", label: 'Hungarian' },+ { value: "ia", label: 'Interlingua' },+ { value: "id", label: 'Indonesian' },+ { value: "is", label: 'Icelandic' },+ { value: "it", label: 'Italian' },+ { value: "mn", label: 'Mongolian' },+ { value: "ms", label: 'Malay' },+ { value: "nl", label: 'Dutch' },+ { value: "no", label: 'Norwegian' },+ { value: "pl", label: 'Polish' },+ { value: "pt", label: 'Portuguese' },+ { value: "ru", label: 'Russian' },+ { value: "sk", label: 'Slovak' },+ { value: "sv", label: 'Swedish' }+ ]+ 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+enddiff --git a/app/controllers/work_packages_controller.rb b/app/controllers/work_packages_controller.rbindex c17fec99524..0bc2313dc6d 100644--- a/app/controllers/work_packages_controller.rb+++ b/app/controllers/work_packages_controller.rb@@ -37,13 +37,13 @@ class WorkPackagesController < ApplicationControlleraccept_key_auth :index, :showbefore_action :authorize_on_work_package,- :project, only: :show+ :project, only: [:show, :generate_pdf_dialog, :generate_pdf]before_action :load_and_authorize_in_optional_project,:check_allowed_export,:protect_from_unauthorized_export, only: %i[index export_dialog]before_action :authorize, only: :show_conflict_flash_message- authorization_checked! :index, :show, :export_dialog+ authorization_checked! :index, :show, :export_dialog, :generate_pdf_dialog, :generate_pdfbefore_action :load_and_validate_query, only: :index, unless: -> { request.format.html? }before_action :load_work_packages, only: :index, if: -> { request.format.atom? }@@ -93,6 +93,19 @@ class WorkPackagesController < ApplicationControllerrespond_with_dialog WorkPackages::Exports::ModalDialogComponent.new(query: @query, project: @project, title: params[:title])end+ def generate_pdf_dialog+ respond_with_dialog WorkPackages::Exports::Generate::ModalDialogComponent.new(work_package: work_package, params: params)+ end++ def generate_pdf+ exporter = WorkPackage::PDFExport::DocumentGenerator.new(work_package, params)+ export = exporter.export!+ send_data(export.content, type: export.mime_type, filename: export.title)+ rescue ::Exports::ExportError => e+ flash[:error] = e.message+ redirect_back(fallback_location: work_package_path(work_package))+ end+def show_conflict_flash_messagescheme = params[:scheme]&.to_sym || :dangerdiff --git a/app/models/work_package/pdf_export/document_generator.rb b/app/models/work_package/pdf_export/document_generator.rbindex 88dd91cad7e..9d566503a11 100644--- a/app/models/work_package/pdf_export/document_generator.rb+++ b/app/models/work_package/pdf_export/document_generator.rb@@ -1,6 +1,6 @@#-- copyright# OpenProject is an open source project management software.-# Copyright (C) 2012-2024 the OpenProject GmbH+# 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.diff --git a/config/initializers/export_formats.rb b/config/initializers/export_formats.rbindex 0f11825fd7b..b58e663763b 100644--- a/config/initializers/export_formats.rb+++ b/config/initializers/export_formats.rb@@ -1,7 +1,5 @@Rails.application.configure do |application|application.config.to_prepare do- Mime::Type.register("application/pdf", :generate_pdf)-Exports::Register.register dolist WorkPackage, WorkPackage::Exports::CSVlist WorkPackage, WorkPackage::PDFExport::WorkPackageListToPdfdiff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex c9afea400d4..1adf5fefc45 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -121,8 +121,8 @@ en:button_uncheck_all: "Uncheck all"button_update: "Update"button_export-pdf: "Download PDF"- button_generate-pdf: "Generate PDF"button_export-atom: "Download Atom"+ button_generate_pdf: "Generate PDF"button_create: "Create"card:diff --git a/config/routes.rb b/config/routes.rbindex 02699c02574..eaf6c71b5af 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -574,6 +574,9 @@ Rails.application.routes.draw doget "hover_card" => "work_packages/hover_card#show", on: :member+ get "generate_pdf_dialog" => "work_packages#generate_pdf_dialog", on: :member+ get "generate_pdf" => "work_packages#generate_pdf", on: :member+# move bulk of wpsget "move/new" => "work_packages/moves#new", on: :collection, as: "new_move"post "move" => "work_packages/moves#create", on: :collection, as: "move"diff --git a/frontend/src/app/features/work-packages/components/wp-table/context-menu-helper/wp-context-menu-helper.service.ts b/frontend/src/app/features/work-packages/components/wp-table/context-menu-helper/wp-context-menu-helper.service.tsindex aeba1575be4..5233ec01d47 100644--- a/frontend/src/app/features/work-packages/components/wp-table/context-menu-helper/wp-context-menu-helper.service.ts+++ b/frontend/src/app/features/work-packages/components/wp-table/context-menu-helper/wp-context-menu-helper.service.ts@@ -91,7 +91,7 @@ export class WorkPackageContextMenuHelperService {// remove some actions on Ganttif (this.wpViewTimeline.isVisible) {allowedActions = allowedActions.filter((el) => {- const ganttNotAllowedActions = ['log_time', 'copy', 'copy_to_other_project', 'export-pdf', 'generate-pdf', 'export-atom', 'log_costs'];+ const ganttNotAllowedActions = ['log_time', 'copy', 'copy_to_other_project', 'export-pdf', 'generate_pdf', 'export-atom', 'log_costs'];return !(ganttNotAllowedActions.includes(el.key));});}diff --git a/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-single-context-menu.ts b/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-single-context-menu.tsindex 2dfd8da3798..89a8259fc5f 100644--- a/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-single-context-menu.ts+++ b/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-single-context-menu.ts@@ -19,6 +19,7 @@ import { TimeEntryCreateService } from 'core-app/shared/components/time_entries/import { WpDestroyModalComponent } from 'core-app/shared/components/modals/wp-destroy-modal/wp-destroy.modal';import { WorkPackageAuthorization } from 'core-app/features/work-packages/services/work-package-authorization.service';import * as moment from 'moment-timezone';+import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service';@Directive({selector: '[wpSingleContextMenu]',@@ -34,6 +35,7 @@ export class WorkPackageSingleContextMenuDirective extends OpContextMenuTriggerreadonly PathHelper:PathHelperService,readonly elementRef:ElementRef,readonly opModalService:OpModalService,+ readonly turboRequests:TurboRequestsService,readonly opContextMenuService:OPContextMenuService,readonly authorisationService:AuthorisationService,protected copyToClipboardService:CopyToClipboardService,@@ -74,6 +76,9 @@ export class WorkPackageSingleContextMenuDirective extends OpContextMenuTrigger// do nothing, the user closed without changes});break;+ case 'generate_pdf':+ void this.turboRequests.requestStream(link as string);+ break;case 'copy_link_to_clipboard': {const url = new URL(String(link), window.location.origin);this.copyToClipboardService.copy(url.toString());diff --git a/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-static-context-menu-actions.ts b/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-static-context-menu-actions.tsindex 0d625387fcb..4a2e0d82f14 100644--- a/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-static-context-menu-actions.ts+++ b/frontend/src/app/shared/components/op-context-menu/wp-context-menu/wp-static-context-menu-actions.ts@@ -36,7 +36,7 @@ export const PERMITTED_CONTEXT_MENU_ACTIONS:WorkPackageAction[] = [link: 'pdf',},{- key: 'generate-pdf',+ key: 'generate_pdf',link: 'generate_pdf',icon: 'icon-export-pdf-with-descriptions',},diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rbindex 8fbe903d6a3..20ea4a61abe 100644--- a/lib/api/v3/work_packages/work_package_representer.rb+++ b/lib/api/v3/work_packages/work_package_representer.rb@@ -140,7 +140,7 @@ module APInext unless OpenProject::FeatureDecisions.generate_pdf_from_work_package_active?{- href: work_package_path(id: represented.id, format: :generate_pdf),+ href: generate_pdf_dialog_work_package_path(id: represented.id),type: "application/pdf",title: "Generate PDF"}