mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-10 17:36:33 +08:00
Log activity for content reordering only when order change [SCI-10730]
This commit is contained in:
parent
df5a414bf5
commit
873a70e425
3 changed files with 32 additions and 15 deletions
|
@ -5,15 +5,18 @@ class ResultOrderableElementsController < ApplicationController
|
|||
before_action :check_manage_permissions
|
||||
|
||||
def reorder
|
||||
position_changed = false
|
||||
ActiveRecord::Base.transaction do
|
||||
params[:result_orderable_element_positions].each do |id, position|
|
||||
result_element = @result.result_orderable_elements.find(id)
|
||||
result_element.insert_at(position)
|
||||
position_changed ||= result_element.insert_at(position)
|
||||
end
|
||||
end
|
||||
|
||||
log_activity(:result_content_rearranged, @my_module.experiment.project, my_module: @my_module.id)
|
||||
@result.touch
|
||||
if position_changed
|
||||
log_activity(:result_content_rearranged, @my_module.experiment.project, my_module: @my_module.id)
|
||||
@result.touch
|
||||
end
|
||||
|
||||
render json: params[:result_orderable_element_positions], status: :ok
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
|
|
|
@ -6,16 +6,23 @@ class StepOrderableElementsController < ApplicationController
|
|||
|
||||
def reorder
|
||||
@step.with_lock do
|
||||
position_changed = false
|
||||
params[:step_orderable_element_positions].each do |id, position|
|
||||
@step.step_orderable_elements.find(id).update_column(:position, position)
|
||||
step_element = @step.step_orderable_elements.find(id)
|
||||
if step_element.position != position
|
||||
position_changed = true
|
||||
step_element.update_column(:position, position)
|
||||
end
|
||||
end
|
||||
|
||||
if @protocol.in_module?
|
||||
log_activity(:task_step_content_rearranged, @my_module.experiment.project, my_module: @my_module.id)
|
||||
else
|
||||
log_activity(:protocol_step_content_rearranged, nil, protocol: @protocol.id)
|
||||
if position_changed
|
||||
if @protocol.in_module?
|
||||
log_activity(:task_step_content_rearranged, @my_module.experiment.project, my_module: @my_module.id)
|
||||
else
|
||||
log_activity(:protocol_step_content_rearranged, nil, protocol: @protocol.id)
|
||||
end
|
||||
@step.touch
|
||||
end
|
||||
@step.touch
|
||||
end
|
||||
|
||||
render json: params[:step_orderable_element_positions], status: :ok
|
||||
|
|
|
@ -241,16 +241,23 @@ class StepsController < ApplicationController
|
|||
|
||||
def reorder
|
||||
@protocol.with_lock do
|
||||
position_changed = false
|
||||
params[:step_positions].each do |id, position|
|
||||
@protocol.steps.find(id).update_column(:position, position)
|
||||
step = @protocol.steps.find(id)
|
||||
if position != step.position
|
||||
position_changed = true
|
||||
step.update_column(:position, position)
|
||||
end
|
||||
end
|
||||
|
||||
if @protocol.in_module?
|
||||
log_activity(:task_steps_rearranged, @my_module.experiment.project, my_module: @my_module.id)
|
||||
else
|
||||
log_activity(:protocol_steps_rearranged, nil, protocol: @protocol.id)
|
||||
if position_changed
|
||||
if @protocol.in_module?
|
||||
log_activity(:task_steps_rearranged, @my_module.experiment.project, my_module: @my_module.id)
|
||||
else
|
||||
log_activity(:protocol_steps_rearranged, nil, protocol: @protocol.id)
|
||||
end
|
||||
@protocol.touch
|
||||
end
|
||||
@protocol.touch
|
||||
end
|
||||
|
||||
render json: {
|
||||
|
|
Loading…
Reference in a new issue