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
Tatuya Kamada
gitlab-ce
Commits
13caadea
Commit
13caadea
authored
Mar 06, 2017
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Addressing review comments
parent
91e46dd4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
160 deletions
+32
-160
app/models/concerns/relative_positioning.rb
app/models/concerns/relative_positioning.rb
+9
-90
spec/models/concerns/relative_positioning_spec.rb
spec/models/concerns/relative_positioning_spec.rb
+20
-69
spec/services/boards/issues/move_service_spec.rb
spec/services/boards/issues/move_service_spec.rb
+3
-1
No files found.
app/models/concerns/relative_positioning.rb
View file @
13caadea
...
...
@@ -4,10 +4,6 @@ module RelativePositioning
MIN_POSITION
=
0
MAX_POSITION
=
Gitlab
::
Database
::
MAX_INT_VALUE
included
do
after_save
:save_positionable_neighbours
end
def
min_relative_position
self
.
class
.
in_projects
(
project
.
id
).
minimum
(
:relative_position
)
end
...
...
@@ -16,92 +12,24 @@ module RelativePositioning
self
.
class
.
in_projects
(
project
.
id
).
maximum
(
:relative_position
)
end
def
prev_relative_position
prev_pos
=
nil
if
self
.
relative_position
prev_pos
=
self
.
class
.
in_projects
(
project
.
id
).
where
(
'relative_position < ?'
,
self
.
relative_position
).
maximum
(
:relative_position
)
end
prev_pos
||
MIN_POSITION
end
def
next_relative_position
next_pos
=
nil
if
self
.
relative_position
next_pos
=
self
.
class
.
in_projects
(
project
.
id
).
where
(
'relative_position > ?'
,
self
.
relative_position
).
minimum
(
:relative_position
)
end
next_pos
||
MAX_POSITION
end
def
move_between
(
before
,
after
)
return
move_
after
(
before
)
if
before
&&
!
after
return
move_
before
(
after
)
if
after
&&
!
before
return
move_
to_end
unless
after
return
move_
to_top
unless
before
pos_before
=
before
.
relative_position
pos_after
=
after
.
relative_position
if
pos_before
&&
pos_after
if
pos_before
==
pos_after
self
.
relative_position
=
pos_before
before
.
move_before
(
self
)
after
.
move_after
(
self
)
@positionable_neighbours
=
[
before
,
after
]
else
self
.
relative_position
=
position_between
(
pos_before
,
pos_after
)
end
elsif
pos_before
self
.
move_after
(
before
)
after
.
move_after
(
self
)
@positionable_neighbours
=
[
after
]
elsif
pos_after
self
.
move_before
(
after
)
before
.
move_before
(
self
)
@positionable_neighbours
=
[
before
]
else
move_to_end
before
.
move_before
(
self
)
after
.
move_after
(
self
)
@positionable_neighbours
=
[
before
,
after
]
end
end
def
move_before
(
after
)
pos_after
=
after
.
relative_position
if
pos_after
self
.
relative_position
=
position_between
(
MIN_POSITION
,
pos_after
)
if
pos_after
&&
(
pos_before
==
pos_after
)
self
.
relative_position
=
pos_before
before
.
decrement!
:relative_position
after
.
increment!
:relative_position
else
move_to_end
after
.
move_after
(
self
)
@positionable_neighbours
=
[
after
]
self
.
relative_position
=
position_between
(
pos_before
,
pos_after
)
end
end
def
move_after
(
before
)
pos_before
=
before
.
relative_position
if
pos_before
self
.
relative_position
=
position_between
(
pos_before
,
MAX_POSITION
)
else
move_to_end
before
.
move_before
(
self
)
@positionable_neighbours
=
[
before
]
end
def
move_to_top
self
.
relative_position
=
position_between
(
MIN_POSITION
,
min_relative_position
)
end
def
move_to_end
...
...
@@ -129,13 +57,4 @@ module RelativePositioning
rand
(
pos_before
.
next
..
pos_after
.
pred
)
end
def
save_positionable_neighbours
return
unless
@positionable_neighbours
status
=
@positionable_neighbours
.
all?
(
&
:save
)
@positionable_neighbours
=
nil
status
end
end
spec/models/concerns/relative_positioning_spec.rb
View file @
13caadea
...
...
@@ -12,68 +12,27 @@ describe Issue, 'RelativePositioning' do
end
describe
'#min_relative_position'
do
it
'returns m
in
imum position'
do
expect
(
issue
1
.
min_relative_position
).
to
eq
issue
.
relative_position
it
'returns m
ax
imum position'
do
expect
(
issue
.
min_relative_position
).
to
eq
issue
.
relative_position
end
end
describe
'#ma
n
_relative_position'
do
describe
'#ma
x
_relative_position'
do
it
'returns maximum position'
do
expect
(
issue
.
max_relative_position
).
to
eq
issue1
.
relative_position
end
end
describe
'#prev_relative_position'
do
it
'returns previous position if there is an issue above'
do
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
end
end
describe
'#next_relative_position'
do
it
'returns next position if there is an issue below'
do
expect
(
issue
.
next_relative_position
).
to
eq
issue1
.
relative_position
end
it
'returns next position if there is no issue below'
do
expect
(
issue1
.
next_relative_position
).
to
eq
RelativePositioning
::
MAX_POSITION
end
end
describe
'#move_before'
do
it
'moves issue before'
do
issue1
.
move_before
(
issue
)
expect
(
issue1
.
relative_position
).
to
be
<
issue
.
relative_position
end
it
'moves unpositioned issue before'
do
issue
.
update_attribute
(
:relative_position
,
nil
)
describe
'#move_to_top'
do
it
'moves issue to the end'
do
new_issue
=
create
:issue
,
project:
project
issue1
.
move_before
(
issue
)
new_issue
.
move_to_top
expect
(
issue1
.
relative_position
).
to
be
<
issue
.
relative_position
expect
(
new_issue
.
relative_position
).
to
be
<
issue
.
relative_position
end
end
describe
'#move_after'
do
it
'moves issue after'
do
issue
.
move_before
(
issue1
)
expect
(
issue
.
relative_position
).
to
be
<
issue1
.
relative_position
end
it
'moves unpositioned issue after'
do
issue1
.
update_attribute
(
:relative_position
,
nil
)
issue
.
move_before
(
issue1
)
expect
(
issue
.
relative_position
).
to
be
<
issue1
.
relative_position
end
end
describe
'#move_to_end'
do
it
'moves issue to the end'
do
...
...
@@ -95,38 +54,30 @@ describe Issue, 'RelativePositioning' do
expect
(
new_issue
.
relative_position
).
to
be
<
issue1
.
relative_position
end
it
'positions issue between
two other if position of last one is nil
'
do
it
'positions issue between
on top
'
do
new_issue
=
create
:issue
,
project:
project
issue1
.
relative_position
=
nil
issue1
.
save
new_issue
.
move_between
(
issue
,
issue1
)
new_issue
.
move_between
(
nil
,
issue
)
expect
(
new_issue
.
relative_position
).
to
be
>
issue
.
relative_position
expect
(
new_issue
.
relative_position
).
to
be
<
issue1
.
relative_position
expect
(
new_issue
.
relative_position
).
to
be
<
issue
.
relative_position
end
it
'positions issue between t
wo other if position of first one is nil
'
do
it
'positions issue between t
o end
'
do
new_issue
=
create
:issue
,
project:
project
issue
.
relative_position
=
nil
issue
.
save
new_issue
.
move_between
(
issue
,
issue1
)
new_issue
.
move_between
(
issue
1
,
nil
)
expect
(
new_issue
.
relative_position
).
to
be
>
issue
.
relative_position
expect
(
new_issue
.
relative_position
).
to
be
<
issue1
.
relative_position
expect
(
new_issue
.
relative_position
).
to
be
>
issue1
.
relative_position
end
it
'calls move_after if after is nil'
do
expect
(
issue
).
to
receive
(
:move_after
)
issue
.
move_between
(
issue1
,
nil
)
end
it
'positions issues even when after and before positions are the same'
do
new_issue
=
create
:issue
,
project:
project
issue1
.
update
relative_position:
issue
.
relative_position
it
'calls move_before if before is nil'
do
expect
(
issue
).
to
receive
(
:move_before
)
new_issue
.
move_between
(
issue
,
issue1
)
issue
.
move_between
(
nil
,
issue1
)
expect
(
new_issue
.
relative_position
).
to
be
>
issue
.
relative_position
expect
(
issue
.
relative_position
).
to
be
<
issue1
.
relative_position
end
end
end
spec/services/boards/issues/move_service_spec.rb
View file @
13caadea
...
...
@@ -94,13 +94,15 @@ describe Boards::Issues::MoveService, services: true do
end
it
'sorts issues'
do
[
issue1
,
issue2
].
each
(
&
:move_to_end
)
issue
.
move_between!
(
issue1
,
issue2
)
params
.
merge!
move_after_iid:
issue
.
iid
,
move_before_iid:
issue2
.
iid
described_class
.
new
(
project
,
user
,
params
).
execute
(
issue1
)
expect
(
issue
1
.
relative_position
).
to
be_between
(
issue
.
relative_position
,
issue2
.
relative_position
)
expect
(
issue
.
relative_position
).
to
be_between
(
issue1
.
relative_position
,
issue2
.
relative_position
)
end
end
end
...
...
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