Commit 46daf01a authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Search for blobs by default inside project. Added pagination for blobs search

parent 634cbd71
...@@ -14,10 +14,17 @@ class SearchContext ...@@ -14,10 +14,17 @@ class SearchContext
result[:projects] = projects.search(query).limit(10) result[:projects] = projects.search(query).limit(10)
# Search inside singe project # Search inside singe project
result[:project] = project = projects.first if projects.length == 1 project = projects.first if projects.length == 1
if params[:search_code].present? if params[:search_code].present?
result[:blobs] = project.repository.search_files(query, params[:repository_ref]) unless project.empty_repo? blobs = []
unless project.empty_repo?
blobs = project.repository.search_files(query, params[:repository_ref])
blobs = Kaminari.paginate_array(blobs).page(params[:page]).per(20)
end
result[:blobs] = blobs
else else
result[:merge_requests] = MergeRequest.where(project_id: project_ids).search(query).limit(10) result[:merge_requests] = MergeRequest.where(project_id: project_ids).search(query).limit(10)
result[:issues] = Issue.where(project_id: project_ids).search(query).limit(10) result[:issues] = Issue.where(project_id: project_ids).search(query).limit(10)
......
...@@ -10,13 +10,13 @@ class SearchController < ApplicationController ...@@ -10,13 +10,13 @@ class SearchController < ApplicationController
group_project_ids = @group.projects.map(&:id) group_project_ids = @group.projects.map(&:id)
project_ids.select! { |id| group_project_ids.include?(id)} project_ids.select! { |id| group_project_ids.include?(id)}
elsif project_id.present? elsif project_id.present?
@project = Project.find(params[:project_id])
project_ids.select! { |id| id == project_id.to_i} project_ids.select! { |id| id == project_id.to_i}
end end
result = SearchContext.new(project_ids, params).execute result = SearchContext.new(project_ids, params).execute
@projects = result[:projects] @projects = result[:projects]
@project = result[:project]
@merge_requests = result[:merge_requests] @merge_requests = result[:merge_requests]
@issues = result[:issues] @issues = result[:issues]
@wiki_pages = result[:wiki_pages] @wiki_pages = result[:wiki_pages]
......
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
= form_tag search_path, method: :get, class: 'navbar-form pull-left' do |f| = form_tag search_path, method: :get, class: 'navbar-form pull-left' do |f|
= text_field_tag "search", nil, placeholder: "Search", class: "search-input" = text_field_tag "search", nil, placeholder: "Search", class: "search-input"
= hidden_field_tag :group_id, @group.try(:id) = hidden_field_tag :group_id, @group.try(:id)
= hidden_field_tag :project_id, @project.try(:id) - if @project && @project.persisted?
= hidden_field_tag :project_id, @project.id
= hidden_field_tag :search_code, true
= hidden_field_tag :repository_ref, @ref = hidden_field_tag :repository_ref, @ref
= submit_tag 'Go' if ENV['RAILS_ENV'] == 'test' = submit_tag 'Go' if ENV['RAILS_ENV'] == 'test'
.search-autocomplete-json.hide{:'data-autocomplete-opts' => search_autocomplete_source } .search-autocomplete-json.hide{:'data-autocomplete-opts' => search_autocomplete_source }
%li
.file_holder
.file_title
= link_to project_blob_path(@project, tree_join(blob.ref, blob.filename), :anchor => "L" + blob.startline.to_s) do
%i.icon-file
%strong
= blob.filename
.file_content.code.term
%div{class: user_color_scheme_class}
= raw blob.colorize( formatter: :gitlab, options: { first_line_number: blob.startline } )
%fieldset %fieldset
%legend %legend
Search results Search results
%span.cgray (#{@projects.count + @merge_requests.count + @issues.count + @wiki_pages.count + @blobs.count}) %span.cgray (#{@projects.count + @merge_requests.count + @issues.count + @wiki_pages.count + @blobs.total_count})
- if @project - if @project
%ul.nav.nav-pills %ul.nav.nav-pills
...@@ -43,17 +43,11 @@ ...@@ -43,17 +43,11 @@
%strong.term %strong.term
= truncate wiki_page.title, length: 50 = truncate wiki_page.title, length: 50
%span.light (#{wiki_page.project.name_with_namespace}) %span.light (#{wiki_page.project.name_with_namespace})
- @blobs.each do |file|
%li - @blobs.each do |blob|
.file_holder = render 'blob', blob: blob
.file_title
= link_to project_blob_path(@project, tree_join(file.ref, file.filename), :anchor => "L" + file.startline.to_s) do = paginate @blobs, theme: 'gitlab'
%i.icon-file
%strong
= file.filename
.file_content.code.term
%div{class: user_color_scheme_class}
= raw file.colorize( formatter: :gitlab, options: { first_line_number: file.startline } )
:javascript :javascript
$(function() { $(function() {
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
%span Looking for %span Looking for
.input .input
= search_field_tag :search, params[:search], placeholder: "issue 143", class: "input-xxlarge search-text-input", id: "dashboard_search" = search_field_tag :search, params[:search], placeholder: "issue 143", class: "input-xxlarge search-text-input", id: "dashboard_search"
= hidden_field_tag :project_id, params[:project_id]
= hidden_field_tag :group_id, params[:group_id]
= hidden_field_tag :search_code, params[:search_code] = hidden_field_tag :search_code, params[:search_code]
= submit_tag 'Search', class: "btn btn-primary wide" = submit_tag 'Search', class: "btn btn-primary wide"
.prepend-top-10 .prepend-top-10
......
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