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
connect the settings UI with the model
as-op29f151e6bd55
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 b0ddd3a43ba..b1809755fb7 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@@ -1,8 +1,10 @@-<%= render(Primer::Alpha::Dialog.new(- title: I18n.t("pdf_generator.dialog.title"),- id: MODAL_ID,- size: :medium_portrait-)) do |dialog| %>+<%= render(+ Primer::Alpha::Dialog.new(+ title: I18n.t("pdf_generator.dialog.title"),+ id: MODAL_ID,+ size: :medium_portrait+ )+ ) do |dialog| %><% dialog.with_header(variant: :large) %><% dialog.with_body do %><%= primer_form_with(@@ -14,93 +16,107 @@},id: GENERATE_PDF_FORM_ID) do- flex_layout do |modal_body|- modal_body.with_row(mt: 0) do- render(Primer::Alpha::Select.new(- name: "template",- label: I18n.t("pdf_generator.dialog.templates.label"),- 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.id- templates_options.each do |entry|- component.option(- label: entry.label,- value: entry.id,- selected: selected == entry.id,- data: {- caption: entry.caption- }+ flex_layout do |modal_body|+ modal_body.with_row(mt: 0) do+ render(+ Primer::Alpha::Select.new(+ name: "template",+ label: I18n.t("pdf_generator.dialog.templates.label"),+ caption: templates_default&.caption || I18n.t("pdf_generator.dialog.templates.none_enabled"),+ disabled: templates_default.nil?,+ 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&.id+ templates_options.each do |entry|+ component.option(+ label: entry.label,+ value: entry.id,+ selected: selected == entry.id,+ data: {+ caption: entry.caption+ }+ )+ end+ end+ end+ modal_body.with_row(mt: 3) do+ render(+ Primer::Alpha::CheckBox.new(+ id: "hyphenation_enabled",+ name: "hyphenation",+ checked: false,+ value: "true",+ unchecked_value: "false",+ label: I18n.t("pdf_generator.dialog.hyphenation.label"),+ caption: I18n.t("pdf_generator.dialog.hyphenation.caption"),+ visually_hide_label: false+ ))end- end- end- modal_body.with_row(mt: 3) do- render(Primer::Alpha::CheckBox.new(- id: "hyphenation_enabled",- name: "hyphenation",- checked: false,- value: "true",- unchecked_value: "false",- label: I18n.t("pdf_generator.dialog.hyphenation.label"),- caption: I18n.t("pdf_generator.dialog.hyphenation.caption"),- visually_hide_label: false- ))- end- modal_body.with_row(mt: 3) do- render(Primer::Alpha::Select.new(- name: "hyphenation_language",- label: I18n.t("pdf_generator.dialog.hyphenation_language.label"),- input_width: :large- )) do |component|- selected = hyphenation_default[:value]- hyphenation_options.each do |entry|- component.option(label: entry[:label], value: entry[:value], selected: selected == entry[:value])+ modal_body.with_row(mt: 3) do+ render(+ Primer::Alpha::Select.new(+ name: "hyphenation_language",+ label: I18n.t("pdf_generator.dialog.hyphenation_language.label"),+ input_width: :large+ )+ ) do |component|+ selected = hyphenation_default[:value]+ hyphenation_options.each do |entry|+ component.option(label: entry[:label], value: entry[:value], selected: selected == entry[:value])+ end+ end+ end+ modal_body.with_row(+ mt: 3,+ classes: templates_default&.id == "attributes" ? nil : "d-none",+ data: {+ template: "attributes",+ "work-packages--export--generate-pdf-form-target": "inputGroups"+ }+ ) do+ render Primer::Alpha::TextField.new(+ name: :footer_text_right,+ label: I18n.t("pdf_generator.dialog.footer_right.label"),+ caption: I18n.t("pdf_generator.dialog.footer_right.caption"),+ visually_hide_label: false,+ value: default_footer_text_right+ )+ end+ modal_body.with_row(+ mt: 3,+ classes: templates_default&.id == "contract" ? nil : "d-none",+ data: {+ template: "contract",+ "work-packages--export--generate-pdf-form-target": "inputGroups"+ }+ ) 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+ )endend- end- modal_body.with_row(mt: 3,- classes: templates_default.id == "attributes" ? nil : "d-none",- data: {- "template": "attributes",- "work-packages--export--generate-pdf-form-target": "inputGroups"- }- ) do- render Primer::Alpha::TextField.new(- name: :footer_text_right,- label: I18n.t("pdf_generator.dialog.footer_right.label"),- caption: I18n.t("pdf_generator.dialog.footer_right.caption"),- visually_hide_label: false,- value: default_footer_text_right- )- end- modal_body.with_row(mt: 3,- classes: templates_default.id == "contract" ? nil : "d-none",- data: {- "template": "contract",- "work-packages--export--generate-pdf-form-target": "inputGroups"- }- ) 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 %><% 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") } %>+ <%= render(+ Primer::ButtonComponent.new(+ scheme: :primary,+ type: :submit,+ form: GENERATE_PDF_FORM_ID,+ disabled: templates_default.nil?,+ data: { "close-dialog-id": MODAL_ID }+ )+ ) { I18n.t("pdf_generator.dialog.submit") } %><% end %><% end %>diff --git a/app/components/work_packages/types/export_configuration_component.html.erb b/app/components/work_packages/types/export_configuration_component.html.erbindex 9c911e11668..657a294e510 100644--- a/app/components/work_packages/types/export_configuration_component.html.erb+++ b/app/components/work_packages/types/export_configuration_component.html.erb@@ -28,57 +28,4 @@ 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-%>+<%= render(WorkPackages::Types::ExportTemplateListComponent.new(type: model)) %>diff --git a/app/components/work_packages/types/export_configuration_component.rb b/app/components/work_packages/types/export_configuration_component.rbindex 057d85a6cc3..17f5ff5c67a 100644--- a/app/components/work_packages/types/export_configuration_component.rb+++ b/app/components/work_packages/types/export_configuration_component.rb@@ -31,34 +31,6 @@module WorkPackagesmodule Typesclass 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"- }- endendendenddiff --git a/app/components/work_packages/types/export_template_list_component.html.erb b/app/components/work_packages/types/export_template_list_component.html.erbnew file mode 100644index 00000000000..3d252d2c665--- /dev/null+++ b/app/components/work_packages/types/export_template_list_component.html.erb@@ -0,0 +1,83 @@+<%#-- 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(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: @type.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: @type.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: @type,+ template:+ ))+ end+ end+ end+ end+%>+diff --git a/app/components/work_packages/types/export_template_list_component.rb b/app/components/work_packages/types/export_template_list_component.rbnew file mode 100644index 00000000000..8e3818e21ab--- /dev/null+++ b/app/components/work_packages/types/export_template_list_component.rb@@ -0,0 +1,72 @@+# 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 ExportTemplateListComponent < ApplicationComponent+ include ApplicationHelper+ include OpPrimer::ComponentHelpers+ include OpTurbo::Streamable++ def initialize(type:)+ super++ @type = type+ end++ def wrapper_data_attributes+ {+ controller: "generic-drag-and-drop",+ "application-target": "dynamic"+ }+ end++ def drag_and_drop_target_config+ {+ "is-drag-and-drop-target": true,+ "target-container-accessor": "& > ul",+ "target-allowed-drag-type": "template"+ }+ end++ def draggable_item_config(template)+ {+ "draggable-id": template.id,+ "draggable-type": "template",+ "drop-url": drop_type_pdf_export_template_path(type_id: @type.id, id: template.id)+ }+ end++ def pdf_export_templates+ @type.pdf_export_templates_for_type+ 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.rbindex 63d73a1a586..0393167a93f 100644--- a/app/controllers/work_packages/types/pdf_export_template_controller.rb+++ b/app/controllers/work_packages/types/pdf_export_template_controller.rb@@ -37,33 +37,70 @@ module WorkPackagesbefore_action :find_template, only: %i[toggle drop]def enable_all- Rails.logger.debug "enable_all"+ return render_404_turbo_stream if @type.nil?- respond_with_turbo_streams+ @type.export_templates_disabled = []+ @type.save!+ respond_section_with_turbo_streamsenddef disable_all- Rails.logger.debug "disable_all"+ return render_404_turbo_stream if @type.nil?- respond_with_turbo_streams+ @type.export_templates_disabled = WorkPackage::PDFExport::Templates::static_templates+ .pluck(:id)+ @type.save!+ respond_section_with_turbo_streamsenddef toggle- return render_404 if @template.nil?+ return render_404_turbo_stream if @template.nil?- Rails.logger.debug { "toggle #{@template.inspect}" }+ toggle_template(@template.id)respond_with_turbo_streamsenddef drop- return render_404 if @template.nil?+ return render_404_turbo_stream if @template.nil?- Rails.logger.debug { "drop #{@template.inspect} #{params[:position]}" }+ position = params[:position].to_i - 1 # drop index starts at 1+ move_template(@template.id, position)respond_to_with_turbo_streamsendprotected+ def move_template(template_id, position)+ template_ids = @type.pdf_export_templates_for_type.map(&:id)+ prev_index = template_ids.find_index(template_id)+ template_ids.delete_at(prev_index) unless prev_index.nil?+ template_ids.insert(position, template_id)+ @type.export_templates_order = template_ids+ @type.save!+ end++ def toggle_template(template_id)+ disabled = @type.export_templates_disabled || []+ if disabled.include?(template_id)+ disabled.delete(template_id)+ else+ disabled.push(template_id)+ end+ @type.export_templates_disabled = disabled+ @type.save!+ end++ def respond_section_with_turbo_streams+ replace_via_turbo_stream(+ component: ::WorkPackages::Types::ExportTemplateListComponent.new(type: @type)+ )+ respond_to_with_turbo_streams+ end++ def render_404_turbo_stream+ render_error_flash_message_via_turbo_stream(message: t(:notice_file_not_found))+ end+def find_type@type = ::Type.find(params[:type_id])enddiff --git a/app/models/type.rb b/app/models/type.rbindex 53cab3d2a9c..af6bb80a8ab 100644--- a/app/models/type.rb+++ b/app/models/type.rb@@ -116,9 +116,7 @@ class Type < ApplicationRecordenddef 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+ WorkPackage::PDFExport::Templates::build_template_list(export_templates_disabled, export_templates_order)endprivatediff --git a/app/models/work_package/pdf_export/templates.rb b/app/models/work_package/pdf_export/templates.rbindex fcaa23be4f2..733ed08c7a5 100644--- a/app/models/work_package/pdf_export/templates.rb+++ b/app/models/work_package/pdf_export/templates.rb@@ -32,7 +32,19 @@ module WorkPackage::PDFExportTemplate = Data.define(:id, :label, :caption, :enabled)class Templates- def self.build_in_templates+ def self.build_template_list(disabled_ids, ordered_ids)+ disabled = disabled_ids || []+ templates = static_templates.map do |build_in_template|+ Template.new(**build_in_template, enabled: disabled.exclude?(build_in_template[:id]))+ end+ order = ordered_ids || []+ return templates if order.empty?++ indexes = order.each_with_index.to_a.to_h+ templates.sort_by { |template| indexes[template.id] }+ end++ def self.static_templates[{id: "attributes",diff --git a/config/locales/en.yml b/config/locales/en.ymlindex e9fb16fa02d..2ab0109de1f 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -2125,6 +2125,7 @@ en:submit: Downloadtemplates:label: "Template"+ none_enabled: "No template has been enabled for this work package type"footer_center:label: Footer textcaption: This text will appear on every page at the center of the footer.