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
d184f27e
Commit
d184f27e
authored
Aug 11, 2017
by
Mehdi Lahmam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Admin::ProjectsFinder by extracting finders as private methods
parent
99bb3dde
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
26 deletions
+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
No files found.
app/controllers/admin/projects_controller.rb
View file @
d184f27e
...
...
@@ -3,9 +3,9 @@ class Admin::ProjectsController < Admin::ApplicationController
before_action
:group
,
only:
[
:show
,
:transfer
]
def
index
finder
=
Admin
::
ProjectsFinder
.
new
(
params:
params
,
current_user:
current_user
)
@
projects
=
finder
.
execute
@
sort
=
finder
.
sort
params
[
:sort
]
||=
'latest_activity_desc'
@
sort
=
params
[
:sort
]
@
projects
=
Admin
::
ProjectsFinder
.
new
(
params:
params
,
current_user:
current_user
).
execute
respond_to
do
|
format
|
format
.
html
...
...
app/finders/admin/projects_finder.rb
View file @
d184f27e
class
Admin::ProjectsFinder
attr_reader
:sort
,
:namespace_id
,
:visibility_level
,
:with_push
,
:abandoned
,
:last_repository_check_failed
,
:archived
,
:personal
,
:name
,
:page
,
:current_user
attr_reader
:params
,
:current_user
def
initialize
(
params
:,
current_user
:)
@params
=
params
@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
def
execute
items
=
Project
.
without_deleted
.
with_statistics
items
=
items
.
in_namespace
(
namespace_id
)
if
namespace_id
.
present?
items
=
items
.
where
(
visibility_level:
visibility_level
)
if
visibility_level
.
present?
items
=
items
.
with_push
if
with_push
.
present?
items
=
items
.
abandoned
if
abandoned
.
present?
items
=
items
.
where
(
last_repository_check_failed:
true
)
if
last_repository_check_failed
.
present?
items
=
items
.
non_archived
unless
archived
.
present?
items
=
items
.
personal
(
current_user
)
if
personal
.
present?
items
=
items
.
search
(
name
)
if
name
.
present?
items
=
items
.
sort
(
sort
)
items
.
includes
(
:namespace
).
order
(
"namespaces.path, projects.name ASC"
).
page
(
page
)
items
=
by_namespace_id
(
items
)
items
=
by_visibilty_level
(
items
)
items
=
by_with_push
(
items
)
items
=
by_abandoned
(
items
)
items
=
by_last_repository_check_failed
(
items
)
items
=
by_archived
(
items
)
items
=
by_personal
(
items
)
items
=
by_name
(
items
)
items
=
sort
(
items
)
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
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