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

Fix updating of IFC models (#8791)

Wieland Lindenthale31cdfbec250
diff --git a/docker/setup/preinstall-common.sh b/docker/setup/preinstall-common.sh
index a790bd6d3f7..56ce61d3fbf 100755
--- a/docker/setup/preinstall-common.sh
+++ b/docker/setup/preinstall-common.sh
@@ -32,7 +32,7 @@ tmpdir=$(mktemp -d)
cd $tmpdir
# Install XKT converter
-npm install xeokit/xeokit-gltf-to-xkt -g
+npm install @xeokit/[email protected] -g
# Install COLLADA2GLTF
wget --quiet https://github.com/KhronosGroup/COLLADA2GLTF/releases/download/v2.1.5/COLLADA2GLTF-v2.1.5-linux.zip
diff --git a/frontend/src/app/modules/bim/ifc_models/pages/viewer/styles/tooltips.sass b/frontend/src/app/modules/bim/ifc_models/pages/viewer/styles/tooltips.sass
index c793c401a69..ed4b546ff08 100644
--- a/frontend/src/app/modules/bim/ifc_models/pages/viewer/styles/tooltips.sass
+++ b/frontend/src/app/modules/bim/ifc_models/pages/viewer/styles/tooltips.sass
@@ -11,7 +11,7 @@
@extend %tooltip--reset-styles
@extend %tooltip--after
content: attr(data-tippy-content)
- // Here in the Xeokit viewer the toolbar alligns with the right border of the viewer's canvas. We need to make sure
+ // Here in the Xeokit viewer the toolbar aligns with the right border of the viewer's canvas. We need to make sure
// that the tooltips of the last button don't get cut off on the right
left: 0
@@ -19,4 +19,4 @@
&::before, &::after
@extend %tooltip--show
- @extend [data-tooltip].tooltip--bottom
\ No newline at end of file
+ @extend .tooltip--bottom
\ No newline at end of file
diff --git a/frontend/src/global_styles/content/_tooltips.sass b/frontend/src/global_styles/content/_tooltips.sass
index 8ea0f6b672c..83fcd462668 100644
--- a/frontend/src/global_styles/content/_tooltips.sass
+++ b/frontend/src/global_styles/content/_tooltips.sass
@@ -130,47 +130,47 @@ $advanced-tooltip--border: 1px solid #a7cbe1
white-space: normal
text-align: left
- &.tooltip--right
- @extend %tooltip--left-right
- &:before, &:after
- left: 100%
- &:before
- margin-left: -2px
- &:after
- margin-left: 10px
+.tooltip--right
+ @extend %tooltip--left-right
+ &:before, &:after
+ left: 100%
+ &:before
+ margin-left: -2px
+ &:after
+ margin-left: 10px
- &.tooltip--left
- @extend %tooltip--left-right
- &:before, &:after
- right: 100%
- &:before
- margin-right: -2px
- &:after
- margin-right: 10px
+.tooltip--left
+ @extend %tooltip--left-right
+ &:before, &:after
+ right: 100%
+ &:before
+ margin-right: -2px
+ &:after
+ margin-right: 10px
- &.tooltip--top
- @extend %tooltip--top-bottom
+.tooltip--top
+ @extend %tooltip--top-bottom
+ &:before, &:after
+ bottom: 100%
+ &:before
+ margin-bottom: $tooltip--arrow-size * -1 + 1
+ &:after
+ margin-bottom: 7px
+ &:hover
&:before, &:after
- bottom: 100%
- &:before
- margin-bottom: $tooltip--arrow-size * -1 + 1
- &:after
- margin-bottom: 7px
- &:hover
- &:before, &:after
- transform: translate(-50%, 0px)
+ transform: translate(-50%, 0px)
- &.tooltip--bottom
- @extend %tooltip--top-bottom
+.tooltip--bottom
+ @extend %tooltip--top-bottom
+ &:before, &:after
+ top: 100%
+ &:before
+ margin-top: $tooltip--arrow-size * -1 + 1
+ &:after
+ margin-top: 7px
+ &:hover
&:before, &:after
- top: 100%
- &:before
- margin-top: $tooltip--arrow-size * -1 + 1
- &:after
- margin-top: 7px
- &:hover
- &:before, &:after
- transform: translate(-50%, 0)
+ transform: translate(-50%, 0)
// tooltips for table content (TODO: legacy?)
table
diff --git a/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb b/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb
index a208ad12a63..371339a6e8d 100644
--- a/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb
+++ b/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb
@@ -44,30 +44,16 @@ module Bim
def index
@ifc_models = @ifc_models
- .includes(:project, :uploader)
+ .includes(:project, :uploader)
end
def new
@ifc_model = @project.ifc_models.build
-
- if OpenProject::Configuration.direct_uploads?
- @pending_upload = Attachment.create_pending_direct_upload(file_name: "model.ifc", author: current_user)
- @form = DirectFogUploader.direct_fog_hash(
- attachment: @pending_upload,
- success_action_redirect: direct_upload_finished_bcf_project_ifc_models_url
- )
- end
+ prepare_form(@ifc_model)
end
def edit
- if OpenProject::Configuration.direct_uploads?
- @pending_upload = Attachment.create_pending_direct_upload(file_name: "model.ifc", author: current_user)
- @form = DirectFogUploader.direct_fog_hash(
- attachment: @pending_upload,
- success_action_redirect: direct_upload_finished_bcf_project_ifc_models_url
- )
- session[:pending_ifc_model_ifc_model_id] = @ifc_model.id
- end
+ prepare_form(@ifc_model)
end
def show
@@ -86,7 +72,6 @@ module Bim
def direct_upload_finished
id = request.params[:key].scan(/\/file\/(\d+)\//).flatten.first
attachment = Attachment.pending_direct_uploads.where(id: id).first
-
if attachment.nil? # this should not happen
flash[:error] = "Direct upload failed."
@@ -101,23 +86,20 @@ module Bim
}
new_model = true
-
if session[:pending_ifc_model_ifc_model_id]
ifc_model = Bim::IfcModels::IfcModel.find_by id: session[:pending_ifc_model_ifc_model_id]
new_model = false
- service_result = update_service_class
- .new(user: current_user, model: ifc_model)
- .call(params.with_indifferent_access)
-
- @ifc_model = service_result.result
+ service_result = ::Bim::IfcModels::UpdateService
+ .new(user: current_user, model: ifc_model)
+ .call(params.with_indifferent_access)
else
service_result = ::Bim::IfcModels::CreateService
- .new(user: current_user)
- .call(params.with_indifferent_access)
+ .new(user: current_user)
+ .call(params.with_indifferent_access)
- @ifc_model = service_result.result
end
+ @ifc_model = service_result.result
session.delete :pending_ifc_model_title
session.delete :pending_ifc_model_is_default
@@ -126,11 +108,11 @@ module Bim
if service_result.success?
::Attachments::FinishDirectUploadJob.perform_later attachment.id
- if new_model
- flash[:notice] = t('ifc_models.flash_messages.upload_successful')
- else
- flash[:notice] = t(:notice_successful_update)
- end
+ flash[:notice] = if new_model
+ t('ifc_models.flash_messages.upload_successful')
+ else
+ t(:notice_successful_update)
+ end
redirect_to action: :index
else
@@ -144,12 +126,12 @@ module Bim
def create
combined_params = permitted_model_params
- .to_h
- .reverse_merge(project: @project)
+ .to_h
+ .reverse_merge(project: @project)
service_result = ::Bim::IfcModels::CreateService
- .new(user: current_user)
- .call(combined_params)
+ .new(user: current_user)
+ .call(combined_params)
@ifc_model = service_result.result
@@ -164,12 +146,12 @@ module Bim
def update
combined_params = permitted_model_params
- .to_h
- .reverse_merge(project: @project)
+ .to_h
+ .reverse_merge(project: @project)
- service_result = update_service_class
- .new(user: current_user, model: @ifc_model)
- .call(combined_params)
+ service_result = ::Bim::IfcModels::UpdateService
+ .new(user: current_user, model: @ifc_model)
+ .call(combined_params)
@ifc_model = service_result.result
@@ -189,40 +171,37 @@ module Bim
private
+ def prepare_form(ifc_model)
+ if OpenProject::Configuration.direct_uploads?
+ @pending_upload = Attachment.create_pending_direct_upload(file_name: "model.ifc", author: current_user)
+ @form = DirectFogUploader.direct_fog_hash(
+ attachment: @pending_upload,
+ success_action_redirect: direct_upload_finished_bcf_project_ifc_models_url
+ )
+ session[:pending_ifc_model_ifc_model_id] = ifc_model.id unless ifc_model.new_record?
+ end
+ end
+
def frontend_redirect(model_ids)
redirect_to bcf_project_frontend_path(models: JSON.dump(Array(model_ids)))
end
def find_all_ifc_models
@ifc_models = @project
- .ifc_models
- .includes(:attachments)
- .order("#{IfcModels::IfcModel.table_name}.created_at ASC")
+ .ifc_models
+ .includes(:attachments)
+ .order("#{IfcModels::IfcModel.table_name}.created_at ASC")
end
def permitted_model_params
- require_params.permit('title', 'ifc_attachment', 'is_default')
- end
-
- def require_params
- if OpenProject::Configuration.direct_uploads?
- params
- else
- params.require(:bim_ifc_models_ifc_model)
- end
+ params
+ .require(:bim_ifc_models_ifc_model)
+ .permit('title', 'ifc_attachment', 'is_default')
end
def find_ifc_model_object
@ifc_model = Bim::IfcModels::IfcModel.find_by(id: params[:id])
end
-
- def update_service_class
- if permitted_model_params[:ifc_attachment].present?
- ::Bim::IfcModels::UpdateWithConversionService
- else
- ::Bim::IfcModels::UpdateWithoutConversionService
- end
- end
end
end
end
diff --git a/modules/bim/app/services/bim/ifc_models/update_with_conversion_service.rb b/modules/bim/app/services/bim/ifc_models/update_service.rb
similarity index 84%
rename from modules/bim/app/services/bim/ifc_models/update_with_conversion_service.rb
rename to modules/bim/app/services/bim/ifc_models/update_service.rb
index 941f07f2875..1ca4c9961a0 100644
--- a/modules/bim/app/services/bim/ifc_models/update_with_conversion_service.rb
+++ b/modules/bim/app/services/bim/ifc_models/update_service.rb
@@ -28,16 +28,24 @@
module Bim
module IfcModels
- class UpdateWithConversionService < ::BaseServices::Update
+ class UpdateService < ::BaseServices::Update
protected
+ def before_perform(params)
+ @ifc_attachment_updated = params[:ifc_attachment].present?
+
+ super
+ end
+
def after_perform(service_result)
if service_result.success?
# As the attachments association does not have the autosave option, we need to remove the
# attachments ourselves
model.attachments.select(&:marked_for_destruction?).each(&:destroy)
- IfcConversionJob.perform_later(service_result.result)
+ if @ifc_attachment_updated
+ IfcConversionJob.perform_later(service_result.result)
+ end
end
service_result
diff --git a/modules/bim/app/services/bim/ifc_models/update_without_conversion_service.rb b/modules/bim/app/services/bim/ifc_models/update_without_conversion_service.rb
deleted file mode 100644
index f498e5aad3d..00000000000
--- a/modules/bim/app/services/bim/ifc_models/update_without_conversion_service.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-#-- copyright
-# OpenProject is a project management system.
-# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
-#
-# 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-2017 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.
-#+
-
-module Bim
- module IfcModels
- class UpdateWithoutConversionService < ::BaseServices::Update
- protected
-
- def after_perform(service_result)
- if service_result.success?
- # As the attachments association does not have the autosave option, we need to remove the
- # attachments ourselves
- model.attachments.select(&:marked_for_destruction?).each(&:destroy)
- end
-
- service_result
- end
- end
- end
-end
diff --git a/modules/bim/bin/setup_dev.sh b/modules/bim/bin/setup_dev.sh
index 4eb0ff2b333..23a630ac307 100755
--- a/modules/bim/bin/setup_dev.sh
+++ b/modules/bim/bin/setup_dev.sh
@@ -12,34 +12,34 @@ if [[ $EUID -ne 0 ]]; then
exit 1
fi
-# Install BIM specifics
-echo "-- (Re-)creating /usr/local/src/bim base folder --"
-rm -rf /usr/local/src/bim || true
-mkdir -p /usr/local/src/bim
-cd /usr/local/src/bim
+# Specifics for BIM edition
+wget -qO- https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
+wget -q https://packages.microsoft.com/config/debian/9/prod.list -O /etc/apt/sources.list.d/microsoft-prod.list
+apt-get update -qq
+apt-get install -y dotnet-runtime-3.1
+
+tmpdir=$(mktemp -d)
+cd $tmpdir
# Install COLLADA2GLTF
-echo "-- Downloading COLLADA2GLTF --"
wget --quiet https://github.com/KhronosGroup/COLLADA2GLTF/releases/download/v2.1.5/COLLADA2GLTF-v2.1.5-linux.zip
-unzip -fq COLLADA2GLTF-v2.1.5-linux.zip -d /usr/lib/COLLADA2GLTF
-ln -fs /usr/lib/COLLADA2GLTF/COLLADA2GLTF-bin /usr/local/bin/COLLADA2GLTF
-rm -rf COLLADA2GLTF-v2.1.5-linux.zip
+unzip -q COLLADA2GLTF-v2.1.5-linux.zip
+mv COLLADA2GLTF-bin "/usr/local/bin/COLLADA2GLTF"
# IFCconvert
-echo "-- Downloading IfcConvert --"
wget --quiet https://s3.amazonaws.com/ifcopenshell-builds/IfcConvert-v0.6.0-9bcd932-linux64.zip
-unzip -q IfcConvert-v0.6.0-9bcd932-linux64.zip -d /usr/local/src/bim/IfcConvert-v0.6.0-9bcd932-linux64
-ln -fs /usr/local/src/bim/IfcConvert-v0.6.0-9bcd932-linux64/IfcConvert /usr/local/bin/IfcConvert
-rm -rf IfcConvert-v0.6.0-9bcd932-linux64.zip
-
-echo "-- Downloading and building xeokit-metadata --"
+unzip -q IfcConvert-v0.6.0-9bcd932-linux64.zip
+mv IfcConvert "/usr/local/bin/IfcConvert"
wget --quiet https://github.com/bimspot/xeokit-metadata/releases/download/1.0.0/xeokit-metadata-linux-x64.tar.gz
tar -zxvf xeokit-metadata-linux-x64.tar.gz
chmod +x xeokit-metadata-linux-x64/xeokit-metadata
-cp -r xeokit-metadata-linux-x64/ /usr/lib/xeokit-metadata
-ln -fs /usr/lib/xeokit-metadata/xeokit-metadata /usr/local/bin/xeokit-metadata
-rm -rf xeokit-metadata-linux-x64.tar.gz
+cp -r xeokit-metadata-linux-x64/ "/usr/lib/xeokit-metadata"
+rm -f /usr/local/bin/xeokit-metadatarm -f /usr/local/bin/xeokit-metadata
+ln -s /usr/lib/xeokit-metadata/xeokit-metadata /usr/local/bin/xeokit-metadata
+
+cd /
+rm -rf $tmpdir
which IfcConvert
echo "✔ IfcConvert is in your path."
@@ -50,18 +50,6 @@ echo "✔ COLLADA2GLTF is in your path."
which xeokit-metadata
echo "✔ xeokit-metadata is in your path. (without .NET yet, see below)"
-echo "DONE - BUT! You still need to:
-
-1. Install the NPM dependency under your user account
-
- npm install xeokit/xeokit-gltf-to-xkt -g
-
-2. install your distribution's version of .NET core:
-
- Ubuntu:
- - With snap simply install the '.NET Runtime 3.1 (LTS)'
- - Add the DOTNET_ROOR environment variable to your .bashrc:
- export DOTNET_ROOT=/snap/dotnet-runtime-31/current
-
- Other OSes, check out and install runtime 3.1:
- https://dotnet.microsoft.com/download"
+echo "DONE - Now execute the following as your development user:
+ $ # Install XKT converter
+ $ npm install @xeokit/[email protected] -g"
diff --git a/modules/bim/spec/services/ifc_models/update_service_spec.rb b/modules/bim/spec/services/ifc_models/update_service_spec.rb
index 6ee78245de0..9a588baa70c 100644
--- a/modules/bim/spec/services/ifc_models/update_service_spec.rb
+++ b/modules/bim/spec/services/ifc_models/update_service_spec.rb
@@ -114,10 +114,10 @@ describe Bim::IfcModels::UpdateService do
context 'if the attachment is altered' do
let(:attachment_marked_for_destruction) { true }
- before do
- allow(ifc_attachment)
- .to receive(:new_record?)
- .and_return(true)
+ let(:call_attributes) do
+ { name: 'Some name',
+ identifier: 'Some identifier',
+ ifc_attachment: ifc_attachment }
end
it 'schedules conversion job' do