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
[#57388] save export settings to database if checkbox is checked
Tobias Dillmann84027523923f
diff --git a/app/components/work_packages/exports/base_export_settings_component.rb b/app/components/work_packages/exports/base_export_settings_component.rbindex 4d71041296b..8f9be5894b4 100644--- a/app/components/work_packages/exports/base_export_settings_component.rb+++ b/app/components/work_packages/exports/base_export_settings_component.rb@@ -44,7 +44,7 @@ module WorkPackagesenddef export_settings- @export_settings ||= query.export_settings.where(format:).first_or_initialize+ @export_settings ||= query.export_settings_for(format)endendenddiff --git a/app/components/work_packages/exports/column_selection_component.rb b/app/components/work_packages/exports/column_selection_component.rbindex 6f519162949..3412854af4f 100644--- a/app/components/work_packages/exports/column_selection_component.rb+++ b/app/components/work_packages/exports/column_selection_component.rb@@ -41,8 +41,7 @@ module WorkPackagessuper()@export_settings = export_settings- # TODO: respond_to can be removed once all ExportSettingComponents have been migrated- @query = export_settings.respond_to?(:query) ? export_settings.query : export_settings+ @query = @export_settings.query@id = id@caption = caption@label = label@@ -61,17 +60,16 @@ module WorkPackagesenddef selected_columns- # TODO: respond_to can be removed once all ExportSettingComponents have been migrated- if export_settings.respond_to?(:settings) && export_settings.settings.key?(:columns)+ if export_settings.settings.key?(:columns)+ # FIXME: the order of the columns is not preservedsaved_cols = export_settings.settings[:columns]- query- .columns- .select { |column| saved_cols.include?(column.name.to_s) }+ available_columns+ .select { |column| saved_cols.include?(column[:id]) }elsequery.columns+ .map { |column| { id: column.name.to_s, name: column.caption } }end- .map { |column| { id: column.name.to_s, name: column.caption } }endendenddiff --git a/app/components/work_packages/exports/csv/export_settings_component.html.erb b/app/components/work_packages/exports/csv/export_settings_component.html.erbindex 6e5f518d60b..a3c90de0ed4 100644--- a/app/components/work_packages/exports/csv/export_settings_component.html.erb+++ b/app/components/work_packages/exports/csv/export_settings_component.html.erb@@ -14,7 +14,7 @@name: "show_descriptions",value: "true",unchecked_value: "false",- checked: export_settings.settings.fetch(:show_descriptions, false),+ checked: export_settings.true?(:show_descriptions),label: I18n.t("export.dialog.xls.include_descriptions.label"),caption: I18n.t("export.dialog.xls.include_descriptions.caption"),visually_hide_label: falsediff --git a/app/components/work_packages/exports/pdf/report/export_settings_component.html.erb b/app/components/work_packages/exports/pdf/report/export_settings_component.html.erbindex f1b81ba086d..4bd8abc39ae 100644--- a/app/components/work_packages/exports/pdf/report/export_settings_component.html.erb+++ b/app/components/work_packages/exports/pdf/report/export_settings_component.html.erb@@ -31,7 +31,7 @@<%= render(Primer::Alpha::CheckBox.new(name: "show_images",- checked: export_settings.settings.fetch(:show_images, true),+ checked: export_settings.settings.fetch(:show_images, true).to_bool,value: "true",unchecked_value: "false",label: I18n.t("export.dialog.pdf.include_images.label"),diff --git a/app/components/work_packages/exports/xls/export_settings_component.html.erb b/app/components/work_packages/exports/xls/export_settings_component.html.erbindex 4faf6dbdd8e..73b40c2bbe4 100644--- a/app/components/work_packages/exports/xls/export_settings_component.html.erb+++ b/app/components/work_packages/exports/xls/export_settings_component.html.erb@@ -14,7 +14,7 @@name: "show_relations",value: "true",unchecked_value: "false",- checked: export_settings.settings.fetch(:show_relations, false),+ checked: export_settings.true?(:show_relations),label: I18n.t("export.dialog.xls.include_relations.label"),caption: I18n.t("export.dialog.xls.include_relations.caption"),visually_hide_label: false@@ -29,7 +29,7 @@name: "show_descriptions",value: "true",unchecked_value: "false",- checked: export_settings.settings.fetch(:show_descriptions, false),+ checked: export_settings.true?(:show_descriptions),label: I18n.t("export.dialog.xls.include_descriptions.label"),caption: I18n.t("export.dialog.xls.include_descriptions.caption"),visually_hide_label: falsediff --git a/app/controllers/work_packages_controller.rb b/app/controllers/work_packages_controller.rbindex 3cce30d327f..a8074869c3c 100644--- a/app/controllers/work_packages_controller.rb+++ b/app/controllers/work_packages_controller.rb@@ -135,6 +135,8 @@ class WorkPackagesController < ApplicationControllerenddef export_list(mime_type)+ save_export_settings if params[:save_export_settings].to_bool+job_id = WorkPackages::Exports::ScheduleService.new(user: current_user).call(query: @query, mime_type:, params:)@@ -169,6 +171,21 @@ class WorkPackagesController < ApplicationControllerprivate+ def save_export_settings+ relevant_keys = %i[format columns show_relations show_descriptions long_text_fields+ show_images gantt_mode gantt_width paper_size]++ user_settings = params.slice(*relevant_keys)++ if user_settings[:format] == "pdf"+ user_settings[:format] = "pdf_#{params[:pdf_export_type]}"+ end++ export_settings = @query.export_settings_for(user_settings[:format])+ export_settings.settings = user_settings+ export_settings.save!+ end+def authorize_on_work_packagedeny_access(not_found: true) unless work_packageenddiff --git a/app/models/export_setting.rb b/app/models/export_setting.rbindex 58bdbf12c60..fb1d9eaf291 100644--- a/app/models/export_setting.rb+++ b/app/models/export_setting.rb@@ -49,6 +49,12 @@ class ExportSetting < ApplicationRecordsuper(value.stringify_keys)end+ # Some boolean settings are saved as string. Use this method to conveniently check if they are+ # set to true. Assumes that all boolean settings default to false.+ def true?(key)+ settings.fetch(key, false).to_bool+ end+privatedef unique_format_per_querydiff --git a/app/models/query.rb b/app/models/query.rbindex 0ede8c5c42b..1e3d99bdc64 100644--- a/app/models/query.rb+++ b/app/models/query.rb@@ -421,6 +421,10 @@ class Query < ApplicationRecordsubproject_filterend+ def export_settings_for(format)+ export_settings.where(format: format).first_or_initialize+ end+private##