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
b49ebf57
Commit
b49ebf57
authored
Jan 09, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use new context for search
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
4791084d
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
20 additions
and
85 deletions
+20
-85
app/assets/stylesheets/generic/nav.scss
app/assets/stylesheets/generic/nav.scss
+1
-4
app/contexts/search_context.rb
app/contexts/search_context.rb
+0
-42
app/controllers/search_controller.rb
app/controllers/search_controller.rb
+8
-28
app/views/search/_filter.html.haml
app/views/search/_filter.html.haml
+2
-2
app/views/search/_global_results.html.haml
app/views/search/_global_results.html.haml
+3
-3
app/views/search/_project_results.html.haml
app/views/search/_project_results.html.haml
+5
-5
app/views/search/_results.html.haml
app/views/search/_results.html.haml
+1
-1
No files found.
app/assets/stylesheets/generic/nav.scss
View file @
b49ebf57
...
...
@@ -7,12 +7,9 @@
background
:
$primary_color
;
}
>
li
>
a
{
@include
border-radius
(
0
);
}
&
.nav-stacked
{
>
li
>
a
{
@include
border-radius
(
0
);
border-left
:
4px
solid
#EEE
;
padding
:
12px
;
color
:
#777
;
...
...
app/contexts/search_context.rb
deleted
100644 → 0
View file @
4791084d
class
SearchContext
attr_accessor
:project_ids
,
:current_user
,
:params
def
initialize
(
project_ids
,
user
,
params
)
@project_ids
,
@current_user
,
@params
=
project_ids
,
user
,
params
.
dup
end
def
execute
query
=
params
[
:search
]
query
=
Shellwords
.
shellescape
(
query
)
if
query
.
present?
return
result
unless
query
.
present?
visibility_levels
=
@current_user
?
[
Gitlab
::
VisibilityLevel
::
INTERNAL
,
Gitlab
::
VisibilityLevel
::
PUBLIC
]
:
[
Gitlab
::
VisibilityLevel
::
PUBLIC
]
result
[
:projects
]
=
Project
.
where
(
"projects.id in (?) OR projects.visibility_level in (?)"
,
project_ids
,
visibility_levels
).
search
(
query
).
limit
(
20
)
# Search inside single project
single_project_search
(
Project
.
where
(
id:
project_ids
),
query
)
result
end
def
single_project_search
(
projects
,
query
)
project
=
projects
.
first
if
projects
.
length
==
1
if
params
[
:search_code
].
present?
result
[
:blobs
]
=
project
.
repository
.
search_files
(
query
,
params
[
:repository_ref
])
unless
project
.
empty_repo?
else
result
[
:merge_requests
]
=
MergeRequest
.
in_projects
(
project_ids
).
search
(
query
).
order
(
'updated_at DESC'
).
limit
(
20
)
result
[
:issues
]
=
Issue
.
where
(
project_id:
project_ids
).
search
(
query
).
order
(
'updated_at DESC'
).
limit
(
20
)
result
[
:wiki_pages
]
=
[]
end
end
def
result
@result
||=
{
projects:
[],
merge_requests:
[],
issues:
[],
wiki_pages:
[],
blobs:
[]
}
end
end
app/controllers/search_controller.rb
View file @
b49ebf57
class
SearchController
<
ApplicationController
def
show
project_id
=
params
[
:project_id
]
group_id
=
params
[
:group_id
]
project_ids
=
find_project_ids
(
group_id
,
project_id
)
result
=
SearchContext
.
new
(
project_ids
,
current_user
,
params
).
execute
@projects
=
result
[
:projects
]
@merge_requests
=
result
[
:merge_requests
]
@issues
=
result
[
:issues
]
@wiki_pages
=
result
[
:wiki_pages
]
@blobs
=
Kaminari
.
paginate_array
(
result
[
:blobs
]).
page
(
params
[
:page
]).
per
(
20
)
@total_results
=
@projects
.
count
+
@merge_requests
.
count
+
@issues
.
count
+
@wiki_pages
.
count
+
@blobs
.
total_count
end
private
def
find_project_ids
(
group_id
,
project_id
)
project_ids
=
current_user
.
authorized_projects
.
map
(
&
:id
)
if
group_id
.
present?
@group
=
Group
.
find
(
group_id
)
group_project_ids
=
@group
.
projects
.
map
(
&
:id
)
project_ids
.
select!
{
|
id
|
group_project_ids
.
include?
(
id
)
}
elsif
project_id
.
present?
@project
=
Project
.
find
(
project_id
)
project_ids
=
@project
.
public?
?
[
@project
.
id
]
:
project_ids
.
select
{
|
id
|
id
==
project_id
.
to_i
}
@project
=
Project
.
find_by_id
(
params
[
:project_id
])
if
params
[
:project_id
].
present?
@group
=
Group
.
find_by_id
(
params
[
:group_id
])
if
params
[
:group_id
].
present?
if
@project
return
access_denied!
unless
can?
(
current_user
,
:download_code
,
@project
)
@search_results
=
Search
::
ProjectContext
.
new
(
@project
,
current_user
,
params
).
execute
else
@search_results
=
Search
::
GlobalContext
.
new
(
current_user
,
params
).
execute
end
project_ids
end
end
app/views/search/_filter.html.haml
View file @
b49ebf57
...
...
@@ -9,7 +9,7 @@
%b
.caret
%ul
.dropdown-menu
%li
=
link_to
search_path
(
group_id:
nil
)
do
=
link_to
search_path
(
group_id:
nil
,
search:
params
[
:search
]
)
do
Any
-
current_user
.
authorized_groups
.
sort_by
(
&
:name
).
each
do
|
group
|
%li
...
...
@@ -27,7 +27,7 @@
%b
.caret
%ul
.dropdown-menu
%li
=
link_to
search_path
(
project_id:
nil
)
do
=
link_to
search_path
(
project_id:
nil
,
search:
params
[
:search
]
)
do
Any
-
current_user
.
authorized_projects
.
sort_by
(
&
:name_with_namespace
).
each
do
|
project
|
%li
...
...
app/views/search/_global_results.html.haml
View file @
b49ebf57
.search_results
%ul
.bordered-list
=
render
partial:
"search/results/project"
,
collection:
@
projects
=
render
partial:
"search/results/merge_request"
,
collection:
@
merge_requests
=
render
partial:
"search/results/issue"
,
collection:
@
issues
=
render
partial:
"search/results/project"
,
collection:
@
search_results
[
:projects
]
=
render
partial:
"search/results/merge_request"
,
collection:
@
search_results
[
:merge_requests
]
=
render
partial:
"search/results/issue"
,
collection:
@
search_results
[
:issues
]
app/views/search/_project_results.html.haml
View file @
b49ebf57
%ul
.nav.nav-pills
%ul
.nav.nav-pills
.append-bottom-20
%li
{
class:
(
"active"
if
params
[
:search_code
].
present?
)}
=
link_to
search_path
(
params
.
merge
(
search_code:
true
))
do
Repository Code
...
...
@@ -9,9 +9,9 @@
.search_results
-
if
params
[
:search_code
].
present?
.blob-results
=
render
partial:
"search/results/blob"
,
collection:
@
blobs
=
paginate
@
blobs
,
theme:
'gitlab'
=
render
partial:
"search/results/blob"
,
collection:
@
search_results
[
:blobs
]
=
paginate
@
search_results
[
:blobs
]
,
theme:
'gitlab'
-
else
%ul
.bordered-list
=
render
partial:
"search/results/merge_request"
,
collection:
@
merge_requests
=
render
partial:
"search/results/issue"
,
collection:
@
issues
=
render
partial:
"search/results/merge_request"
,
collection:
@
search_results
[
:merge_requests
]
=
render
partial:
"search/results/issue"
,
collection:
@
search_results
[
:issues
]
app/views/search/_results.html.haml
View file @
b49ebf57
%fieldset
%legend
Search results
%span
.cgray
(
#{
@
total_results
}
)
%span
.cgray
(
#{
@
search_results
[
:total_results
]
}
)
-
if
@project
=
render
"project_results"
...
...
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