Commit 5f31989a authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Search improved

parent 8dc29896
...@@ -4,9 +4,11 @@ class SearchController < ApplicationController ...@@ -4,9 +4,11 @@ class SearchController < ApplicationController
if query.blank? if query.blank?
@projects = [] @projects = []
@merge_requests = [] @merge_requests = []
@issues = []
else else
@projects = Project.search(query).limit(10) @projects = current_user.projects.search(query).limit(10)
@merge_requests = MergeRequest.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 end
end end
...@@ -42,6 +42,10 @@ class Issue < ActiveRecord::Base ...@@ -42,6 +42,10 @@ class Issue < ActiveRecord::Base
opened.assigned(user) opened.assigned(user)
end end
def self.search query
where("title like :query", :query => "%#{query}%")
end
def today? def today?
Date.today == created_at.to_date Date.today == created_at.to_date
end end
......
...@@ -97,6 +97,10 @@ class User < ActiveRecord::Base ...@@ -97,6 +97,10 @@ class User < ActiveRecord::Base
def cared_merge_requests def cared_merge_requests
MergeRequest.where("author_id = :id or assignee_id = :id", :id => self.id).opened MergeRequest.where("author_id = :id or assignee_id = :id", :id => self.id).opened
end end
def project_ids
projects.map(&:id)
end
end end
# == Schema Information # == Schema Information
# #
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
%small Nothing here %small Nothing here
- else - else
- if @projects.any? - if @projects.any?
%h4 Projects
.padded
- @projects.each do |project| - @projects.each do |project|
= link_to project do = link_to project do
%h4 %h4
...@@ -23,6 +25,8 @@ ...@@ -23,6 +25,8 @@
last activity at last activity at
= project.last_activity_date.stamp("Aug 25, 2011") = project.last_activity_date.stamp("Aug 25, 2011")
- if @merge_requests.any? - if @merge_requests.any?
%h4 Merge Requests
.padded
- @merge_requests.each do |merge_request| - @merge_requests.each do |merge_request|
= link_to [merge_request.project, merge_request] do = link_to [merge_request.project, merge_request] do
%h5 %h5
...@@ -35,6 +39,21 @@ ...@@ -35,6 +39,21 @@
= merge_request.updated_at.stamp("Aug 25, 2011") = merge_request.updated_at.stamp("Aug 25, 2011")
%strong %strong
%span.label= merge_request.project.name %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 :javascript
$(function() { $(function() {
$(".search_results").highlight("#{params[:search]}"); $(".search_results").highlight("#{params[:search]}");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment