mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-29 03:01:58 +08:00
Rework molecule registration activities [SCI-5999]
This commit is contained in:
parent
12bb44147c
commit
56576960b0
7 changed files with 52 additions and 34 deletions
|
@ -16,7 +16,7 @@ class BioEddieAssetsController < ApplicationController
|
|||
create_create_bio_eddie_activity(asset, current_user)
|
||||
|
||||
if asset && bio_eddie_params[:object_type] == 'Step'
|
||||
log_registration_activity(asset) if bio_eddie_params[:schedule_for_registration] == 'true'
|
||||
create_register_bio_eddie_activity(asset, current_user) if bio_eddie_params[:schedule_for_registration] == 'true'
|
||||
render json: {
|
||||
html: render_to_string(partial: 'assets/asset.html.erb', locals: {
|
||||
asset: asset,
|
||||
|
@ -24,7 +24,7 @@ class BioEddieAssetsController < ApplicationController
|
|||
})
|
||||
}
|
||||
elsif asset && bio_eddie_params[:object_type] == 'Result'
|
||||
log_registration_activity(asset) if bio_eddie_params[:schedule_for_registration] == 'true'
|
||||
create_register_bio_eddie_activity(asset, current_user) if bio_eddie_params[:schedule_for_registration] == 'true'
|
||||
render json: { status: 'created' }, status: :ok
|
||||
else
|
||||
render json: asset.errors, status: :unprocessable_entity
|
||||
|
@ -37,7 +37,7 @@ class BioEddieAssetsController < ApplicationController
|
|||
create_edit_bio_eddie_activity(asset, current_user, :finish_editing)
|
||||
|
||||
if asset
|
||||
log_registration_activity(asset) if bio_eddie_params[:schedule_for_registration] == 'true'
|
||||
create_register_bio_eddie_activity(asset, current_user) if bio_eddie_params[:schedule_for_registration] == 'true'
|
||||
render json: { url: rails_representation_url(asset.medium_preview),
|
||||
id: asset.id,
|
||||
file_name: asset.blob.metadata['name'] }
|
||||
|
@ -46,6 +46,21 @@ class BioEddieAssetsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
asset = current_team.assets.find(bio_eddie_params[:id])
|
||||
|
||||
if asset
|
||||
create_delete_bio_eddie_activity(asset, current_user)
|
||||
if asset.destroy
|
||||
render json: { flash: I18n.t('assets.file_deleted', file_name: asset.file_name) }
|
||||
else
|
||||
render json: {}, status: :unprocessable_entity
|
||||
end
|
||||
else
|
||||
render json: { error: t('bio_eddie.no_molecules_found') }, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def license
|
||||
license_file_path = Rails.root.join('data/bioeddie/license.cxl')
|
||||
if File.file?(license_file_path)
|
||||
|
@ -130,19 +145,4 @@ class BioEddieAssetsController < ApplicationController
|
|||
def bio_eddie_params
|
||||
params.permit(:id, :description, :object_id, :object_type, :name, :image, :schedule_for_registration)
|
||||
end
|
||||
|
||||
def log_registration_activity(asset)
|
||||
Activities::CreateActivityService
|
||||
.call(
|
||||
activity_type: :register_molecule,
|
||||
owner: current_user,
|
||||
team: asset.team,
|
||||
project: asset&.my_module&.experiment&.project,
|
||||
subject: asset,
|
||||
message_items: {
|
||||
description: asset.blob.metadata['description'],
|
||||
name: asset.blob.metadata['name']
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,6 +29,12 @@ module BioEddieActions
|
|||
bio_eddie_find_target_object(asset, current_user, 'delete')
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def bio_eddie_asset_validation(asset)
|
||||
asset && asset.file.metadata[:asset_type] == 'bio_eddie'
|
||||
end
|
||||
|
@ -55,10 +61,13 @@ module BioEddieActions
|
|||
|
||||
return unless step && protocol
|
||||
|
||||
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' } }
|
||||
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']
|
||||
}
|
||||
|
||||
default_step_items[:action] = action if action
|
||||
if protocol.in_module?
|
||||
|
@ -72,6 +81,7 @@ module BioEddieActions
|
|||
message_items = { protocol: protocol.id }
|
||||
end
|
||||
message_items = default_step_items.merge(message_items)
|
||||
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: type_of,
|
||||
owner: current_user,
|
||||
|
@ -90,7 +100,9 @@ module BioEddieActions
|
|||
|
||||
message_items = {
|
||||
result: result.id,
|
||||
asset_type => { id: asset.id, value_for: 'file_name' }
|
||||
asset_type => { id: asset.id, value_for: 'file_name' },
|
||||
description: asset.blob.metadata['description'],
|
||||
name: asset.blob.metadata['name']
|
||||
}
|
||||
|
||||
message_items[:action] = action if action
|
||||
|
|
|
@ -65,7 +65,7 @@ module Activities
|
|||
end
|
||||
|
||||
def activity_subject_parents
|
||||
subject_parents(@activity.subject, [])
|
||||
subject_parents(@activity.subject, []).compact
|
||||
end
|
||||
|
||||
def subject_parents(subject, parents)
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
<% if deletable %>
|
||||
<li role="separator" class="divider"></li>
|
||||
<li>
|
||||
<a class="delete-asset" href="<%= asset_destroy_path(asset) %>" data-file-name="<%= asset.render_file_name %>">
|
||||
<a class="delete-asset" href="<%= asset.bio_eddie? ? bio_eddie_asset_path(asset) : asset_destroy_path(asset) %>" data-file-name="<%= asset.render_file_name %>">
|
||||
<i class="fas fa-trash"></i>
|
||||
<%= t("assets.context_menu.delete") %>
|
||||
</a>
|
||||
|
|
|
@ -319,21 +319,24 @@ class Extends
|
|||
delete_molecule_on_step: 174,
|
||||
delete_molecule_on_result: 175,
|
||||
delete_molecule_on_step_in_repository: 176,
|
||||
register_molecule: 165
|
||||
register_molecule_on_step: 177,
|
||||
register_molecule_on_result: 178,
|
||||
register_molecule_on_step_in_repository: 179
|
||||
}
|
||||
|
||||
ACTIVITY_GROUPS = {
|
||||
projects: [*0..7, 32, 33, 34, 95, 108, 65, 109, *158..162],
|
||||
task_results: [23, 26, 25, 42, 24, 40, 41, 99, 110, 122, 116, 128, 169, 172, 175],
|
||||
task_results: [23, 26, 25, 42, 24, 40, 41, 99, 110, 122, 116, 128, 169, 172, 175, 178],
|
||||
task: [8, 58, 9, 59, *10..14, 35, 36, 37, 53, 54, *60..63, 138, 139, 140, 64, 66, 106, 126, 120, 132,
|
||||
*146..148, 168, 171, 174],
|
||||
task_protocol: [15, 22, 16, 18, 19, 20, 21, 17, 38, 39, 100, 111, 45, 46, 47, 121, 124, 115, 118, 127, 130, 137],
|
||||
*146..148, 168],
|
||||
task_protocol: [15, 22, 16, 18, 19, 20, 21, 17, 38, 39, 100, 111, 45, 46, 47, 121, 124, 115, 118, 127, 130, 137,
|
||||
171, 174, 177],
|
||||
task_inventory: [55, 56, 146, 147],
|
||||
experiment: [*27..31, 57],
|
||||
reports: [48, 50, 49, 163, 164],
|
||||
inventories: [70, 71, 105, 144, 145, 72, 73, 74, 102, 142, 143, 75, 76, 77, 78, 96, 107, 113, 114, *133..136],
|
||||
protocol_repository: [80, 103, 89, 87, 79, 90, 91, 88, 85, 86, 84, 81, 82,
|
||||
83, 101, 112, 123, 125, 117, 119, 129, 131, 170, 173, 176],
|
||||
83, 101, 112, 123, 125, 117, 119, 129, 131, 170, 173, 176, 179],
|
||||
team: [92, 94, 93, 97, 104]
|
||||
}
|
||||
|
||||
|
|
|
@ -200,9 +200,9 @@ en:
|
|||
delete_molecule_on_step_html: "%{user} deleted molecule %{asset_name} on protocol's step %{step_position} %{step} on task %{my_module}."
|
||||
delete_molecule_on_result_html: "%{user} deleted molecule %{asset_name} on result %{result}."
|
||||
delete_molecule_on_step_in_repository_html: "%{user} deleted molecule %{asset_name} on protocol %{protocol}'s step %{step_position} %{step}."
|
||||
|
||||
|
||||
register_molecule_html: "%{user} scheduled the %{name} molecule for registration."
|
||||
register_molecule_on_step_html: "%{user} registered molecule %{asset_name} on protocol's step %{step_position} %{step} on task %{my_module}."
|
||||
register_molecule_on_result_html: "%{user} registered molecule %{asset_name} on result %{result}."
|
||||
register_molecule_on_step_in_repository_html: "%{user} registered molecule %{asset_name} on protocol %{protocol}'s step %{step_position} %{step}."
|
||||
|
||||
activity_name:
|
||||
create_project: "Project created"
|
||||
|
@ -360,6 +360,9 @@ en:
|
|||
delete_molecule_on_step: "Molecule on task step deleted"
|
||||
delete_molecule_on_result: "Molecule on result deleted"
|
||||
delete_molecule_on_step_in_repository: "Molecule on step deleted"
|
||||
register_molecule_on_step: "Molecule on task step registered"
|
||||
register_molecule_on_result: "Molecule on result registered"
|
||||
register_molecule_on_step_in_repository: "Molecule on step registered"
|
||||
|
||||
|
||||
activity_group:
|
||||
|
|
|
@ -770,7 +770,7 @@ Rails.application.routes.draw do
|
|||
end
|
||||
end
|
||||
|
||||
resources :bio_eddie_assets, only: %i(create update) do
|
||||
resources :bio_eddie_assets, only: %i(create update destroy) do
|
||||
collection do
|
||||
get :license
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue