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
Boxiang Sun
gitlab-ce
Commits
46997c6a
Commit
46997c6a
authored
Jan 15, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unnecessary contexts
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
234b86c9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
0 additions
and
200 deletions
+0
-200
app/contexts/filter_context.rb
app/contexts/filter_context.rb
+0
-58
app/contexts/issues/list_context.rb
app/contexts/issues/list_context.rb
+0
-39
app/contexts/merge_requests_load_context.rb
app/contexts/merge_requests_load_context.rb
+0
-38
spec/contexts/filter_context_spec.rb
spec/contexts/filter_context_spec.rb
+0
-65
No files found.
app/contexts/filter_context.rb
deleted
100644 → 0
View file @
234b86c9
class
FilterContext
attr_accessor
:klass
,
:current_user
,
:params
def
initialize
(
klass
,
current_user
,
params
)
@klass
=
klass
@current_user
=
current_user
@params
=
params
end
def
execute
items
=
by_scope
items
=
by_state
(
items
)
items
=
by_project
(
items
)
items
=
by_search
(
items
)
end
private
def
by_scope
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
def
by_state
(
items
)
case
params
[
:status
]
when
'closed'
items
.
closed
when
'all'
items
else
items
.
opened
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
app/contexts/issues/list_context.rb
deleted
100644 → 0
View file @
234b86c9
module
Issues
class
ListContext
<
BaseContext
attr_accessor
:issues
def
execute
@issues
=
@project
.
issues
@issues
=
case
params
[
:state
]
when
'all'
then
@issues
when
'closed'
then
@issues
.
closed
else
@issues
.
opened
end
@issues
=
case
params
[
:scope
]
when
'assigned-to-me'
then
@issues
.
assigned_to
(
current_user
)
when
'created-by-me'
then
@issues
.
authored
(
current_user
)
else
@issues
end
@issues
=
@issues
.
tagged_with
(
params
[
:label_name
])
if
params
[
:label_name
].
present?
@issues
=
@issues
.
includes
(
:author
,
:project
)
# Filter by specific assignee_id (or lack thereof)?
if
params
[
:assignee_id
].
present?
@issues
=
@issues
.
where
(
assignee_id:
(
params
[
:assignee_id
]
==
'0'
?
nil
:
params
[
:assignee_id
]))
end
# Filter by specific milestone_id (or lack thereof)?
if
params
[
:milestone_id
].
present?
@issues
=
@issues
.
where
(
milestone_id:
(
params
[
:milestone_id
]
==
'0'
?
nil
:
params
[
:milestone_id
]))
end
# Sort by :sort param
@issues
=
@issues
.
sort
(
params
[
:sort
])
@issues
end
end
end
app/contexts/merge_requests_load_context.rb
deleted
100644 → 0
View file @
234b86c9
# Build collection of Merge Requests
# based on filtering passed via params for @project
class
MergeRequestsLoadContext
<
BaseContext
def
execute
merge_requests
=
@project
.
merge_requests
merge_requests
=
case
params
[
:state
]
when
'all'
then
merge_requests
when
'closed'
then
merge_requests
.
closed
else
merge_requests
.
opened
end
merge_requests
=
case
params
[
:scope
]
when
'assigned-to-me'
then
merge_requests
.
assigned_to
(
current_user
)
when
'created-by-me'
then
merge_requests
.
authored
(
current_user
)
else
merge_requests
end
merge_requests
=
merge_requests
.
page
(
params
[
:page
]).
per
(
20
)
merge_requests
=
merge_requests
.
includes
(
:author
,
:source_project
,
:target_project
).
order
(
"created_at desc"
)
# Filter by specific assignee_id (or lack thereof)?
if
params
[
:assignee_id
].
present?
merge_requests
=
merge_requests
.
where
(
assignee_id:
(
params
[
:assignee_id
]
==
'0'
?
nil
:
params
[
:assignee_id
]))
end
# Filter by specific milestone_id (or lack thereof)?
if
params
[
:milestone_id
].
present?
merge_requests
=
merge_requests
.
where
(
milestone_id:
(
params
[
:milestone_id
]
==
'0'
?
nil
:
params
[
:milestone_id
]))
end
# Sort by :sort param
merge_requests
=
merge_requests
.
sort
(
params
[
:sort
])
merge_requests
end
end
spec/contexts/filter_context_spec.rb
deleted
100644 → 0
View file @
234b86c9
require
'spec_helper'
describe
FilterContext
do
let
(
:user
)
{
create
:user
}
let
(
:user2
)
{
create
:user
}
let
(
:project1
)
{
create
(
:project
)
}
let
(
:project2
)
{
create
(
:project
)
}
let
(
:merge_request1
)
{
create
(
:merge_request
,
author:
user
,
source_project:
project1
,
target_project:
project2
)
}
let
(
:merge_request2
)
{
create
(
:merge_request
,
author:
user
,
source_project:
project2
,
target_project:
project1
)
}
let
(
:merge_request3
)
{
create
(
:merge_request
,
author:
user
,
source_project:
project2
,
target_project:
project2
)
}
let
(
:issue1
)
{
create
(
:issue
,
assignee:
user
,
project:
project1
)
}
let
(
:issue2
)
{
create
(
:issue
,
assignee:
user
,
project:
project2
)
}
let
(
:issue3
)
{
create
(
:issue
,
assignee:
user2
,
project:
project2
)
}
before
do
project1
.
team
<<
[
user
,
:master
]
project2
.
team
<<
[
user
,
:developer
]
end
describe
'merge requests'
do
before
:each
do
merge_request1
merge_request2
merge_request3
end
it
'should filter by scope'
do
params
=
{
scope:
'authored'
}
merge_requests
=
FilterContext
.
new
(
MergeRequest
,
user
,
params
).
execute
merge_requests
.
size
.
should
==
3
end
it
'should filter by project'
do
params
=
{
project_id:
project1
.
id
,
scope:
'authored'
}
merge_requests
=
FilterContext
.
new
(
MergeRequest
,
user
,
params
).
execute
merge_requests
.
size
.
should
==
1
end
end
describe
'issues'
do
before
:each
do
issue1
issue2
issue3
end
it
'should filter by all'
do
params
=
{
scope:
"all"
}
issues
=
FilterContext
.
new
(
Issue
,
user
,
params
).
execute
issues
.
size
.
should
==
3
end
it
'should filter by assignee'
do
params
=
{}
issues
=
FilterContext
.
new
(
Issue
,
user
,
params
).
execute
issues
.
size
.
should
==
2
end
it
'should filter by project'
do
params
=
{
project_id:
project1
.
id
}
issues
=
FilterContext
.
new
(
Issue
,
user
,
params
).
execute
issues
.
size
.
should
==
1
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