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

[#54297] PDF export gantt chart options

as-op70ae8760576a
diff --git a/app/models/work_package/pdf_export/gantt.rb b/app/models/work_package/pdf_export/gantt.rb
index e47a275f191..3545c7c70e9 100644
--- a/app/models/work_package/pdf_export/gantt.rb
+++ b/app/models/work_package/pdf_export/gantt.rb
@@ -44,32 +44,34 @@
# 2. Paint the Gantt chart into the PDF
module WorkPackage::PDFExport::Gantt
+ GANTT_DAY_COLUMN_WIDTHS = [64, 32, 24, 18].freeze
+ GANTT_COLUMN_WIDTHS = [128, 64, 32, 24].freeze
+ GANTT_COLUMN_WIDTHS_NAMES = %w[very_wide wide medium narrow].freeze
+ GANTT_MODE_NAMES = %w[day month quarter].freeze
+ GANTT_MODE_DEFAULT = "day".freeze
+ GANTT_COLUMN_DEFAULT = "wide".freeze
+
def write_work_packages_gantt!(work_packages, id_wp_meta_map)
wps = work_packages.select { |work_package| work_package.start_date || work_package.due_date }
return if wps.empty?
- column_width, mode = gantt_settings(options[:zoom] || 1)
+ mode = gantt_settings_mode
+ column_width = gantt_settings_column_width(mode)
write_gantt(mode, column_width, id_wp_meta_map, wps)
end
private
- def gantt_settings(zoom)
- zoom_levels = [
- [:day, 32],
- [:day, 24],
- [:day, 18],
- [:month, 128],
- [:month, 64],
- [:month, 32],
- [:month, 24],
- [:quarter, 128],
- [:quarter, 64],
- [:quarter, 32],
- [:quarter, 24]
- ]
- mode, column_width = zoom_levels[zoom.to_i - 1].nil? ? zoom_levels[1] : zoom_levels[zoom.to_i - 1]
- [column_width, mode]
+ def gantt_settings_mode
+ mode = options[:gantt_mode] || GANTT_MODE_DEFAULT
+ mode = GANTT_MODE_DEFAULT if GANTT_MODE_NAMES.exclude?(mode)
+ mode.to_sym
+ end
+
+ def gantt_settings_column_width(mode)
+ width_index = GANTT_COLUMN_WIDTHS_NAMES.find_index(options[:gantt_width] || GANTT_COLUMN_DEFAULT)
+ width_index = GANTT_COLUMN_WIDTHS_NAMES.find_index(GANTT_COLUMN_DEFAULT) if width_index.nil?
+ mode == :day ? GANTT_DAY_COLUMN_WIDTHS[width_index] : GANTT_COLUMN_WIDTHS[width_index]
end
def gantt_builder(mode, column_width)
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index eb656690dda..5d4ffd60639 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -364,6 +364,19 @@ 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/shared/components/modals/export-modal/wp-table-export.modal.html b/frontend/src/app/shared/components/modals/export-modal/wp-table-export.modal.html
index ebf9cdb3d7c..8eed57bdddc 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" class="op-export-options op-export-options-grid" [ngClass]="{'-hidden': isLoading}">
+ <ul *ngIf="exportOptions && !ganttOption" class="op-export-options op-export-options-grid" [ngClass]="{'-hidden': isLoading}">
<li
*ngFor="let option of exportOptions"
class="op-export-options--option"
@@ -17,7 +17,7 @@
<a
[attr.href]="option.url"
class="op-export-options--option-link"
- (click)="triggerByLink(option.url, $event)"
+ (click)="triggerByOption(option, $event)"
id="export-{{ option.identifier }}"
>
<op-icon icon-classes="icon-export-{{ option.identifier }} icon-big"></op-icon>
@@ -25,34 +25,50 @@
</a>
</li>
</ul>
- <div *ngIf="exportOptions">
- GANTT-DEBUG:
- <div style="display: flex; flex-direction: row">
- <select class="debug-export-values" name="zoom">
- <option value="1">Zoom: 1 (Day, 32px)</option>
- <option selected value="2">Zoom: 2 (Day, 24px)</option>
- <option value="3">Zoom: 3 (Day, 18px)</option>
- <option value="4">Zoom: 4 (Month, 128px)</option>
- <option value="5">Zoom: 5 (Month, 64px)</option>
- <option value="6">Zoom: 6 (Month, 32px)</option>
- <option value="7">Zoom: 7 (Month, 24px)</option>
- <option value="8">Zoom: 8 (Quarter, 128px)</option>
- <option value="9">Zoom: 9 (Quarter, 64px)</option>
- <option value="10">Zoom: 10 (Quarter, 32px)</option>
- <option value="11">Zoom: 11 (Quarter, 24px)</option>
- </select>
- <select class="debug-export-values" name="paper_size">
- <option selected value="EXECUTIVE">Page size: EXECUTIVE</option>
- <option value="A4">Page size: A4</option>
- <option value="A3">Page size: A3</option>
- <option value="A2">Page size: A2</option>
- <option value="A1">Page size: A1</option>
- <option value="A0">Page size: A0</option>
- </select>
- </div>
+ <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">
<button
type="button"
diff --git a/frontend/src/app/shared/components/modals/export-modal/wp-table-export.modal.sass b/frontend/src/app/shared/components/modals/export-modal/wp-table-export.modal.sass
index 797df7b37c7..5b5d49be610 100644
--- a/frontend/src/app/shared/components/modals/export-modal/wp-table-export.modal.sass
+++ b/frontend/src/app/shared/components/modals/export-modal/wp-table-export.modal.sass
@@ -8,3 +8,7 @@
.export-options
&.-hidden
display: none
+
+ .gantt-export-options
+ display: flex
+ justify-content: center
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 2941d2af26c..c0c4684c114 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
@@ -3,7 +3,9 @@ import {
} from '@angular/core';
import { OpModalLocalsMap } from 'core-app/shared/components/modal/modal.types';
import { OpModalComponent } from 'core-app/shared/components/modal/modal.component';
-import { WorkPackageViewColumnsService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-columns.service';
+import {
+ WorkPackageViewColumnsService,
+} from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-columns.service';
import { WorkPackageCollectionResource } from 'core-app/features/hal/resources/wp-collection-resource';
import { HalLink } from 'core-app/features/hal/hal-link/hal-link';
import { I18nService } from 'core-app/core/i18n/i18n.service';
@@ -17,11 +19,18 @@ import { OpModalLocalsToken } from 'core-app/shared/components/modal/modal.servi
import { 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;
}
+interface ExportOptions {
+ identifier:string;
+ label:string;
+ url:string;
+}
+
/**
Modal for exporting work packages to different formats. The user may choose from a variety of formats (e.g. PDF and CSV).
The modal might also be used to only display the progress of an export. This will happen if a link for exporting is provided via the locals.
@@ -34,13 +43,62 @@ interface ExportLink extends HalLink {
export class WpTableExportModalComponent extends OpModalComponent implements OnInit {
public $element:HTMLElement;
- public exportOptions:{ identifier:string, label:string, url:string }[];
+ 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.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: 'EXECUTIVE',
+ // supported page sizes: https://github.com/prawnpdf/pdf-core/blob/6017800c46ce6cb43e0c8c8904e5e08d8e90b259/lib/pdf/core/page_geometry.rb
+ options: [
+ { label: 'Executive', value: 'EXECUTIVE' },
+ { label: 'Folio', value: 'FOLIO' },
+ { label: 'Letter', value: 'LETTER' },
+ { label: 'Tabloid', value: 'TABLOID' },
+ { label: 'A4', value: 'A4' },
+ { label: 'A3', value: 'A3' },
+ { label: 'A2', value: 'A2' },
+ { label: 'A1', value: 'A1' },
+ { label: 'A0', value: 'A0' },
+ ],
+ },
+ };
+ 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'),
};
constructor(
@@ -53,6 +111,7 @@ export class WpTableExportModalComponent extends OpModalComponent implements OnI
readonly wpTableColumns:WorkPackageViewColumnsService,
readonly opStaticQueries:StaticQueriesService,
readonly loadingIndicator:LoadingIndicatorService,
+ private wpViewTimeline:WorkPackageViewTimelineService,
readonly toastService:ToastService,
) {
super(locals, cdRef, elementRef);
@@ -74,7 +133,7 @@ export class WpTableExportModalComponent extends OpModalComponent implements OnI
}
private buildExportOptions(results:WorkPackageCollectionResource) {
- return results.representations.map((format) => {
+ let options = results.representations.map((format) => {
const link = format.$link as ExportLink;
return {
@@ -83,18 +142,45 @@ export class WpTableExportModalComponent extends OpModalComponent implements OnI
url: 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);
+ }
}
- triggerByLink(url:string, event:MouseEvent):void {
+ isGanttOption(option:ExportOptions):boolean {
+ return option.url.includes('&gantt=true');
+ }
+
+ exportGantt(event:MouseEvent):void {
event.preventDefault();
- document.querySelectorAll('.debug-export-values').forEach((el:HTMLSelectElement) => {
- const exportName = el.getAttribute('name');
- const exportValue = el.value;
- if (exportName && exportValue) {
- url += `&${exportName}=${exportValue}`;
- }
+ 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);
});
- this.requestExport(url);
+ return url.toString();
}
/**
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 636f6bbd2c5..3e25d0769ab 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
@@ -67,7 +67,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 } }
+ let(:options) { { gantt: true, gantt_mode: "day", gantt_width: "wide" } }
let(:query_attributes) { {} }
let(:column_names) { %w[id subject status] }
let!(:query) do