Merge pull request #1492 from okriuchykhin/ok_SCI_3037

Fix protocols in team export service [SCI-3037]
This commit is contained in:
Alex Kriuchykhin 2019-02-15 13:08:45 +01:00 committed by GitHub
commit 372ca31e42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 47 deletions

View file

@ -4,10 +4,8 @@ module ModelExporters
class ExperimentExporter < ModelExporter
def initialize(experiment_id)
@include_archived = true
@experiment = Experiment.find_by_id(experiment_id)
raise StandardError, 'Can not load experiment' unless @experiment
@assets_to_copy = []
super()
@experiment = Experiment.find(experiment_id)
end
def export_template_to_dir
@ -64,43 +62,6 @@ module ModelExporters
}
end
def protocol(protocol)
{
protocol: protocol,
protocol_protocol_keywords: protocol.protocol_protocol_keywords,
steps: protocol.steps.map { |s| step(s) }
}
end
def step(step)
@assets_to_copy.push(step.assets.to_a) if step.assets.present?
{
step: step,
checklists: step.checklists.map { |c| checklist(c) },
step_comments: step.step_comments,
step_assets: step.step_assets,
assets: step.assets,
step_tables: step.step_tables,
tables: step.tables.map { |t| table(t) }
}
end
def checklist(checklist)
{
checklist: checklist,
checklist_items: checklist.checklist_items
}
end
def table(table)
return {} if table.nil?
table_json = table.as_json(except: %i(contents data_vector))
table_json['contents'] = Base64.encode64(table.contents)
table_json['data_vector'] = Base64.encode64(table.data_vector)
table_json
end
def result(result)
@assets_to_copy.push(result.asset) if result.asset.present?
{

View file

@ -4,6 +4,14 @@ require 'fileutils'
module ModelExporters
class ModelExporter
attr_accessor :assets_to_copy
attr_accessor :tiny_mce_assets_to_copy
def initialize
@assets_to_copy = []
@tiny_mce_assets_to_copy = []
end
def copy_files(assets, attachment_name, dir_name)
assets.flatten.each do |a|
next unless a.public_send(attachment_name).present?
@ -33,5 +41,42 @@ module ModelExporters
def export_to_dir
raise NotImplementedError, '#export_to_dir method not implemented.'
end
def protocol(protocol)
{
protocol: protocol,
protocol_protocol_keywords: protocol.protocol_protocol_keywords,
steps: protocol.steps.map { |s| step(s) }
}
end
def step(step)
@assets_to_copy.push(step.assets.to_a) if step.assets.present?
{
step: step,
checklists: step.checklists.map { |c| checklist(c) },
step_comments: step.step_comments,
step_assets: step.step_assets,
assets: step.assets,
step_tables: step.step_tables,
tables: step.tables.map { |t| table(t) }
}
end
def checklist(checklist)
{
checklist: checklist,
checklist_items: checklist.checklist_items
}
end
def table(table)
return {} if table.nil?
table_json = table.as_json(except: %i(contents data_vector))
table_json['contents'] = Base64.encode64(table.contents)
table_json['data_vector'] = Base64.encode64(table.data_vector)
table_json
end
end
end

View file

@ -3,11 +3,8 @@
module ModelExporters
class TeamExporter < ModelExporter
def initialize(team_id)
@team = Team.includes(:user_teams).find_by_id(team_id)
raise StandardError, 'Can not load team' unless @team
@assets_to_copy = []
@tiny_mce_assets_to_copy = []
super()
@team = Team.includes(:user_teams).find(team_id)
end
def export_to_dir
@ -57,7 +54,9 @@ module ModelExporters
custom_fields: team.custom_fields,
repositories: team.repositories.map { |r| repository(r) },
tiny_mce_assets: team.tiny_mce_assets,
protocols: team.protocols.where(my_module: nil).map { |pr| protocol(pr) },
protocols: team.protocols.where(my_module: nil).map do |pr|
protocol(pr)
end,
protocol_keywords: team.protocol_keywords,
projects: team.projects.map { |p| project(p) }
}