|
|
|
@ -1,5 +1,3 @@ |
|
|
|
|
#-- encoding: UTF-8 |
|
|
|
|
|
|
|
|
|
#-- copyright |
|
|
|
|
# OpenProject is an open source project management software. |
|
|
|
|
# Copyright (C) 2012-2021 the OpenProject GmbH |
|
|
|
@ -31,6 +29,8 @@ |
|
|
|
|
module Bim::Bcf |
|
|
|
|
module Viewpoints |
|
|
|
|
class SetAttributesService < ::BaseServices::SetAttributes |
|
|
|
|
private |
|
|
|
|
|
|
|
|
|
def set_attributes(params) |
|
|
|
|
super |
|
|
|
|
|
|
|
|
@ -38,7 +38,7 @@ module Bim::Bcf |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def set_default_attributes(_params) |
|
|
|
|
model.json_viewpoint['guid'] = model.uuid |
|
|
|
|
viewpoint['guid'] = model.uuid |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def set_snapshot |
|
|
|
@ -46,10 +46,10 @@ module Bim::Bcf |
|
|
|
|
|
|
|
|
|
name = "snapshot.#{snapshot_extension}" |
|
|
|
|
file = OpenProject::Files |
|
|
|
|
.create_uploaded_file(name: name, |
|
|
|
|
content_type: snapshot_content_type, |
|
|
|
|
content: snapshot_binary_contents, |
|
|
|
|
binary: true) |
|
|
|
|
.create_uploaded_file(name: name, |
|
|
|
|
content_type: snapshot_content_type, |
|
|
|
|
content: snapshot_binary_contents, |
|
|
|
|
binary: true) |
|
|
|
|
|
|
|
|
|
# This might break once the service is also used |
|
|
|
|
# to update existing viewpoints as the snapshot method will |
|
|
|
@ -60,9 +60,9 @@ module Bim::Bcf |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def snapshot_data_complete? |
|
|
|
|
model.json_viewpoint['snapshot'] && |
|
|
|
|
viewpoint['snapshot'] && |
|
|
|
|
snapshot_extension && |
|
|
|
|
snapshot_base_64 && |
|
|
|
|
snapshot_base64 && |
|
|
|
|
snapshot_url_parts.length > 1 |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -70,9 +70,9 @@ module Bim::Bcf |
|
|
|
|
# Return nil when the extension is not within the specified set |
|
|
|
|
# which will lead to the snapshot not being created. |
|
|
|
|
# The contract will catch the error. |
|
|
|
|
return unless model.json_viewpoint['snapshot'] |
|
|
|
|
return unless viewpoint['snapshot'] |
|
|
|
|
|
|
|
|
|
case model.json_viewpoint['snapshot']['snapshot_type'] |
|
|
|
|
case viewpoint['snapshot']['snapshot_type'] |
|
|
|
|
when 'png' |
|
|
|
|
'image/png' |
|
|
|
|
when 'jpg' |
|
|
|
@ -81,11 +81,11 @@ module Bim::Bcf |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def snapshot_extension |
|
|
|
|
model.json_viewpoint['snapshot']['snapshot_type'] |
|
|
|
|
viewpoint['snapshot']['snapshot_type'] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def snapshot_base_64 |
|
|
|
|
model.json_viewpoint['snapshot']['snapshot_data'] |
|
|
|
|
def snapshot_base64 |
|
|
|
|
viewpoint['snapshot']['snapshot_data'] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def snapshot_binary_contents |
|
|
|
@ -93,7 +93,11 @@ module Bim::Bcf |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def snapshot_url_parts |
|
|
|
|
snapshot_base_64.match(/\Adata:([-\w]+\/[-\w+.]+)?;base64,(.*)/m) || [] |
|
|
|
|
snapshot_base64.match(/\Adata:([-\w]+\/[-\w+.]+)?;base64,(.*)/m) || [] |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def viewpoint |
|
|
|
|
model.json_viewpoint |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|