Skip to content

Commit ac8247b

Browse files
committed
Improved search. added filters
1 parent f6c482c commit ac8247b

File tree

7 files changed

+117
-106
lines changed

7 files changed

+117
-106
lines changed

app/assets/stylesheets/common.scss

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
html {
2-
overflow-y: scroll;
2+
overflow-y: scroll;
33
}
44

55
/** LAYOUT **/
@@ -277,8 +277,20 @@ p.time {
277277
}
278278
}
279279

280+
.search-holder {
281+
label, input {
282+
height: 30px;
283+
padding: 0;
284+
font-size: 14px;
285+
}
286+
label {
287+
line-height: 30px;
288+
color: #666;
289+
}
290+
}
291+
280292
.highlight_word {
281-
background: #EEDC94;
293+
border-bottom: 2px solid #F90;
282294
}
283295

284296
.status_info {

app/controllers/search_controller.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
class SearchController < ApplicationController
22
def show
3-
result = SearchContext.new(current_user.authorized_projects.map(&:id), params).execute
3+
project_id = params[:project_id]
4+
group_id = params[:group_id]
5+
6+
project_ids = current_user.authorized_projects.map(&:id)
7+
8+
if group_id.present?
9+
group_project_ids = Group.find(group_id).projects.map(&:id)
10+
project_ids.select! { |id| group_project_ids.include?(id)}
11+
elsif project_id.present?
12+
project_ids.select! { |id| id == project_id.to_i}
13+
end
14+
15+
result = SearchContext.new(project_ids, params).execute
416

517
@projects = result[:projects]
618
@merge_requests = result[:merge_requests]

app/helpers/application_helper.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def grouped_options_refs(destination = :tree)
7272
end
7373

7474
def search_autocomplete_source
75-
projects = current_user.authorized_projects.map { |p| { label: p.name_with_namespace, url: project_path(p) } }
76-
groups = current_user.authorized_groups.map { |group| { label: "<group> #{group.name}", url: group_path(group) } }
75+
projects = current_user.authorized_projects.map { |p| { label: "project: #{p.name_with_namespace}", url: project_path(p) } }
76+
groups = current_user.authorized_groups.map { |group| { label: "group: #{group.name}", url: group_path(group) } }
7777

7878
default_nav = [
7979
{ label: "My Profile", url: profile_path },
@@ -83,29 +83,29 @@ def search_autocomplete_source
8383
]
8484

8585
help_nav = [
86-
{ label: "API Help", url: help_api_path },
87-
{ label: "Markdown Help", url: help_markdown_path },
88-
{ label: "Permissions Help", url: help_permissions_path },
89-
{ label: "Public Access Help", url: help_public_access_path },
90-
{ label: "Rake Tasks Help", url: help_raketasks_path },
91-
{ label: "SSH Keys Help", url: help_ssh_path },
92-
{ label: "System Hooks Help", url: help_system_hooks_path },
93-
{ label: "Web Hooks Help", url: help_web_hooks_path },
94-
{ label: "Workflow Help", url: help_workflow_path },
86+
{ label: "help: API Help", url: help_api_path },
87+
{ label: "help: Markdown Help", url: help_markdown_path },
88+
{ label: "help: Permissions Help", url: help_permissions_path },
89+
{ label: "help: Public Access Help", url: help_public_access_path },
90+
{ label: "help: Rake Tasks Help", url: help_raketasks_path },
91+
{ label: "help: SSH Keys Help", url: help_ssh_path },
92+
{ label: "help: System Hooks Help", url: help_system_hooks_path },
93+
{ label: "help: Web Hooks Help", url: help_web_hooks_path },
94+
{ label: "help: Workflow Help", url: help_workflow_path },
9595
]
9696

9797
project_nav = []
9898
if @project && @project.repository && @project.repository.root_ref
9999
project_nav = [
100-
{ label: "#{@project.name} Issues", url: project_issues_path(@project) },
101-
{ label: "#{@project.name} Commits", url: project_commits_path(@project, @ref || @project.repository.root_ref) },
102-
{ label: "#{@project.name} Merge Requests", url: project_merge_requests_path(@project) },
103-
{ label: "#{@project.name} Milestones", url: project_milestones_path(@project) },
104-
{ label: "#{@project.name} Snippets", url: project_snippets_path(@project) },
105-
{ label: "#{@project.name} Team", url: project_team_index_path(@project) },
106-
{ label: "#{@project.name} Tree", url: project_tree_path(@project, @ref || @project.repository.root_ref) },
107-
{ label: "#{@project.name} Wall", url: wall_project_path(@project) },
108-
{ label: "#{@project.name} Wiki", url: project_wikis_path(@project) },
100+
{ label: "#{@project.name_with_namespace} - Issues", url: project_issues_path(@project) },
101+
{ label: "#{@project.name_with_namespace} - Commits", url: project_commits_path(@project, @ref || @project.repository.root_ref) },
102+
{ label: "#{@project.name_with_namespace} - Merge Requests", url: project_merge_requests_path(@project) },
103+
{ label: "#{@project.name_with_namespace} - Milestones", url: project_milestones_path(@project) },
104+
{ label: "#{@project.name_with_namespace} - Snippets", url: project_snippets_path(@project) },
105+
{ label: "#{@project.name_with_namespace} - Team", url: project_team_index_path(@project) },
106+
{ label: "#{@project.name_with_namespace} - Tree", url: project_tree_path(@project, @ref || @project.repository.root_ref) },
107+
{ label: "#{@project.name_with_namespace} - Wall", url: wall_project_path(@project) },
108+
{ label: "#{@project.name_with_namespace} - Wiki", url: project_wikis_path(@project) },
109109
]
110110
end
111111

app/views/layouts/_search.html.haml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.search
22
= form_tag search_path, method: :get, class: 'navbar-form pull-left' do |f|
33
= text_field_tag "search", nil, placeholder: "Search", class: "search-input"
4+
= hidden_field_tag :group_id, @group.try(:id)
5+
= hidden_field_tag :project_id, @project.try(:id)
46

57
:javascript
68
$(function(){

app/views/search/_filter.html.haml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
%fieldset
2+
%legend Groups:
3+
%ul.nav.nav-pills.nav-stacked
4+
%li{class: ("active" if params[:group_id].blank?)}
5+
= link_to search_path(group_id: nil, search: params[:search]) do
6+
Any
7+
- current_user.authorized_groups.each do |group|
8+
%li{class: ("active" if params[:group_id] == group.id.to_s)}
9+
= link_to search_path(group_id: group.id, search: params[:search]) do
10+
= group.name
11+
12+
%fieldset
13+
%legend Projects:
14+
%ul.nav.nav-pills.nav-stacked
15+
%li{class: ("active" if params[:project_id].blank?)}
16+
= link_to search_path(project_id: nil, search: params[:search]) do
17+
Any
18+
- current_user.authorized_projects.each do |project|
19+
%li{class: ("active" if params[:project_id] == project.id.to_s)}
20+
= link_to search_path(project_id: project.id, search: params[:search]) do
21+
= project.name_with_namespace
22+
23+
= hidden_field_tag :group_id, params[:group_id]
24+
= hidden_field_tag :project_id, params[:project_id]

app/views/search/_result.html.haml

Lines changed: 34 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,38 @@
1-
%br
2-
%h3.page_title
3-
Search results
4-
%span.cgray (#{@projects.count + @merge_requests.count + @issues.count + @wiki_pages.count})
5-
%hr
1+
%fieldset
2+
%legend
3+
Search results
4+
%span.cgray (#{@projects.count + @merge_requests.count + @issues.count + @wiki_pages.count})
65
.search_results
7-
.row
8-
.span6
9-
%table
10-
%thead
11-
%tr
12-
%th Projects
13-
%tbody
14-
- @projects.each do |project|
15-
%tr
16-
%td
17-
= link_to project do
18-
%strong.term= project.name_with_namespace
19-
%small.cgray
20-
last activity at
21-
= project.last_activity_date.stamp("Aug 25, 2011")
22-
- if @projects.blank?
23-
%tr
24-
%td
25-
%h4.nothing_here_message No Projects
26-
%br
27-
%table
28-
%thead
29-
%tr
30-
%th Merge Requests
31-
%tbody
32-
- @merge_requests.each do |merge_request|
33-
%tr
34-
%td
35-
= link_to [merge_request.project, merge_request] do
36-
%span.badge.badge-info ##{merge_request.id}
37-
&ndash;
38-
%strong.term= truncate merge_request.title, length: 50
39-
%strong.right
40-
%span.label= merge_request.project.name
41-
- if @merge_requests.blank?
42-
%tr
43-
%td
44-
%h4.nothing_here_message No Merge Requests
45-
.span6
46-
%table
47-
%thead
48-
%tr
49-
%th Issues
50-
%tbody
51-
- @issues.each do |issue|
52-
%tr
53-
%td
54-
= link_to [issue.project, issue] do
55-
%span.badge.badge-info ##{issue.id}
56-
&ndash;
57-
%strong.term= truncate issue.title, length: 40
58-
%strong.right
59-
%span.label= issue.project.name
60-
- if @issues.blank?
61-
%tr
62-
%td
63-
%h4.nothing_here_message No Issues
64-
.span6
65-
%table
66-
%thead
67-
%tr
68-
%th Wiki
69-
%tbody
70-
- @wiki_pages.each do |wiki_page|
71-
%tr
72-
%td
73-
= link_to project_wiki_path(wiki_page.project, wiki_page) do
74-
%strong.term= truncate wiki_page.title, length: 40
75-
%strong.right
76-
%span.label= wiki_page.project.name
77-
- if @wiki_pages.blank?
78-
%tr
79-
%td
80-
%h4.nothing_here_message No wiki pages
6+
%ul.well-list
7+
- @projects.each do |project|
8+
%li
9+
project:
10+
= link_to project do
11+
%strong.term= project.name_with_namespace
12+
- @merge_requests.each do |merge_request|
13+
%li
14+
merge request:
15+
= link_to [merge_request.project, merge_request] do
16+
%span ##{merge_request.id}
17+
%strong.term
18+
= truncate merge_request.title, length: 50
19+
%span.light (#{merge_request.project.name_with_namespace})
20+
- @issues.each do |issue|
21+
%li
22+
issue:
23+
= link_to [issue.project, issue] do
24+
%span ##{issue.id}
25+
%strong.term
26+
= truncate issue.title, length: 50
27+
%span.light (#{issue.project.name_with_namespace})
28+
- @wiki_pages.each do |wiki_page|
29+
%li
30+
wiki:
31+
= link_to project_wiki_path(wiki_page.project, wiki_page) do
32+
%strong.term
33+
= truncate wiki_page.title, length: 50
34+
%span.light (#{wiki_page.project.name_with_namespace})
35+
8136
:javascript
8237
$(function() {
8338
$(".search_results .term").highlight("#{escape_javascript(params[:search])}");

app/views/search/show.html.haml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
= form_tag search_path, method: :get, class: 'form-inline' do |f|
2-
.padded
2+
.search-holder
33
= label_tag :search do
4-
%strong Looking for
4+
%span Looking for
55
.input
66
= search_field_tag :search, params[:search], placeholder: "issue 143", class: "input-xxlarge search-text-input", id: "dashboard_search"
77
= submit_tag 'Search', class: "btn primary wide"
8-
- if params[:search].present?
9-
= render 'search/result'
8+
.clearfix
9+
.row
10+
.span3
11+
= render 'filter', f: f
12+
.span9
13+
.results
14+
- if params[:search].present?
15+
= render 'search/result'

0 commit comments

Comments
 (0)