Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
56707777
Commit
56707777
authored
Mar 10, 2017
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Issue sorting] Filling positions preferable in the middle
parent
67686e38
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
24 deletions
+39
-24
app/models/concerns/relative_positioning.rb
app/models/concerns/relative_positioning.rb
+13
-10
spec/models/concerns/relative_positioning_spec.rb
spec/models/concerns/relative_positioning_spec.rb
+26
-14
No files found.
app/models/concerns/relative_positioning.rb
View file @
56707777
...
@@ -2,6 +2,7 @@ module RelativePositioning
...
@@ -2,6 +2,7 @@ module RelativePositioning
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
MIN_POSITION
=
0
MIN_POSITION
=
0
START_POSITION
=
Gitlab
::
Database
::
MAX_INT_VALUE
/
2
MAX_POSITION
=
Gitlab
::
Database
::
MAX_INT_VALUE
MAX_POSITION
=
Gitlab
::
Database
::
MAX_INT_VALUE
DISTANCE
=
500
DISTANCE
=
500
...
@@ -9,10 +10,6 @@ module RelativePositioning
...
@@ -9,10 +10,6 @@ module RelativePositioning
after_save
:save_positionable_neighbours
after_save
:save_positionable_neighbours
end
end
def
min_relative_position
self
.
class
.
in_projects
(
project
.
id
).
minimum
(
:relative_position
)
end
def
max_relative_position
def
max_relative_position
self
.
class
.
in_projects
(
project
.
id
).
maximum
(
:relative_position
)
self
.
class
.
in_projects
(
project
.
id
).
maximum
(
:relative_position
)
end
end
...
@@ -27,7 +24,7 @@ module RelativePositioning
...
@@ -27,7 +24,7 @@ module RelativePositioning
maximum
(
:relative_position
)
maximum
(
:relative_position
)
end
end
prev_pos
||
MIN_POSITION
prev_pos
end
end
def
next_relative_position
def
next_relative_position
...
@@ -40,7 +37,7 @@ module RelativePositioning
...
@@ -40,7 +37,7 @@ module RelativePositioning
minimum
(
:relative_position
)
minimum
(
:relative_position
)
end
end
next_pos
||
MAX_POSITION
next_pos
end
end
def
move_between
(
before
,
after
)
def
move_between
(
before
,
after
)
...
@@ -72,7 +69,7 @@ module RelativePositioning
...
@@ -72,7 +69,7 @@ module RelativePositioning
end
end
def
move_to_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
end
private
private
...
@@ -87,10 +84,16 @@ module RelativePositioning
...
@@ -87,10 +84,16 @@ module RelativePositioning
pos_before
,
pos_after
=
[
pos_before
,
pos_after
].
sort
pos_before
,
pos_after
=
[
pos_before
,
pos_after
].
sort
if
pos_after
-
pos_before
>
DISTANCE
*
2
if
pos_after
-
pos_before
<
DISTANCE
*
2
(
pos_after
+
pos_before
)
/
2
else
if
pos_before
==
MIN_POSITION
pos_after
-
DISTANCE
elsif
pos_after
==
MAX_POSITION
pos_before
+
DISTANCE
pos_before
+
DISTANCE
else
else
pos_before
+
(
pos_after
-
pos_before
)
/
2
(
pos_after
+
pos_before
)
/
2
end
end
end
end
end
...
...
spec/models/concerns/relative_positioning_spec.rb
View file @
56707777
...
@@ -12,12 +12,6 @@ describe Issue, 'RelativePositioning' do
...
@@ -12,12 +12,6 @@ describe Issue, 'RelativePositioning' do
end
end
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
describe
'#max_relative_position'
do
it
'returns maximum position'
do
it
'returns maximum position'
do
expect
(
issue
.
max_relative_position
).
to
eq
issue1
.
relative_position
expect
(
issue
.
max_relative_position
).
to
eq
issue1
.
relative_position
...
@@ -29,8 +23,8 @@ describe Issue, 'RelativePositioning' do
...
@@ -29,8 +23,8 @@ describe Issue, 'RelativePositioning' do
expect
(
issue1
.
prev_relative_position
).
to
eq
issue
.
relative_position
expect
(
issue1
.
prev_relative_position
).
to
eq
issue
.
relative_position
end
end
it
'returns
minimum position
if there is no issue above'
do
it
'returns
nil
if there is no issue above'
do
expect
(
issue
.
prev_relative_position
).
to
eq
RelativePositioning
::
MIN_POSITION
expect
(
issue
.
prev_relative_position
).
to
eq
nil
end
end
end
end
...
@@ -39,8 +33,8 @@ describe Issue, 'RelativePositioning' do
...
@@ -39,8 +33,8 @@ describe Issue, 'RelativePositioning' do
expect
(
issue
.
next_relative_position
).
to
eq
issue1
.
relative_position
expect
(
issue
.
next_relative_position
).
to
eq
issue1
.
relative_position
end
end
it
'returns n
ext position
if there is no issue below'
do
it
'returns n
il
if there is no issue below'
do
expect
(
issue1
.
next_relative_position
).
to
eq
RelativePositioning
::
MAX_POSITION
expect
(
issue1
.
next_relative_position
).
to
eq
nil
end
end
end
end
...
@@ -110,15 +104,33 @@ describe Issue, 'RelativePositioning' do
...
@@ -110,15 +104,33 @@ describe Issue, 'RelativePositioning' do
expect
(
issue
.
relative_position
).
to
be
<
issue1
.
relative_position
expect
(
issue
.
relative_position
).
to
be
<
issue1
.
relative_position
end
end
it
'positions issue
closer to before-issue
if distance is big enough'
do
it
'positions issue
in the middle of other two
if distance is big enough'
do
issue
.
update
relative_position:
1
00
issue
.
update
relative_position:
60
00
issue1
.
update
relative_position:
6
000
issue1
.
update
relative_position:
10
000
new_issue
.
move_between
(
issue
,
issue1
)
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
end
it
'positions issue in the middle of other two if distance is not big enough'
do
it
'positions issue in the middle of other two if distance is not big enough'
do
issue
.
update
relative_position:
100
issue
.
update
relative_position:
100
issue1
.
update
relative_position:
400
issue1
.
update
relative_position:
400
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment