Fix normalize_module_position method [SCI-5508]

This commit is contained in:
aignatov-bio 2021-02-19 14:41:57 +01:00
parent a89c5fef13
commit 58a5126a13
2 changed files with 6 additions and 2 deletions

View file

@ -65,7 +65,7 @@ class ExperimentsController < ApplicationController
def canvas
redirect_to module_archive_experiment_path(@experiment) if @experiment.archived_branch?
@project = @experiment.project
@active_modules = @experiment.my_modules.active.includes(:tags, :inputs, :outputs)
@active_modules = @experiment.my_modules.active.order(:name).includes(:tags, :inputs, :outputs)
current_team_switch(@project.team)
end

View file

@ -471,7 +471,11 @@ class Experiment < ApplicationRecord
x_diff = my_modules.active.pluck(:x).min
y_diff = my_modules.active.pluck(:y).min
my_modules.active.each do |m|
moving_direction = {
x: x_diff.positive? ? :asc : :desc,
y: y_diff.positive? ? :asc : :desc
}
my_modules.active.order(moving_direction).each do |m|
m.update!(x: m.x - x_diff, y: m.y - y_diff)
end
my_modules.reload