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
5e96ee34
Commit
5e96ee34
authored
Jan 15, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement FilteringService
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
1fc42d99
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
119 additions
and
0 deletions
+119
-0
app/services/filtering_service.rb
app/services/filtering_service.rb
+119
-0
No files found.
app/services/filtering_service.rb
0 → 100644
View file @
5e96ee34
# FilteringService class
#
# Used to filter Issues and MergeRequests collections by set of params
#
# Arguments:
# klass - actual class like Issue or MergeRequest
# current_user - which user use
# params:
# scope: 'created-by-me' or 'assigned-to-me' or 'all'
# state: 'open' or 'closed' or 'all'
# group_id: integer
# project_id: integer
# milestone_id: integer
# assignee_id: integer
# search: string
# label_name: string
# sort: string
#
class
FilteringService
attr_accessor
:klass
,
:current_user
,
:params
def
execute
(
klass
,
current_user
,
params
)
@klass
=
klass
@current_user
=
current_user
@params
=
params
items
=
by_scope
items
=
by_state
(
items
)
items
=
by_group
(
items
)
items
=
by_project
(
items
)
items
=
by_search
(
items
)
items
=
by_milestone
(
items
)
items
=
by_assignee
(
items
)
items
=
by_label
(
items
)
items
=
sort
(
items
)
end
private
def
by_scope
table_name
=
klass
.
table_name
case
params
[
:scope
]
when
'created-by-me'
,
'authored'
then
current_user
.
send
(
table_name
)
when
'all'
then
klass
.
of_projects
(
current_user
.
authorized_projects
.
pluck
(
:id
))
when
'assigned-to-me'
then
current_user
.
send
(
"assigned_
#{
table_name
}
"
)
else
raise
'You must specify default scope'
end
end
def
by_state
(
items
)
case
params
[
:state
]
when
'closed'
items
.
closed
when
'all'
items
when
'opened'
items
.
opened
else
raise
'You must specify default state'
end
end
def
by_group
(
items
)
if
params
[
:group_id
].
present?
items
=
items
.
of_group
(
Group
.
find
(
params
[
:group_id
]))
end
items
end
def
by_project
(
items
)
if
params
[
:project_id
].
present?
items
=
items
.
of_projects
(
params
[
:project_id
])
end
items
end
def
by_search
(
items
)
if
params
[
:search
].
present?
items
=
items
.
search
(
params
[
:search
])
end
items
end
def
sort
(
items
)
items
.
sort
(
params
[
:sort
])
end
def
by_milestone
(
items
)
if
params
[
:milestone_id
].
present?
items
=
items
.
where
(
milestone_id:
(
params
[
:milestone_id
]
==
'0'
?
nil
:
params
[
:milestone_id
]))
end
items
end
def
by_assignee
(
items
)
if
params
[
:assignee_id
].
present?
items
=
items
.
where
(
assignee_id:
(
params
[
:assignee_id
]
==
'0'
?
nil
:
params
[
:assignee_id
]))
end
items
end
def
by_label
(
items
)
if
params
[
:label_name
].
present?
items
=
items
.
tagged_with
(
params
[
:label_name
])
end
items
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