Skip to content
GitLab
Next
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
GitLab FOSS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
GitLab.org
GitLab FOSS
Commits
56707777
Commit
56707777
authored
8 years ago
by
Valery Sizov
Browse files
Options
Downloads
Patches
Plain Diff
[Issue sorting] Filling positions preferable in the middle
parent
67686e38
No related branches found
No related tags found
1 merge request
!9837
Fix relative position calculation
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/concerns/relative_positioning.rb
+13
-10
13 additions, 10 deletions
app/models/concerns/relative_positioning.rb
spec/models/concerns/relative_positioning_spec.rb
+26
-14
26 additions, 14 deletions
spec/models/concerns/relative_positioning_spec.rb
with
39 additions
and
24 deletions
app/models/concerns/relative_positioning.rb
+
13
−
10
View file @
56707777
...
...
@@ -2,6 +2,7 @@ module RelativePositioning
extend
ActiveSupport
::
Concern
MIN_POSITION
=
0
START_POSITION
=
Gitlab
::
Database
::
MAX_INT_VALUE
/
2
MAX_POSITION
=
Gitlab
::
Database
::
MAX_INT_VALUE
DISTANCE
=
500
...
...
@@ -9,10 +10,6 @@ module RelativePositioning
after_save
:save_positionable_neighbours
end
def
min_relative_position
self
.
class
.
in_projects
(
project
.
id
).
minimum
(
:relative_position
)
end
def
max_relative_position
self
.
class
.
in_projects
(
project
.
id
).
maximum
(
:relative_position
)
end
...
...
@@ -27,7 +24,7 @@ def prev_relative_position
maximum
(
:relative_position
)
end
prev_pos
||
MIN_POSITION
prev_pos
end
def
next_relative_position
...
...
@@ -40,7 +37,7 @@ def next_relative_position
minimum
(
:relative_position
)
end
next_pos
||
MAX_POSITION
next_pos
end
def
move_between
(
before
,
after
)
...
...
@@ -72,7 +69,7 @@ def move_after(before)
end
def
move_to_end
self
.
relative_position
=
position_between
(
max_relative_position
,
MAX_POSITION
)
self
.
relative_position
=
position_between
(
max_relative_position
||
START_POSITION
,
MAX_POSITION
)
end
private
...
...
@@ -87,10 +84,16 @@ def position_between(pos_before, pos_after)
pos_before
,
pos_after
=
[
pos_before
,
pos_after
].
sort
if
pos_after
-
pos_before
>
DISTANCE
*
2
pos_before
+
DISTANCE
if
pos_after
-
pos_before
<
DISTANCE
*
2
(
pos_after
+
pos_before
)
/
2
else
pos_before
+
(
pos_after
-
pos_before
)
/
2
if
pos_before
==
MIN_POSITION
pos_after
-
DISTANCE
elsif
pos_after
==
MAX_POSITION
pos_before
+
DISTANCE
else
(
pos_after
+
pos_before
)
/
2
end
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/models/concerns/relative_positioning_spec.rb
+
26
−
14
View file @
56707777
...
...
@@ -12,12 +12,6 @@
end
end
describe
'#min_relative_position'
do
it
'returns maximum position'
do
expect
(
issue
.
min_relative_position
).
to
eq
issue
.
relative_position
end
end
describe
'#max_relative_position'
do
it
'returns maximum position'
do
expect
(
issue
.
max_relative_position
).
to
eq
issue1
.
relative_position
...
...
@@ -29,8 +23,8 @@
expect
(
issue1
.
prev_relative_position
).
to
eq
issue
.
relative_position
end
it
'returns
minimum position
if there is no issue above'
do
expect
(
issue
.
prev_relative_position
).
to
eq
RelativePositioning
::
MIN_POSITION
it
'returns
nil
if there is no issue above'
do
expect
(
issue
.
prev_relative_position
).
to
eq
nil
end
end
...
...
@@ -39,8 +33,8 @@
expect
(
issue
.
next_relative_position
).
to
eq
issue1
.
relative_position
end
it
'returns n
ext position
if there is no issue below'
do
expect
(
issue1
.
next_relative_position
).
to
eq
RelativePositioning
::
MAX_POSITION
it
'returns n
il
if there is no issue below'
do
expect
(
issue1
.
next_relative_position
).
to
eq
nil
end
end
...
...
@@ -110,15 +104,33 @@
expect
(
issue
.
relative_position
).
to
be
<
issue1
.
relative_position
end
it
'positions issue
closer to before-issue
if distance is big enough'
do
issue
.
update
relative_position:
1
00
issue1
.
update
relative_position:
6
000
it
'positions issue
in the middle of other two
if distance is big enough'
do
issue
.
update
relative_position:
60
00
issue1
.
update
relative_position:
10
000
new_issue
.
move_between
(
issue
,
issue1
)
expect
(
new_issue
.
relative_position
).
to
eq
(
100
+
RelativePositioning
::
DISTANCE
)
expect
(
new_issue
.
relative_position
).
to
eq
(
8000
)
end
it
'positions issue closer to the middle if we are at the very top'
do
issue1
.
update
relative_position:
6000
new_issue
.
move_between
(
nil
,
issue1
)
expect
(
new_issue
.
relative_position
).
to
eq
(
6000
-
RelativePositioning
::
DISTANCE
)
end
it
'positions issue closer to the middle if we are at the very bottom'
do
issue
.
update
relative_position:
6000
issue1
.
update
relative_position:
nil
new_issue
.
move_between
(
issue
,
nil
)
expect
(
new_issue
.
relative_position
).
to
eq
(
6000
+
RelativePositioning
::
DISTANCE
)
end
it
'positions issue in the middle of other two if distance is not big enough'
do
issue
.
update
relative_position:
100
issue1
.
update
relative_position:
400
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment