mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-08 14:15:35 +08:00
Fix Hound errors
This commit is contained in:
parent
0d56cea3e4
commit
67768c8865
3 changed files with 21 additions and 27 deletions
|
@ -154,7 +154,7 @@ class CanvasController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# Make sure move parameter is valid
|
# Make sure move parameter is valid
|
||||||
to_move = Hash.new
|
to_move = {}
|
||||||
if can_move_modules(@experiment) && update_params[:move].present?
|
if can_move_modules(@experiment) && update_params[:move].present?
|
||||||
begin
|
begin
|
||||||
to_move = JSON.parse(update_params[:move])
|
to_move = JSON.parse(update_params[:move])
|
||||||
|
@ -173,17 +173,15 @@ class CanvasController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# Distinguish between moving modules/module_groups
|
# Distinguish between moving modules/module_groups
|
||||||
to_move_groups = Hash.new
|
to_move_groups = {}
|
||||||
to_move.each do |key, value|
|
to_move.each do |key, value|
|
||||||
if key.match(/.*,.*/)
|
if key =~ /.*,.*/
|
||||||
to_move_groups[key.split(',')] = value
|
to_move_groups[key.split(',')] = value
|
||||||
to_move.delete(key)
|
to_move.delete(key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if error then
|
render_403 and return if error
|
||||||
render_403 and return
|
|
||||||
end
|
|
||||||
|
|
||||||
# Make sure that to_clone is an array of pairs,
|
# Make sure that to_clone is an array of pairs,
|
||||||
# as well as that all IDs exist
|
# as well as that all IDs exist
|
||||||
|
|
|
@ -476,7 +476,6 @@ class Experiment < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Move modules; this method accepts a map where keys
|
# Move modules; this method accepts a map where keys
|
||||||
# represent IDs of modules, and values represent experiment
|
# represent IDs of modules, and values represent experiment
|
||||||
# IDs of new names to which the given modules should be moved.
|
# IDs of new names to which the given modules should be moved.
|
||||||
|
@ -486,20 +485,20 @@ class Experiment < ActiveRecord::Base
|
||||||
to_move.each do |id, experiment_id|
|
to_move.each do |id, experiment_id|
|
||||||
my_module = my_modules.find_by_id(id)
|
my_module = my_modules.find_by_id(id)
|
||||||
experiment = project.experiments.find_by_id(experiment_id)
|
experiment = project.experiments.find_by_id(experiment_id)
|
||||||
if my_module.present? && experiment.present?
|
next unless my_module.present? && experiment.present?
|
||||||
my_module.experiment = experiment
|
|
||||||
|
|
||||||
# Calculate new module position
|
my_module.experiment = experiment
|
||||||
new_pos = my_module.get_new_position
|
|
||||||
my_module.x = new_pos[:x]
|
|
||||||
my_module.y = new_pos[:y]
|
|
||||||
|
|
||||||
unless my_module.outputs.destroy_all && my_module.inputs.destroy_all
|
# Calculate new module position
|
||||||
raise ActiveRecord::ActiveRecordError
|
new_pos = my_module.get_new_position
|
||||||
end
|
my_module.x = new_pos[:x]
|
||||||
|
my_module.y = new_pos[:y]
|
||||||
|
|
||||||
my_module.save!
|
unless my_module.outputs.destroy_all && my_module.inputs.destroy_all
|
||||||
|
raise ActiveRecord::ActiveRecordError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
my_module.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -324,25 +324,23 @@ class MyModule < ActiveRecord::Base
|
||||||
# Find an empty position for the restored module. It's
|
# Find an empty position for the restored module. It's
|
||||||
# basically a first empty row with empty space inside x=[0, 32).
|
# basically a first empty row with empty space inside x=[0, 32).
|
||||||
def get_new_position
|
def get_new_position
|
||||||
if experiment.blank?
|
return { x: 0, y: 0 } if experiment.blank?
|
||||||
return { x: 0, y: 0 }
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get all modules position that overlap with first column, [0, WIDTH) and
|
# Get all modules position that overlap with first column, [0, WIDTH) and
|
||||||
# sort them by y coordinate.
|
# sort them by y coordinate.
|
||||||
positions = experiment.active_modules.collect{ |m| [m.x, m.y] }
|
positions = experiment.active_modules.collect { |m| [m.x, m.y] }
|
||||||
.select{ |x, y| x >= 0 && x < WIDTH }
|
.select { |x, _| x >= 0 && x < WIDTH }
|
||||||
.sort_by{ |x, y| y }
|
.sort_by { |_, y| y }
|
||||||
return { x: 0, y: 0 } if positions.empty? || positions.first[1] >= HEIGHT
|
return { x: 0, y: 0 } if positions.empty? || positions.first[1] >= HEIGHT
|
||||||
|
|
||||||
# It looks we'll have to find a gap between the modules if it exists (at
|
# It looks we'll have to find a gap between the modules if it exists (at
|
||||||
# least 2*HEIGHT wide
|
# least 2*HEIGHT wide
|
||||||
ind = positions.each_cons(2).map{ |f, s| s[1]-f[1] }
|
ind = positions.each_cons(2).map { |f, s| s[1] - f[1] }
|
||||||
.index { |y| y >= 2*HEIGHT }
|
.index { |y| y >= 2 * HEIGHT }
|
||||||
return { x: 0, y: positions[ind][1] + HEIGHT } if ind
|
return { x: 0, y: positions[ind][1] + HEIGHT } if ind
|
||||||
|
|
||||||
# We lucked out, no gaps, therefore we need to add it after the last element
|
# We lucked out, no gaps, therefore we need to add it after the last element
|
||||||
return { x: 0, y: positions.last[1] + HEIGHT }
|
{ x: 0, y: positions.last[1] + HEIGHT }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -350,5 +348,4 @@ class MyModule < ActiveRecord::Base
|
||||||
def create_blank_protocol
|
def create_blank_protocol
|
||||||
protocols << Protocol.new_blank_for_module(self)
|
protocols << Protocol.new_blank_for_module(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue