mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-04 14:44:26 +08:00
Merge pull request #1493 from mlorb/ml-sci-3033-v2
Add flag for archived tasks to experiment exporter [SCI-3033]
This commit is contained in:
commit
600f20486e
4 changed files with 17 additions and 10 deletions
|
@ -100,12 +100,6 @@ class Experiment < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def active_module_groups
|
||||
my_module_groups.joins(:my_modules)
|
||||
.where('my_modules.archived = ?', false)
|
||||
.distinct
|
||||
end
|
||||
|
||||
def active_modules
|
||||
my_modules.where(archived: false)
|
||||
end
|
||||
|
|
|
@ -10,6 +10,10 @@ class MyModuleGroup < ApplicationRecord
|
|||
optional: true
|
||||
has_many :my_modules, inverse_of: :my_module_group, dependent: :nullify
|
||||
|
||||
scope :without_archived_modules, (lambda do
|
||||
joins(:my_modules).where('my_modules.archived = ?', false).distinct
|
||||
end)
|
||||
|
||||
def deep_clone_to_experiment(current_user, experiment)
|
||||
clone = MyModuleGroup.new(
|
||||
created_by: created_by,
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
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
|
||||
|
||||
|
@ -11,6 +12,7 @@ module ModelExporters
|
|||
|
||||
def export_template_to_dir
|
||||
@asset_counter = 0
|
||||
@include_archived = false
|
||||
@experiment.transaction do
|
||||
@experiment.uuid ||= SecureRandom.uuid
|
||||
@dir_to_export = FileUtils.mkdir_p(
|
||||
|
@ -35,10 +37,17 @@ module ModelExporters
|
|||
end
|
||||
|
||||
def experiment
|
||||
if @include_archived
|
||||
my_modules = @experiment.my_modules
|
||||
my_module_groups = @experiment.my_module_groups
|
||||
else
|
||||
my_modules = @experiment.my_modules.active
|
||||
my_module_groups = @experiment.my_module_groups.without_archived_modules
|
||||
end
|
||||
return {
|
||||
experiment: @experiment,
|
||||
my_modules: @experiment.my_modules.map { |m| my_module(m) },
|
||||
my_module_groups: @experiment.my_module_groups
|
||||
my_modules: my_modules.map { |m| my_module(m) },
|
||||
my_module_groups: my_module_groups
|
||||
}, @assets_to_copy
|
||||
end
|
||||
|
||||
|
|
|
@ -37,9 +37,9 @@ describe TemplatesService do
|
|||
expect(tmpl_exp.name).to eq(demo_exp.name)
|
||||
expect(tmpl_exp.uuid).to_not eq(nil)
|
||||
expect(tmpl_exp.my_modules.pluck(:name))
|
||||
.to match_array(demo_exp.my_modules.pluck(:name))
|
||||
.to match_array(demo_exp.active_my_modules.pluck(:name))
|
||||
tmpl_tasks = tmpl_exp.my_modules
|
||||
demo_tasks = demo_exp.my_modules
|
||||
demo_tasks = demo_exp.active_my_modules
|
||||
demo_tasks.each do |demo_task|
|
||||
tmpl_task = tmpl_tasks.find_by_name(demo_task.name)
|
||||
expect(tmpl_task.name).to eq(demo_task.name)
|
||||
|
|
Loading…
Reference in a new issue