mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-21 07:26:15 +08:00
Merge pull request #1492 from okriuchykhin/ok_SCI_3037
Fix protocols in team export service [SCI-3037]
This commit is contained in:
commit
372ca31e42
|
@ -4,10 +4,8 @@ module ModelExporters
|
||||||
class ExperimentExporter < ModelExporter
|
class ExperimentExporter < ModelExporter
|
||||||
def initialize(experiment_id)
|
def initialize(experiment_id)
|
||||||
@include_archived = true
|
@include_archived = true
|
||||||
@experiment = Experiment.find_by_id(experiment_id)
|
super()
|
||||||
raise StandardError, 'Can not load experiment' unless @experiment
|
@experiment = Experiment.find(experiment_id)
|
||||||
|
|
||||||
@assets_to_copy = []
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def export_template_to_dir
|
def export_template_to_dir
|
||||||
|
@ -64,43 +62,6 @@ module ModelExporters
|
||||||
}
|
}
|
||||||
end
|
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)
|
def result(result)
|
||||||
@assets_to_copy.push(result.asset) if result.asset.present?
|
@assets_to_copy.push(result.asset) if result.asset.present?
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,14 @@ require 'fileutils'
|
||||||
|
|
||||||
module ModelExporters
|
module ModelExporters
|
||||||
class ModelExporter
|
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)
|
def copy_files(assets, attachment_name, dir_name)
|
||||||
assets.flatten.each do |a|
|
assets.flatten.each do |a|
|
||||||
next unless a.public_send(attachment_name).present?
|
next unless a.public_send(attachment_name).present?
|
||||||
|
@ -33,5 +41,42 @@ module ModelExporters
|
||||||
def export_to_dir
|
def export_to_dir
|
||||||
raise NotImplementedError, '#export_to_dir method not implemented.'
|
raise NotImplementedError, '#export_to_dir method not implemented.'
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,11 +3,8 @@
|
||||||
module ModelExporters
|
module ModelExporters
|
||||||
class TeamExporter < ModelExporter
|
class TeamExporter < ModelExporter
|
||||||
def initialize(team_id)
|
def initialize(team_id)
|
||||||
@team = Team.includes(:user_teams).find_by_id(team_id)
|
super()
|
||||||
raise StandardError, 'Can not load team' unless @team
|
@team = Team.includes(:user_teams).find(team_id)
|
||||||
|
|
||||||
@assets_to_copy = []
|
|
||||||
@tiny_mce_assets_to_copy = []
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def export_to_dir
|
def export_to_dir
|
||||||
|
@ -57,7 +54,9 @@ module ModelExporters
|
||||||
custom_fields: team.custom_fields,
|
custom_fields: team.custom_fields,
|
||||||
repositories: team.repositories.map { |r| repository(r) },
|
repositories: team.repositories.map { |r| repository(r) },
|
||||||
tiny_mce_assets: team.tiny_mce_assets,
|
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,
|
protocol_keywords: team.protocol_keywords,
|
||||||
projects: team.projects.map { |p| project(p) }
|
projects: team.projects.map { |p| project(p) }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue