Merge pull request #9381 from opf/task/33448-work-package-exports-fail-when-column-bcf-snapshot-active

Fix #33448: Format WP column "BCF snapshot" as string
pull/9600/head
ulferts 3 years ago committed by GitHub
commit 59f691d325
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      app/models/work_package/exporter/formatters.rb
  2. 2
      app/models/work_package/exporter/formatters/default.rb
  3. 1
      modules/bim/lib/open_project/bim/engine.rb
  4. 11
      modules/bim/lib/open_project/bim/work_package/exporter/formatters/bcf_thumbnail.rb
  5. 62
      modules/bim/spec/lib/open_project/bim/work_package/exporter/formatters/bcf_thumbnail_spec.rb

@ -1,10 +1,18 @@
module WorkPackage::Exporter
module Formatters
def self.default_formatter_strings
@default_formatter_strings ||= %i[default costs estimated_hours].map do |key|
"WorkPackage::Exporter::Formatters::#{key.to_s.camelize}"
end
end
def self.all_formatter_strings
@all_formatter_strings ||= default_formatter_strings
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
all_formatter_strings.map do |formatter_string|
Kernel.const_get(formatter_string)
end
end
@ -12,8 +20,8 @@ module WorkPackage::Exporter
all.map(&:key)
end
def self.register(clz)
@formatters << clz
def self.register(class_string)
@all_formatter_strings = all_formatter_strings + [class_string]
end
##

@ -41,4 +41,4 @@ module WorkPackage::Exporter
end
end
end
end
end

@ -213,6 +213,7 @@ module OpenProject::Bim
config.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::BcfThumbnailColumn

@ -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
end

@ -0,0 +1,62 @@
#-- 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
Loading…
Cancel
Save