mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-06 20:05:55 +08:00
Merge pull request #4152 from aignatov-bio/ai-sci-6875-update-team-import-export
Update team import/export scripts [SCI-6875]
This commit is contained in:
commit
81773151a4
2 changed files with 43 additions and 21 deletions
|
@ -43,15 +43,26 @@ module ModelExporters
|
||||||
@assets_to_copy.push(step.assets.to_a) if step.assets.present?
|
@assets_to_copy.push(step.assets.to_a) if step.assets.present?
|
||||||
{
|
{
|
||||||
step: step,
|
step: step,
|
||||||
checklists: step.checklists.map { |c| checklist(c) },
|
step_orderable_elements: step.step_orderable_elements.map { |e| step_orderable_element(e) },
|
||||||
step_comments: step.step_comments,
|
step_comments: step.step_comments,
|
||||||
step_assets: step.step_assets,
|
step_assets: step.step_assets,
|
||||||
assets: step.assets.map { |a| assets_data(a) },
|
assets: step.assets.map { |a| assets_data(a) },
|
||||||
step_tables: step.step_tables,
|
|
||||||
tables: step.tables.map { |t| table(t) }
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def step_orderable_element(element)
|
||||||
|
element_json = element.as_json
|
||||||
|
case element.orderable_type
|
||||||
|
when 'StepText'
|
||||||
|
element_json['step_text'] = element.orderable.as_json
|
||||||
|
when 'Checklist'
|
||||||
|
element_json['checklist'] = checklist(element.orderable)
|
||||||
|
when 'StepTable'
|
||||||
|
element_json['table'] = table(element.orderable.table)
|
||||||
|
end
|
||||||
|
element_json
|
||||||
|
end
|
||||||
|
|
||||||
def assets_data(asset)
|
def assets_data(asset)
|
||||||
return unless asset.file.attached?
|
return unless asset.file.attached?
|
||||||
|
|
||||||
|
|
|
@ -808,27 +808,39 @@ class TeamImporter
|
||||||
step_comment.save!
|
step_comment.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
step_json['tables'].each do |table_json|
|
step_json['step_orderable_elements'].each do |element_json|
|
||||||
table = Table.new(table_json)
|
if element_json['step_text']
|
||||||
orig_table_id = table.id
|
orderable = StepText.new(element_json['step_text'])
|
||||||
table.id = nil
|
orderable.step_id = step.id
|
||||||
table.created_by_id = user_id || find_user(table.created_by_id)
|
orderable.id = nil
|
||||||
table.last_modified_by_id =
|
orderable.save!
|
||||||
user_id || find_user(table.last_modified_by_id)
|
elsif element_json['table']
|
||||||
table.team = protocol.team
|
table = Table.new(element_json['table'])
|
||||||
table.contents = Base64.decode64(table.contents)
|
orig_table_id = table.id
|
||||||
table.data_vector = Base64.decode64(table.data_vector)
|
table.id = nil
|
||||||
table.save!
|
table.created_by_id = user_id || find_user(table.created_by_id)
|
||||||
@table_mappings[orig_table_id] = table.id
|
table.last_modified_by_id =
|
||||||
StepTable.create!(step: step, table: table)
|
user_id || find_user(table.last_modified_by_id)
|
||||||
|
table.team = protocol.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 = StepTable.create!(step: step, table: table)
|
||||||
|
elsif element_json['checklist']
|
||||||
|
orderable = create_step_checklist(element_json['checklist'], step, user_id)
|
||||||
|
end
|
||||||
|
StepOrderableElement.create!(
|
||||||
|
position: element_json['position'],
|
||||||
|
step: step,
|
||||||
|
orderable: orderable
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
step_json['assets'].each do |asset_json|
|
step_json['assets'].each do |asset_json|
|
||||||
asset = create_asset(asset_json, protocol.team, user_id)
|
asset = create_asset(asset_json, protocol.team, user_id)
|
||||||
StepAsset.create!(step: step, asset: asset)
|
StepAsset.create!(step: step, asset: asset)
|
||||||
end
|
end
|
||||||
|
|
||||||
create_step_checklists(step_json['checklists'], step, user_id)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -915,8 +927,7 @@ class TeamImporter
|
||||||
asset
|
asset
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_step_checklists(step_checklists_json, step, user_id = nil)
|
def create_step_checklist(checklist_json, step, user_id = nil)
|
||||||
step_checklists_json.each do |checklist_json|
|
|
||||||
checklist = Checklist.new(checklist_json['checklist'])
|
checklist = Checklist.new(checklist_json['checklist'])
|
||||||
orig_checklist_id = checklist.id
|
orig_checklist_id = checklist.id
|
||||||
checklist.id = nil
|
checklist.id = nil
|
||||||
|
@ -937,7 +948,7 @@ class TeamImporter
|
||||||
user_id || find_user(checklist_item.last_modified_by_id)
|
user_id || find_user(checklist_item.last_modified_by_id)
|
||||||
checklist_item.save!
|
checklist_item.save!
|
||||||
end
|
end
|
||||||
end
|
checklist
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_reports(reports_json, team)
|
def create_reports(reports_json, team)
|
||||||
|
|
Loading…
Add table
Reference in a new issue