mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-12-09 13:46:21 +08:00
Fix protocols in team export service [SCI-3037]
This commit is contained in:
parent
61eb79bcfc
commit
445098fe45
4 changed files with 65 additions and 48 deletions
|
|
@ -3,10 +3,8 @@
|
|||
module ModelExporters
|
||||
class ExperimentExporter < ModelExporter
|
||||
def initialize(experiment_id)
|
||||
@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
|
||||
|
|
@ -49,48 +47,13 @@ module ModelExporters
|
|||
task_comments: my_module.task_comments,
|
||||
my_module_repository_rows: my_module.my_module_repository_rows,
|
||||
user_my_modules: my_module.user_my_modules,
|
||||
protocols: my_module.protocols.map { |pr| protocol(pr) },
|
||||
protocols: my_module.protocols.map do |pr|
|
||||
ProtocolExporter.new(pr.id).protocol
|
||||
end,
|
||||
results: my_module.results.map { |res| result(res) }
|
||||
}
|
||||
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?
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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,21 @@ module ModelExporters
|
|||
def export_to_dir
|
||||
raise NotImplementedError, '#export_to_dir method not implemented.'
|
||||
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
|
||||
|
|
|
|||
31
app/services/model_exporters/protocol_exporter.rb
Normal file
31
app/services/model_exporters/protocol_exporter.rb
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ModelExporters
|
||||
class ProtocolExporter < ModelExporter
|
||||
def initialize(protocol_id)
|
||||
super()
|
||||
@protocol = Protocol.find(protocol_id)
|
||||
end
|
||||
|
||||
def 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
|
||||
end
|
||||
end
|
||||
|
|
@ -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|
|
||||
ProtocolExporter.new(pr.id).protocol
|
||||
end,
|
||||
protocol_keywords: team.protocol_keywords,
|
||||
projects: team.projects.map { |p| project(p) }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue