result[:projects] = projects.search(query).limit(10)
# 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?
- 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
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)
group_project_ids = @group.projects.map(&:id)
project_ids.select! { |id| group_project_ids.include?(id)}
elsif project_id.present?
+ @project = Project.find(params[:project_id])
project_ids.select! { |id| id == project_id.to_i}
end
result = SearchContext.new(project_ids, params).execute
@projects = result[:projects]
- @project = result[:project]
@merge_requests = result[:merge_requests]
@issues = result[:issues]
@wiki_pages = result[:wiki_pages]
= form_tag search_path, method: :get, class: 'navbar-form pull-left' do |f|
= text_field_tag "search", nil, placeholder: "Search", class: "search-input"
= 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
= submit_tag 'Go' if ENV['RAILS_ENV'] == 'test'
.search-autocomplete-json.hide{:'data-autocomplete-opts' => search_autocomplete_source }
--- /dev/null
+%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
%legend
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
%ul.nav.nav-pills
%strong.term
= truncate wiki_page.title, length: 50
%span.light (#{wiki_page.project.name_with_namespace})
- - @blobs.each do |file|
- %li
- .file_holder
- .file_title
- = link_to project_blob_path(@project, tree_join(file.ref, file.filename), :anchor => "L" + file.startline.to_s) do
- %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 } )
+
+ - @blobs.each do |blob|
+ = render 'blob', blob: blob
+
+ = paginate @blobs, theme: 'gitlab'
:javascript
$(function() {
%span Looking for
.input
= 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]
= submit_tag 'Search', class: "btn btn-primary wide"
.prepend-top-10