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
1e64333c
Commit
1e64333c
authored
Dec 25, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor FilterContext
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
1a2e11c8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
34 deletions
+43
-34
app/contexts/filter_context.rb
app/contexts/filter_context.rb
+37
-10
app/controllers/dashboard_controller.rb
app/controllers/dashboard_controller.rb
+2
-20
app/controllers/groups_controller.rb
app/controllers/groups_controller.rb
+4
-4
No files found.
app/contexts/filter_context.rb
View file @
1e64333c
class
FilterContext
class
FilterContext
attr_accessor
:
items
,
:params
attr_accessor
:
klass
,
:current_user
,
:params
def
initialize
(
items
,
params
)
def
initialize
(
klass
,
current_user
,
params
)
@items
=
items
@klass
=
klass
@current_user
=
current_user
@params
=
params
@params
=
params
end
end
def
execute
def
execute
apply_filter
(
items
)
items
=
by_scope
items
=
by_state
(
items
)
items
=
by_project
(
items
)
items
=
by_search
(
items
)
end
end
def
apply_filter
items
private
if
params
[
:project_id
].
present?
items
=
items
.
of_projects
(
params
[
:project_id
])
end
if
params
[
:search
].
present?
def
by_scope
items
=
items
.
search
(
params
[
:search
])
table_name
=
klass
.
table_name
case
params
[
:scope
]
when
'authored'
then
current_user
.
send
(
table_name
)
when
'all'
then
klass
.
of_projects
(
current_user
.
authorized_projects
.
pluck
(
:id
))
else
current_user
.
send
(
"assigned_
#{
table_name
}
"
)
end
end
end
def
by_state
(
items
)
case
params
[
:status
]
case
params
[
:status
]
when
'closed'
when
'closed'
items
.
closed
items
.
closed
...
@@ -28,4 +39,20 @@ class FilterContext
...
@@ -28,4 +39,20 @@ class FilterContext
items
.
opened
items
.
opened
end
end
end
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
end
end
app/controllers/dashboard_controller.rb
View file @
1e64333c
...
@@ -51,30 +51,12 @@ class DashboardController < ApplicationController
...
@@ -51,30 +51,12 @@ class DashboardController < ApplicationController
end
end
def
merge_requests
def
merge_requests
@merge_requests
=
case
params
[
:scope
]
@merge_requests
=
FilterContext
.
new
(
MergeRequest
,
current_user
,
params
).
execute
when
'authored'
then
current_user
.
merge_requests
when
'all'
then
MergeRequest
.
where
(
target_project_id:
current_user
.
authorized_projects
.
pluck
(
:id
))
else
current_user
.
assigned_merge_requests
end
@merge_requests
=
FilterContext
.
new
(
@merge_requests
,
params
).
execute
@merge_requests
=
@merge_requests
.
recent
.
page
(
params
[
:page
]).
per
(
20
)
@merge_requests
=
@merge_requests
.
recent
.
page
(
params
[
:page
]).
per
(
20
)
end
end
def
issues
def
issues
@issues
=
case
params
[
:scope
]
@issues
=
FilterContext
.
new
(
Issue
,
current_user
,
params
).
execute
when
'authored'
then
current_user
.
issues
when
'all'
then
Issue
.
where
(
project_id:
current_user
.
authorized_projects
.
pluck
(
:id
))
else
current_user
.
assigned_issues
end
@issues
=
FilterContext
.
new
(
@issues
,
params
).
execute
@issues
=
@issues
.
recent
.
page
(
params
[
:page
]).
per
(
20
)
@issues
=
@issues
.
recent
.
page
(
params
[
:page
]).
per
(
20
)
@issues
=
@issues
.
includes
(
:author
,
:project
)
@issues
=
@issues
.
includes
(
:author
,
:project
)
...
...
app/controllers/groups_controller.rb
View file @
1e64333c
...
@@ -45,15 +45,15 @@ class GroupsController < ApplicationController
...
@@ -45,15 +45,15 @@ class GroupsController < ApplicationController
# Get authored or assigned open merge requests
# Get authored or assigned open merge requests
def
merge_requests
def
merge_requests
@merge_requests
=
current_user
.
cared_merge_requests
.
of_group
(
@group
)
@merge_requests
=
FilterContext
.
new
(
MergeRequest
,
current_user
,
params
).
execute
@merge_requests
=
FilterContext
.
new
(
@merge_requests
,
params
).
execute
@merge_requests
=
@merge_requests
.
of_group
(
@group
)
@merge_requests
=
@merge_requests
.
recent
.
page
(
params
[
:page
]).
per
(
20
)
@merge_requests
=
@merge_requests
.
recent
.
page
(
params
[
:page
]).
per
(
20
)
end
end
# Get only assigned issues
# Get only assigned issues
def
issues
def
issues
@issues
=
current_user
.
assigned_issues
.
of_group
(
@group
)
@issues
=
FilterContext
.
new
(
Issue
,
current_user
,
params
).
execute
@issues
=
FilterContext
.
new
(
@issues
,
params
).
execute
@issues
=
@issues
.
of_group
(
@group
)
@issues
=
@issues
.
recent
.
page
(
params
[
:page
]).
per
(
20
)
@issues
=
@issues
.
recent
.
page
(
params
[
:page
]).
per
(
20
)
@issues
=
@issues
.
includes
(
:author
,
:project
)
@issues
=
@issues
.
includes
(
:author
,
:project
)
...
...
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