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
Jérome Perrin
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
...
@@ -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
View file @
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
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