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
Fix #33448: Format WP column "BCF snapshot" as string
Wieland Lindenthal4935d3a3d4dc
diff --git a/app/models/work_package/exporter/formatters.rb b/app/models/work_package/exporter/formatters.rbindex 0b6e86ac26a..d3b9358f777 100644--- a/app/models/work_package/exporter/formatters.rb+++ b/app/models/work_package/exporter/formatters.rb@@ -1,11 +1,11 @@module WorkPackage::Exportermodule Formatters+ @@formatters = %i[default costs estimated_hours].map do |key|+ Kernel.const_get("WorkPackage::Exporter::Formatters::#{key.to_s.camelize}")+ end+def self.all- @formatters ||= begin- %i[default costs estimated_hours].map do |key|- Kernel.const_get("WorkPackage::Exporter::Formatters::#{key.to_s.camelize}")- end- end+ @@formattersenddef self.keys@@ -13,7 +13,7 @@ module WorkPackage::Exporterenddef self.register(clz)- @formatters << clz+ @@formatters << clzend##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 06d5706bfed..4e79dd5af5d 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@@ -317,4 +317,10 @@ class WorkPackage::PDFExport::WorkPackageListToPdf < WorkPackage::Exporter::Basefalseendend++ def make_bcf_thumbnail_field_value(work_package)+ # A BCF viewpoint must have a snapshot. So it's safe to check for+ # viewpoint existence only.+ work_package.bcf_issue.viewpoints.any? ? 'X' : ''+ endenddiff --git a/modules/bim/lib/open_project/bim/engine.rb b/modules/bim/lib/open_project/bim/engine.rbindex e9bc9723bdc..0e23108e1c2 100644--- a/modules/bim/lib/open_project/bim/engine.rb+++ b/modules/bim/lib/open_project/bim/engine.rb@@ -213,6 +213,7 @@ module OpenProject::Bimconfig.to_prepare do::WorkPackage::Exporter.register_for_list(:bcf, OpenProject::Bim::BcfXml::Exporter)+ ::WorkPackage::Exporter::Formatters.register(OpenProject::Bim::WorkPackage::Exporter::Formatters::BcfThumbnail)::Queries::Register.filter ::Query, ::Bim::Queries::WorkPackages::Filter::BcfIssueAssociatedFilter::Queries::Register.column ::Query, ::Bim::Queries::WorkPackages::Columns::BcfThumbnailColumndiff --git a/modules/bim/lib/open_project/bim/work_package/exporter/formatters/bcf_thumbnail.rb b/modules/bim/lib/open_project/bim/work_package/exporter/formatters/bcf_thumbnail.rbnew file mode 100644index 00000000000..404be2ecc50--- /dev/null+++ b/modules/bim/lib/open_project/bim/work_package/exporter/formatters/bcf_thumbnail.rb@@ -0,0 +1,11 @@+module OpenProject::Bim::WorkPackage::Exporter::Formatters+ class BcfThumbnail < WorkPackage::Exporter::Formatters::Default+ def self.apply?(column)+ column.is_a? ::Bim::Queries::WorkPackages::Columns::BcfThumbnailColumn+ end++ def format(work_package, column, **options)+ work_package&.bcf_issue&.viewpoints&.any? ? "x" : ''+ end+ end+enddiff --git a/modules/bim/spec/lib/open_project/bim/work_package/exporter/formatters/bcf_thumbnail_spec.rb b/modules/bim/spec/lib/open_project/bim/work_package/exporter/formatters/bcf_thumbnail_spec.rbnew file mode 100644index 00000000000..9ff8f1c276a--- /dev/null+++ b/modules/bim/spec/lib/open_project/bim/work_package/exporter/formatters/bcf_thumbnail_spec.rb@@ -0,0 +1,63 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++require 'spec_helper'++describe OpenProject::Bim::WorkPackage::Exporter::Formatters::BcfThumbnail do+ let(:bcf_thumbnail_column) { ::Bim::Queries::WorkPackages::Columns::BcfThumbnailColumn.new("Some column name") }+ let(:not_bcf_thumbnail_column) { "This not a BcfThumbnailColumn" }++ describe '::apply?' do+ it 'returns TRUE for any other class' do+ expect(described_class.apply?(bcf_thumbnail_column)).to be_truthy+ end++ it 'returns FALSE for any other class' do+ expect(described_class.apply?(not_bcf_thumbnail_column)).to be_falsey+ end+ end++ describe '::format' do+ let(:work_package_with_viewpoint) { FactoryBot.create(:work_package) }+ let(:bcf_issue) { FactoryBot.create(:bcf_issue_with_viewpoint, work_package: work_package_with_viewpoint) }+ let(:work_package_without_viewpoint) { FactoryBot.create(:work_package) }++ before do+ bcf_issue+ end++ it 'returns "x" for work packages that have BCF issues with at least one viewpoint' do+ expect(described_class.new.format(work_package_with_viewpoint, bcf_thumbnail_column)).to eql('x')+ end++ it 'returns "" for work packages without viewpoints attached' do+ expect(described_class.new.format(work_package_without_viewpoint, bcf_thumbnail_column)).to eql('')+ end+ end+end+