mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-12-17 14:19:05 +08:00
Merge pull request #6264 from ivanscinote/SCI-9247-ensure-team-export-works-with-new-results
Ensure team export works with new results [SCI-9247]
This commit is contained in:
commit
c6272afe27
2 changed files with 67 additions and 39 deletions
|
|
@ -79,16 +79,27 @@ module ModelExporters
|
||||||
end
|
end
|
||||||
|
|
||||||
def result(result)
|
def result(result)
|
||||||
@assets_to_copy.push(result.asset) if result.asset.present?
|
@assets_to_copy.push(result.assets.to_a) if result.assets.present?
|
||||||
{
|
{
|
||||||
result: result,
|
result: result,
|
||||||
|
result_orderable_elements: result.result_orderable_elements.map { |e| result_orderable_element(e) },
|
||||||
result_comments: result.result_comments,
|
result_comments: result.result_comments,
|
||||||
asset: result_assets_data(result.asset),
|
result_assets: result.result_assets,
|
||||||
table: table(result.table),
|
assets: result.assets.map { |a| assets_data(a) }
|
||||||
result_text: result.result_text
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def result_orderable_element(element)
|
||||||
|
element_json = element.as_json
|
||||||
|
case element.orderable_type
|
||||||
|
when 'ResultText'
|
||||||
|
element_json['step_text'] = element.orderable.as_json
|
||||||
|
when 'ResultTable'
|
||||||
|
element_json['table'] = table(element.orderable.table)
|
||||||
|
end
|
||||||
|
element_json
|
||||||
|
end
|
||||||
|
|
||||||
def result_assets_data(asset)
|
def result_assets_data(asset)
|
||||||
return unless asset&.file&.attached?
|
return unless asset&.file&.attached?
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -245,9 +245,12 @@ class TeamImporter
|
||||||
res.result_comments.each do |comment|
|
res.result_comments.each do |comment|
|
||||||
comment.save! if update_annotation(comment.message)
|
comment.save! if update_annotation(comment.message)
|
||||||
end
|
end
|
||||||
next unless res.result_text
|
|
||||||
|
|
||||||
res.save! if update_annotation(res.result_text.text)
|
res.result_orderable_elements.each do |element|
|
||||||
|
next unless element.orderable_type == 'ResultText'
|
||||||
|
|
||||||
|
element.save! if update_annotation(element.orderable.text)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -750,10 +753,18 @@ class TeamImporter
|
||||||
|
|
||||||
def create_protocols(protocols_json, my_module = nil, team = nil,
|
def create_protocols(protocols_json, my_module = nil, team = nil,
|
||||||
user_id = nil)
|
user_id = nil)
|
||||||
|
|
||||||
|
sorted_protocols = protocols_json.sort_by { |p| p['id'] }
|
||||||
|
|
||||||
puts 'Creating protocols...'
|
puts 'Creating protocols...'
|
||||||
protocols_json.each do |protocol_json|
|
sorted_protocols.each do |protocol_json|
|
||||||
protocol = Protocol.new(protocol_json['protocol'])
|
protocol = Protocol.new(protocol_json['protocol'])
|
||||||
orig_protocol_id = protocol.id
|
orig_protocol_id = protocol.id
|
||||||
|
protocol.last_modified_by_id =
|
||||||
|
user_id || find_user(protocol.last_modified_by_id)
|
||||||
|
protocol.published_by_id =
|
||||||
|
user_id || find_user(protocol.published_by_id)
|
||||||
|
|
||||||
if protocol.name
|
if protocol.name
|
||||||
protocol_name_unique = false
|
protocol_name_unique = false
|
||||||
original_name = protocol.name
|
original_name = protocol.name
|
||||||
|
|
@ -777,6 +788,7 @@ class TeamImporter
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protocol.id = nil
|
protocol.id = nil
|
||||||
protocol.added_by_id = find_user(protocol.added_by_id)
|
protocol.added_by_id = find_user(protocol.added_by_id)
|
||||||
protocol.added_by_id ||= my_module.present? ? my_module.created_by_id : team.created_by_id
|
protocol.added_by_id ||= my_module.present? ? my_module.created_by_id : team.created_by_id
|
||||||
|
|
@ -785,6 +797,7 @@ class TeamImporter
|
||||||
protocol.restored_by_id = find_user(protocol.restored_by_id)
|
protocol.restored_by_id = find_user(protocol.restored_by_id)
|
||||||
protocol.my_module = my_module unless protocol.my_module_id.nil?
|
protocol.my_module = my_module unless protocol.my_module_id.nil?
|
||||||
protocol.skip_user_assignments = true
|
protocol.skip_user_assignments = true
|
||||||
|
protocol.previous_version_id = @protocol_mappings[protocol.previous_version_id] if protocol.previous_version_id
|
||||||
protocol.parent_id = @protocol_mappings[protocol.parent_id] unless protocol.parent_id.nil?
|
protocol.parent_id = @protocol_mappings[protocol.parent_id] unless protocol.parent_id.nil?
|
||||||
protocol.save!
|
protocol.save!
|
||||||
|
|
||||||
|
|
@ -879,38 +892,6 @@ class TeamImporter
|
||||||
user_id || find_user(result.last_modified_by_id)
|
user_id || find_user(result.last_modified_by_id)
|
||||||
result.archived_by_id = find_user(result.archived_by_id)
|
result.archived_by_id = find_user(result.archived_by_id)
|
||||||
result.restored_by_id = find_user(result.restored_by_id)
|
result.restored_by_id = find_user(result.restored_by_id)
|
||||||
|
|
||||||
if result_json['table'].present?
|
|
||||||
table = Table.new(result_json['table'])
|
|
||||||
orig_table_id = table.id
|
|
||||||
table.id = nil
|
|
||||||
table.created_by_id = user_id || find_user(table.created_by_id)
|
|
||||||
table.last_modified_by_id =
|
|
||||||
user_id || find_user(table.last_modified_by_id)
|
|
||||||
table.team = my_module.experiment.project.team
|
|
||||||
table.contents = Base64.decode64(table.contents)
|
|
||||||
table.data_vector = Base64.decode64(table.data_vector)
|
|
||||||
table.save!
|
|
||||||
@table_mappings[orig_table_id] = table.id
|
|
||||||
result.table = table
|
|
||||||
end
|
|
||||||
|
|
||||||
if result_json['asset'].present?
|
|
||||||
asset = create_asset(result_json['asset'],
|
|
||||||
my_module.experiment.project.team,
|
|
||||||
user_id)
|
|
||||||
result.asset = asset
|
|
||||||
end
|
|
||||||
|
|
||||||
if result_json['result_text'].present?
|
|
||||||
result_text = ResultText.new(result_json['result_text'])
|
|
||||||
orig_result_text_id = result_text.id
|
|
||||||
result_text.id = nil
|
|
||||||
result_text.result = result
|
|
||||||
result_text.save!
|
|
||||||
@result_text_mappings[orig_result_text_id] = result_text.id
|
|
||||||
end
|
|
||||||
|
|
||||||
result.save!
|
result.save!
|
||||||
@result_mappings[orig_result_id] = result.id
|
@result_mappings[orig_result_id] = result.id
|
||||||
@result_counter += 1
|
@result_counter += 1
|
||||||
|
|
@ -925,6 +906,42 @@ class TeamImporter
|
||||||
result_comment.result = result
|
result_comment.result = result
|
||||||
result_comment.save!
|
result_comment.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
result_json['result_orderable_elements'].each do |element_json|
|
||||||
|
if element_json['orderable_type'] == 'ResultText'
|
||||||
|
orderable = ResultText.new(element_json['result_text'])
|
||||||
|
orig_result_text_id = orderable.id
|
||||||
|
orderable.result_id = result.id
|
||||||
|
orderable.id = nil
|
||||||
|
orderable.save!
|
||||||
|
@result_text_mappings[orig_result_text_id] = orderable.id
|
||||||
|
elsif element_json['orderable_type'] == 'ResultTable'
|
||||||
|
table = Table.new(element_json['table'])
|
||||||
|
orig_table_id = table.id
|
||||||
|
table.id = nil
|
||||||
|
table.created_by_id = user_id || find_user(table.created_by_id)
|
||||||
|
table.last_modified_by_id =
|
||||||
|
user_id || find_user(table.last_modified_by_id)
|
||||||
|
table.team = my_module.experiment.project.team
|
||||||
|
table.contents = Base64.decode64(table.contents)
|
||||||
|
table.data_vector = Base64.decode64(table.data_vector)
|
||||||
|
table.save!
|
||||||
|
@table_mappings[orig_table_id] = table.id
|
||||||
|
orderable = ResultTable.create!(result: result, table: table)
|
||||||
|
end
|
||||||
|
ResultOrderableElement.create!(
|
||||||
|
position: element_json['position'],
|
||||||
|
result: result,
|
||||||
|
orderable: orderable
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
result_json['assets'].each do |asset_json|
|
||||||
|
asset = create_asset(asset_json,
|
||||||
|
my_module.experiment.project.team,
|
||||||
|
user_id)
|
||||||
|
ResultAsset.create!(result: result, asset: asset)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue