mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-06 03:46:39 +08:00
Regenerate user assignments when moving task workflow [SCI-6262] (#3668)
This commit is contained in:
parent
22623c821d
commit
0749fbdf7b
1 changed files with 50 additions and 44 deletions
|
@ -327,53 +327,59 @@ class Experiment < ApplicationRecord
|
||||||
# it's obviously not updated. Position for entire module group is updated
|
# it's obviously not updated. Position for entire module group is updated
|
||||||
# to bottom left corner.
|
# to bottom left corner.
|
||||||
def move_module_groups(to_move, current_user)
|
def move_module_groups(to_move, current_user)
|
||||||
to_move.each do |ids, experiment_id|
|
ActiveRecord::Base.transaction do
|
||||||
modules = my_modules.find(ids)
|
to_move.each do |ids, experiment_id|
|
||||||
groups = Set.new(modules.map(&:my_module_group))
|
modules = my_modules.find(ids)
|
||||||
experiment = project.experiments.find_by_id(experiment_id)
|
groups = Set.new(modules.map(&:my_module_group))
|
||||||
|
experiment = project.experiments.find_by_id(experiment_id)
|
||||||
|
|
||||||
groups.each do |group|
|
groups.each do |group|
|
||||||
next unless group && experiment.present?
|
next unless group && experiment.present?
|
||||||
|
|
||||||
# Find the lowest point for current modules(max_y) and the leftmost
|
# Find the lowest point for current modules(max_y) and the leftmost
|
||||||
# module(min_x)
|
# module(min_x)
|
||||||
active_modules = experiment.my_modules.active
|
active_modules = experiment.my_modules.active
|
||||||
if active_modules.blank?
|
if active_modules.blank?
|
||||||
max_y = 0
|
max_y = 0
|
||||||
min_x = 0
|
min_x = 0
|
||||||
else
|
else
|
||||||
max_y = active_modules.maximum(:y) + MyModule::HEIGHT
|
max_y = active_modules.maximum(:y) + MyModule::HEIGHT
|
||||||
min_x = active_modules.minimum(:x)
|
min_x = active_modules.minimum(:x)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Set new positions
|
||||||
|
curr_min_x = modules.min_by(&:x).x
|
||||||
|
curr_min_y = modules.min_by(&:y).y
|
||||||
|
modules.each { |m| m.x += -curr_min_x + min_x }
|
||||||
|
modules.each { |m| m.y += -curr_min_y + max_y }
|
||||||
|
|
||||||
|
modules.each do |m|
|
||||||
|
experiment_org = m.experiment
|
||||||
|
m.experiment = experiment
|
||||||
|
m.save!
|
||||||
|
|
||||||
|
# regenerate user assignments
|
||||||
|
m.user_assignments.destroy_all
|
||||||
|
UserAssignments::GenerateUserAssignmentsJob.new(m, current_user).perform_now
|
||||||
|
|
||||||
|
# Add activity
|
||||||
|
Activities::CreateActivityService.call(
|
||||||
|
activity_type: :move_task,
|
||||||
|
owner: current_user,
|
||||||
|
subject: m,
|
||||||
|
project: experiment.project,
|
||||||
|
team: experiment.project.team,
|
||||||
|
message_items: {
|
||||||
|
my_module: m.id,
|
||||||
|
experiment_original: experiment_org.id,
|
||||||
|
experiment_new: experiment.id
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
group.experiment = experiment
|
||||||
|
group.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set new positions
|
|
||||||
curr_min_x = modules.min_by(&:x).x
|
|
||||||
curr_min_y = modules.min_by(&:y).y
|
|
||||||
modules.each { |m| m.x += -curr_min_x + min_x }
|
|
||||||
modules.each { |m| m.y += -curr_min_y + max_y }
|
|
||||||
|
|
||||||
modules.each do |m|
|
|
||||||
experiment_org = m.experiment
|
|
||||||
m.experiment = experiment
|
|
||||||
m.save!
|
|
||||||
|
|
||||||
# Add activity
|
|
||||||
Activities::CreateActivityService.call(
|
|
||||||
activity_type: :move_task,
|
|
||||||
owner: current_user,
|
|
||||||
subject: m,
|
|
||||||
project: experiment.project,
|
|
||||||
team: experiment.project.team,
|
|
||||||
message_items: {
|
|
||||||
my_module: m.id,
|
|
||||||
experiment_original: experiment_org.id,
|
|
||||||
experiment_new: experiment.id
|
|
||||||
}
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
group.experiment = experiment
|
|
||||||
group.save!
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue