Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
9895d670
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9895d670
编写于
3月 07, 2017
作者:
V
Valery Sizov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Issue Board Sorting] More accurate move through the list
上级
1497db75
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
95 addition
and
22 deletion
+95
-22
app/models/concerns/relative_positioning.rb
app/models/concerns/relative_positioning.rb
+52
-10
spec/models/concerns/relative_positioning_spec.rb
spec/models/concerns/relative_positioning_spec.rb
+36
-5
spec/services/boards/issues/move_service_spec.rb
spec/services/boards/issues/move_service_spec.rb
+7
-7
未找到文件。
app/models/concerns/relative_positioning.rb
浏览文件 @
9895d670
...
...
@@ -4,6 +4,10 @@ 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
...
...
@@ -12,32 +16,61 @@ 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_
to_end
unless
after
return
move_
to_top
unless
before
return
move_
after
(
before
)
unless
after
return
move_
before
(
after
)
unless
before
pos_before
=
before
.
relative_position
pos_after
=
after
.
relative_position
if
pos_after
&&
(
pos_before
==
pos_after
)
self
.
relative_position
=
pos_before
before
.
decrement!
:relative_position
after
.
increment!
:relative_position
before
.
move_before
(
self
)
after
.
move_after
(
self
)
@positionable_neighbours
=
[
before
,
after
]
else
self
.
relative_position
=
position_between
(
pos_before
,
pos_after
)
end
end
def
move_
to_top
self
.
relative_position
=
position_between
(
MIN_POSITION
,
min_
relative_position
)
def
move_
before
(
after
)
self
.
relative_position
=
position_between
(
after
.
prev_relative_position
,
after
.
relative_position
)
end
def
move_
to_end
self
.
relative_position
=
position_between
(
max_relative_position
,
MAX_POSITION
)
def
move_
after
(
before
)
self
.
relative_position
=
position_between
(
before
.
relative_position
,
before
.
next_relative_position
)
end
def
move_
between!
(
*
args
)
move_between
(
*
args
)
&&
save!
def
move_
to_end
self
.
relative_position
=
position_between
(
max_relative_position
,
MAX_POSITION
)
end
private
...
...
@@ -57,4 +90,13 @@ 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
浏览文件 @
9895d670
...
...
@@ -24,13 +24,44 @@ describe Issue, 'RelativePositioning' do
end
end
describe
'#move_to_top'
do
it
'moves issue to the end'
do
new_issue
=
create
:issue
,
project:
project
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
new_issue
.
move_to_top
it
'returns minimum position if there is no issue above'
do
expect
(
issue
.
prev_relative_position
).
to
eq
RelativePositioning
::
MIN_POSITION
end
end
expect
(
new_issue
.
relative_position
).
to
be
<
issue
.
relative_position
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
,
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
...
...
spec/services/boards/issues/move_service_spec.rb
浏览文件 @
9895d670
...
...
@@ -78,10 +78,10 @@ describe Boards::Issues::MoveService, services: true do
end
context
'when moving to same list'
do
let
(
:issue
)
{
create
(
:labeled_issue
,
project:
project
,
labels:
[
bug
,
development
])
}
let
(
:issue
)
{
create
(
:labeled_issue
,
project:
project
,
labels:
[
bug
,
development
])
}
let
(
:issue1
)
{
create
(
:labeled_issue
,
project:
project
,
labels:
[
bug
,
development
])
}
let
(
:issue2
)
{
create
(
:labeled_issue
,
project:
project
,
labels:
[
bug
,
development
])
}
let
(
:params
)
{
{
board_id:
board1
.
id
,
from_list_id:
list1
.
id
,
to_list_id:
list1
.
id
}
}
let
(
:params
)
{
{
board_id:
board1
.
id
,
from_list_id:
list1
.
id
,
to_list_id:
list1
.
id
}
}
it
'returns false'
do
expect
(
described_class
.
new
(
project
,
user
,
params
).
execute
(
issue
)).
to
eq
false
...
...
@@ -94,13 +94,13 @@ describe Boards::Issues::MoveService, services: true do
end
it
'sorts issues'
do
[
issue
1
,
issue2
].
each
(
&
:move_to_end
)
issue
.
move_between!
(
issue1
,
issue2
)
[
issue
,
issue1
,
issue2
].
each
do
|
issue
|
issue
.
move_to_end
&&
issue
.
save!
end
params
.
merge!
(
move_after_iid:
issue
.
iid
,
move_before_iid:
issue2
.
iid
)
params
.
merge!
(
move_after_iid:
issue
1
.
iid
,
move_before_iid:
issue2
.
iid
)
described_class
.
new
(
project
,
user
,
params
).
execute
(
issue
1
)
described_class
.
new
(
project
,
user
,
params
).
execute
(
issue
)
expect
(
issue
.
relative_position
).
to
be_between
(
issue1
.
relative_position
,
issue2
.
relative_position
)
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录