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
use I18n, start adjusting dialog spec, start deconstructing angular dialog
as-op0a0ab1c77aec
diff --git a/app/components/work_packages/exports/modal_dialog_component.html.erb b/app/components/work_packages/exports/modal_dialog_component.html.erbindex adedc34b4ce..564b3bda15e 100644--- a/app/components/work_packages/exports/modal_dialog_component.html.erb+++ b/app/components/work_packages/exports/modal_dialog_component.html.erb@@ -1,5 +1,5 @@<%= render(Primer::Alpha::Dialog.new(- title: t('js.label_export'),+ title: I18n.t('export.dialog.title'),size: :xlarge,id: MODAL_ID,data: {@@ -11,8 +11,8 @@<% 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|+ <%= render(Primer::Beta::Text.new(tag: "legend", font_size: :normal, mb: 2, font_weight: :bold)) { I18n.t('export.dialog.format.label') } %>+ <%= render(Primer::Alpha::SegmentedControl.new(ml: 0, mb: 2, "aria-label": I18n.t('export.dialog.format.label'), size: :medium)) do |component|export_formats_settings.each do |format|component.with_item(label: format[:label], icon: format[:icon], selected: format[:selected],@@ -53,6 +53,6 @@"work-packages--export--dialog-target": "submit"},scheme: :primary, type: :submit,- form: "#{EXPORT_FORM_ID}-#{export_formats_settings.find { |e| e[:selected] }[:id]}")) { "Export" } %>+ form: "#{EXPORT_FORM_ID}-#{export_formats_settings.find { |e| e[:selected] }[:id]}")) { I18n.t('export.dialog.submit') } %><% end %><% end %>diff --git a/app/components/work_packages/exports/modal_dialog_component.rb b/app/components/work_packages/exports/modal_dialog_component.rbindex b00623470ff..93f374c1607 100644--- a/app/components/work_packages/exports/modal_dialog_component.rb+++ b/app/components/work_packages/exports/modal_dialog_component.rb@@ -52,12 +52,15 @@ module WorkPackagesdef export_formats_settings[- { label: "PDF", id: "pdf", icon: :"op-pdf",+ { id: "pdf", icon: :"op-pdf",+ label: I18n.t("export.dialog.format.options.pdf.label"),component: WorkPackages::Exports::PDF::ExportSettingsComponent,selected: true },- { label: "XLS", id: "xls", icon: :"op-xls",+ { id: "xls", icon: :"op-xls",+ label: I18n.t("export.dialog.format.options.xls.label"),component: WorkPackages::Exports::XLS::ExportSettingsComponent },- { label: "CSV", id: "csv", icon: :"op-file-csv",+ { id: "csv", icon: :"op-file-csv",+ label: I18n.t("export.dialog.format.options.csv.label"),component: WorkPackages::Exports::CSV::ExportSettingsComponent }]enddiff --git a/app/components/work_packages/exports/pdf/export_settings_component.html.erb b/app/components/work_packages/exports/pdf/export_settings_component.html.erbindex 555c4802047..81b072843ed 100644--- a/app/components/work_packages/exports/pdf/export_settings_component.html.erb+++ b/app/components/work_packages/exports/pdf/export_settings_component.html.erb@@ -9,7 +9,7 @@mb: 3,full_width: true,name: "pdf_export_type",- label: "PDF export type")) do |component|+ label: I18n.t("export.dialog.pdf.export_type.label"))) do |component|pdf_export_types.each do |entry|component.radio_button(label: entry[:label],value: entry[:value],@@ -57,9 +57,9 @@<hr/><%= render(Primer::Alpha::CheckBox.new(name: 'show_images',checked: true,- label: "Include images",+ label: I18n.t("export.dialog.pdf.include_images.label"),+ caption: I18n.t("export.dialog.pdf.include_images.caption"),disabled: current_pdf_export_type != "report",- caption: "Exclude images to reduce the size of the PDF export.",visually_hide_label: false)) %><% end %><% if gantt_chart_allowed? %>@@ -68,40 +68,21 @@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 %>++ <% gantt_selects.each do |entry| %>+ <%= render(Primer::Alpha::Select.new(+ name: entry[:name],+ label: entry[:label],+ caption: entry[:caption],+ size: :medium,+ disabled: current_pdf_export_type != "gantt",+ value: entry[:options].find { |e| e[:default] }[:value])+ ) do |component|+ entry[:options].each do |entry|+ component.option(label: entry[:label], value: entry[:value])+ end+ 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.rbindex 4cbc5a56f8d..093c3967135 100644--- a/app/components/work_packages/exports/pdf/export_settings_component.rb+++ b/app/components/work_packages/exports/pdf/export_settings_component.rb@@ -42,12 +42,15 @@ module WorkPackagesdef 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.",+ { value: "table",+ label: I18n.t("export.dialog.pdf.export_type.options.table.label"),+ caption: I18n.t("export.dialog.pdf.export_type.options.table.caption") },+ { value: "report",+ label: I18n.t("export.dialog.pdf.export_type.options.report.label"),+ caption: I18n.t("export.dialog.pdf.export_type.options.report.caption") },+ { value: "gantt",+ label: I18n.t("export.dialog.pdf.export_type.options.gantt.label"),+ caption: I18n.t("export.dialog.pdf.export_type.options.gantt.caption"),disabled: !gantt_chart_allowed? }]end@@ -58,21 +61,43 @@ module WorkPackages.map { |s| { id: s.name, name: s.caption } }end+ def gantt_selects+ [+ {+ name: "gantt_mode",+ label: I18n.t("export.dialog.pdf.gantt_zoom_levels.label"),+ caption: I18n.t("export.dialog.pdf.gantt_zoom_levels.caption"),+ options: gantt_zoom_levels+ },+ {+ name: "gantt_width",+ label: I18n.t("export.dialog.pdf.column_width.label"),+ options: gantt_column_widths+ },+ {+ name: "paper_size",+ label: I18n.t("export.dialog.pdf.paper_size.label"),+ caption: I18n.t("export.dialog.pdf.paper_size.caption"),+ options: pdf_paper_sizes+ }+ ]+ 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" }+ { label: t("export.dialog.pdf.gantt_zoom_levels.options.days"), value: "day", default: true },+ { label: t("export.dialog.pdf.gantt_zoom_levels.options.weeks"), value: "week" },+ { label: t("export.dialog.pdf.gantt_zoom_levels.options.months"), value: "month" },+ { label: t("export.dialog.pdf.gantt_zoom_levels.options.quarters"), value: "quarter" }]enddef 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" }+ { label: t("export.dialog.pdf.column_width.options.narrow"), value: "narrow" },+ { label: t("export.dialog.pdf.column_width.options.medium"), value: "medium", default: true },+ { label: t("export.dialog.pdf.column_width.options.wide"), value: "wide" },+ { label: t("export.dialog.pdf.column_width.options.very_wide"), value: "very_wide" }]enddiff --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 7f5799f862e..85f6d3edc9a 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@@ -17,8 +17,8 @@endcontainer.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.",+ label: I18n.t("export.dialog.xls.show_relations.label"),+ caption: I18n.t("export.dialog.xls.show_relations.caption"),visually_hide_label: false))endenddiff --git a/app/models/work_package/pdf_export/common.rb b/app/models/work_package/pdf_export/common.rbindex f9e95c2b98e..cadbc07230b 100644--- a/app/models/work_package/pdf_export/common.rb+++ b/app/models/work_package/pdf_export/common.rb@@ -298,7 +298,7 @@ module WorkPackage::PDFExport::Commonenddef with_attachments?- options[:show_images] == "true"+ options[:show_images] == "true" || options[:show_images] == "1"enddef 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.rbindex 8ea7d89301a..4b23f7f82b4 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::Queryenddef with_images?- options[:show_images] == "true"+ options[:show_images] == "true" || options[:show_images] == "1"endenddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex ec15f345508..4c15d55f800 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1742,6 +1742,57 @@ en:subproject: "Subproject: %{name}"export:+ dialog:+ title: "Export"+ submit: "Export"+ format:+ label: "File format"+ options:+ csv:+ label: "CSV"+ pdf:+ label: "PDF"+ xls:+ label: "XLS"+ pdf:+ export_type:+ label: "PDF export type"+ options:+ table:+ label: "Table"+ caption: "Export the work packages list in a table with the desired columns."+ report:+ label: "Report"+ caption: "Export the work package on a detailed report of all work packages in the list."+ gantt:+ label: "Gantt chart"+ caption: "Export the work packages list in a Gantt diagram view."+ include_images:+ label: "Include images"+ caption: "Exclude images to reduce the size of the PDF export."+ gantt_zoom_levels:+ label: "Zoom levels"+ caption: "Select what is the zoom level for dates displayed in the chart."+ options:+ days: "Days"+ weeks: "Weeks"+ months: "Months"+ quarters: "Quarters"+ column_width:+ label: "Table column width"+ options:+ narrow: "Narrow"+ medium: "Medium"+ wide: "Wide"+ very_wide: "Very wide"+ paper_size:+ label: "Paper size"+ caption: "Depending on the chart size more than one page might be exported."++ xls:+ show_relations:+ label: "Show relations"+ caption: "This option will create a duplicate of each work package for every relation this has with another work package."your_work_packages_export: "Your work packages export"succeeded: "The export has completed successfully."failed: "The export has failed: %{message}"diff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex 94c578f0020..37036cd3426 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -378,19 +378,6 @@ en:description: >Select the initial zoom level that should be shown when autozoom is not available.- export:- title: "Gantt chart PDF options"- button_export: "Export"- column_widths:- narrow: "Narrow"- medium: "Medium"- wide: "Wide"- very_wide: "Very wide"- options:- date_zoom: "Date zoom"- paper_size: "Paper size"- column_widths: "Column widths"-general_text_no: "no"general_text_yes: "yes"general_text_No: "No"diff --git a/frontend/src/app/core/turbo/turbo-requests.service.ts b/frontend/src/app/core/turbo/turbo-requests.service.tsindex 41532ce7c83..30d83c7dda9 100644--- a/frontend/src/app/core/turbo/turbo-requests.service.ts+++ b/frontend/src/app/core/turbo/turbo-requests.service.ts@@ -10,8 +10,8 @@ export class TurboRequestsService {}- public request(url:string):Promise<unknown> {- return fetch(url)+ public request(url:string, init:RequestInit = {}):Promise<unknown> {+ return fetch(url, init).then((response) => {if (!response.ok) {throw new Error(`HTTP ${response.status}: ${response.statusText}`);@@ -22,4 +22,12 @@ export class TurboRequestsService {.then((html) => renderStreamMessage(html)).catch((error) => this.toast.addError(error as string));}++ public requestStream(url:string):Promise<unknown> {+ return this.request(url, {+ method: 'GET',+ headers: { Accept: 'text/vnd.turbo-stream.html' },+ credentials: 'same-origin',+ });+ }}diff --git a/frontend/src/app/shared/components/modals/export-modal/wp-table-export.modal.html b/frontend/src/app/shared/components/modals/export-modal/wp-table-export.modal.htmlindex 8eed57bdddc..3b7ab4fe554 100644--- a/frontend/src/app/shared/components/modals/export-modal/wp-table-export.modal.html+++ b/frontend/src/app/shared/components/modals/export-modal/wp-table-export.modal.html@@ -9,7 +9,7 @@<div class="spot-divider"></div><div class="spot-modal--body spot-container">- <ul *ngIf="exportOptions && !ganttOption" class="op-export-options op-export-options-grid" [ngClass]="{'-hidden': isLoading}">+ <ul *ngIf="exportOptions" class="op-export-options op-export-options-grid" [ngClass]="{'-hidden': isLoading}"><li*ngFor="let option of exportOptions"class="op-export-options--option"@@ -25,50 +25,8 @@</a></li></ul>- <div *ngIf="exportOptions && ganttOption" class="gantt-export-options">- <form class="form">- <section class="form--section">- <h3 class="form--section-title">{{text.ganttOptionSectionTitle}}</h3>- <div *ngFor="let field of ganttFieldsArray" class="form--field">- <label- for="{{field.id}}"- class="form--label">- {{ field.label }}- </label>- <div class="form--field-container">- <div class="form--select-container">- <select class="form--select"- [attr.id]="field.id"- [ngModelOptions]="{standalone: true}"- [(ngModel)]="field.value">- <option *ngFor="let option of field.options"- [textContent]="option.label"- [ngValue]="option.value">- </option>- </select>- </div>- </div>- </div>- </section>- <div>- <button class="button -primary" (click)="exportGantt($event)">{{text.ganttExport}}</button>- </div>- </form>- </div></div><div class="spot-action-bar hidden-for-mobile">-- <div *ngIf="ganttOption" class="spot-action-bar--left">- <button- type="button"- class="button"- (click)="closeGanttOptions($event)"- >- <op-icon icon-classes="button--icon icon-arrow-left1"></op-icon>- {{ text.backButton }}- </button>- </div>-<div class="spot-action-bar--right"><buttontype="button"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.tsindex 982f1374884..ad07e283cda 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@@ -19,7 +19,6 @@ import { OpModalLocalsToken } from 'core-app/shared/components/modal/modal.serviimport { QueryResource } from 'core-app/features/hal/resources/query-resource';import { StaticQueriesService } from 'core-app/shared/components/op-view-select/op-static-queries.service';import isPersistedResource from 'core-app/features/hal/helpers/is-persisted-resource';-import { WorkPackageViewTimelineService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-timeline.service';interface ExportLink extends HalLink {identifier:string;@@ -44,62 +43,12 @@ export class WpTableExportModalComponent extends OpModalComponent implements OnIpublic $element:HTMLElement;public exportOptions:ExportOptions[];- public ganttOption?:ExportOptions;-- public ganttFields = {- dates: {- id: 'gantt-option-mode',- label: this.I18n.t('js.gantt_chart.export.options.date_zoom'),- paramName: 'gantt_mode',- value: 'day',- options: [- { label: this.I18n.t('js.gantt_chart.zoom.days'), value: 'day' },- { label: this.I18n.t('js.gantt_chart.zoom.weeks'), value: 'week' },- { label: this.I18n.t('js.gantt_chart.zoom.months'), value: 'month' },- { label: this.I18n.t('js.gantt_chart.zoom.quarters'), value: 'quarter' },- ],- },- zoom: {- id: 'gantt-option-width',- label: this.I18n.t('js.gantt_chart.export.options.column_widths'),- paramName: 'gantt_width',- value: 'medium',- options: [- { label: this.I18n.t('js.gantt_chart.export.column_widths.narrow'), value: 'narrow' },- { label: this.I18n.t('js.gantt_chart.export.column_widths.medium'), value: 'medium' },- { label: this.I18n.t('js.gantt_chart.export.column_widths.wide'), value: 'wide' },- { label: this.I18n.t('js.gantt_chart.export.column_widths.very_wide'), value: 'very_wide' },- ],- },- paperSize: {- id: 'pdf-option-paper-size',- label: this.I18n.t('js.gantt_chart.export.options.paper_size'),- paramName: 'paper_size',- value: 'A4',- // supported page sizes: https://github.com/prawnpdf/pdf-core/blob/6017800c46ce6cb43e0c8c8904e5e08d8e90b259/lib/pdf/core/page_geometry.rb- options: [- { label: 'A4', value: 'A4' },- { 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' },- ],- },- };-- public ganttFieldsArray = Object.values(this.ganttFields);public text = {title: this.I18n.t('js.label_export'),closePopup: this.I18n.t('js.close_popup_title'),exportPreparing: this.I18n.t('js.label_export_preparing'),cancelButton: this.I18n.t('js.button_cancel'),- ganttOptionSectionTitle: this.I18n.t('js.gantt_chart.export.title'),- ganttExport: this.I18n.t('js.gantt_chart.export.button_export'),backButton: this.I18n.t('js.button_back'),};@@ -113,7 +62,6 @@ export class WpTableExportModalComponent extends OpModalComponent implements OnIreadonly wpTableColumns:WorkPackageViewColumnsService,readonly opStaticQueries:StaticQueriesService,readonly loadingIndicator:LoadingIndicatorService,- private wpViewTimeline:WorkPackageViewTimelineService,readonly toastService:ToastService,) {super(locals, cdRef, elementRef);@@ -144,43 +92,12 @@ export class WpTableExportModalComponent extends OpModalComponent implements OnIurl: this.addColumnsAndTitleToHref(format.href as string),};});- if (!this.wpViewTimeline.isVisible) {- options = options.filter((option) => !this.isGanttOption(option));- }return options;}triggerByOption(option:ExportOptions, event:MouseEvent):void {event.preventDefault();- if (this.isGanttOption(option)) {- this.ganttOption = option;- } else {- this.requestExport(option.url);- }- }-- isGanttOption(option:ExportOptions):boolean {- return option.url.includes('pdf_export_type=gantt');- }-- exportGantt(event:MouseEvent):void {- event.preventDefault();- if (this.ganttOption) {- this.requestExport(this.addGanttOptionsToHref(this.ganttOption.url));- }- }-- closeGanttOptions(event:MouseEvent):void {- event.preventDefault();- this.ganttOption = undefined;- }-- private addGanttOptionsToHref(href:string) {- const url = URI(href);- this.ganttFieldsArray.forEach((field) => {- url.addSearch(field.paramName, field.value);- });- return url.toString();+ this.requestExport(option.url);}/**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.tsindex 873c12c6edc..4fc090b6bd5 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@@ -53,6 +53,7 @@ import {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';+import { TurboRequestsService } from "core-app/core/turbo/turbo-requests.service";@Directive({selector: '[opSettingsContextMenu]',@@ -80,6 +81,7 @@ export class OpSettingsMenuDirective extends OpContextMenuTrigger {readonly wpTableColumns:WorkPackageViewColumnsService,readonly urlParamsHelper:UrlParamsHelperService,readonly opStaticQueries:StaticQueriesService,+ readonly turboRequests:TurboRequestsService,readonly I18n:I18nService,) {super(elementRef, opContextMenu);@@ -338,18 +340,7 @@ export class OpSettingsMenuDirective extends OpContextMenuTrigger {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);- });+ void this.turboRequests.requestStream(href);}return true;},diff --git a/spec/features/work_packages/export_spec.rb b/spec/features/work_packages/export_spec.rbindex 048386be960..44bc58f68bc 100644--- a/spec/features/work_packages/export_spec.rb+++ b/spec/features/work_packages/export_spec.rb@@ -33,319 +33,234 @@ RSpec.describe "work package export" dolet(:project) { create(:project_with_types, types: [type_a, type_b]) }let(:export_type) { "CSV" }let(:current_user) { create(:admin) }-let(:type_a) { create(:type, name: "Type A") }let(:type_b) { create(:type, name: "Type B") }-let(:wp1) { create(:work_package, project:, done_ratio: 25, type: type_a) }let(:wp2) { create(:work_package, project:, done_ratio: 0, type: type_a) }let(:wp3) { create(:work_package, project:, done_ratio: 0, type: type_b) }let(:wp4) { create(:work_package, project:, done_ratio: 0, type: type_a) }-let(:work_packages_page) { WorkPackagesPage.new(project) }let(:wp_table) { Pages::WorkPackagesTable.new(project) }- let(:columns) { Components::WorkPackages::Columns.new }- let(:filters) { Components::WorkPackages::Filters.new }- let(:group_by) { Components::WorkPackages::GroupBy.new }- let(:hierarchies) { Components::WorkPackages::Hierarchies.new }let(:settings_menu) { Components::WorkPackages::SettingsMenu.new }+ let(:export_sub_type) { nil }+ let(:expected_params) { {} }+ let(:expected_mime_type) { anything }let(:query) { create(:query, user: current_user, project:) }- let!(:query_tl) do- query = build(:query_with_view_gantt, user: current_user, project:)- query.column_names = ["id", "type", "subject"]- query.filters.clear- query.timeline_visible = true- query.timeline_zoom_level = "days"- query.name = "Query with Timeline"- query.save!- query- end+ let(:expected_columns) { query.displayable_columns.map { |c| c.name.to_s } - ["bcf_thumbnail"] }+ let(:default_params) { {} }before do- @download_list = DownloadList.new+ service_instance = instance_double(WorkPackages::Exports::ScheduleService)+ allow(WorkPackages::Exports::ScheduleService)+ .to receive(:new)+ .with(user: current_user)+ .and_return(service_instance)++ allow(service_instance)+ .to receive(:call)+ .with(query: anything, mime_type: expected_mime_type, params: has_mandatory_params(expected_params))+ .and_return(ServiceResult.success(result: "uuid of the export job"))+wp1wp2wp3wp4- login_as(current_user)- end-- subject { @download_list.refresh_from(page).latest_downloaded_content }-- def expect_export- settings_menu.open_and_choose "Export"- click_on export_type- expect_export_in_queue- end+ query.column_names = expected_columns+ query.save!- def expect_export_in_queue- # Expect to get a response regarding queuing- expect(page).to have_content I18n.t("js.job_status.generic_messages.in_queue"),- wait: 10- # Expect title- expect(page).to have_test_selector "job-status--header", text: I18n.t("export.your_work_packages_export")+ login_as(current_user)end- def perform!(expect_success = true)- begin- perform_enqueued_jobs- rescue StandardError- # nothing- end-- if expect_success- expect(page).to have_text("The export has completed successfully")+ RSpec::Matchers.define :has_mandatory_params do |expected|+ match do |actual|+ expected.count do |key, value|+ actual[key.to_sym] == value+ end == expected.sizeendend- def export!(expect_success = true)+ def open_export_dialog!+ wp_table.visit_query querywork_packages_page.ensure_loaded- expect_export- perform!(expect_success)+ settings_menu.open_and_choose I18n.t("js.toolbar.settings.export")+ click_on export_typeend- after do- DownloadList.clear+ def export!+ click_on I18n.t("export.dialog.submit")end- context "CSV export" do- context "with default filter" do- before do- work_packages_page.visit_index- filters.expect_filter_count 1- filters.open- end-- it "shows all work packages with the default filters", :js do- export!+ context "with Query options", :js do+ let(:export_type) { I18n.t("export.dialog.format.options.pdf.label") }+ let(:expected_mime_type) { :pdf }- expect(subject).to have_text(wp1.description)- expect(subject).to have_text(wp2.description)- expect(subject).to have_text(wp3.description)- expect(subject).to have_text(wp4.description)-- # results are ordered by ID (asc) and not grouped by type- expect(subject.scan(/Type (A|B)/).flatten).to eq %w(A A B A)- end+ before do+ open_export_dialog!+ end- it "shows all work packages grouped by", :js do- group_by.enable_via_menu "Type"+ # these values must be looped through the dialog into the export- wp_table.expect_work_package_listed(wp1)- wp_table.expect_work_package_listed(wp2)- wp_table.expect_work_package_listed(wp3)- wp_table.expect_work_package_listed(wp4)+ context "with hierarchies" do+ let(:expected_params) { { showHierarchies: "true" } }+ it "starts an export with hierarchies" do+ query.show_hierarchies = true+ query.save!export!-- expect(subject).to have_text(wp1.description)- expect(subject).to have_text(wp2.description)- expect(subject).to have_text(wp3.description)- expect(subject).to have_text(wp4.description)-- # grouped by type- expect(subject.scan(/Type (A|B)/).flatten).to eq %w(A A A B)end+ end- it "shows only the work package with the right progress if filtered this way", :js do- filters.add_filter_by "% Complete", "is", ["25"], "percentageDone"-- sleep 1- loading_indicator_saveguard-- wp_table.expect_work_package_listed(wp1)- wp_table.ensure_work_package_not_listed!(wp2, wp3)+ context "with sums" do+ let(:expected_params) { { showSums: "true" } }+ it "starts an export with sums" do+ query.display_sums = trueexport!-- expect(subject).to have_text(wp1.description)- expect(subject).to have_no_text(wp2.description)- expect(subject).to have_no_text(wp3.description)end+ end- it "shows only work packages of the filtered type", :js do- filters.add_filter_by "Type", "is (OR)", wp3.type.name-- expect(page).to have_no_content(wp2.description) # safeguard-- sleep(0.5)+ context "with grouping" do+ let(:expected_params) { { group_by: "project" } }+ it "starts an export grouped" do+ query.group_by = "project"export!-- expect(subject).to have_no_text(wp1.description)- expect(subject).to have_no_text(wp2.description)- expect(subject).to have_text(wp3.description)end+ end- it "exports selected columns", :js do- columns.add "% Complete"+ context "with subprojects" do+ let(:expected_params) { { includeSubprojects: "true" } }+ it "starts an export with subprojects" do+ query.include_subprojects = trueexport!-- expect(subject).to have_text("% Complete")- expect(subject).to have_text("25")endend+ end- describe "with a manually sorted query", :js do- let(:query) do- create(:query,- user: current_user,- project:)- end-- before do- OrderedWorkPackage.create(query:, work_package: wp4, position: 0)- OrderedWorkPackage.create(query:, work_package: wp1, position: 1)- OrderedWorkPackage.create(query:, work_package: wp2, position: 2)- OrderedWorkPackage.create(query:, work_package: wp3, position: 3)-- query.add_filter("manual_sort", "ow", [])- query.sort_criteria = [[:manual_sorting, "asc"]]- query.save!- end+ context "with CSV export", :js do+ let(:export_type) { I18n.t("export.dialog.format.options.csv.label") }+ let(:expected_mime_type) { :csv }+ let(:expected_params) { default_params }- it "returns the correct number of work packages" do- wp_table.visit_query query- wp_table.expect_work_package_listed(wp1, wp2, wp3, wp4)- wp_table.expect_work_package_order(wp4, wp1, wp2, wp3)+ before do+ open_export_dialog!+ end- export!+ it "exports a csv" do+ export!+ end+ end- expect(page).to have_css(".job-status--modal .icon-checkmark", wait: 10)- expect(page).to have_content("The export has completed successfully.")+ context "with XLS export", :js do+ let(:export_type) { I18n.t("export.dialog.format.options.xls.label") }+ let(:expected_mime_type) { :xls }+ let(:expected_params) { default_params }- expect(subject).to have_text(wp1.description)- expect(subject).to have_text(wp2.description)- expect(subject).to have_text(wp3.description)- expect(subject).to have_text(wp4.description)+ before do+ open_export_dialog!+ end- # results are ordered by ID (asc) and not grouped by type- expect(subject.scan(/WorkPackage No\. \d+,/)).to eq([wp4, wp1, wp2, wp3].map { |wp| "#{wp.subject}," })- end+ it "exports a xls" do+ export!endendcontext "PDF export", :js do+ let(:expected_mime_type) { :pdf }+before do- query.column_names = query.displayable_columns.map { |c| c.name.to_s } - ["bcf_thumbnail"]- query.save!- allow_any_instance_of(WorkPackage::PDFExport::WorkPackageListToPdf)- .to receive(:export!)- .and_return(- Exports::Result.new(format: :pdf,- title: "foo",- content: Tempfile.new("something"),- mime_type: "application/pdf")- )+ open_export_dialog!endcontext "table" do- let(:export_type) { I18n.t("export.format.pdf_overview_table") }-- context "with many columns" do- before do- # Despite attempts to provoke the error by having a lot of columns, the pdf- # is still being drawn successfully. We thus have to fake the error.- allow_any_instance_of(WorkPackage::PDFExport::WorkPackageListToPdf)- .to receive(:export!)- .and_raise(I18n.t(:error_pdf_export_too_many_columns))- end-- it "returns the error" do- wp_table.visit_query query- export!(false)- expect(page)- .to have_content(I18n.t(:error_pdf_export_too_many_columns), wait: 10)- end- end+ let(:export_type) { I18n.t("export.dialog.format.options.pdf.label") }+ let(:export_sub_type) { I18n.t("export.dialog.pdf.export_type.options.table.label") }+ let(:expected_params) { default_params.merge({ pdf_export_type: "table" }) }it "exports a pdf table" do- wp_table.visit_query query+ choose export_sub_typeexport!endendcontext "report" do- let(:export_type) { I18n.t("export.format.pdf_report") }+ let(:export_type) { I18n.t("export.dialog.format.options.pdf.label") }+ let(:export_sub_type) { I18n.t("export.dialog.pdf.export_type.options.report.label") }- it "exports a pdf report" do- wp_table.visit_query query- export!+ context "with image" do+ let(:expected_params) { default_params.merge({ pdf_export_type: "report", show_images: "1" }) }++ it "exports a pdf report with image by default" do+ choose export_sub_type+ export!+ end++ it "exports a pdf report with checked input" do+ choose export_sub_type+ check I18n.t("export.dialog.pdf.include_images.label")+ export!+ endend- end- context "report with images" do- let(:export_type) { I18n.t("export.format.pdf_report_with_images") }+ context "without images" do+ let(:expected_params) { default_params.merge({ pdf_export_type: "report", show_images: "0" }) }- it "exports a pdf report with images" do- wp_table.visit_query query- export!+ it "exports a pdf report with checked input" do+ choose export_sub_type+ uncheck I18n.t("export.dialog.pdf.include_images.label")+ export!+ endendendcontext "gantt" do- let(:export_type) { I18n.t("export.format.pdf_gantt") }-- context "not in module gantt and not EE" do- it "has no gantt export" do- wp_table.visit_query query- work_packages_page.ensure_loaded- settings_menu.open_and_choose "Export"- expect(page).to have_no_content(export_type)+ let(:export_type) { I18n.t("export.dialog.format.options.pdf.label") }+ let(:export_sub_type) { I18n.t("export.dialog.pdf.export_type.options.gantt.label") }++ context "with EE not active" do+ it "gantt is disabled" do+ expect(page).to have_field("pdf_export_type_gantt", type: "radio", disabled: true)endend- context "in module gantt" do- let(:wp_table) { Pages::WorkPackagesTimeline.new(project) }+ context "with EE active", with_ee: %i[gantt_pdf_export] do+ let(:expected_params) { default_params.merge({ pdf_export_type: "gantt" }) }- context "EE not active" do- it "has no gantt export" do- wp_table.visit_query query_tl- settings_menu.open_and_choose "Export"- expect(page).to have_no_content(export_type)- end+ before do+ choose export_sub_typeend- context "EE active", with_ee: %i[gantt_pdf_export] do- it "exports a gantt pdf" do- wp_table.visit_query query_tl- settings_menu.open_and_choose "Export"- click_on export_type- expect(page).to have_content I18n.t("js.gantt_chart.export.title").upcase- click_on I18n.t("js.gantt_chart.export.button_export")- expect_export_in_queue- perform!- end+ it "exports a gantt chart pdf" do+ export!end- end- end- end- # Atom exports are not downloaded. In fact, it is not even a download but rather- # a feed one can follow.- context "Atom export", :js do- let(:export_type) { "Atom" }+ context "with zoom level" do+ let(:expected_params) { default_params.merge({ pdf_export_type: "gantt", gantt_mode: "week" }) }- context "with default filter" do- before do- work_packages_page.visit_index- filters.expect_filter_count 1- filters.open- end+ it "exports a pdf gantt chart by weeks" do+ select I18n.t("export.dialog.pdf.gantt_zoom_levels.options.weeks"), from: "gantt_mode"+ export!+ end+ end- it "shows an xml with work packages" do- settings_menu.open_and_choose "Export"+ context "with column width" do+ let(:expected_params) { default_params.merge({ pdf_export_type: "gantt", gantt_width: "very_wide" }) }- # The feed is opened in a new tab- new_window = window_opened_by { click_on export_type }+ it "exports a pdf gantt chart by column width" do+ select I18n.t("export.dialog.pdf.column_width.options.very_wide"), from: "gantt_width"+ export!+ end+ end- within_window new_window do- expect(page).to have_text(wp1.description)- expect(page).to have_text(wp2.description)- expect(page).to have_text(wp3.description)- expect(page).to have_text(wp4.description)+ context "with paper size" do+ let(:expected_params) { default_params.merge({ pdf_export_type: "gantt", paper_size: "A1" }) }++ it "exports a pdf gantt chart in A1" do+ select "A1", from: "paper_size"+ export!+ endendendend