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
Léo-Paul Géneau
gitlab-ce
Commits
46daf01a
Commit
46daf01a
authored
May 14, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Search for blobs by default inside project. Added pagination for blobs search
parent
634cbd71
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
16 deletions
+31
-16
app/contexts/search_context.rb
app/contexts/search_context.rb
+9
-2
app/controllers/search_controller.rb
app/controllers/search_controller.rb
+1
-1
app/views/layouts/_search.html.haml
app/views/layouts/_search.html.haml
+3
-1
app/views/search/_blob.html.haml
app/views/search/_blob.html.haml
+10
-0
app/views/search/_result.html.haml
app/views/search/_result.html.haml
+6
-12
app/views/search/show.html.haml
app/views/search/show.html.haml
+2
-0
No files found.
app/contexts/search_context.rb
View file @
46daf01a
...
...
@@ -14,10 +14,17 @@ class SearchContext
result
[
:projects
]
=
projects
.
search
(
query
).
limit
(
10
)
# Search inside singe project
result
[
:project
]
=
project
=
projects
.
first
if
projects
.
length
==
1
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?
blobs
=
[]
unless
project
.
empty_repo?
blobs
=
project
.
repository
.
search_files
(
query
,
params
[
:repository_ref
])
blobs
=
Kaminari
.
paginate_array
(
blobs
).
page
(
params
[
:page
]).
per
(
20
)
end
result
[
:blobs
]
=
blobs
else
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
)
...
...
app/controllers/search_controller.rb
View file @
46daf01a
...
...
@@ -10,13 +10,13 @@ class SearchController < ApplicationController
group_project_ids
=
@group
.
projects
.
map
(
&
:id
)
project_ids
.
select!
{
|
id
|
group_project_ids
.
include?
(
id
)}
elsif
project_id
.
present?
@project
=
Project
.
find
(
params
[
:project_id
])
project_ids
.
select!
{
|
id
|
id
==
project_id
.
to_i
}
end
result
=
SearchContext
.
new
(
project_ids
,
params
).
execute
@projects
=
result
[
:projects
]
@project
=
result
[
:project
]
@merge_requests
=
result
[
:merge_requests
]
@issues
=
result
[
:issues
]
@wiki_pages
=
result
[
:wiki_pages
]
...
...
app/views/layouts/_search.html.haml
View file @
46daf01a
...
...
@@ -2,7 +2,9 @@
=
form_tag
search_path
,
method: :get
,
class:
'navbar-form pull-left'
do
|
f
|
=
text_field_tag
"search"
,
nil
,
placeholder:
"Search"
,
class:
"search-input"
=
hidden_field_tag
:group_id
,
@group
.
try
(
:id
)
=
hidden_field_tag
:project_id
,
@project
.
try
(
:id
)
-
if
@project
&&
@project
.
persisted?
=
hidden_field_tag
:project_id
,
@project
.
id
=
hidden_field_tag
:search_code
,
true
=
hidden_field_tag
:repository_ref
,
@ref
=
submit_tag
'Go'
if
ENV
[
'RAILS_ENV'
]
==
'test'
.search-autocomplete-json.hide
{
:'data-autocomplete-opts'
=>
search_autocomplete_source
}
app/views/search/_blob.html.haml
0 → 100644
View file @
46daf01a
%li
.file_holder
.file_title
=
link_to
project_blob_path
(
@project
,
tree_join
(
blob
.
ref
,
blob
.
filename
),
:anchor
=>
"L"
+
blob
.
startline
.
to_s
)
do
%i
.icon-file
%strong
=
blob
.
filename
.file_content.code.term
%div
{
class:
user_color_scheme_class
}
=
raw
blob
.
colorize
(
formatter: :gitlab
,
options:
{
first_line_number:
blob
.
startline
}
)
app/views/search/_result.html.haml
View file @
46daf01a
%fieldset
%legend
Search results
%span
.cgray
(
#{
@projects
.
count
+
@merge_requests
.
count
+
@issues
.
count
+
@wiki_pages
.
count
+
@blobs
.
count
}
)
%span
.cgray
(
#{
@projects
.
count
+
@merge_requests
.
count
+
@issues
.
count
+
@wiki_pages
.
count
+
@blobs
.
total_
count
}
)
-
if
@project
%ul
.nav.nav-pills
...
...
@@ -43,17 +43,11 @@
%strong
.term
=
truncate
wiki_page
.
title
,
length:
50
%span
.light
(
#{
wiki_page
.
project
.
name_with_namespace
}
)
-
@blobs
.
each
do
|
file
|
%li
.file_holder
.file_title
=
link_to
project_blob_path
(
@project
,
tree_join
(
file
.
ref
,
file
.
filename
),
:anchor
=>
"L"
+
file
.
startline
.
to_s
)
do
%i
.icon-file
%strong
=
file
.
filename
.file_content.code.term
%div
{
class:
user_color_scheme_class
}
=
raw
file
.
colorize
(
formatter: :gitlab
,
options:
{
first_line_number:
file
.
startline
}
)
-
@blobs
.
each
do
|
blob
|
=
render
'blob'
,
blob:
blob
=
paginate
@blobs
,
theme:
'gitlab'
:javascript
$
(
function
()
{
...
...
app/views/search/show.html.haml
View file @
46daf01a
...
...
@@ -4,6 +4,8 @@
%span
Looking for
.input
=
search_field_tag
:search
,
params
[
:search
],
placeholder:
"issue 143"
,
class:
"input-xxlarge search-text-input"
,
id:
"dashboard_search"
=
hidden_field_tag
:project_id
,
params
[
:project_id
]
=
hidden_field_tag
:group_id
,
params
[
:group_id
]
=
hidden_field_tag
:search_code
,
params
[
:search_code
]
=
submit_tag
'Search'
,
class:
"btn btn-primary wide"
.prepend-top-10
...
...
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