summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-01-09 12:37:12 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-01-09 12:37:12 +0200
commitb49ebf5737ce95bcab792c18bddc1a4675f148ed (patch)
treeaa54c0a7b8bee018761ec70d15df110655a0761c
parent4791084d7c9356c16ead5bf3162fd132fa10c979 (diff)
downloadgitlab-ce-b49ebf5737ce95bcab792c18bddc1a4675f148ed.tar.gz
Use new context for search
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/assets/stylesheets/generic/nav.scss5
-rw-r--r--app/contexts/search_context.rb42
-rw-r--r--app/controllers/search_controller.rb36
-rw-r--r--app/views/search/_filter.html.haml4
-rw-r--r--app/views/search/_global_results.html.haml6
-rw-r--r--app/views/search/_project_results.html.haml10
-rw-r--r--app/views/search/_results.html.haml2
7 files changed, 20 insertions, 85 deletions
diff --git a/app/assets/stylesheets/generic/nav.scss b/app/assets/stylesheets/generic/nav.scss
index ec01988d52d..8d9fd4786a5 100644
--- a/app/assets/stylesheets/generic/nav.scss
+++ b/app/assets/stylesheets/generic/nav.scss
@@ -7,12 +7,9 @@
background: $primary_color;
}
- > li > a {
- @include border-radius(0);
- }
-
&.nav-stacked {
> li > a {
+ @include border-radius(0);
border-left: 4px solid #EEE;
padding: 12px;
color: #777;
diff --git a/app/contexts/search_context.rb b/app/contexts/search_context.rb
deleted file mode 100644
index 5985ab1fb0c..00000000000
--- a/app/contexts/search_context.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-class SearchContext
- attr_accessor :project_ids, :current_user, :params
-
- def initialize(project_ids, user, params)
- @project_ids, @current_user, @params = project_ids, user, params.dup
- end
-
- def execute
- query = params[:search]
- query = Shellwords.shellescape(query) if query.present?
-
- return result unless query.present?
- visibility_levels = @current_user ? [ Gitlab::VisibilityLevel::INTERNAL, Gitlab::VisibilityLevel::PUBLIC ] : [ Gitlab::VisibilityLevel::PUBLIC ]
- result[:projects] = Project.where("projects.id in (?) OR projects.visibility_level in (?)", project_ids, visibility_levels).search(query).limit(20)
-
- # Search inside single project
- single_project_search(Project.where(id: project_ids), query)
- result
- end
-
- def single_project_search(projects, query)
- project = projects.first if projects.length == 1
-
- if params[:search_code].present?
- result[:blobs] = project.repository.search_files(query, params[:repository_ref]) unless project.empty_repo?
- else
- result[:merge_requests] = MergeRequest.in_projects(project_ids).search(query).order('updated_at DESC').limit(20)
- result[:issues] = Issue.where(project_id: project_ids).search(query).order('updated_at DESC').limit(20)
- result[:wiki_pages] = []
- end
- end
-
- def result
- @result ||= {
- projects: [],
- merge_requests: [],
- issues: [],
- wiki_pages: [],
- blobs: []
- }
- end
-end
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
index 407048233e1..ba8f08c5b82 100644
--- a/app/controllers/search_controller.rb
+++ b/app/controllers/search_controller.rb
@@ -1,33 +1,13 @@
class SearchController < ApplicationController
def show
- project_id = params[:project_id]
- group_id = params[:group_id]
-
- project_ids = find_project_ids(group_id, project_id)
-
- result = SearchContext.new(project_ids, current_user, params).execute
-
- @projects = result[:projects]
- @merge_requests = result[:merge_requests]
- @issues = result[:issues]
- @wiki_pages = result[:wiki_pages]
- @blobs = Kaminari.paginate_array(result[:blobs]).page(params[:page]).per(20)
- @total_results = @projects.count + @merge_requests.count + @issues.count + @wiki_pages.count + @blobs.total_count
- end
-
- private
-
- def find_project_ids(group_id, project_id)
- project_ids = current_user.authorized_projects.map(&:id)
-
- if group_id.present?
- @group = Group.find(group_id)
- group_project_ids = @group.projects.map(&:id)
- project_ids.select! { |id| group_project_ids.include?(id) }
- elsif project_id.present?
- @project = Project.find(project_id)
- project_ids = @project.public? ? [@project.id] : project_ids.select { |id| id == project_id.to_i }
+ @project = Project.find_by_id(params[:project_id]) if params[:project_id].present?
+ @group = Group.find_by_id(params[:group_id]) if params[:group_id].present?
+
+ if @project
+ return access_denied! unless can?(current_user, :download_code, @project)
+ @search_results = Search::ProjectContext.new(@project, current_user, params).execute
+ else
+ @search_results = Search::GlobalContext.new(current_user, params).execute
end
- project_ids
end
end
diff --git a/app/views/search/_filter.html.haml b/app/views/search/_filter.html.haml
index f7a00b23480..979b18e3856 100644
--- a/app/views/search/_filter.html.haml
+++ b/app/views/search/_filter.html.haml
@@ -9,7 +9,7 @@
%b.caret
%ul.dropdown-menu
%li
- = link_to search_path(group_id: nil) do
+ = link_to search_path(group_id: nil, search: params[:search]) do
Any
- current_user.authorized_groups.sort_by(&:name).each do |group|
%li
@@ -27,7 +27,7 @@
%b.caret
%ul.dropdown-menu
%li
- = link_to search_path(project_id: nil) do
+ = link_to search_path(project_id: nil, search: params[:search]) do
Any
- current_user.authorized_projects.sort_by(&:name_with_namespace).each do |project|
%li
diff --git a/app/views/search/_global_results.html.haml b/app/views/search/_global_results.html.haml
index 6e6feeb6c5a..7f4f0e5e000 100644
--- a/app/views/search/_global_results.html.haml
+++ b/app/views/search/_global_results.html.haml
@@ -1,5 +1,5 @@
.search_results
%ul.bordered-list
- = render partial: "search/results/project", collection: @projects
- = render partial: "search/results/merge_request", collection: @merge_requests
- = render partial: "search/results/issue", collection: @issues
+ = render partial: "search/results/project", collection: @search_results[:projects]
+ = render partial: "search/results/merge_request", collection: @search_results[:merge_requests]
+ = render partial: "search/results/issue", collection: @search_results[:issues]
diff --git a/app/views/search/_project_results.html.haml b/app/views/search/_project_results.html.haml
index 8d04dd27cca..70819ad18b4 100644
--- a/app/views/search/_project_results.html.haml
+++ b/app/views/search/_project_results.html.haml
@@ -1,4 +1,4 @@
-%ul.nav.nav-pills
+%ul.nav.nav-pills.append-bottom-20
%li{class: ("active" if params[:search_code].present?)}
= link_to search_path(params.merge(search_code: true)) do
Repository Code
@@ -9,9 +9,9 @@
.search_results
- if params[:search_code].present?
.blob-results
- = render partial: "search/results/blob", collection: @blobs
- = paginate @blobs, theme: 'gitlab'
+ = render partial: "search/results/blob", collection: @search_results[:blobs]
+ = paginate @search_results[:blobs], theme: 'gitlab'
- else
%ul.bordered-list
- = render partial: "search/results/merge_request", collection: @merge_requests
- = render partial: "search/results/issue", collection: @issues
+ = render partial: "search/results/merge_request", collection: @search_results[:merge_requests]
+ = render partial: "search/results/issue", collection: @search_results[:issues]
diff --git a/app/views/search/_results.html.haml b/app/views/search/_results.html.haml
index 75f134aae66..2f92eccc4c9 100644
--- a/app/views/search/_results.html.haml
+++ b/app/views/search/_results.html.haml
@@ -1,7 +1,7 @@
%fieldset
%legend
Search results
- %span.cgray (#{@total_results})
+ %span.cgray (#{@search_results[:total_results]})
- if @project
= render "project_results"