2021-07-20 03:33:28 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module BioEddieActions
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def create_edit_bio_eddie_activity(asset, current_user, started_editing)
|
|
|
|
action = case started_editing
|
|
|
|
when :start_editing
|
|
|
|
t('activities.file_editing.started')
|
|
|
|
when :finish_editing
|
|
|
|
t('activities.file_editing.finished')
|
|
|
|
end
|
|
|
|
return unless bio_eddie_asset_validation(asset)
|
|
|
|
|
|
|
|
bio_eddie_find_target_object(asset, current_user, 'edit', action)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_create_bio_eddie_activity(asset, current_user)
|
|
|
|
return unless bio_eddie_asset_validation(asset)
|
|
|
|
|
|
|
|
bio_eddie_find_target_object(asset, current_user, 'create')
|
|
|
|
end
|
|
|
|
|
2021-08-13 21:15:45 +08:00
|
|
|
def create_register_bio_eddie_activity(asset, current_user)
|
|
|
|
return unless bio_eddie_asset_validation(asset)
|
|
|
|
|
|
|
|
bio_eddie_find_target_object(asset, current_user, 'register')
|
|
|
|
end
|
|
|
|
|
2021-07-20 03:33:28 +08:00
|
|
|
def bio_eddie_asset_validation(asset)
|
|
|
|
asset && asset.file.metadata[:asset_type] == 'bio_eddie'
|
|
|
|
end
|
|
|
|
|
|
|
|
def bio_eddie_asset_type(asset, klass)
|
|
|
|
return true if asset.step_asset&.step.instance_of?(klass)
|
|
|
|
return true if asset.result_asset&.result.instance_of?(klass)
|
|
|
|
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def bio_eddie_find_target_object(asset, current_user, activity_type, action = nil)
|
|
|
|
if bio_eddie_asset_type(asset, Step)
|
|
|
|
bio_eddie_step_activity(asset, current_user, activity_type, action)
|
|
|
|
elsif bio_eddie_asset_type(asset, Result)
|
|
|
|
bio_eddie_result_activity(asset, current_user, activity_type, action)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def bio_eddie_step_activity(asset, current_user, activity, action = nil)
|
|
|
|
step = asset.step_asset&.step
|
|
|
|
asset_type = 'asset_name'
|
|
|
|
protocol = step&.protocol
|
|
|
|
|
|
|
|
return unless step && protocol
|
|
|
|
|
2021-08-13 21:15:45 +08:00
|
|
|
default_step_items = {
|
|
|
|
step: step.id,
|
|
|
|
step_position: { id: step.id, value_for: 'position_plus_one' },
|
|
|
|
asset_type => { id: asset.id, value_for: 'file_name' },
|
|
|
|
description: asset.blob.metadata['description'],
|
|
|
|
name: asset.blob.metadata['name']
|
|
|
|
}
|
2021-07-20 03:33:28 +08:00
|
|
|
|
|
|
|
default_step_items[:action] = action if action
|
|
|
|
if protocol.in_module?
|
|
|
|
project = protocol.my_module.experiment.project
|
|
|
|
team = project.team
|
|
|
|
type_of = "#{activity}_molecule_on_step".to_sym
|
|
|
|
message_items = { my_module: protocol.my_module.id }
|
|
|
|
else
|
|
|
|
type_of = "#{activity}_molecule_on_step_in_repository".to_sym
|
|
|
|
team = protocol.team
|
|
|
|
message_items = { protocol: protocol.id }
|
|
|
|
end
|
|
|
|
message_items = default_step_items.merge(message_items)
|
2021-08-13 21:15:45 +08:00
|
|
|
|
2021-07-20 03:33:28 +08:00
|
|
|
Activities::CreateActivityService
|
|
|
|
.call(activity_type: type_of,
|
|
|
|
owner: current_user,
|
|
|
|
subject: protocol,
|
|
|
|
team: team,
|
|
|
|
project: project,
|
|
|
|
message_items: message_items)
|
|
|
|
end
|
|
|
|
|
|
|
|
def bio_eddie_result_activity(asset, current_user, activity, action = nil)
|
|
|
|
result = asset.result_asset&.result
|
|
|
|
asset_type = 'asset_name'
|
|
|
|
my_module = result&.my_module
|
|
|
|
|
|
|
|
return unless result && my_module
|
|
|
|
|
|
|
|
message_items = {
|
|
|
|
result: result.id,
|
2021-08-13 21:15:45 +08:00
|
|
|
asset_type => { id: asset.id, value_for: 'file_name' },
|
|
|
|
description: asset.blob.metadata['description'],
|
|
|
|
name: asset.blob.metadata['name']
|
2021-07-20 03:33:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
message_items[:action] = action if action
|
|
|
|
Activities::CreateActivityService
|
2021-08-11 15:50:00 +08:00
|
|
|
.call(activity_type: "#{activity}_molecule_on_result".to_sym,
|
2021-07-20 03:33:28 +08:00
|
|
|
owner: current_user,
|
|
|
|
subject: result,
|
|
|
|
team: my_module.experiment.project.team,
|
|
|
|
project: my_module.experiment.project,
|
|
|
|
message_items: message_items)
|
|
|
|
end
|
|
|
|
end
|