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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
e254ea9e
Commit
e254ea9e
authored
Aug 23, 2017
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use relative position for group issue boards
parent
4702f5f7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
239 additions
and
5 deletions
+239
-5
app/models/concerns/relative_positioning.rb
app/models/concerns/relative_positioning.rb
+9
-5
app/models/issue.rb
app/models/issue.rb
+1
-0
ee/app/models/concerns/ee/relative_positioning.rb
ee/app/models/concerns/ee/relative_positioning.rb
+22
-0
spec/ee/spec/models/ee/relative_positioning_spec.rb
spec/ee/spec/models/ee/relative_positioning_spec.rb
+207
-0
No files found.
app/models/concerns/relative_positioning.rb
View file @
e254ea9e
...
@@ -10,8 +10,12 @@ module RelativePositioning
...
@@ -10,8 +10,12 @@ module RelativePositioning
after_save
:save_positionable_neighbours
after_save
:save_positionable_neighbours
end
end
def
project_ids
project
.
id
end
def
max_relative_position
def
max_relative_position
self
.
class
.
in_projects
(
project
.
id
).
maximum
(
:relative_position
)
self
.
class
.
in_projects
(
project
_ids
).
maximum
(
:relative_position
)
end
end
def
prev_relative_position
def
prev_relative_position
...
@@ -19,7 +23,7 @@ module RelativePositioning
...
@@ -19,7 +23,7 @@ module RelativePositioning
if
self
.
relative_position
if
self
.
relative_position
prev_pos
=
self
.
class
prev_pos
=
self
.
class
.
in_projects
(
project
.
id
)
.
in_projects
(
project
_ids
)
.
where
(
'relative_position < ?'
,
self
.
relative_position
)
.
where
(
'relative_position < ?'
,
self
.
relative_position
)
.
maximum
(
:relative_position
)
.
maximum
(
:relative_position
)
end
end
...
@@ -32,7 +36,7 @@ module RelativePositioning
...
@@ -32,7 +36,7 @@ module RelativePositioning
if
self
.
relative_position
if
self
.
relative_position
next_pos
=
self
.
class
next_pos
=
self
.
class
.
in_projects
(
project
.
id
)
.
in_projects
(
project
_ids
)
.
where
(
'relative_position > ?'
,
self
.
relative_position
)
.
where
(
'relative_position > ?'
,
self
.
relative_position
)
.
minimum
(
:relative_position
)
.
minimum
(
:relative_position
)
end
end
...
@@ -59,7 +63,7 @@ module RelativePositioning
...
@@ -59,7 +63,7 @@ module RelativePositioning
pos_after
=
before
.
next_relative_position
pos_after
=
before
.
next_relative_position
if
before
.
shift_after?
if
before
.
shift_after?
issue_to_move
=
self
.
class
.
in_projects
(
project
.
id
).
find_by!
(
relative_position:
pos_after
)
issue_to_move
=
self
.
class
.
in_projects
(
project
_ids
).
find_by!
(
relative_position:
pos_after
)
issue_to_move
.
move_after
issue_to_move
.
move_after
@positionable_neighbours
=
[
issue_to_move
]
@positionable_neighbours
=
[
issue_to_move
]
...
@@ -74,7 +78,7 @@ module RelativePositioning
...
@@ -74,7 +78,7 @@ module RelativePositioning
pos_before
=
after
.
prev_relative_position
pos_before
=
after
.
prev_relative_position
if
after
.
shift_before?
if
after
.
shift_before?
issue_to_move
=
self
.
class
.
in_projects
(
project
.
id
).
find_by!
(
relative_position:
pos_before
)
issue_to_move
=
self
.
class
.
in_projects
(
project
_ids
).
find_by!
(
relative_position:
pos_before
)
issue_to_move
.
move_before
issue_to_move
.
move_before
@positionable_neighbours
=
[
issue_to_move
]
@positionable_neighbours
=
[
issue_to_move
]
...
...
app/models/issue.rb
View file @
e254ea9e
...
@@ -2,6 +2,7 @@ require 'carrierwave/orm/activerecord'
...
@@ -2,6 +2,7 @@ require 'carrierwave/orm/activerecord'
class
Issue
<
ActiveRecord
::
Base
class
Issue
<
ActiveRecord
::
Base
prepend
EE
::
Issue
prepend
EE
::
Issue
prepend
EE
::
RelativePositioning
include
InternalId
include
InternalId
include
Issuable
include
Issuable
...
...
ee/app/models/concerns/ee/relative_positioning.rb
0 → 100644
View file @
e254ea9e
module
EE
# Issue position on list boards should be relative to all group projects
module
RelativePositioning
extend
ActiveSupport
::
Concern
def
board_group
@group
||=
project
.
group
end
def
has_group_boards?
board_group
&&
board_group
.
boards
.
any?
end
def
project_ids
if
has_group_boards?
board_group
.
projects
.
pluck
(
:id
)
else
super
end
end
end
end
spec/ee/spec/models/ee/relative_positioning_spec.rb
0 → 100644
View file @
e254ea9e
require
'spec_helper'
describe
EE
::
RelativePositioning
do
let
(
:group
)
{
create
(
:group
)
}
let!
(
:board
)
{
create
(
:board
,
group:
group
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
group
)
}
let
(
:project1
)
{
create
(
:project
,
namespace:
group
)
}
let
(
:issue
)
{
create
(
:issue
,
project:
project
)
}
let
(
:issue1
)
{
create
(
:issue
,
project:
project1
)
}
let
(
:new_issue
)
{
create
(
:issue
,
project:
project1
)
}
before
do
[
issue
,
issue1
].
each
do
|
issue
|
issue
.
move_to_end
&&
issue
.
save
end
end
describe
'#max_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 nil if there is no issue above'
do
expect
(
issue
.
prev_relative_position
).
to
eq
nil
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 nil if there is no issue below'
do
expect
(
issue1
.
next_relative_position
).
to
eq
nil
end
end
describe
'#move_before'
do
it
'moves issue before'
do
[
issue1
,
issue
].
each
(
&
:move_to_end
)
issue
.
move_before
(
issue1
)
expect
(
issue
.
relative_position
).
to
be
<
issue1
.
relative_position
end
end
describe
'#move_after'
do
it
'moves issue after'
do
[
issue
,
issue1
].
each
(
&
:move_to_end
)
issue
.
move_after
(
issue1
)
expect
(
issue
.
relative_position
).
to
be
>
issue1
.
relative_position
end
end
describe
'#move_to_end'
do
it
'moves issue to the end'
do
new_issue
.
move_to_end
expect
(
new_issue
.
relative_position
).
to
be
>
issue1
.
relative_position
end
end
describe
'#shift_after?'
do
it
'returns true'
do
issue
.
update
(
relative_position:
issue1
.
relative_position
-
1
)
expect
(
issue
.
shift_after?
).
to
be_truthy
end
it
'returns false'
do
issue
.
update
(
relative_position:
issue1
.
relative_position
-
2
)
expect
(
issue
.
shift_after?
).
to
be_falsey
end
end
describe
'#shift_before?'
do
it
'returns true'
do
issue
.
update
(
relative_position:
issue1
.
relative_position
+
1
)
expect
(
issue
.
shift_before?
).
to
be_truthy
end
it
'returns false'
do
issue
.
update
(
relative_position:
issue1
.
relative_position
+
2
)
expect
(
issue
.
shift_before?
).
to
be_falsey
end
end
describe
'#move_between'
do
it
'positions issue between two other'
do
new_issue
.
move_between
(
issue
,
issue1
)
expect
(
new_issue
.
relative_position
).
to
be
>
issue
.
relative_position
expect
(
new_issue
.
relative_position
).
to
be
<
issue1
.
relative_position
end
it
'positions issue between on top'
do
new_issue
.
move_between
(
nil
,
issue
)
expect
(
new_issue
.
relative_position
).
to
be
<
issue
.
relative_position
end
it
'positions issue between to end'
do
new_issue
.
move_between
(
issue1
,
nil
)
expect
(
new_issue
.
relative_position
).
to
be
>
issue1
.
relative_position
end
it
'positions issues even when after and before positions are the same'
do
issue1
.
update
relative_position:
issue
.
relative_position
new_issue
.
move_between
(
issue
,
issue1
)
expect
(
new_issue
.
relative_position
).
to
be
>
issue
.
relative_position
expect
(
issue
.
relative_position
).
to
be
<
issue1
.
relative_position
end
it
'positions issues between other two if distance is 1'
do
issue1
.
update
relative_position:
issue
.
relative_position
+
1
new_issue
.
move_between
(
issue
,
issue1
)
expect
(
new_issue
.
relative_position
).
to
be
>
issue
.
relative_position
expect
(
issue
.
relative_position
).
to
be
<
issue1
.
relative_position
end
it
'positions issue in the middle of other two if distance is big enough'
do
issue
.
update
relative_position:
6000
issue1
.
update
relative_position:
10000
new_issue
.
move_between
(
issue
,
issue1
)
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
::
IDEAL_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
::
IDEAL_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
new_issue
.
move_between
(
issue
,
issue1
)
expect
(
new_issue
.
relative_position
).
to
eq
(
250
)
end
it
'positions issue in the middle of other two is there is no place'
do
issue
.
update
relative_position:
100
issue1
.
update
relative_position:
101
new_issue
.
move_between
(
issue
,
issue1
)
expect
(
new_issue
.
relative_position
).
to
be_between
(
issue
.
relative_position
,
issue1
.
relative_position
)
end
it
'uses rebalancing if there is no place'
do
issue
.
update
relative_position:
100
issue1
.
update
relative_position:
101
issue2
=
create
(
:issue
,
relative_position:
102
,
project:
project
)
new_issue
.
update
relative_position:
103
new_issue
.
move_between
(
issue1
,
issue2
)
new_issue
.
save!
expect
(
new_issue
.
relative_position
).
to
be_between
(
issue1
.
relative_position
,
issue2
.
relative_position
)
expect
(
issue
.
reload
.
relative_position
).
not_to
eq
(
100
)
end
it
'positions issue right if we pass none-sequential parameters'
do
issue
.
update
relative_position:
99
issue1
.
update
relative_position:
101
issue2
=
create
(
:issue
,
relative_position:
102
,
project:
project
)
new_issue
.
update
relative_position:
103
new_issue
.
move_between
(
issue
,
issue2
)
new_issue
.
save!
expect
(
new_issue
.
relative_position
).
to
be
(
100
)
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