2018-01-09 22:57:06 +08:00
|
|
|
module DelayedUploaderDemo
|
|
|
|
# Get asset from demo_files folder
|
2017-03-24 21:46:20 +08:00
|
|
|
def self.get_asset(user, team, file_name)
|
2016-11-14 22:55:44 +08:00
|
|
|
Asset.new(
|
|
|
|
file: File.open(
|
2018-01-09 22:57:06 +08:00
|
|
|
"#{Rails.root}/app/assets/demo_files/#{file_name}", 'r'
|
2016-11-14 22:55:44 +08:00
|
|
|
),
|
|
|
|
created_by: user,
|
2017-03-24 21:46:20 +08:00
|
|
|
team: team,
|
2016-11-14 22:55:44 +08:00
|
|
|
last_modified_by: user
|
|
|
|
)
|
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
|
2016-11-14 22:55:44 +08:00
|
|
|
# Generates results asset for given module, file_name assumes file is located
|
2018-01-09 22:57:06 +08:00
|
|
|
# in demo_files.
|
2016-11-14 22:55:44 +08:00
|
|
|
def self.generate_result_asset(
|
|
|
|
my_module:,
|
|
|
|
current_user:,
|
2017-03-24 21:46:20 +08:00
|
|
|
current_team:,
|
2016-11-14 22:55:44 +08:00
|
|
|
result_name:,
|
|
|
|
created_at: Time.now,
|
2019-02-27 00:46:35 +08:00
|
|
|
file_name:,
|
|
|
|
comment: nil
|
2016-11-14 22:55:44 +08:00
|
|
|
)
|
2017-03-24 21:46:20 +08:00
|
|
|
temp_asset = get_asset(current_user, current_team, file_name)
|
2016-11-14 22:55:44 +08:00
|
|
|
temp_result = Result.new(
|
|
|
|
created_at: created_at,
|
|
|
|
user: current_user,
|
|
|
|
my_module: my_module,
|
|
|
|
name: result_name,
|
|
|
|
asset: temp_asset
|
|
|
|
)
|
2016-07-21 19:11:15 +08:00
|
|
|
|
2016-11-14 22:55:44 +08:00
|
|
|
temp_result.save
|
|
|
|
temp_asset.save
|
2019-02-27 00:46:35 +08:00
|
|
|
|
|
|
|
# Generate comment if it exists
|
|
|
|
generate_result_comment(temp_result, current_user, comment) if comment
|
|
|
|
|
2017-01-25 17:24:50 +08:00
|
|
|
temp_asset.post_process_file(my_module.experiment.project.team)
|
2016-11-14 22:55:44 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
|
2016-11-14 22:55:44 +08:00
|
|
|
# Adds asset to existing step
|
2017-03-24 21:46:20 +08:00
|
|
|
def self.add_step_asset(step:, current_user:, current_team:, file_name:)
|
|
|
|
temp_asset =
|
2018-01-09 22:57:06 +08:00
|
|
|
DelayedUploaderDemo.get_asset(current_user, current_team, file_name)
|
2016-11-14 22:55:44 +08:00
|
|
|
step.assets << temp_asset
|
2017-01-25 17:24:50 +08:00
|
|
|
temp_asset.post_process_file(step.my_module.experiment.project.team)
|
2016-11-14 22:55:44 +08:00
|
|
|
end
|
2019-02-27 00:46:35 +08:00
|
|
|
|
|
|
|
def self.generate_result_comment(result, user, message, created_at = nil)
|
2019-02-28 14:29:25 +08:00
|
|
|
created_at ||= result.created_at
|
2019-02-27 00:46:35 +08:00
|
|
|
ResultComment.create(
|
|
|
|
user: user,
|
|
|
|
message: message,
|
|
|
|
created_at: created_at,
|
|
|
|
result: result
|
|
|
|
)
|
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|