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

[#48274] Work packages export modal with settings

as-opcde8111e69f9
diff --git a/app/components/work_packages/exports/base_export_settings_component.rb b/app/components/work_packages/exports/base_export_settings_component.rb
new file mode 100644
index 00000000000..395d959a31a
--- /dev/null
+++ b/app/components/work_packages/exports/base_export_settings_component.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2024 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 Exports
+ class BaseExportSettingsComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
+ include OpPrimer::ComponentHelpers
+ include OpTurbo::Streamable
+ include WorkPackagesHelper
+
+ attr_reader :query
+
+ def initialize(query)
+ super
+
+ @query = query
+ end
+
+ def selected_columns
+ query
+ .columns
+ .map { |s| { id: s.name, name: s.caption } }
+ end
+ end
+ 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
new file mode 100644
index 00000000000..1646d40d2e5
--- /dev/null
+++ b/app/components/work_packages/exports/csv/export_settings_component.html.erb
@@ -0,0 +1,19 @@
+<%=
+ flex_layout do |container|
+ container.with_row do |_columns|
+ helpers.angular_component_tag "opce-draggable-autocompleter",
+ inputs: {
+ options: work_packages_columns_options,
+ selected: selected_columns,
+ protected: protected_work_packages_columns_options,
+ name: 'columns',
+ id: 'columns-select-export-csv',
+ dragAreaName: 'columns-select-export-csv',
+ inputLabel: I18n.t(:"queries.configure_view.columns.input_label"),
+ inputPlaceholder: I18n.t(:"queries.configure_view.columns.input_placeholder"),
+ dragAreaLabel: I18n.t(:"queries.configure_view.columns.drag_area_label"),
+ appendToComponent: true
+ }
+ end
+ end
+%>
diff --git a/app/components/work_packages/exports/csv/export_settings_component.rb b/app/components/work_packages/exports/csv/export_settings_component.rb
new file mode 100644
index 00000000000..f4474454039
--- /dev/null
+++ b/app/components/work_packages/exports/csv/export_settings_component.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2024 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 Exports
+ module CSV
+ class ExportSettingsComponent < BaseExportSettingsComponent
+ end
+ end
+ end
+end
diff --git a/app/components/work_packages/exports/modal_dialog_component.html.erb b/app/components/work_packages/exports/modal_dialog_component.html.erb
new file mode 100644
index 00000000000..adedc34b4ce
--- /dev/null
+++ b/app/components/work_packages/exports/modal_dialog_component.html.erb
@@ -0,0 +1,58 @@
+<%= render(Primer::Alpha::Dialog.new(
+ title: t('js.label_export'),
+ size: :xlarge,
+ id: MODAL_ID,
+ data: {
+ "application-target": "dynamic",
+ controller: "work-packages--export--dialog"
+ }
+)) do |dialog| %>
+ <% dialog.with_header(variant: :large) %>
+ <% dialog.with_body do %>
+ <% flex_layout do |modal_body| %>
+ <% modal_body.with_row do |_format| %>
+ <%= render(Primer::Beta::Text.new(tag: "legend", font_size: :normal, mb: 2, font_weight: :bold)) { "Export format" } %>
+ <%= render(Primer::Alpha::SegmentedControl.new(ml: 0, mb: 2, "aria-label": "Export format", size: :medium)) do |component|
+ export_formats_settings.each do |format|
+ component.with_item(
+ label: format[:label], icon: format[:icon], selected: format[:selected],
+ data: {
+ "work-packages--export--dialog-format-param": format[:id],
+ action: "click:segmented-control#select click->work-packages--export--dialog#formatChanged"
+ })
+ end
+ end %>
+ <hr/>
+ <% end %>
+ <% export_formats_settings.each do |format| %>
+ <% modal_body.with_row(
+ classes: format[:selected] ? nil : "d-none",
+ data: { format: format[:id], "work-packages--export--dialog-target": "formatTab" }
+ ) do |_format_tabs| %>
+ <%= primer_form_with(
+ url: export_format_url(format[:id]),
+ id: "#{EXPORT_FORM_ID}-#{format[:id]}",
+ data: {
+ "application-target": "dynamic",
+ action: "submit->work-packages--export--form#submitForm",
+ controller: "work-packages--export--form",
+ }
+ ) do |form| %>
+ <input type="hidden" name="query" value="<%= query_params %>">
+ <%= render(format[:component].new(query)) %>
+ <% 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(
+ data: {
+ "close-dialog-id": MODAL_ID,
+ "work-packages--export--dialog-target": "submit"
+ },
+ scheme: :primary, type: :submit,
+ form: "#{EXPORT_FORM_ID}-#{export_formats_settings.find { |e| e[:selected] }[:id]}")) { "Export" } %>
+ <% end %>
+<% end %>
diff --git a/app/components/work_packages/exports/modal_dialog_component.rb b/app/components/work_packages/exports/modal_dialog_component.rb
new file mode 100644
index 00000000000..c9976f791a0
--- /dev/null
+++ b/app/components/work_packages/exports/modal_dialog_component.rb
@@ -0,0 +1,66 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2024 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 Exports
+ class ModalDialogComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
+ MODAL_ID = "op-work-packages-export-dialog"
+ EXPORT_FORM_ID = "op-work-packages-export-dialog-form"
+ include OpTurbo::Streamable
+ include OpPrimer::ComponentHelpers
+
+ attr_reader :query, :project, :query_params
+
+ def initialize(query:, project:)
+ super
+
+ @query = query
+ @project = project
+ @query_params = ::API::V3::Queries::QueryParamsRepresenter.new(query).to_h.to_json
+ end
+
+ def export_format_url(format)
+ if @project.nil?
+ index_work_packages_path(format:)
+ else
+ project_work_packages_path(project, format:)
+ end
+ end
+
+ def export_formats_settings
+ [
+ { label: "PDF", id: 'pdf', icon: :"op-pdf", component: WorkPackages::Exports::PDF::ExportSettingsComponent, selected: true },
+ { label: "XLS", id: 'xls', icon: :"op-xls", component: WorkPackages::Exports::XLS::ExportSettingsComponent },
+ { label: "CSV", id: 'csv', icon: :"op-file-csv", component: WorkPackages::Exports::CSV::ExportSettingsComponent }
+ ]
+ end
+ end
+ end
+end
diff --git a/app/components/work_packages/exports/pdf/export_settings_component.html.erb b/app/components/work_packages/exports/pdf/export_settings_component.html.erb
new file mode 100644
index 00000000000..5774c63721b
--- /dev/null
+++ b/app/components/work_packages/exports/pdf/export_settings_component.html.erb
@@ -0,0 +1,107 @@
+<%=
+ flex_layout(data: {
+ "application-target": "dynamic",
+ controller: "work-packages--export--pdf--settings"
+ }) do |container| %>
+
+ <%= container.with_row do %>
+ <%= render(Primer::Alpha::RadioButtonGroup.new(
+ mb: 3,
+ full_width: true,
+ name: "pdf_export_type",
+ label: "PDF export type")) do |component|
+ pdf_export_types.each do |entry|
+ component.radio_button(label: entry[:label],
+ value: entry[:value],
+ checked: current_pdf_export_type == entry[:value],
+ disabled: entry[:disabled] ? true : nil,
+ data: {
+ "work-packages--export--pdf--settings-name-param": entry[:value],
+ action: "work-packages--export--pdf--settings#typeChanged"
+ },
+ caption: entry[:caption])
+ end
+ end %>
+ <hr/>
+ <% end %>
+
+ <% container.with_row(
+ mt: 2,
+ classes: %w[table report].include?(current_pdf_export_type) ? nil : "d-none",
+ data: {
+ table: true,
+ report: true,
+ "work-packages--export--pdf--settings-target": "fields"
+ }) do |_columns|
+ helpers.angular_component_tag "opce-draggable-autocompleter",
+ inputs: {
+ options: work_packages_columns_options,
+ selected: selected_columns,
+ protected: protected_work_packages_columns_options,
+ name: 'columns',
+ id: 'columns-select-export-pdf',
+ inputLabel: I18n.t(:"queries.configure_view.columns.input_label"),
+ inputPlaceholder: I18n.t(:"queries.configure_view.columns.input_placeholder"),
+ dragAreaName: 'columns-select-export-pdf',
+ dragAreaLabel: I18n.t(:"queries.configure_view.columns.drag_area_label"),
+ appendToComponent: true
+ }
+ end %>
+
+ <%= container.with_row(
+ classes: current_pdf_export_type == "report" ? nil : "d-none",
+ data: {
+ report: true,
+ "work-packages--export--pdf--settings-target": "fields"
+ }) do |_pdf_report_images| %>
+ <hr/>
+ <%= render(Primer::Alpha::CheckBox.new(name: 'show_images',
+ checked: true,
+ label: "Include images",
+ disabled: current_pdf_export_type != "report",
+ caption: "Exclude images to reduce the size of the PDF export.",
+ visually_hide_label: false)) %>
+ <% end %>
+ <% if is_gantt_chart_allowed? %>
+ <%= container.with_row(classes: current_pdf_export_type == "gantt" ? nil : "d-none",
+ data: {
+ gantt: true,
+ "work-packages--export--pdf--settings-target": "fields"
+ }) do |_pdf_gantt_paper_size| %>
+ <%= render(Primer::Alpha::Select.new(
+ name: "gantt_mode",
+ label: "Zoom level",
+ size: :medium,
+ disabled: current_pdf_export_type != "gantt",
+ caption: "Select what is the zoom level for dates displayed in the chart.",
+ value: gantt_zoom_levels.find { |e| e[:default] }[:value])
+ ) do |component|
+ gantt_zoom_levels.each do |entry|
+ component.option(label: entry[:label], value: entry[:value])
+ end
+ end %>
+ <%= render(Primer::Alpha::Select.new(
+ name: "gantt_width",
+ label: "Table column width",
+ disabled: current_pdf_export_type != "gantt",
+ size: :medium,
+ value: gantt_column_widths.find { |e| e[:default] }[:value])
+ ) do |component|
+ gantt_column_widths.each do |entry|
+ component.option(label: entry[:label], value: entry[:value])
+ end
+ end %>
+ <%= render(Primer::Alpha::Select.new(
+ name: "paper_size",
+ label: "Paper size",
+ size: :medium,
+ disabled: current_pdf_export_type != "gantt",
+ value: pdf_paper_sizes.find { |e| e[:default] }[:value])
+ ) do |component|
+ pdf_paper_sizes.each do |entry|
+ component.option(label: entry[:label], value: entry[:value])
+ end
+ end %>
+ <% end %>
+ <% end %>
+<% end %>
diff --git a/app/components/work_packages/exports/pdf/export_settings_component.rb b/app/components/work_packages/exports/pdf/export_settings_component.rb
new file mode 100644
index 00000000000..75bc83cd2f1
--- /dev/null
+++ b/app/components/work_packages/exports/pdf/export_settings_component.rb
@@ -0,0 +1,95 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2024 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 Exports
+ module PDF
+ class ExportSettingsComponent < BaseExportSettingsComponent
+ def current_pdf_export_type
+ 'table'
+ end
+
+ def is_gantt_chart_allowed?
+ EnterpriseToken.allows_to?(:gantt_pdf_export)
+ end
+
+ def pdf_export_types
+ [
+ { label: "Table", value: 'table',
+ caption: "Export the work packages list in a table with the desired columns." },
+ { label: "Report", value: 'report',
+ caption: "Export the work package on a detailed report of all work packages in the list." },
+ { label: "Gantt chart", value: 'gantt',
+ caption: "Export the work packages list in a Gantt diagram view.",
+ disabled: !is_gantt_chart_allowed? }
+ ]
+ end
+
+ def selected_columns
+ query
+ .columns
+ .map { |s| { id: s.name, name: s.caption } }
+ end
+
+ def gantt_zoom_levels
+ [
+ { label: t('js.gantt_chart.zoom.days'), value: 'day', default: true },
+ { label: t('js.gantt_chart.zoom.weeks'), value: 'week' },
+ { label: t('js.gantt_chart.zoom.months'), value: 'month' },
+ { label: t('js.gantt_chart.zoom.quarters'), value: 'quarter' }
+ ]
+ end
+
+ def gantt_column_widths
+ [
+ { label: t('js.gantt_chart.export.column_widths.narrow'), value: 'narrow' },
+ { label: t('js.gantt_chart.export.column_widths.medium'), value: 'medium', default: true },
+ { label: t('js.gantt_chart.export.column_widths.wide'), value: 'wide' },
+ { label: t('js.gantt_chart.export.column_widths.very_wide'), value: 'very_wide' }
+ ]
+ end
+
+ def pdf_paper_sizes
+ [
+ { label: 'A4', value: 'A4', default: true },
+ { label: 'A3', value: 'A3' },
+ { label: 'A2', value: 'A2' },
+ { label: 'A1', value: 'A1' },
+ { label: 'A0', value: 'A0' },
+ { label: 'Executive', value: 'EXECUTIVE' },
+ { label: 'Folio', value: 'FOLIO' },
+ { label: 'Letter', value: 'LETTER' },
+ { label: 'Tabloid', value: 'TABLOID' },
+ ]
+ end
+ end
+ end
+ end
+end
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.erb
new file mode 100644
index 00000000000..7f5799f862e
--- /dev/null
+++ b/app/components/work_packages/exports/xls/export_settings_component.html.erb
@@ -0,0 +1,25 @@
+<%=
+ flex_layout do |container|
+ container.with_row(mb: 2) do |_columns|
+ helpers.angular_component_tag "opce-draggable-autocompleter",
+ inputs: {
+ options: work_packages_columns_options,
+ selected: selected_columns,
+ protected: protected_work_packages_columns_options,
+ name: 'columns',
+ id: 'columns-select-export-xls',
+ inputLabel: I18n.t(:"queries.configure_view.columns.input_label"),
+ inputPlaceholder: I18n.t(:"queries.configure_view.columns.input_placeholder"),
+ dragAreaName: 'columns-select-export-xls',
+ dragAreaLabel: I18n.t(:"queries.configure_view.columns.drag_area_label"),
+ appendToComponent: true
+ }
+ end
+ container.with_row do |_xls_include_relations|
+ render(Primer::Alpha::CheckBox.new(name: 'show_relations',
+ label: "Include relations",
+ caption: "This option will create a duplicate of each work package for every relation this has with another work package.",
+ visually_hide_label: false))
+ end
+ end
+%>
diff --git a/app/components/work_packages/exports/xls/export_settings_component.rb b/app/components/work_packages/exports/xls/export_settings_component.rb
new file mode 100644
index 00000000000..130c2b7a239
--- /dev/null
+++ b/app/components/work_packages/exports/xls/export_settings_component.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2024 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 Exports
+ module XLS
+ class ExportSettingsComponent < BaseExportSettingsComponent
+ end
+ end
+ end
+end
diff --git a/app/controllers/work_packages_controller.rb b/app/controllers/work_packages_controller.rb
index b1236fe344c..af7f1819d51 100644
--- a/app/controllers/work_packages_controller.rb
+++ b/app/controllers/work_packages_controller.rb
@@ -31,6 +31,7 @@ class WorkPackagesController < ApplicationController
include PaginationHelper
include Layout
include WorkPackagesControllerHelper
+ include OpTurbo::DialogStreamHelper
accept_key_auth :index, :show
@@ -39,11 +40,14 @@ class WorkPackagesController < ApplicationController
before_action :load_and_authorize_in_optional_project,
:check_allowed_export,
:protect_from_unauthorized_export, only: :index
- authorization_checked! :index, :show
+ authorization_checked! :index, :show, :export_dialog
before_action :load_and_validate_query, only: :index, unless: -> { request.format.html? }
before_action :load_work_packages, only: :index, if: -> { request.format.atom? }
+ before_action :load_and_authorize_in_optional_project, only: :export_dialog, if: -> { request.format.html? }
+ before_action :load_query, only: :export_dialog, if: -> { request.format.html? }
+
def index
respond_to do |format|
format.html do
@@ -84,13 +88,17 @@ class WorkPackagesController < ApplicationController
end
end
+ def export_dialog
+ respond_with_dialog WorkPackages::Exports::ModalDialogComponent.new(query: @query, project: @project)
+ end
+
protected
def export_list(mime_type)
job_id = WorkPackages::Exports::ScheduleService
- .new(user: current_user)
- .call(query: @query, mime_type:, params:)
- .result
+ .new(user: current_user)
+ .call(query: @query, mime_type:, params:)
+ .result
if request.headers["Accept"]&.include?("application/json")
render json: { job_id: }
@@ -101,8 +109,8 @@ class WorkPackagesController < ApplicationController
def export_single(mime_type)
exporter = Exports::Register
- .single_exporter(WorkPackage, mime_type)
- .new(work_package, params)
+ .single_exporter(WorkPackage, mime_type)
+ .new(work_package, params)
export = exporter.export!
send_data(export.content, type: export.mime_type, filename: export.title)
@@ -144,19 +152,19 @@ class WorkPackagesController < ApplicationController
def journals
@journals ||= begin
- order =
- if current_user.wants_comments_in_reverse_order?
- Journal.arel_table["created_at"].desc
- else
- Journal.arel_table["created_at"].asc
- end
-
- work_package
- .journals
- .changing
- .includes(:user)
- .order(order).to_a
- end
+ order =
+ if current_user.wants_comments_in_reverse_order?
+ Journal.arel_table["created_at"].desc
+ else
+ Journal.arel_table["created_at"].asc
+ end
+
+ work_package
+ .journals
+ .changing
+ .includes(:user)
+ .order(order).to_a
+ end
end
def index_redirect_path
diff --git a/app/helpers/work_packages_controller_helper.rb b/app/helpers/work_packages_controller_helper.rb
index 55d9f019bc8..7b1cf15506c 100644
--- a/app/helpers/work_packages_controller_helper.rb
+++ b/app/helpers/work_packages_controller_helper.rb
@@ -35,7 +35,7 @@ module WorkPackagesControllerHelper
end
def check_allowed_export
- return unless params[:format] == "pdf" && params[:gantt] == "true"
+ return unless params[:format] == "pdf" && params[:pdf_export_type] == "gantt"
render_403 unless EnterpriseToken.allows_to?(:gantt_pdf_export)
end
@@ -52,6 +52,11 @@ module WorkPackagesControllerHelper
::Exports::Register.single_formats(WorkPackage).map(&:to_s)
end
+ def load_query
+ @query ||= retrieve_query(@project)
+ @query.name = params[:title] if params[:title].present?
+ end
+
def load_and_validate_query
@query ||= retrieve_query(@project)
@query.name = params[:title] if params[:title].present?
diff --git a/app/models/work_package/pdf_export/common.rb b/app/models/work_package/pdf_export/common.rb
index 8d566dd3b33..f9e95c2b98e 100644
--- a/app/models/work_package/pdf_export/common.rb
+++ b/app/models/work_package/pdf_export/common.rb
@@ -282,11 +282,11 @@ module WorkPackage::PDFExport::Common
end
def wants_report?
- options[:show_report]
+ options[:pdf_export_type] == "report"
end
def wants_gantt?
- options[:gantt]
+ options[:pdf_export_type] == "gantt"
end
def with_cover?
@@ -298,7 +298,7 @@ module WorkPackage::PDFExport::Common
end
def with_attachments?
- options[:show_images]
+ options[:show_images] == "true"
end
def build_pdf_filename(base)
diff --git a/app/models/work_package/pdf_export/work_package_list_to_pdf.rb b/app/models/work_package/pdf_export/work_package_list_to_pdf.rb
index 195e79cb417..8ea7d89301a 100644
--- a/app/models/work_package/pdf_export/work_package_list_to_pdf.rb
+++ b/app/models/work_package/pdf_export/work_package_list_to_pdf.rb
@@ -248,6 +248,6 @@ class WorkPackage::PDFExport::WorkPackageListToPdf < WorkPackage::Exports::Query
end
def with_images?
- options[:show_images]
+ options[:show_images] == "true"
end
end
diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rb
index 43adc367370..3cbf2786414 100644
--- a/config/initializers/permissions.rb
+++ b/config/initializers/permissions.rb
@@ -288,7 +288,7 @@ Rails.application.reloader.to_prepare do
wpt.permission :export_work_packages,
{
- work_packages: %i[index all]
+ work_packages: %i[index export_dialog all]
},
permissible_on: %i[work_package project],
dependencies: :view_work_packages
diff --git a/config/routes.rb b/config/routes.rb
index 44e5ae35f53..4960de17050 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -302,6 +302,7 @@ Rails.application.routes.draw do
get "/report/:detail" => "work_packages/reports#report_details"
get "/report" => "work_packages/reports#report"
get "menu" => "work_packages/menus#show"
+ get "/export_dialog" => "work_packages#export_dialog"
end
# states managed by client-side routing on work_package#index
@@ -560,6 +561,7 @@ Rails.application.routes.draw do
controller: "work_packages/progress",
as: :work_package_progress
end
+ get "/export_dialog" => "work_packages#export_dialog", on: :collection, as: "export_dialog"
# states managed by client-side (angular) routing on work_package#show
get "/" => "work_packages#index", on: :collection, as: "index"
@@ -569,7 +571,7 @@ Rails.application.routes.draw do
get "(/*state)" => "work_packages#show", on: :member, as: "", constraints: { id: /\d+/, state: /(?!shares).+/ }
get "/share_upsale" => "work_packages#index", on: :collection, as: "share_upsale"
get "/edit" => "work_packages#show", on: :member, as: "edit"
- end
+ end
resources :versions, only: %i[show edit update destroy] do
member do
diff --git a/frontend/src/app/shared/components/autocompleter/draggable-autocomplete/draggable-autocomplete.component.ts b/frontend/src/app/shared/components/autocompleter/draggable-autocomplete/draggable-autocomplete.component.ts
index 36b59bb82a8..35d0afcea98 100644
--- a/frontend/src/app/shared/components/autocompleter/draggable-autocomplete/draggable-autocomplete.component.ts
+++ b/frontend/src/app/shared/components/autocompleter/draggable-autocomplete/draggable-autocomplete.component.ts
@@ -61,6 +61,9 @@ export class DraggableAutocompleteComponent extends UntilDestroyedMixin implemen
/** Label to display drag&drop area */
@Input() dragAreaLabel = '';
+ /** Name of drag&drop area group */
+ @Input() dragAreaName = 'columns';
+
/** Decide whether to bind the component to the component or to the body */
/** Binding to the component in case the component is inside a Primer Dialog which uses popover */
@Input() appendToComponent = false;
@@ -96,19 +99,19 @@ export class DraggableAutocompleteComponent extends UntilDestroyedMixin implemen
// Setup groups
this.columnsGroup = this.dragula.createGroup(
- 'columns',
+ this.dragAreaName,
{ mirrorContainer: this.appendToComponent ? document.getElementById('op-draggable-autocomplete-container')! : document.body },
);
// Set cursor when dragging
- this.dragula.drag('columns')
+ this.dragula.drag(this.dragAreaName)
.pipe(this.untilDestroyed())
.subscribe(() => setBodyCursor('move', 'important'));
// Reset cursor when cancel or dropped
merge(
- this.dragula.drop('columns'),
- this.dragula.cancel('columns'),
+ this.dragula.drop(this.dragAreaName),
+ this.dragula.cancel(this.dragAreaName),
)
.pipe(this.untilDestroyed())
.subscribe(() => setBodyCursor('auto'));
@@ -147,7 +150,7 @@ export class DraggableAutocompleteComponent extends UntilDestroyedMixin implemen
ngOnDestroy():void {
super.ngOnDestroy();
- this.dragula.destroy('columns');
+ this.dragula.destroy(this.dragAreaName);
}
select(item:DraggableOption|undefined) {
diff --git a/frontend/src/app/shared/components/modals/export-modal/wp-table-export.modal.ts b/frontend/src/app/shared/components/modals/export-modal/wp-table-export.modal.ts
index 1dea6a7c263..982f1374884 100644
--- a/frontend/src/app/shared/components/modals/export-modal/wp-table-export.modal.ts
+++ b/frontend/src/app/shared/components/modals/export-modal/wp-table-export.modal.ts
@@ -160,7 +160,7 @@ export class WpTableExportModalComponent extends OpModalComponent implements OnI
}
isGanttOption(option:ExportOptions):boolean {
- return option.url.includes('&gantt=true');
+ return option.url.includes('pdf_export_type=gantt');
}
exportGantt(event:MouseEvent):void {
diff --git a/frontend/src/app/shared/components/op-context-menu/handlers/op-settings-dropdown-menu.directive.ts b/frontend/src/app/shared/components/op-context-menu/handlers/op-settings-dropdown-menu.directive.ts
index c2ed099b9fa..873c12c6edc 100644
--- a/frontend/src/app/shared/components/op-context-menu/handlers/op-settings-dropdown-menu.directive.ts
+++ b/frontend/src/app/shared/components/op-context-menu/handlers/op-settings-dropdown-menu.directive.ts
@@ -26,9 +26,7 @@
// See COPYRIGHT and LICENSE files for more details.
//++
-import {
- Directive, ElementRef, Injector, Input,
-} from '@angular/core';
+import { Directive, ElementRef, Injector, Input } from '@angular/core';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { AuthorisationService } from 'core-app/core/model-auth/model-auth.service';
import { OpContextMenuTrigger } from 'core-app/shared/components/op-context-menu/handlers/op-context-menu-trigger.directive';
@@ -45,10 +43,16 @@ import {
} from 'core-app/shared/components/editable-toolbar-title/editable-toolbar-title.component';
import { QuerySharingModalComponent } from 'core-app/shared/components/modals/share-modal/query-sharing.modal';
import { QueryGetIcalUrlModalComponent } from 'core-app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal';
-import { WpTableExportModalComponent } from 'core-app/shared/components/modals/export-modal/wp-table-export.modal';
import { SaveQueryModalComponent } from 'core-app/shared/components/modals/save-modal/save-query.modal';
import { QueryFormResource } from 'core-app/features/hal/resources/query-form-resource';
import isPersistedResource from 'core-app/features/hal/helpers/is-persisted-resource';
+import * as Turbo from '@hotwired/turbo';
+import {
+ WorkPackageViewColumnsService
+} from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-columns.service';
+import { StaticQueriesService } from 'core-app/shared/components/op-view-select/op-static-queries.service';
+import { UrlParamsHelperService } from 'core-app/features/work-packages/components/wp-query/url-params-helper';
+import * as URI from 'urijs';
@Directive({
selector: '[opSettingsContextMenu]',
@@ -73,6 +77,9 @@ export class OpSettingsMenuDirective extends OpContextMenuTrigger {
readonly states:States,
readonly injector:Injector,
readonly querySpace:IsolatedQuerySpace,
+ readonly wpTableColumns:WorkPackageViewColumnsService,
+ readonly urlParamsHelper:UrlParamsHelperService,
+ readonly opStaticQueries:StaticQueriesService,
readonly I18n:I18nService,
) {
super(elementRef, opContextMenu);
@@ -161,6 +168,34 @@ export class OpSettingsMenuDirective extends OpContextMenuTrigger {
return false;
}
+ private addColumnsAndTitleToHref(href:string) {
+ const columns = this.wpTableColumns.getColumns();
+
+ const columnIds = columns.map((column) => column.id);
+
+ const url = URI(href);
+ // Remove current columns
+ url.removeSearch('columns[]');
+ url.addSearch('columns[]', columnIds);
+
+ // Add the query title for the export
+ const query = this.querySpace.query.value;
+ if (query) {
+ url.removeSearch('title');
+ url.addSearch('title', this.queryTitle(query));
+ }
+
+ return url.toString();
+ }
+
+ private queryTitle(query:QueryResource):string {
+ return isPersistedResource(query) ? query.name : this.staticQueryName(query);
+ }
+
+ protected staticQueryName(query:QueryResource):string {
+ return this.opStaticQueries.getStaticName(query);
+ }
+
private buildItems() {
this.items = [
{
@@ -298,9 +333,24 @@ export class OpSettingsMenuDirective extends OpContextMenuTrigger {
icon: 'icon-export',
onClick: ($event:JQuery.TriggeredEvent) => {
if (this.allowWorkPackageAction($event, 'representations')) {
- this.opModalService.show(WpTableExportModalComponent, this.injector);
+ // old angular export form: this.opModalService.show(WpTableExportModalComponent, this.injector);
+ // TODO: better way to get the export URL
+ const url = new URL(window.location.href);
+ url.pathname = `${url.pathname}/export_dialog`;
+ const href = this.addColumnsAndTitleToHref(url.toString());
+ // TODO: export angular=>fetch=>turbo in a utility function
+ fetch(href, {
+ method: 'GET',
+ headers: { Accept: 'text/vnd.turbo-stream.html' },
+ credentials: 'same-origin',
+ })
+ .then((r) => r.text())
+ .then((html) => Turbo.renderStreamMessage(html))
+ .catch(error => {
+ // TODO: error handling
+ console.error(error);
+ });
}
-
return true;
},
},
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/export/dialog.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/export/dialog.controller.ts
new file mode 100644
index 00000000000..e0046aa2b50
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/export/dialog.controller.ts
@@ -0,0 +1,27 @@
+import { Controller } from '@hotwired/stimulus';
+
+export default class DialogController extends Controller {
+ static targets = [
+ 'formatTab', 'submit',
+ ];
+
+ declare readonly formatTabTargets:HTMLInputElement[];
+ declare readonly submitTarget:HTMLInputElement;
+
+ formatChanged({ params: { format } }:{ params:{ format:string } }) {
+ this.formatTabTargets.forEach((element:HTMLElement) => {
+ if (element.getAttribute('data-format') === format) {
+ element.classList.remove('d-none');
+ this.adjustFormSubmitTarget(element);
+ } else {
+ element.classList.add('d-none');
+ }
+ });
+ }
+
+ private adjustFormSubmitTarget(element:HTMLElement) {
+ const form = element.querySelector('form');
+ const form_id = form?.getAttribute('id') as string;
+ this.submitTarget.setAttribute('form', form_id);
+ }
+}
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/export/form.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/export/form.controller.ts
new file mode 100644
index 00000000000..b673ef68fd5
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/export/form.controller.ts
@@ -0,0 +1,52 @@
+import { Controller } from '@hotwired/stimulus';
+
+export default class FormController extends Controller<HTMLFormElement> {
+ submitForm(evt:CustomEvent) {
+ evt.preventDefault(); // Don't submit
+ const formatURL = this.element.getAttribute('action')
+ const searchParams = this.getExportParams()
+ const exportURL = `${formatURL}?${searchParams.toString()}`;
+ fetch(exportURL, {
+ method: 'GET',
+ headers: { Accept: 'application/json' },
+ credentials: 'same-origin',
+ })
+ .then((r) => r.json())
+ .then((result:{ job_id:string }) => {
+ // TODO: implement with turbo and open job modal
+ window.location.href = `/job_statuses/${result.job_id}`;
+ })
+ .catch(error => {
+ // TODO: error handling
+ alert(error.message);
+ });
+ }
+
+ private createSearchParams(params:Object) {
+ const searchParams = new URLSearchParams();
+ Object.entries(params).forEach(([key, values]) => {
+ if (Array.isArray(values)) {
+ values.forEach((value) => {
+ searchParams.append(key + '[]', value);
+ });
+ } else {
+ searchParams.append(key, values);
+ }
+ });
+ return searchParams;
+ }
+
+ private getExportParams() {
+ const data = new FormData(this.element)
+ const query = JSON.parse(data.get('query') as string)
+ for (let [key, value] of (data as any)) {
+ // Skip hidden fields
+ if (['query', 'utf8', 'authenticity_token'].includes(key)) {
+ continue
+ }
+ query[key] = (key === 'columns') ? value.split(' ') : value
+ }
+ const formatURL = this.element.getAttribute('action')
+ return this.createSearchParams(query);
+ }
+}
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/export/pdf/settings.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/export/pdf/settings.controller.ts
new file mode 100644
index 00000000000..0fcdd5f2237
--- /dev/null
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/export/pdf/settings.controller.ts
@@ -0,0 +1,27 @@
+import { Controller } from '@hotwired/stimulus';
+
+export default class PDFExportSettingsController extends Controller {
+ static targets = [
+ 'fields',
+ ];
+
+ declare readonly fieldsTargets:HTMLInputElement[];
+
+ private silenceFormFields(element:HTMLElement, silence:boolean) {
+ element.querySelectorAll('input, select').forEach((input:HTMLInputElement) => {
+ input.disabled = silence;
+ });
+ }
+
+ typeChanged({ params: { name } }:{ params:{ name:string } }) {
+ this.fieldsTargets.forEach((element:HTMLElement) => {
+ if (element.getAttribute(`data-${name}`) === 'true') {
+ element.classList.remove('d-none');
+ this.silenceFormFields(element, false)
+ } else {
+ element.classList.add('d-none');
+ this.silenceFormFields(element, true)
+ }
+ });
+ }
+}
diff --git a/lib/api/v3/work_packages/work_package_collection_representer.rb b/lib/api/v3/work_packages/work_package_collection_representer.rb
index 55ffc56e791..822932e6d1a 100644
--- a/lib/api/v3/work_packages/work_package_collection_representer.rb
+++ b/lib/api/v3/work_packages/work_package_collection_representer.rb
@@ -269,7 +269,8 @@ module API
def representation_format_pdf
representation_format "pdf",
i18n_key: "pdf_overview_table",
- mime_type: "application/pdf"
+ mime_type: "application/pdf",
+ url_query_extras: "pdf_export_type=table"
end
def representation_format_pdf_report_with_images
@@ -277,7 +278,7 @@ module API
format: "pdf",
i18n_key: "pdf_report_with_images",
mime_type: "application/pdf",
- url_query_extras: "show_images=true&show_report=true"
+ url_query_extras: "pdf_export_type=report&show_images=true"
end
def representation_format_pdf_report
@@ -285,7 +286,7 @@ module API
format: "pdf",
i18n_key: "pdf_report",
mime_type: "application/pdf",
- url_query_extras: "show_report=true"
+ url_query_extras: "pdf_export_type=report"
end
def representation_format_pdf_gantt
@@ -295,7 +296,7 @@ module API
format: "pdf",
i18n_key: "pdf_gantt",
mime_type: "application/pdf",
- url_query_extras: "gantt=true"
+ url_query_extras: "pdf_export_type=gantt"
end
def representation_format_xls
diff --git a/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb
index 8c6089022d8..fd9ca4b5a7e 100644
--- a/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb
+++ b/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb
@@ -125,20 +125,20 @@ RSpec.describe API::V3::WorkPackages::WorkPackageCollectionRepresenter do
expected_query_params = query_params.merge(pageSize: 30, offset: 1)
JSON.parse([
{
- href: work_packages_path({ format: "pdf" }.merge(expected_query_params)),
+ href: work_packages_path({ format: "pdf", pdf_export_type: "table" }.merge(expected_query_params)),
type: "application/pdf",
identifier: "pdf",
title: I18n.t("export.format.pdf_overview_table")
},
{
- href: work_packages_path({ format: "pdf", show_images: true, show_report: true }
+ href: work_packages_path({ format: "pdf", pdf_export_type: "report", show_images: true }
.merge(expected_query_params)),
identifier: "pdf-with-descriptions",
type: "application/pdf",
title: I18n.t("export.format.pdf_report_with_images")
},
{
- href: work_packages_path({ format: "pdf", show_report: true }.merge(expected_query_params)),
+ href: work_packages_path({ format: "pdf", pdf_export_type: "report" }.merge(expected_query_params)),
identifier: "pdf-descr",
type: "application/pdf",
title: I18n.t("export.format.pdf_report")
@@ -175,20 +175,20 @@ RSpec.describe API::V3::WorkPackages::WorkPackageCollectionRepresenter do
expected_query_params = query_params.merge(pageSize: 30, offset: 1)
JSON.parse([
{
- href: project_work_packages_path(project, { format: "pdf" }.merge(expected_query_params)),
+ href: project_work_packages_path(project, { format: "pdf", pdf_export_type: "table" }.merge(expected_query_params)),
type: "application/pdf",
identifier: "pdf",
title: I18n.t("export.format.pdf_overview_table")
},
{
- href: project_work_packages_path(project, { format: "pdf", show_images: true, show_report: true }
+ href: project_work_packages_path(project, { format: "pdf", pdf_export_type: "report", show_images: true }
.merge(expected_query_params)),
type: "application/pdf",
identifier: "pdf-with-descriptions",
title: I18n.t("export.format.pdf_report_with_images")
},
{
- href: project_work_packages_path(project, { format: "pdf", show_report: true }.merge(expected_query_params)),
+ href: project_work_packages_path(project, { format: "pdf", pdf_export_type: "report" }.merge(expected_query_params)),
type: "application/pdf",
identifier: "pdf-descr",
title: I18n.t("export.format.pdf_report")
diff --git a/spec/models/work_packages/pdf_export/work_package_list_to_pdf_gantt_spec.rb b/spec/models/work_packages/pdf_export/work_package_list_to_pdf_gantt_spec.rb
index a1040f3d8ef..d8c94d92cf5 100644
--- a/spec/models/work_packages/pdf_export/work_package_list_to_pdf_gantt_spec.rb
+++ b/spec/models/work_packages/pdf_export/work_package_list_to_pdf_gantt_spec.rb
@@ -68,7 +68,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
create(:user,
member_with_permissions: { project => %w[view_work_packages export_work_packages] })
end
- let(:options) { { gantt: true, gantt_mode: "day", gantt_width: "wide", paper_size: "EXECUTIVE" } }
+ let(:options) { { pdf_export_type: "gantt", gantt_mode: "day", gantt_width: "wide", paper_size: "EXECUTIVE" } }
let(:query_attributes) { {} }
let(:column_names) { %w[id subject status] }
let!(:query) do
diff --git a/spec/models/work_packages/pdf_export/work_package_list_to_pdf_spec.rb b/spec/models/work_packages/pdf_export/work_package_list_to_pdf_spec.rb
index 4f542a0b4f5..7dc9d95ef0a 100644
--- a/spec/models/work_packages/pdf_export/work_package_list_to_pdf_spec.rb
+++ b/spec/models/work_packages/pdf_export/work_package_list_to_pdf_spec.rb
@@ -219,7 +219,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
end
describe "with a request for a PDF Report" do
- let(:options) { { show_report: true } }
+ let(:options) { { pdf_export_type: "report" } }
it "contains correct data" do
expect(pdf_strings).to eq [
@@ -236,7 +236,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
end
describe "with a request for a PDF Report with hierarchies" do
- let(:options) { { show_report: true } }
+ let(:options) { { pdf_export_type: "report" } }
let(:query_attributes) { { show_hierarchies: true } }
it "contains correct data" do
@@ -254,7 +254,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
end
describe "with a request for a PDF Report with sums" do
- let(:options) { { show_report: true } }
+ let(:options) { { pdf_export_type: "report" } }
let(:query_attributes) { { display_sums: true } }
it "contains correct data" do
@@ -275,7 +275,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
end
describe "with a request for a PDF Report grouped with sums" do
- let(:options) { { show_report: true } }
+ let(:options) { { pdf_export_type: "report" } }
let(:query_attributes) { { display_sums: true, group_by: "type" } }
it "contains correct data" do
@@ -298,7 +298,7 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageListToPdf do
end
describe "with a request for a PDF Report grouped by a custom field with sums" do
- let(:options) { { show_report: true } }
+ let(:options) { { pdf_export_type: "report" } }
let(:query_attributes) { { display_sums: true, group_by: list_custom_field.column_name } }
it "contains correct data" do