Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
2c6b0d96f2b9
Commit
2c6b0d96
authored
Mar 16, 2012
by
Dmitriy Zaporozhets
Browse files
Simple search implementation
parent
b7dd8d5106af
Changes
13
Hide whitespace changes
Inline
Side-by-side
app/assets/javascripts/application.js
View file @
2c6b0d96
...
...
@@ -11,6 +11,7 @@
//= require jquery.tagify
//= require jquery.cookie
//= require jquery.endless-scroll
//= require jquery.highlight
//= require bootstrap-modal
//= require modernizr
//= require chosen
...
...
app/assets/stylesheets/common.scss
View file @
2c6b0d96
...
...
@@ -947,3 +947,7 @@
padding
:
4px
;
margin
:
2px
;
}
.highlight_word
{
background
:
#EEDC94
;
}
app/controllers/search_controller.rb
0 → 100644
View file @
2c6b0d96
class
SearchController
<
ApplicationController
def
show
query
=
params
[
:search
]
if
query
.
blank?
@projects
=
[]
@merge_requests
=
[]
else
@projects
=
Project
.
search
(
query
).
limit
(
10
)
@merge_requests
=
MergeRequest
.
search
(
query
).
limit
(
10
)
end
end
end
app/models/merge_request.rb
View file @
2c6b0d96
...
...
@@ -37,6 +37,10 @@
scope
:closed
,
where
(
:closed
=>
true
)
scope
:assigned
,
lambda
{
|
u
|
where
(
:assignee_id
=>
u
.
id
)}
def
self
.
search
query
where
(
"title like :query"
,
:query
=>
"%
#{
query
}
%"
)
end
def
validate_branches
if
target_branch
==
source_branch
errors
.
add
:base
,
"You can not use same branch for source and target branches"
...
...
app/models/project.rb
View file @
2c6b0d96
...
...
@@ -54,6 +54,10 @@
UsersProject
.
access_roles
end
def
self
.
search
query
where
(
"name like :query or code like :query or path like :query"
,
:query
=>
"%
#{
query
}
%"
)
end
def
to_param
code
end
...
...
app/views/dashboard/_projects_feed.html.haml
View file @
2c6b0d96
-
@active_
projects
.
first
(
5
).
each
do
|
project
|
-
projects
.
first
(
5
).
each
do
|
project
|
.wll
=
link_to
project
do
%h4
...
...
app/views/dashboard/index.html.haml
View file @
2c6b0d96
...
...
@@ -20,7 +20,7 @@
.row
.dashboard_block
.row
.span10
=
render
"dashboard/projects_feed"
.span10
=
render
"dashboard/projects_feed"
,
:projects
=>
@active_projects
.span4.right
-
if
current_user
.
can_create_project?
.alert-message.block-message.warning
...
...
app/views/layouts/_app_menu.html.haml
View file @
2c6b0d96
%nav
.main_menu
=
render
"layouts/const_menu_links"
=
link_to
"Projects"
,
projects_path
,
:class
=>
"
#{
"current"
if
current_page?
(
projects_path
)
}
"
=
link_to
"Search"
,
search_path
,
:class
=>
"
#{
"current"
if
current_page?
(
search_path
)
}
"
=
link_to
"Issues"
,
dashboard_issues_path
,
:class
=>
"
#{
"current"
if
current_page?
(
dashboard_issues_path
)
}
"
,
:id
=>
"issues_slide"
=
link_to
"Requests"
,
dashboard_merge_requests_path
,
:class
=>
"
#{
"current"
if
current_page?
(
dashboard_merge_requests_path
)
}
"
,
:id
=>
"merge_requests_slide"
=
link_to
"Help"
,
help_path
,
:class
=>
"
#{
"current"
if
controller
.
controller_name
==
"help"
}
"
app/views/layouts/_head_panel.html.haml
View file @
2c6b0d96
...
...
@@ -7,7 +7,9 @@
%h1
GITLAB
%h1
.project_name
=
title
.search
=
text_field_tag
"search"
,
nil
,
:placeholder
=>
"Search"
,
:class
=>
"search-input"
.search
=
form_tag
search_path
,
:method
=>
:get
do
|
f
|
=
text_field_tag
"search"
,
nil
,
:placeholder
=>
"Search"
,
:class
=>
"search-input"
-
if
current_user
.
is_admin?
=
link_to
admin_projects_path
,
:class
=>
"admin_link"
,
:title
=>
"Admin area"
do
=
image_tag
"admin.PNG"
,
:width
=>
16
...
...
app/views/search/_result.html.haml
0 → 100644
View file @
2c6b0d96
app/views/search/show.html.haml
0 → 100644
View file @
2c6b0d96
=
form_tag
search_path
,
:method
=>
:get
do
|
f
|
.padded
=
label_tag
:search
,
"Looking for"
.input
=
text_field_tag
:search
,
params
[
:search
],
:placeholder
=>
"issue 143"
,
:class
=>
"xxlarge"
=
submit_tag
'Search'
,
:class
=>
"btn primary"
-
if
params
[
:search
].
present?
%br
%h3
Search results
%hr
.search_results
-
if
@projects
.
empty?
&&
@merge_requests
.
empty?
%h3
%small
Nothing here
-
else
-
if
@projects
.
any?
-
@projects
.
each
do
|
project
|
=
link_to
project
do
%h4
%span
.ico.project
=
project
.
name
%small
last activity at
=
project
.
last_activity_date
.
stamp
(
"Aug 25, 2011"
)
-
if
@merge_requests
.
any?
-
@merge_requests
.
each
do
|
merge_request
|
=
link_to
[
merge_request
.
project
,
merge_request
]
do
%h5
Merge Request
#
=
merge_request
.
id
–
=
truncate
merge_request
.
title
,
:length
=>
50
%small
updated at
=
merge_request
.
updated_at
.
stamp
(
"Aug 25, 2011"
)
%strong
%span
.label
=
merge_request
.
project
.
name
:javascript
$
(
function
()
{
$
(
"
.search_results
"
).
highlight
(
"
#{
params
[
:search
]
}
"
);
})
config/routes.rb
View file @
2c6b0d96
Gitlab
::
Application
.
routes
.
draw
do
get
'search'
=>
"search#show"
# Optionally, enable Resque here
require
'resque/server'
...
...
vendor/assets/javascripts/jquery.highlight.js
0 → 100644
View file @
2c6b0d96
/*
highlight v3
Highlights arbitrary terms.
<http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html>
MIT license.
Johann Burkard
<http://johannburkard.de>
<mailto:jb@eaio.com>
*/
jQuery
.
fn
.
highlight
=
function
(
pat
)
{
function
innerHighlight
(
node
,
pat
)
{
var
skip
=
0
;
if
(
node
.
nodeType
==
3
)
{
var
pos
=
node
.
data
.
toUpperCase
().
indexOf
(
pat
);
if
(
pos
>=
0
)
{
var
spannode
=
document
.
createElement
(
'
span
'
);
spannode
.
className
=
'
highlight_word
'
;
var
middlebit
=
node
.
splitText
(
pos
);
var
endbit
=
middlebit
.
splitText
(
pat
.
length
);
var
middleclone
=
middlebit
.
cloneNode
(
true
);
spannode
.
appendChild
(
middleclone
);
middlebit
.
parentNode
.
replaceChild
(
spannode
,
middlebit
);
skip
=
1
;
}
}
else
if
(
node
.
nodeType
==
1
&&
node
.
childNodes
&&
!
/
(
script|style
)
/i
.
test
(
node
.
tagName
))
{
for
(
var
i
=
0
;
i
<
node
.
childNodes
.
length
;
++
i
)
{
i
+=
innerHighlight
(
node
.
childNodes
[
i
],
pat
);
}
}
return
skip
;
}
return
this
.
each
(
function
()
{
innerHighlight
(
this
,
pat
.
toUpperCase
());
});
};
jQuery
.
fn
.
removeHighlight
=
function
()
{
return
this
.
find
(
"
span.highlight
"
).
each
(
function
()
{
this
.
parentNode
.
firstChild
.
nodeName
;
with
(
this
.
parentNode
)
{
replaceChild
(
this
.
firstChild
,
this
);
normalize
();
}
}).
end
();
};
Write
Preview
Supports
Markdown
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