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] CSV export reads from ExportSetting

Tobias Dillmannab2ae3ac4b8c
diff --git a/app/components/work_packages/exports/base_export_settings_component.rb b/app/components/work_packages/exports/base_export_settings_component.rb
index 16fdbc293dd..ee154d96f01 100644
--- a/app/components/work_packages/exports/base_export_settings_component.rb
+++ b/app/components/work_packages/exports/base_export_settings_component.rb
@@ -42,6 +42,10 @@ module WorkPackages
@query = query
end
+
+ def export_settings
+ @export_settings ||= query.export_settings.where(format: "csv").first_or_initialize
+ end
end
end
end
diff --git a/app/components/work_packages/exports/column_selection_component.rb b/app/components/work_packages/exports/column_selection_component.rb
index 0ac1182a797..6f519162949 100644
--- a/app/components/work_packages/exports/column_selection_component.rb
+++ b/app/components/work_packages/exports/column_selection_component.rb
@@ -33,14 +33,16 @@ module WorkPackages
class ColumnSelectionComponent < ApplicationComponent
include WorkPackagesHelper
- attr_reader :query, :id, :caption, :label
+ attr_reader :export_settings, :query, :id, :caption, :label
- def initialize(query, id, caption,
+ def initialize(export_settings, id, caption,
label = I18n.t(:"queries.configure_view.columns.input_label"),
required: true)
super()
- @query = query
+ @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
@id = id
@caption = caption
@label = label
@@ -59,8 +61,16 @@ module WorkPackages
end
def selected_columns
- query
- .columns
+ # TODO: respond_to can be removed once all ExportSettingComponents have been migrated
+ if export_settings.respond_to?(:settings) && export_settings.settings.key?(:columns)
+ saved_cols = export_settings.settings[:columns]
+ query
+ .columns
+ .select { |column| saved_cols.include?(column.name.to_s) }
+ else
+ query
+ .columns
+ end
.map { |column| { id: column.name.to_s, name: column.caption } }
end
end
diff --git a/app/components/work_packages/exports/csv/export_settings_component.html.erb b/app/components/work_packages/exports/csv/export_settings_component.html.erb
index 387bbccad53..6e5f518d60b 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
@@ -1,7 +1,7 @@
<%= flex_layout do |container| %>
<%= container.with_row do |_columns| %>
<%= render WorkPackages::Exports::ColumnSelectionComponent.new(
- query,
+ export_settings,
"columns-select-export-csv",
I18n.t("export.dialog.columns.input_caption_table")
) %>
@@ -14,6 +14,7 @@
name: "show_descriptions",
value: "true",
unchecked_value: "false",
+ checked: export_settings.settings.fetch(:show_descriptions, false),
label: I18n.t("export.dialog.xls.include_descriptions.label"),
caption: I18n.t("export.dialog.xls.include_descriptions.caption"),
visually_hide_label: false