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
679d0d6d
Commit
679d0d6d
authored
Oct 09, 2012
by
randx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Context refactoring. Move Issues list, Search logic to context
parent
63fe042d
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
100 additions
and
83 deletions
+100
-83
app/contexts/commit_load_context.rb
app/contexts/commit_load_context.rb
+4
-4
app/contexts/issues_list_context.rb
app/contexts/issues_list_context.rb
+29
-0
app/contexts/merge_requests_load_context.rb
app/contexts/merge_requests_load_context.rb
+1
-1
app/contexts/search_context.rb
app/contexts/search_context.rb
+27
-0
app/controllers/commit_controller.rb
app/controllers/commit_controller.rb
+1
-1
app/controllers/dashboard_controller.rb
app/controllers/dashboard_controller.rb
+3
-3
app/controllers/groups_controller.rb
app/controllers/groups_controller.rb
+7
-15
app/controllers/issues_controller.rb
app/controllers/issues_controller.rb
+3
-34
app/controllers/merge_requests_controller.rb
app/controllers/merge_requests_controller.rb
+5
-5
app/controllers/milestones_controller.rb
app/controllers/milestones_controller.rb
+1
-1
app/controllers/refs_controller.rb
app/controllers/refs_controller.rb
+3
-3
app/controllers/search_controller.rb
app/controllers/search_controller.rb
+4
-10
app/helpers/issues_helper.rb
app/helpers/issues_helper.rb
+9
-0
app/models/event.rb
app/models/event.rb
+1
-4
app/roles/issue_commonality.rb
app/roles/issue_commonality.rb
+2
-2
No files found.
app/contexts/commit_load.rb
→
app/contexts/commit_load
_context
.rb
View file @
679d0d6d
class
CommitLoad
<
BaseContext
class
CommitLoad
Context
<
BaseContext
def
execute
def
execute
result
=
{
result
=
{
commit:
nil
,
commit:
nil
,
suppress_diff:
false
,
suppress_diff:
false
,
line_notes:
[],
line_notes:
[],
notes_count:
0
,
notes_count:
0
,
note:
nil
,
note:
nil
,
status: :ok
status: :ok
}
}
commit
=
project
.
commit
(
params
[
:id
])
commit
=
project
.
commit
(
params
[
:id
])
if
commit
if
commit
commit
=
CommitDecorator
.
decorate
(
commit
)
commit
=
CommitDecorator
.
decorate
(
commit
)
line_notes
=
project
.
commit_line_notes
(
commit
)
line_notes
=
project
.
commit_line_notes
(
commit
)
...
...
app/contexts/issues_list_context.rb
0 → 100644
View file @
679d0d6d
class
IssuesListContext
<
BaseContext
include
IssuesHelper
attr_accessor
:issues
def
execute
@issues
=
case
params
[
:f
]
when
issues_filter
[
:all
]
then
@project
.
issues
when
issues_filter
[
:closed
]
then
@project
.
issues
.
closed
when
issues_filter
[
:to_me
]
then
@project
.
issues
.
opened
.
assigned
(
current_user
)
else
@project
.
issues
.
opened
end
@issues
=
@issues
.
tagged_with
(
params
[
:label_name
])
if
params
[
:label_name
].
present?
@issues
=
@issues
.
includes
(
:author
,
:project
).
order
(
"updated_at"
)
# 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
@issues
end
end
app/contexts/merge_requests_load.rb
→
app/contexts/merge_requests_load
_context
.rb
View file @
679d0d6d
class
MergeRequestsLoad
<
BaseContext
class
MergeRequestsLoad
Context
<
BaseContext
def
execute
def
execute
type
=
params
[
:f
]
type
=
params
[
:f
]
...
...
app/contexts/search_context.rb
0 → 100644
View file @
679d0d6d
class
SearchContext
attr_accessor
:project_ids
,
:params
def
initialize
(
project_ids
,
params
)
@project_ids
,
@params
=
project_ids
,
params
.
dup
end
def
execute
query
=
params
[
:search
]
return
result
unless
query
.
present?
result
[
:projects
]
=
Project
.
where
(
id:
project_ids
).
search
(
query
).
limit
(
10
)
result
[
:merge_requests
]
=
MergeRequest
.
where
(
project_id:
project_ids
).
search
(
query
).
limit
(
10
)
result
[
:issues
]
=
Issue
.
where
(
project_id:
project_ids
).
search
(
query
).
limit
(
10
)
result
end
def
result
@result
||=
{
projects:
[],
merge_requests:
[],
issues:
[]
}
end
end
app/controllers/commit_controller.rb
View file @
679d0d6d
...
@@ -8,7 +8,7 @@ class CommitController < ProjectResourceController
...
@@ -8,7 +8,7 @@ class CommitController < ProjectResourceController
before_filter
:require_non_empty_project
before_filter
:require_non_empty_project
def
show
def
show
result
=
CommitLoad
.
new
(
project
,
current_user
,
params
).
execute
result
=
CommitLoad
Context
.
new
(
project
,
current_user
,
params
).
execute
@commit
=
result
[
:commit
]
@commit
=
result
[
:commit
]
git_not_found!
unless
@commit
git_not_found!
unless
@commit
...
...
app/controllers/dashboard_controller.rb
View file @
679d0d6d
...
@@ -6,7 +6,7 @@ class DashboardController < ApplicationController
...
@@ -6,7 +6,7 @@ class DashboardController < ApplicationController
@projects
=
current_user
.
projects_with_events
@projects
=
current_user
.
projects_with_events
@projects
=
@projects
.
page
(
params
[
:page
]).
per
(
20
)
@projects
=
@projects
.
page
(
params
[
:page
]).
per
(
20
)
@events
=
Event
.
recent_for_user
(
current_user
).
limit
(
20
).
offset
(
params
[
:offset
]
||
0
)
@events
=
Event
.
in_projects
(
current_user
.
project_ids
).
limit
(
20
).
offset
(
params
[
:offset
]
||
0
)
@last_push
=
current_user
.
recent_push
@last_push
=
current_user
.
recent_push
respond_to
do
|
format
|
respond_to
do
|
format
|
...
@@ -19,14 +19,14 @@ class DashboardController < ApplicationController
...
@@ -19,14 +19,14 @@ class DashboardController < ApplicationController
# Get authored or assigned open merge requests
# Get authored or assigned open merge requests
def
merge_requests
def
merge_requests
@projects
=
current_user
.
projects
.
all
@projects
=
current_user
.
projects
.
all
@merge_requests
=
current_user
.
cared_merge_requests
.
order
(
"created_at DESC"
)
.
page
(
params
[
:page
]).
per
(
20
)
@merge_requests
=
current_user
.
cared_merge_requests
.
recent
.
page
(
params
[
:page
]).
per
(
20
)
end
end
# Get only assigned issues
# Get only assigned issues
def
issues
def
issues
@projects
=
current_user
.
projects
.
all
@projects
=
current_user
.
projects
.
all
@user
=
current_user
@user
=
current_user
@issues
=
current_user
.
assigned_issues
.
opened
.
order
(
"created_at DESC"
)
.
page
(
params
[
:page
]).
per
(
20
)
@issues
=
current_user
.
assigned_issues
.
opened
.
recent
.
page
(
params
[
:page
]).
per
(
20
)
@issues
=
@issues
.
includes
(
:author
,
:project
)
@issues
=
@issues
.
includes
(
:author
,
:project
)
respond_to
do
|
format
|
respond_to
do
|
format
|
...
...
app/controllers/groups_controller.rb
View file @
679d0d6d
...
@@ -6,10 +6,7 @@ class GroupsController < ApplicationController
...
@@ -6,10 +6,7 @@ class GroupsController < ApplicationController
before_filter
:projects
before_filter
:projects
def
show
def
show
@events
=
Event
.
where
(
project_id:
project_ids
).
@events
=
Event
.
in_projects
(
project_ids
).
limit
(
20
).
offset
(
params
[
:offset
]
||
0
)
order
(
'id DESC'
).
limit
(
20
).
offset
(
params
[
:offset
]
||
0
)
@last_push
=
current_user
.
recent_push
@last_push
=
current_user
.
recent_push
respond_to
do
|
format
|
respond_to
do
|
format
|
...
@@ -22,14 +19,14 @@ class GroupsController < ApplicationController
...
@@ -22,14 +19,14 @@ 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
@merge_requests
=
current_user
.
cared_merge_requests
@merge_requests
=
@merge_requests
.
of_group
(
@group
).
order
(
"created_at DESC"
)
.
page
(
params
[
:page
]).
per
(
20
)
@merge_requests
=
@merge_requests
.
of_group
(
@group
).
recent
.
page
(
params
[
:page
]).
per
(
20
)
end
end
# Get only assigned issues
# Get only assigned issues
def
issues
def
issues
@user
=
current_user
@user
=
current_user
@issues
=
current_user
.
assigned_issues
.
opened
@issues
=
current_user
.
assigned_issues
.
opened
@issues
=
@issues
.
of_group
(
@group
).
order
(
"created_at DESC"
)
.
page
(
params
[
:page
]).
per
(
20
)
@issues
=
@issues
.
of_group
(
@group
).
recent
.
page
(
params
[
:page
]).
per
(
20
)
@issues
=
@issues
.
includes
(
:author
,
:project
)
@issues
=
@issues
.
includes
(
:author
,
:project
)
respond_to
do
|
format
|
respond_to
do
|
format
|
...
@@ -39,16 +36,11 @@ class GroupsController < ApplicationController
...
@@ -39,16 +36,11 @@ class GroupsController < ApplicationController
end
end
def
search
def
search
query
=
params
[
:search
]
result
=
SearchContext
.
new
(
project_ids
,
params
).
execute
@merge_requests
=
[]
@issues
=
[]
if
query
.
present?
@projects
=
result
[
:projects
]
@projects
=
@projects
.
search
(
query
).
limit
(
10
)
@merge_requests
=
result
[
:merge_requests
]
@merge_requests
=
MergeRequest
.
where
(
project_id:
project_ids
).
search
(
query
).
limit
(
10
)
@issues
=
result
[
:issues
]
@issues
=
Issue
.
where
(
project_id:
project_ids
).
search
(
query
).
limit
(
10
)
end
end
end
def
people
def
people
...
...
app/controllers/issues_controller.rb
View file @
679d0d6d
class
IssuesController
<
ProjectResourceController
class
IssuesController
<
ProjectResourceController
before_filter
:module_enabled
before_filter
:module_enabled
before_filter
:issue
,
only:
[
:edit
,
:update
,
:destroy
,
:show
]
before_filter
:issue
,
only:
[
:edit
,
:update
,
:destroy
,
:show
]
helper_method
:issues_filter
# Allow read any issue
# Allow read any issue
before_filter
:authorize_read_issue!
before_filter
:authorize_read_issue!
...
@@ -19,7 +18,6 @@ class IssuesController < ProjectResourceController
...
@@ -19,7 +18,6 @@ class IssuesController < ProjectResourceController
def
index
def
index
@issues
=
issues_filtered
@issues
=
issues_filtered
@issues
=
@issues
.
page
(
params
[
:page
]).
per
(
20
)
@issues
=
@issues
.
page
(
params
[
:page
]).
per
(
20
)
respond_to
do
|
format
|
respond_to
do
|
format
|
...
@@ -54,7 +52,7 @@ class IssuesController < ProjectResourceController
...
@@ -54,7 +52,7 @@ class IssuesController < ProjectResourceController
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
do
format
.
html
do
if
@issue
.
valid?
if
@issue
.
valid?
redirect_to
project_issue_path
(
@project
,
@issue
)
redirect_to
project_issue_path
(
@project
,
@issue
)
else
else
render
:new
render
:new
...
@@ -69,7 +67,7 @@ class IssuesController < ProjectResourceController
...
@@ -69,7 +67,7 @@ class IssuesController < ProjectResourceController
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
js
format
.
js
format
.
html
do
format
.
html
do
if
@issue
.
valid?
if
@issue
.
valid?
redirect_to
[
@project
,
@issue
]
redirect_to
[
@project
,
@issue
]
else
else
...
@@ -134,35 +132,6 @@ class IssuesController < ProjectResourceController
...
@@ -134,35 +132,6 @@ class IssuesController < ProjectResourceController
end
end
def
issues_filtered
def
issues_filtered
@issues
=
case
params
[
:f
]
@issues
=
IssuesListContext
.
new
(
project
,
current_user
,
params
).
execute
when
issues_filter
[
:all
]
then
@project
.
issues
when
issues_filter
[
:closed
]
then
@project
.
issues
.
closed
when
issues_filter
[
:to_me
]
then
@project
.
issues
.
opened
.
assigned
(
current_user
)
else
@project
.
issues
.
opened
end
@issues
=
@issues
.
tagged_with
(
params
[
:label_name
])
if
params
[
:label_name
].
present?
@issues
=
@issues
.
includes
(
:author
,
:project
).
order
(
"updated_at"
)
# 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
@issues
end
def
issues_filter
{
all:
"all"
,
closed:
"closed"
,
to_me:
"assigned-to-me"
,
open:
"open"
}
end
end
end
end
app/controllers/merge_requests_controller.rb
View file @
679d0d6d
...
@@ -18,7 +18,7 @@ class MergeRequestsController < ProjectResourceController
...
@@ -18,7 +18,7 @@ class MergeRequestsController < ProjectResourceController
def
index
def
index
@merge_requests
=
MergeRequestsLoad
.
new
(
project
,
current_user
,
params
).
execute
@merge_requests
=
MergeRequestsLoad
Context
.
new
(
project
,
current_user
,
params
).
execute
end
end
def
show
def
show
...
@@ -55,7 +55,7 @@ class MergeRequestsController < ProjectResourceController
...
@@ -55,7 +55,7 @@ class MergeRequestsController < ProjectResourceController
@merge_request
.
reload_code
@merge_request
.
reload_code
redirect_to
[
@project
,
@merge_request
],
notice:
'Merge request was successfully created.'
redirect_to
[
@project
,
@merge_request
],
notice:
'Merge request was successfully created.'
else
else
render
action:
"new"
render
action:
"new"
end
end
end
end
...
@@ -70,7 +70,7 @@ class MergeRequestsController < ProjectResourceController
...
@@ -70,7 +70,7 @@ class MergeRequestsController < ProjectResourceController
end
end
def
automerge_check
def
automerge_check
if
@merge_request
.
unchecked?
if
@merge_request
.
unchecked?
@merge_request
.
check_if_can_be_merged
@merge_request
.
check_if_can_be_merged
end
end
render
json:
{
state:
@merge_request
.
human_state
}
render
json:
{
state:
@merge_request
.
human_state
}
...
@@ -125,7 +125,7 @@ class MergeRequestsController < ProjectResourceController
...
@@ -125,7 +125,7 @@ class MergeRequestsController < ProjectResourceController
def
validates_merge_request
def
validates_merge_request
# Show git not found page if target branch doesnt exist
# Show git not found page if target branch doesnt exist
return
git_not_found!
unless
@project
.
repo
.
heads
.
map
(
&
:name
).
include?
(
@merge_request
.
target_branch
)
return
git_not_found!
unless
@project
.
repo
.
heads
.
map
(
&
:name
).
include?
(
@merge_request
.
target_branch
)
# Show git not found page if source branch doesnt exist
# Show git not found page if source branch doesnt exist
# and there is no saved commits between source & target branch
# and there is no saved commits between source & target branch
...
@@ -136,7 +136,7 @@ class MergeRequestsController < ProjectResourceController
...
@@ -136,7 +136,7 @@ class MergeRequestsController < ProjectResourceController
# Build a note object for comment form
# Build a note object for comment form
@note
=
@project
.
notes
.
new
(
noteable:
@merge_request
)
@note
=
@project
.
notes
.
new
(
noteable:
@merge_request
)
# Get commits from repository
# Get commits from repository
# or from cache if already merged
# or from cache if already merged
@commits
=
@merge_request
.
commits
@commits
=
@merge_request
.
commits
@commits
=
CommitDecorator
.
decorate
(
@commits
)
@commits
=
CommitDecorator
.
decorate
(
@commits
)
...
...
app/controllers/milestones_controller.rb
View file @
679d0d6d
...
@@ -54,7 +54,7 @@ class MilestonesController < ProjectResourceController
...
@@ -54,7 +54,7 @@ class MilestonesController < ProjectResourceController
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
js
format
.
js
format
.
html
do
format
.
html
do
if
@milestone
.
valid?
if
@milestone
.
valid?
redirect_to
[
@project
,
@milestone
]
redirect_to
[
@project
,
@milestone
]
else
else
...
...
app/controllers/refs_controller.rb
View file @
679d0d6d
...
@@ -9,9 +9,9 @@ class RefsController < ProjectResourceController
...
@@ -9,9 +9,9 @@ class RefsController < ProjectResourceController
before_filter
:ref
before_filter
:ref
before_filter
:define_tree_vars
,
only:
[
:blob
,
:logs_tree
]
before_filter
:define_tree_vars
,
only:
[
:blob
,
:logs_tree
]
def
switch
def
switch
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
do
format
.
html
do
new_path
=
if
params
[
:destination
]
==
"tree"
new_path
=
if
params
[
:destination
]
==
"tree"
project_tree_path
(
@project
,
@ref
)
project_tree_path
(
@project
,
@ref
)
else
else
...
...
app/controllers/search_controller.rb
View file @
679d0d6d
class
SearchController
<
ApplicationController
class
SearchController
<
ApplicationController
def
show
def
show
query
=
params
[
:search
]
result
=
SearchContext
.
new
(
current_user
.
project_ids
,
params
).
execute
@projects
=
[]
@projects
=
result
[
:projects
]
@merge_requests
=
[]
@merge_requests
=
result
[
:merge_requests
]
@issues
=
[]
@issues
=
result
[
:issues
]
if
query
.
present?
@projects
=
current_user
.
projects
.
search
(
query
).
limit
(
10
)
@merge_requests
=
MergeRequest
.
where
(
project_id:
current_user
.
project_ids
).
search
(
query
).
limit
(
10
)
@issues
=
Issue
.
where
(
project_id:
current_user
.
project_ids
).
search
(
query
).
limit
(
10
)
end
end
end
end
end
app/helpers/issues_helper.rb
View file @
679d0d6d
...
@@ -43,4 +43,13 @@ module IssuesHelper
...
@@ -43,4 +43,13 @@ module IssuesHelper
# Milestone uses :title, Issue uses :name
# Milestone uses :title, Issue uses :name
OpenStruct
.
new
(
id:
0
,
title:
'Unspecified'
,
name:
'Unassigned'
)
OpenStruct
.
new
(
id:
0
,
title:
'Unspecified'
,
name:
'Unassigned'
)
end
end
def
issues_filter
{
all:
"all"
,
closed:
"closed"
,
to_me:
"assigned-to-me"
,
open:
"open"
}
end
end
end
app/models/event.rb
View file @
679d0d6d
...
@@ -30,6 +30,7 @@ class Event < ActiveRecord::Base
...
@@ -30,6 +30,7 @@ class Event < ActiveRecord::Base
# Scopes
# Scopes
scope
:recent
,
order
(
"created_at DESC"
)
scope
:recent
,
order
(
"created_at DESC"
)
scope
:code_push
,
where
(
action:
Pushed
)
scope
:code_push
,
where
(
action:
Pushed
)
scope
:in_projects
,
->
(
project_ids
)
{
where
(
project_id:
project_ids
).
recent
}
class
<<
self
class
<<
self
def
determine_action
(
record
)
def
determine_action
(
record
)
...
@@ -39,10 +40,6 @@ class Event < ActiveRecord::Base
...
@@ -39,10 +40,6 @@ class Event < ActiveRecord::Base
Event
::
Commented
Event
::
Commented
end
end
end
end
def
recent_for_user
user
where
(
project_id:
user
.
projects
.
map
(
&
:id
)).
recent
end
end
end
# Next events currently enabled for system
# Next events currently enabled for system
...
...
app/roles/issue_commonality.rb
View file @
679d0d6d
# Contains common functionality
# Contains common functionality shared between Issues and MergeRequests
# shared between Issues and MergeRequests
module
IssueCommonality
module
IssueCommonality
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
...
@@ -18,6 +17,7 @@ module IssueCommonality
...
@@ -18,6 +17,7 @@ module IssueCommonality
scope
:closed
,
where
(
closed:
true
)
scope
:closed
,
where
(
closed:
true
)
scope
:of_group
,
->
(
group
)
{
where
(
project_id:
group
.
project_ids
)
}
scope
:of_group
,
->
(
group
)
{
where
(
project_id:
group
.
project_ids
)
}
scope
:assigned
,
->
(
u
)
{
where
(
assignee_id:
u
.
id
)}
scope
:assigned
,
->
(
u
)
{
where
(
assignee_id:
u
.
id
)}
scope
:recent
,
order
(
"created_at DESC"
)
delegate
:name
,
delegate
:name
,
:email
,
:email
,
...
...
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