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

[#57388] PDF gantt export reads from ExportSetting

Tobias Dillmann2007af06bfc7
diff --git a/app/components/work_packages/exports/pdf/gantt/export_settings_component.html.erb b/app/components/work_packages/exports/pdf/gantt/export_settings_component.html.erb
index 5fbfbf17a05..eaea64b4869 100644
--- a/app/components/work_packages/exports/pdf/gantt/export_settings_component.html.erb
+++ b/app/components/work_packages/exports/pdf/gantt/export_settings_component.html.erb
@@ -8,9 +8,9 @@
size: :medium,
input_width: :small
)) do |component|
- selected = entry[:options].find { |e| e[:default] }[:value]
- entry[:options].each do |entry|
- component.option(label: entry[:label], value: entry[:value], selected: selected == entry[:value])
+ selected = find_selected_option(entry)
+ entry[:options].each do |e|
+ component.option(label: e[:label], value: e[:value], selected: selected[:value] == e[:value])
end
end %>
<% end %>
diff --git a/app/components/work_packages/exports/pdf/gantt/export_settings_component.rb b/app/components/work_packages/exports/pdf/gantt/export_settings_component.rb
index 3f1a2497d10..d409b9acf90 100644
--- a/app/components/work_packages/exports/pdf/gantt/export_settings_component.rb
+++ b/app/components/work_packages/exports/pdf/gantt/export_settings_component.rb
@@ -33,6 +33,10 @@ module WorkPackages
module PDF
module Gantt
class ExportSettingsComponent < BaseExportSettingsComponent
+ def format
+ "pdf_gantt"
+ end
+
def gantt_selects
[
{
@@ -55,6 +59,26 @@ module WorkPackages
]
end
+ # Reads the saved value from the export settings and returns the selected option.
+ # When there is no saved value, returns the default option.
+ # @param [Hash] entry one entry from `gantt_selects`
+ def find_selected_option(entry)
+ select_name = entry[:name].to_sym
+ if export_settings.settings.key?(select_name)
+ saved_value = export_settings.settings[select_name]
+
+ entry[:options].find { |option| option[:value] == saved_value } || find_default_option(entry)
+ else
+ find_default_option(entry)
+ end
+ end
+
+ # Returns the default option for a gantt_select entry.
+ # @param [Hash] entry one entry from `gantt_selects`
+ def find_default_option(entry)
+ entry[:options].find { |option| option[:default] }
+ end
+
def gantt_zoom_levels
[
{ label: t("export.dialog.pdf.gantt_zoom_levels.options.days"), value: "day", default: true },