summaryrefslogtreecommitdiff
path: root/app/models/concerns/relative_positioning.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/concerns/relative_positioning.rb')
-rw-r--r--app/models/concerns/relative_positioning.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/models/concerns/relative_positioning.rb b/app/models/concerns/relative_positioning.rb
index 7f559f0a7ed..75dfed6d58f 100644
--- a/app/models/concerns/relative_positioning.rb
+++ b/app/models/concerns/relative_positioning.rb
@@ -53,13 +53,13 @@ module RelativePositioning
return [size, starting_from] if size >= MIN_GAP
+ terminus = context.at_position(starting_from)
+
if at_end
- terminus = context.max_sibling
terminus.shift_left
max_relative_position = terminus.relative_position
[[(MAX_POSITION - max_relative_position) / gaps, IDEAL_DISTANCE].min, max_relative_position]
else
- terminus = context.min_sibling
terminus.shift_right
min_relative_position = terminus.relative_position
[[(min_relative_position - MIN_POSITION) / gaps, IDEAL_DISTANCE].min, min_relative_position]
@@ -79,6 +79,8 @@ module RelativePositioning
objects = objects.reject(&:relative_position)
return 0 if objects.empty?
+ objects.first.check_repositioning_allowed!
+
number_of_gaps = objects.size # 1 to the nearest neighbour, and one between each
representative = RelativePositioning.mover.context(objects.first)
@@ -123,6 +125,12 @@ module RelativePositioning
::Gitlab::RelativePositioning::Mover.new(START_POSITION, (MIN_POSITION..MAX_POSITION))
end
+ # To be overriden on child classes whenever
+ # blocking position updates is necessary.
+ def check_repositioning_allowed!
+ nil
+ end
+
def move_between(before, after)
before, after = [before, after].sort_by(&:relative_position) if before && after