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
add admin settings tab for pdf export templates
as-op119733f4ad54
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.erbindex bd1890be501..049f924104f 100644--- a/app/components/work_packages/exports/generate/modal_dialog_component.html.erb+++ b/app/components/work_packages/exports/generate/modal_dialog_component.html.erb@@ -19,19 +19,19 @@render(Primer::Alpha::Select.new(name: "template",label: I18n.t("pdf_generator.dialog.templates.label"),- caption: templates_default[:caption],+ caption: templates_default.caption,input_width: :large,data: {"work-packages--export--generate-pdf-form-target": "templates",action: "change->work-packages--export--generate-pdf-form#templatesChanged"})) do |component|- selected = templates_default[:value]+ selected = templates_default.idtemplates_options.each do |entry|component.option(label: entry[:label],- value: entry[:value],- selected: selected == entry[:value],+ value: entry[:id],+ selected: selected == entry[:id],data: {caption: entry[:caption]}diff --git a/app/components/work_packages/exports/generate/modal_dialog_component.rb b/app/components/work_packages/exports/generate/modal_dialog_component.rbindex de229e2e293..f6c44ec5ecd 100644--- a/app/components/work_packages/exports/generate/modal_dialog_component.rb+++ b/app/components/work_packages/exports/generate/modal_dialog_component.rb@@ -32,12 +32,11 @@ require "text/hyphen"module WorkPackagesmodule Exportsmodule Generate- class ModalDialogComponent < ApplicationComponent- MODAL_ID = "op-work-package-generate-pdf-dialog"- GENERATE_PDF_FORM_ID = "op-work-packages-generate-pdf-dialog-form"+ class ModalDialogComponent <ApplicationComponent+ MODAL_ID="op-work-package-generate-pdf-dialog"+ GENERATE_PDF_FORM_ID="op-work-packages-generate-pdf-dialog-form"include OpTurbo::Streamableinclude OpPrimer::ComponentHelpers-attr_reader :work_package, :paramsdef initialize(work_package:, params:)@@ -60,18 +59,7 @@ module WorkPackagesenddef templates_options- [- {- label: I18n.t("pdf_generator.template_attributes.label"),- caption: I18n.t("pdf_generator.template_attributes.caption"),- value: "attributes"- },- {- label: I18n.t("pdf_generator.template_contract.label"),- caption: I18n.t("pdf_generator.template_contract.caption"),- value: "contract"- }- ]+ work_package.type.pdf_export_templates_for_type.filter(&:enabled)enddef hyphenation_defaultdiff --git a/app/components/work_packages/types/export_configuration_component.html.erb b/app/components/work_packages/types/export_configuration_component.html.erbnew file mode 100644index 00000000000..9c911e11668--- /dev/null+++ b/app/components/work_packages/types/export_configuration_component.html.erb@@ -0,0 +1,84 @@+<%#-- 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.++++#%>++<p><%= I18n.t("types.edit.export_configuration.intro") %></p>++<%=+ component_wrapper(data: wrapper_data_attributes) do+ render(border_box_container(mb: 3, data: drag_and_drop_target_config)) do |component|+ component.with_header(font_weight: :bold, py: 2) do+ flex_layout(justify_content: :space_between, align_items: :center) do |section_header_container|+ section_header_container.with_column(py: 2) do+ render(Primer::Beta::Text.new(font_weight: :bold)) do+ I18n.t("types.edit.export_configuration.pdf_export_templates.label")+ end+ end+ section_header_container.with_column(flex_layout: true, justify_content: :flex_end) do |actions_container|+ actions_container.with_column do+ render(Primer::Beta::Button.new(+ tag: :a,+ href: enable_all_type_pdf_export_template_index_path(type_id: model.id),+ scheme: :invisible,+ font_weight: :bold,+ color: :subtle,+ "aria-label": t("projects.settings.actions.label_enable_all"),+ data: { "turbo-method": :put, "turbo-stream": true }+ )) do |button|+ button.with_leading_visual_icon(icon: "check-circle", color: :subtle)+ I18n.t("types.edit.export_configuration.pdf_export_templates.actions.label_enable_all")+ end+ end+ actions_container.with_column do+ render(Primer::Beta::Button.new(+ tag: :a,+ href: disable_all_type_pdf_export_template_index_path(type_id: model.id),+ scheme: :invisible,+ font_weight: :bold,+ color: :subtle,+ "aria-label": t("projects.settings.actions.label_disable_all"),+ data: { "turbo-method": :put, "turbo-stream": true }+ )) do |button|+ button.with_leading_visual_icon(icon: "x-circle", color: :subtle)+ I18n.t("types.edit.export_configuration.pdf_export_templates.actions.label_disable_all")+ end+ end+ end+ end+ end+ pdf_export_templates.each do |template|+ component.with_row(data: draggable_item_config(template)) do+ render(WorkPackages::Types::ExportTemplateRowComponent.new(+ type: model,+ template:+ ))+ end+ end+ end+ end+%>diff --git a/app/components/work_packages/types/export_configuration_component.rb b/app/components/work_packages/types/export_configuration_component.rbnew file mode 100644index 00000000000..7d015df32fd--- /dev/null+++ b/app/components/work_packages/types/export_configuration_component.rb@@ -0,0 +1,64 @@+# 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 WorkPackages+ module Types+ class ExportConfigurationComponent <ApplicationComponent+ include OpPrimer::ComponentHelpers+ include OpTurbo::Streamable+ def pdf_export_templates+ @model.pdf_export_templates_for_type+ end++ def wrapper_data_attributes+ {+ controller: "generic-drag-and-drop",+ "application-target": "dynamic"+ }+ end++ def draggable_item_config(template)+ {+ "draggable-id": template.id,+ "draggable-type": "template",+ "drop-url": drop_type_pdf_export_template_path(type_id: @model.id, id: template.id)+ }+ end++ def drag_and_drop_target_config+ {+ "is-drag-and-drop-target": true,+ "target-container-accessor": "& > ul",+ "target-allowed-drag-type": "template"+ }+ end+ end+ end+enddiff --git a/app/components/work_packages/types/export_template_row_component.html.erb b/app/components/work_packages/types/export_template_row_component.html.erbnew file mode 100644index 00000000000..c30f06bdf23--- /dev/null+++ b/app/components/work_packages/types/export_template_row_component.html.erb@@ -0,0 +1,60 @@+<%#-- 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.++++#%>+<%=+ component_wrapper do+ flex_layout(align_items: :center) do |item_information|+ item_information.with_column(mr: 2) do+ render(Primer::OpenProject::DragHandle.new(draggable: true))+ end+ item_information.with_column(flex: 1, flex_layout: true) do |title_container|+ title_container.with_column(pt: 1, mr: 2) do+ render(Primer::Beta::Text.new) do+ @template.label+ end+ end+ title_container.with_column(pt: 1, mr: 2) do+ render(Primer::Beta::Text.new(font_size: :small, color: :subtle)) do+ @template.caption+ end+ end+ end+ item_information.with_column(py: 1, mr: 2) do+ render(Primer::Alpha::ToggleSwitch.new(+ src: toggle_type_pdf_export_template_path(type_id: @type.id, id: @template.id),+ csrf_token: form_authenticity_token,+ data: { "turbo-method": :post, "turbo-stream": true },+ checked: active_in_type?,+ size: :small,+ status_label_position: :start,+ classes: "op-primer-adjustments__toggle-switch--hidden-loading-indicator"+ ))+ end+ end+ end+%>diff --git a/app/components/work_packages/types/export_template_row_component.rb b/app/components/work_packages/types/export_template_row_component.rbnew file mode 100644index 00000000000..9fd3dc0b90d--- /dev/null+++ b/app/components/work_packages/types/export_template_row_component.rb@@ -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 WorkPackages+ module Types+ class ExportTemplateRowComponent <ApplicationComponent+ include ApplicationHelper+ include OpPrimer::ComponentHelpers+ include OpTurbo::Streamable+ def initialize(type:, template:)+ super++ @template = template+ @type = type+ end++ private++ def active_in_type?+ @template.enabled+ end+ end+ end+enddiff --git a/app/controllers/work_packages/types/pdf_export_template_controller.rb b/app/controllers/work_packages/types/pdf_export_template_controller.rbnew file mode 100644index 00000000000..c47882f7f24--- /dev/null+++ b/app/controllers/work_packages/types/pdf_export_template_controller.rb@@ -0,0 +1,76 @@+# 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 WorkPackages+ module Types+ class PdfExportTemplateController <ApplicationController+ include OpTurbo::ComponentStream+ before_action :require_admin+ before_action :find_type, only: %i[toggle drop enable_all disable_all]+ before_action :find_template, only: %i[toggle drop]++ def enable_all+ Rails.logger.debug "enable_all"++ respond_with_turbo_streams+ end++ def disable_all+ Rails.logger.debug "disable_all"++ respond_with_turbo_streams+ end++ def toggle+ return render_404 if @template.nil?++ Rails.logger.debug { "toggle #{@template.inspect}" }+ respond_with_turbo_streams+ end++ def drop+ return render_404 if @template.nil?++ Rails.logger.debug { "drop #{@template.inspect} #{params[:position]}" }+ respond_to_with_turbo_streams+ end++ protected++ def find_type+ @type = ::Type.find(params[:type_id])+ end++ def find_template+ @template = @type.pdf_export_templates_for_type.find { |t| t.id == params[:id] }+ end+ end+ end+enddiff --git a/app/helpers/types_helper.rb b/app/helpers/types_helper.rbindex 2e9c38b7012..f4458d04870 100644--- a/app/helpers/types_helper.rb+++ b/app/helpers/types_helper.rb@@ -49,6 +49,12 @@ module ::TypesHelperpartial: "types/form/projects",path: edit_tab_type_path(id: @type.id, tab: :projects),label: "types.edit.projects.tab"+ },+ {+ name: "export_configuration",+ path: edit_tab_type_path(id: @type.id, tab: :export_configuration),+ label: "types.edit.export_configuration.tab",+ view_component: WorkPackages::Types::ExportConfigurationComponent}]diff --git a/app/models/type.rb b/app/models/type.rbindex 1eadea9c31c..646afefacf1 100644--- a/app/models/type.rb+++ b/app/models/type.rb@@ -28,7 +28,7 @@# See COPYRIGHT and LICENSE files for more details.#++-class Type < ApplicationRecord+class Type <ApplicationRecord# Work Package attributes for this type# and constraints to specific attributes (by plugins).include ::Type::Attributes@@ -38,6 +38,9 @@ class Type < ApplicationRecordattribute :patterns, Types::Patterns::CollectionType.new+ store_attribute :pdf_export_templates, :export_templates_disabled, :json+ store_attribute :pdf_export_templates, :export_templates_order, :json+before_destroy :check_integritybelongs_to :color, optional: true, class_name: "Color"@@ -112,6 +115,12 @@ class Type < ApplicationRecordpatterns.all_enabledend+ def pdf_export_templates_for_type+ WorkPackage::PDFExport::Templates::build_in_templates.map do |build_in_template|+ WorkPackage::PDFExport::Template.new(**build_in_template, enabled: true)+ end+ end+privatedef check_integritydiff --git a/app/models/work_package/pdf_export/templates.rb b/app/models/work_package/pdf_export/templates.rbnew file mode 100644index 00000000000..fcaa23be4f2--- /dev/null+++ b/app/models/work_package/pdf_export/templates.rb@@ -0,0 +1,50 @@+# 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+ Template = Data.define(:id, :label, :caption, :enabled)++ class Templates+ def self.build_in_templates+ [+ {+ id: "attributes",+ label: I18n.t("pdf_generator.template_attributes.label"),+ caption: I18n.t("pdf_generator.template_attributes.caption")+ },+ {+ id: "contract",+ label: I18n.t("pdf_generator.template_contract.label"),+ caption: I18n.t("pdf_generator.template_contract.caption")+ }+ ]+ end+ end+enddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex eb1d67a4c8a..2f5d0c7f6cf 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -143,7 +143,7 @@ en:back_to_index: "Click here to go back to the list of connection."technical_warning_html: |This LDAP form requires technical knowledge of your LDAP / Active Directory setup.- <br/>+ <br><a href="https://www.openproject.org/help/administration/manage-ldap-authentication/">Please visit our documentation for detailed instructions</a>.attribute_texts:name: Arbitrary name of the LDAP connection@@ -153,7 +153,7 @@ en:admin_map_html: "Optional: The attribute key in LDAP that <strong>if present</strong> marks the OpenProject user an admin. Leave empty when in doubt."system_user_dn_html: |Enter the DN of the system user used for read-only access.- <br/>+ <br>Example: uid=openproject,ou=system,dc=example,dc=comsystem_user_password: Enter the bind password of the system userbase_dn: |@@ -196,7 +196,7 @@ en:verify_peer: "Verify SSL certificate"verify_peer_description_html: >Enables strict SSL verification of the certificate trusted chain.- <br/>+ <br><strong>Warning:</strong> Unchecking this option disables SSL verification of the LDAP server certificate.This exposes your connection to Man in the Middle attacks.tls_certificate_description: "If the LDAP server certificate is not in the trust sources of this system, you can add it manually here. Enter a PEM X509 certifiate string."@@ -627,7 +627,7 @@ en:status_readonly_html: |Check this option to mark work packages with this status as read-only.No attributes can be changed with the exception of the status.- <br/>+ <br><strong>Note</strong>: Inherited values (e.g., from children or relations) will still apply.index:no_results_title_text: There are currently no work package statuses.@@ -674,6 +674,14 @@ en:pattern:label: "Subject pattern"caption: "Search for an attribute or add text. To create a space between elements add it as a text."+ export_configuration:+ tab: "Generate PDF"+ intro: "Select which templates from those that are available you would like to enable for this type. The template determines the design and attributes visible in the exported PDF of a work package using this type. The first template on the list is selected by default."+ pdf_export_templates:+ label: "PDF Export templates"+ actions:+ label_enable_all: "Enable all"+ label_disable_all: "Disable all"versions:overview:@@ -2963,8 +2971,7 @@ en:label_global_role: "Global role"label_not_changeable: "(not changeable)"label_global: "Global"- label_seeded_from_env_warning: This record has been created through a setting / environment variable. It is not editable through UI.-+ label_seeded_from_env_warning: This record has been created through a setting environment variable. It is not editable through UI.macro_execution_error: "Error executing the macro %{macro_name}"macro_unavailable: "Macro %{macro_name} cannot be displayed."macros:@@ -2984,7 +2991,6 @@ en:invalid_type: "No type found with name '%{type}' in project '%{project}'."link_name: "New work package"link_name_type: "New %{type_name}"-mail:actions: "Actions"digests:@@ -3067,7 +3073,6 @@ en:troubleshooting:text: "For more information, check file storages"link_text: "troubleshooting documentation"-mail_body_account_activation_request: "A new user (%{value}) has registered. The account is pending your approval:"mail_body_account_information: "Your account information"mail_body_account_information_external: "You can use your %{value} account to log in."diff --git a/config/routes.rb b/config/routes.rbindex d04b116b2c1..521d312af51 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -140,6 +140,19 @@ Rails.application.routes.draw doaction: "update_subject_configuration"end+ resources :pdf_export_template, only: %i[],+ controller: "work_packages/types/pdf_export_template",+ path: "pdf_export_template" do+ member do+ post :toggle+ put :drop+ end+ collection do+ put :enable_all+ put :disable_all+ end+ end+collection dopost "move/:id", action: "move"enddiff --git a/db/migrate/20250210163523_add_export_templates_to_type.rb b/db/migrate/20250210163523_add_export_templates_to_type.rbnew file mode 100644index 00000000000..73cb7f9a1f8--- /dev/null+++ b/db/migrate/20250210163523_add_export_templates_to_type.rb@@ -0,0 +1,35 @@+# 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.+#++++class AddExportTemplatesToType <ActiveRecord::Migration[7.1]+ def change+ add_column :types, :pdf_export_templates, :jsonb, default: {}+ end+end