Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
d184f27e
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,发现更多精彩内容 >>
提交
d184f27e
编写于
8月 11, 2017
作者:
M
Mehdi Lahmam
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor Admin::ProjectsFinder by extracting finders as private methods
上级
99bb3dde
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
54 addition
and
26 deletion
+54
-26
app/controllers/admin/projects_controller.rb
app/controllers/admin/projects_controller.rb
+3
-3
app/finders/admin/projects_finder.rb
app/finders/admin/projects_finder.rb
+51
-23
未找到文件。
app/controllers/admin/projects_controller.rb
浏览文件 @
d184f27e
...
@@ -3,9 +3,9 @@ class Admin::ProjectsController < Admin::ApplicationController
...
@@ -3,9 +3,9 @@ class Admin::ProjectsController < Admin::ApplicationController
before_action
:group
,
only:
[
:show
,
:transfer
]
before_action
:group
,
only:
[
:show
,
:transfer
]
def
index
def
index
finder
=
Admin
::
ProjectsFinder
.
new
(
params:
params
,
current_user:
current_user
)
params
[
:sort
]
||=
'latest_activity_desc'
@
projects
=
finder
.
execute
@
sort
=
params
[
:sort
]
@
sort
=
finder
.
sort
@
projects
=
Admin
::
ProjectsFinder
.
new
(
params:
params
,
current_user:
current_user
).
execute
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
format
.
html
...
...
app/finders/admin/projects_finder.rb
浏览文件 @
d184f27e
class
Admin::ProjectsFinder
class
Admin::ProjectsFinder
attr_reader
:sort
,
:namespace_id
,
:visibility_level
,
:with_push
,
attr_reader
:params
,
:current_user
:abandoned
,
:last_repository_check_failed
,
:archived
,
:personal
,
:name
,
:page
,
:current_user
def
initialize
(
params
:,
current_user
:)
def
initialize
(
params
:,
current_user
:)
@params
=
params
@current_user
=
current_user
@current_user
=
current_user
@sort
=
params
.
fetch
(
:sort
)
{
'latest_activity_desc'
}
@namespace_id
=
params
[
:namespace_id
]
@visibility_level
=
params
[
:visibility_level
]
@with_push
=
params
[
:with_push
]
@abandoned
=
params
[
:abandoned
]
@last_repository_check_failed
=
params
[
:last_repository_check_failed
]
@archived
=
params
[
:archived
]
@personal
=
params
[
:personal
]
@name
=
params
[
:name
]
@page
=
params
[
:page
]
end
end
def
execute
def
execute
items
=
Project
.
without_deleted
.
with_statistics
items
=
Project
.
without_deleted
.
with_statistics
items
=
items
.
in_namespace
(
namespace_id
)
if
namespace_id
.
present?
items
=
by_namespace_id
(
items
)
items
=
items
.
where
(
visibility_level:
visibility_level
)
if
visibility_level
.
present?
items
=
by_visibilty_level
(
items
)
items
=
items
.
with_push
if
with_push
.
present?
items
=
by_with_push
(
items
)
items
=
items
.
abandoned
if
abandoned
.
present?
items
=
by_abandoned
(
items
)
items
=
items
.
where
(
last_repository_check_failed:
true
)
if
last_repository_check_failed
.
present?
items
=
by_last_repository_check_failed
(
items
)
items
=
items
.
non_archived
unless
archived
.
present?
items
=
by_archived
(
items
)
items
=
items
.
personal
(
current_user
)
if
personal
.
present?
items
=
by_personal
(
items
)
items
=
items
.
search
(
name
)
if
name
.
present?
items
=
by_name
(
items
)
items
=
items
.
sort
(
sort
)
items
=
sort
(
items
)
items
.
includes
(
:namespace
).
order
(
"namespaces.path, projects.name ASC"
).
page
(
page
)
items
.
includes
(
:namespace
).
order
(
"namespaces.path, projects.name ASC"
).
page
(
params
[
:page
])
end
private
def
by_namespace_id
(
items
)
params
[
:namespace_id
].
present?
?
items
.
in_namespace
(
params
[
:namespace_id
])
:
items
end
def
by_visibilty_level
(
items
)
params
[
:visibility_level
].
present?
?
items
.
where
(
visibility_level:
params
[
:visibility_level
])
:
items
end
def
by_with_push
(
items
)
params
[
:with_push
].
present?
?
items
.
with_push
:
items
end
def
by_abandoned
(
items
)
params
[
:abandoned
].
present?
?
items
.
abandoned
:
items
end
def
by_last_repository_check_failed
(
items
)
params
[
:last_repository_check_failed
].
present?
?
items
.
where
(
last_repository_check_failed:
true
)
:
items
end
def
by_archived
(
items
)
items
.
non_archived
unless
params
[
:archived
].
present?
end
def
by_personal
(
items
)
params
[
:personal
].
present?
?
items
.
personal
(
current_user
)
:
items
end
def
by_name
(
items
)
params
[
:name
].
present?
?
items
.
search
(
params
[
:name
])
:
items
end
def
sort
(
items
)
sort
=
params
.
fetch
(
:sort
)
{
'latest_activity_desc'
}
items
.
sort
(
sort
)
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录