mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-29 03:35:25 +08:00
generate custom repository when user is created [fixes SCI-2020]
This commit is contained in:
parent
ccba5d3eb3
commit
18eab358c7
1 changed files with 82 additions and 0 deletions
|
@ -25,6 +25,88 @@ module FirstTimeDataGenerator
|
|||
# Do nothing
|
||||
return unless team
|
||||
|
||||
# create custom repository samples
|
||||
repository = Repository.create(
|
||||
name: 'Samples',
|
||||
team: team,
|
||||
created_by: user
|
||||
)
|
||||
|
||||
# create list value column for sample types
|
||||
repository_column_sample_types = RepositoryColumn.create(
|
||||
repository: repository,
|
||||
created_by: user,
|
||||
data_type: :RepositoryListValue,
|
||||
name: 'Sample Types'
|
||||
)
|
||||
|
||||
# create list value column for sample groups
|
||||
repository_column_sample_groups = RepositoryColumn.create(
|
||||
repository: repository,
|
||||
created_by: user,
|
||||
data_type: :RepositoryListValue,
|
||||
name: 'Sample Groups'
|
||||
)
|
||||
|
||||
# create few list items for sample types
|
||||
repository_items_sample_types = []
|
||||
['Potato leaves', 'Tea leaves', 'Potato bug'].each do |name|
|
||||
item = RepositoryListItem.create(
|
||||
data: name,
|
||||
created_by: user,
|
||||
last_modified_by: user,
|
||||
repository_column: repository_column_sample_types,
|
||||
repository: repository
|
||||
)
|
||||
repository_items_sample_types << item
|
||||
end
|
||||
|
||||
# create few list items for sample groups
|
||||
repository_items_sample_groups = []
|
||||
%i(Fodder Nutrient Seed).each do |name|
|
||||
item = RepositoryListItem.create(
|
||||
data: name,
|
||||
created_by: user,
|
||||
last_modified_by: user,
|
||||
repository_column: repository_column_sample_groups,
|
||||
repository: repository
|
||||
)
|
||||
repository_items_sample_groups << item
|
||||
end
|
||||
|
||||
# Generate random custom respository sample names and assign sample types
|
||||
# and groups
|
||||
repository_sample_name = (0...3).map{65.+(rand(26)).chr}.join << '/'
|
||||
for i in 1..5
|
||||
repository_row = RepositoryRow.create(
|
||||
repository: repository,
|
||||
created_by: user,
|
||||
last_modified_by: user,
|
||||
name: repository_sample_name + i.to_s
|
||||
)
|
||||
RepositoryListValue.create(
|
||||
created_by: user,
|
||||
last_modified_by: user,
|
||||
repository_list_item: repository_items_sample_types[
|
||||
rand(0..(repository_items_sample_types.length - 1))
|
||||
],
|
||||
repository_cell_attributes: {
|
||||
repository_row: repository_row,
|
||||
repository_column: repository_column_sample_types
|
||||
}
|
||||
)
|
||||
RepositoryListValue.create(
|
||||
created_by: user,
|
||||
last_modified_by: user,
|
||||
repository_list_item: repository_items_sample_groups[
|
||||
rand(0..(repository_items_sample_groups.length - 1))
|
||||
],
|
||||
repository_cell_attributes: {
|
||||
repository_row: repository_row,
|
||||
repository_column: repository_column_sample_groups
|
||||
}
|
||||
)
|
||||
end
|
||||
# Create sample types
|
||||
SampleType.create(
|
||||
name: 'Potato leaves',
|
||||
|
|
Loading…
Reference in a new issue