From 58a5126a13265b20c772270d5d3a648910ec3de6 Mon Sep 17 00:00:00 2001 From: aignatov-bio Date: Fri, 19 Feb 2021 14:41:57 +0100 Subject: [PATCH] Fix normalize_module_position method [SCI-5508] --- app/controllers/experiments_controller.rb | 2 +- app/models/experiment.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/experiments_controller.rb b/app/controllers/experiments_controller.rb index 1eb70c58a..869345b4d 100644 --- a/app/controllers/experiments_controller.rb +++ b/app/controllers/experiments_controller.rb @@ -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 diff --git a/app/models/experiment.rb b/app/models/experiment.rb index 6b7a23edf..8e9b06ec7 100644 --- a/app/models/experiment.rb +++ b/app/models/experiment.rb @@ -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