summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-04-14 11:16:11 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-04-14 11:16:11 +0300
commit5f31989a0501c12ae609709f8707841ec3fc7e31 (patch)
treedf242773dc5f69f777c832970958462f2070eb27 /app
parent8dc2989665bc6a568fbeba1aec9e9cc8d480fbae (diff)
downloadgitlab-ce-5f31989a0501c12ae609709f8707841ec3fc7e31.tar.gz
Search improved
Diffstat (limited to 'app')
-rw-r--r--app/controllers/search_controller.rb6
-rw-r--r--app/models/issue.rb4
-rw-r--r--app/models/user.rb4
-rw-r--r--app/views/search/show.html.haml59
4 files changed, 51 insertions, 22 deletions
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
index 8a452fe0914..dfc318c5fb1 100644
--- a/app/controllers/search_controller.rb
+++ b/app/controllers/search_controller.rb
@@ -4,9 +4,11 @@ class SearchController < ApplicationController
if query.blank?
@projects = []
@merge_requests = []
+ @issues = []
else
- @projects = Project.search(query).limit(10)
- @merge_requests = MergeRequest.search(query).limit(10)
+ @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
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 5ca257960a2..5fe0e0b2b45 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -42,6 +42,10 @@ class Issue < ActiveRecord::Base
opened.assigned(user)
end
+ def self.search query
+ where("title like :query", :query => "%#{query}%")
+ end
+
def today?
Date.today == created_at.to_date
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 2601de2791a..3149de432c5 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -97,6 +97,10 @@ class User < ActiveRecord::Base
def cared_merge_requests
MergeRequest.where("author_id = :id or assignee_id = :id", :id => self.id).opened
end
+
+ def project_ids
+ projects.map(&:id)
+ end
end
# == Schema Information
#
diff --git a/app/views/search/show.html.haml b/app/views/search/show.html.haml
index 69a0a704329..a7df49b9b4c 100644
--- a/app/views/search/show.html.haml
+++ b/app/views/search/show.html.haml
@@ -14,27 +14,46 @@
%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")
+ %h4 Projects
+ .padded
+ - @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
- &ndash;
- = truncate merge_request.title, :length => 50
- %small
- updated at
- = merge_request.updated_at.stamp("Aug 25, 2011")
- %strong
- %span.label= merge_request.project.name
+ %h4 Merge Requests
+ .padded
+ - @merge_requests.each do |merge_request|
+ = link_to [merge_request.project, merge_request] do
+ %h5
+ Merge Request #
+ = merge_request.id
+ &ndash;
+ = truncate merge_request.title, :length => 50
+ %small
+ updated at
+ = merge_request.updated_at.stamp("Aug 25, 2011")
+ %strong
+ %span.label= merge_request.project.name
+ - if @issues.any?
+ %h4 Issues
+ .padded
+ - @issues.each do |issue|
+ = link_to [issue.project, issue] do
+ %h5
+ Issue #
+ = issue.id
+ &ndash;
+ = truncate issue.title, :length => 50
+ %small
+ updated at
+ = issue.updated_at.stamp("Aug 25, 2011")
+ %strong
+ %span.label= issue.project.name
:javascript
$(function() {
$(".search_results").highlight("#{params[:search]}");