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
Add week support of Gantt PDF export.
Eric Guofd372a9db865
diff --git a/app/models/work_package/pdf_export/gantt.rb b/app/models/work_package/pdf_export/gantt.rbindex 5b9b827b60c..98ab9b03070 100644--- a/app/models/work_package/pdf_export/gantt.rb+++ b/app/models/work_package/pdf_export/gantt.rb@@ -47,7 +47,7 @@ module WorkPackage::PDFExport::GanttGANTT_DAY_COLUMN_WIDTHS = [64, 32, 24, 18].freezeGANTT_COLUMN_WIDTHS = [128, 64, 32, 24].freezeGANTT_COLUMN_WIDTHS_NAMES = %w[very_wide wide medium narrow].freeze- GANTT_MODE_NAMES = %w[day month quarter].freeze+ GANTT_MODE_NAMES = %w[day week month quarter].freezeGANTT_MODE_DEFAULT = "day".freezeGANTT_COLUMN_DEFAULT = "wide".freeze@@ -76,6 +76,8 @@ module WorkPackage::PDFExport::Ganttdef gantt_builder(mode, column_width)case mode+ when :week+ GanttBuilderWeeks.new(pdf, heading, column_width)when :monthGanttBuilderMonths.new(pdf, heading, column_width)when :quarterdiff --git a/app/models/work_package/pdf_export/gantt/gantt_builder.rb b/app/models/work_package/pdf_export/gantt/gantt_builder.rbindex 9b643b408f4..2e570a592ff 100644--- a/app/models/work_package/pdf_export/gantt/gantt_builder.rb+++ b/app/models/work_package/pdf_export/gantt/gantt_builder.rb@@ -243,6 +243,8 @@ module WorkPackage::PDFExport::Ganttbuild_header_cells_quarters(top, height, columns)when :monthsbuild_header_cells_months(top, height, columns)+ when :weeks+ build_header_cells_weeks(top, height, columns)when :daysbuild_header_cells_days(top, height, columns)else@@ -318,6 +320,13 @@ module WorkPackage::PDFExport::Gantt->(month_tuple) { Date.new(month_tuple[0], month_tuple[1], 1).strftime("%b") })end+ def build_header_cells_weeks(top, height, columns)+ build_header_cells_parts(columns, top, height,+ ->(date) { [date.year, date.cweek] },+ ->(date, week_tuple) { date.year == week_tuple[0] && date.cweek == week_tuple[1] },+ ->(week_tuple) { "W#{week_tuple[1]}" })+ end+# Builds the day row header cells for the given columns# @param [Float] top# @param [Float] heightdiff --git a/app/models/work_package/pdf_export/gantt/gantt_builder_weeks.rb b/app/models/work_package/pdf_export/gantt/gantt_builder_weeks.rbnew file mode 100644index 00000000000..9fe3bbf88bc--- /dev/null+++ b/app/models/work_package/pdf_export/gantt/gantt_builder_weeks.rb@@ -0,0 +1,69 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-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 WorkPackage::PDFExport::Gantt+ class GanttBuilderWeeks < GanttBuilder+ def build_column_dates_range(range)+ range+ .map { |d| [d.year, d.cweek] }+ .uniq+ .map { |year, week| Date.commercial(year, week, 1) }+ end++ def header_row_parts+ %i[years months weeks]+ end++ def work_packages_on_date(date, work_packages)+ work_packages.select { |work_package| wp_on_week?(work_package, date) }+ end++ def calc_start_offset(work_package, date)+ start_date = work_package.start_date || work_package.due_date+ return 0 if start_date <= date.beginning_of_week++ width_per_day = @column_width.to_f / 7+ day_in_week = (start_date - date.beginning_of_week).to_i+ day_in_week * width_per_day+ end++ def calc_end_offset(work_package, date)+ end_date = work_package.due_date || work_package.start_date+ return 0 if end_date >= date.end_of_week++ width_per_day = @column_width.to_f / 7+ day_in_week = (end_date - date.beginning_of_week).to_i+ @column_width - (day_in_week * width_per_day)+ end++ def wp_on_week?(work_package, date)+ start_date, end_date = wp_dates(work_package)+ (start_date.beginning_of_week..end_date.end_of_week).cover?(date)+ end+ end+enddiff --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 d1a894e2fe7..1dea6a7c263 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@@ -54,6 +54,7 @@ export class WpTableExportModalComponent extends OpModalComponent implements OnIvalue: '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' },],