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
iv
gitlab-ce
Commits
5d2bd5ec
Commit
5d2bd5ec
authored
Mar 16, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simple search implementation
parent
b2c13bdd
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
127 additions
and
4 deletions
+127
-4
app/assets/javascripts/application.js
app/assets/javascripts/application.js
+1
-0
app/assets/stylesheets/common.scss
app/assets/stylesheets/common.scss
+4
-0
app/controllers/search_controller.rb
app/controllers/search_controller.rb
+12
-0
app/models/merge_request.rb
app/models/merge_request.rb
+4
-0
app/models/project.rb
app/models/project.rb
+4
-0
app/views/dashboard/_projects_feed.html.haml
app/views/dashboard/_projects_feed.html.haml
+1
-1
app/views/dashboard/index.html.haml
app/views/dashboard/index.html.haml
+1
-1
app/views/layouts/_app_menu.html.haml
app/views/layouts/_app_menu.html.haml
+1
-0
app/views/layouts/_head_panel.html.haml
app/views/layouts/_head_panel.html.haml
+3
-1
app/views/search/_result.html.haml
app/views/search/_result.html.haml
+1
-0
app/views/search/show.html.haml
app/views/search/show.html.haml
+41
-0
config/routes.rb
config/routes.rb
+1
-1
vendor/assets/javascripts/jquery.highlight.js
vendor/assets/javascripts/jquery.highlight.js
+53
-0
No files found.
app/assets/javascripts/application.js
View file @
5d2bd5ec
...
...
@@ -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 @
5d2bd5ec
...
...
@@ -947,3 +947,7 @@ p.time {
padding
:
4px
;
margin
:
2px
;
}
.highlight_word
{
background
:
#EEDC94
;
}
app/controllers/search_controller.rb
0 → 100644
View file @
5d2bd5ec
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 @
5d2bd5ec
...
...
@@ -37,6 +37,10 @@ class MergeRequest < ActiveRecord::Base
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 @
5d2bd5ec
...
...
@@ -54,6 +54,10 @@ class Project < ActiveRecord::Base
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 @
5d2bd5ec
-
@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 @
5d2bd5ec
...
...
@@ -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 @
5d2bd5ec
%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 @
5d2bd5ec
...
...
@@ -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 @
5d2bd5ec
app/views/search/show.html.haml
0 → 100644
View file @
5d2bd5ec
=
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 @
5d2bd5ec
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 @
5d2bd5ec
/*
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
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