Commit d5fe1e57 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Draft improvements to search layout

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 8140c682
...@@ -4,20 +4,22 @@ class SearchController < ApplicationController ...@@ -4,20 +4,22 @@ class SearchController < ApplicationController
def show def show
return if params[:search].nil? || params[:search].blank? return if params[:search].nil? || params[:search].blank?
@search_term = params[:search]
if params[:project_id].present? if params[:project_id].present?
@project = Project.find_by(id: params[:project_id]) @project = Project.find_by(id: params[:project_id])
@project = nil unless can?(current_user, :download_code, @project) @project = nil unless can?(current_user, :download_code, @project)
end end
if params[:group_id].present? if params[:group_id].present?
@group = Group.find_by(id: params[:group_id]) @group = Group.find_by(id: params[:group_id])
@group = nil unless can?(current_user, :read_group, @group) @group = nil unless can?(current_user, :read_group, @group)
end end
@scope = params[:scope] @scope = params[:scope]
@show_snippets = params[:snippets].eql? 'true' @show_snippets = params[:snippets].eql? 'true'
@search_results = @search_results =
if @project if @project
unless %w(blobs notes issues merge_requests wiki_blobs). unless %w(blobs notes issues merge_requests wiki_blobs).
include?(@scope) include?(@scope)
...@@ -37,6 +39,7 @@ class SearchController < ApplicationController ...@@ -37,6 +39,7 @@ class SearchController < ApplicationController
end end
Search::GlobalService.new(current_user, params).execute Search::GlobalService.new(current_user, params).execute
end end
@objects = @search_results.objects(@scope, params[:page]) @objects = @search_results.objects(@scope, params[:page])
end end
......
.search .search
= 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|
= search_field_tag "search", nil, placeholder: search_placeholder, class: "search-input" = search_field_tag "search", @search_term, placeholder: search_placeholder, class: "search-input"
= hidden_field_tag :group_id, @group.try(:id) = hidden_field_tag :group_id, @group.try(:id)
- if @project && @project.persisted? - if @project && @project.persisted?
= hidden_field_tag :project_id, @project.id = hidden_field_tag :project_id, @project.id
......
%ul.nav.nav-sidebar.search-filter
- if @project
= render 'layouts/nav/search/project'
- elsif @show_snippets
= render 'layouts/nav/search/snippet'
- else
%li{class: ("active" if @scope == 'projects')}
= link_to search_filter_path(scope: 'projects') do
= icon('bookmark fw')
%span
Projects
%span.count
= @search_results.projects_count
%li{class: ("active" if @scope == 'issues')}
= link_to search_filter_path(scope: 'issues') do
= icon('exclamation-circle fw')
%span
Issues
%span.count
= @search_results.issues_count
%li{class: ("active" if @scope == 'merge_requests')}
= link_to search_filter_path(scope: 'merge_requests') do
= icon('tasks fw')
%span
Merge requests
%span.count
= @search_results.merge_requests_count
%li{class: ("active" if @scope == 'blobs')}
= link_to search_filter_path(scope: 'blobs') do
= icon('code fw')
%span
Code
%span.count
= @search_results.blobs_count
%li{class: ("active" if @scope == 'issues')}
= link_to search_filter_path(scope: 'issues') do
= icon('exclamation-circle fw')
%span
Issues
%span.count
= @search_results.issues_count
%li{class: ("active" if @scope == 'merge_requests')}
= link_to search_filter_path(scope: 'merge_requests') do
= icon('tasks fw')
%span
Merge requests
%span.count
= @search_results.merge_requests_count
%li{class: ("active" if @scope == 'notes')}
= link_to search_filter_path(scope: 'notes') do
= icon('comments fw')
%span
Comments
%span.count
= @search_results.notes_count
%li{class: ("active" if @scope == 'wiki_blobs')}
= link_to search_filter_path(scope: 'wiki_blobs') do
= icon('book fw')
%span
Wiki
%span.count
= @search_results.wiki_blobs_count
%li{class: ("active" if @scope == 'snippet_blobs')}
= link_to search_filter_path(scope: 'snippet_blobs', snippets: true, group_id: nil, project_id: nil) do
= icon('code fw')
%span
Snippet Contents
%span.count
= @search_results.snippet_blobs_count
%li{class: ("active" if @scope == 'snippet_titles')}
= link_to search_filter_path(scope: 'snippet_titles', snippets: true, group_id: nil, project_id: nil) do
= icon('book fw')
%span
Titles and Filenames
%span.count
= @search_results.snippet_titles_count
...@@ -2,9 +2,5 @@ ...@@ -2,9 +2,5 @@
%html{ lang: "en"} %html{ lang: "en"}
= render "layouts/head", title: "Search" = render "layouts/head", title: "Search"
%body{class: "#{app_theme} application", :'data-page' => body_data_page} %body{class: "#{app_theme} application", :'data-page' => body_data_page}
= render "layouts/broadcast"
= render "layouts/head_panel", title: link_to("Search", search_path) = render "layouts/head_panel", title: link_to("Search", search_path)
.container.navless-container = render 'layouts/page', sidebar: 'layouts/nav/search'
.content
= render "layouts/flash"
= yield
%ul.nav.nav-pills.nav-stacked.search-filter
%li{class: ("active" if @scope == 'projects')}
= link_to search_filter_path(scope: 'projects') do
Projects
.pull-right
= @search_results.projects_count
%li{class: ("active" if @scope == 'issues')}
= link_to search_filter_path(scope: 'issues') do
Issues
.pull-right
= @search_results.issues_count
%li{class: ("active" if @scope == 'merge_requests')}
= link_to search_filter_path(scope: 'merge_requests') do
Merge requests
.pull-right
= @search_results.merge_requests_count
%ul.nav.nav-pills.nav-stacked.search-filter
%li{class: ("active" if @scope == 'blobs')}
= link_to search_filter_path(scope: 'blobs') do
%i.fa.fa-code
Code
.pull-right
= @search_results.blobs_count
%li{class: ("active" if @scope == 'issues')}
= link_to search_filter_path(scope: 'issues') do
%i.fa.fa-exclamation-circle
Issues
.pull-right
= @search_results.issues_count
%li{class: ("active" if @scope == 'merge_requests')}
= link_to search_filter_path(scope: 'merge_requests') do
%i.fa.fa-code-fork
Merge requests
.pull-right
= @search_results.merge_requests_count
%li{class: ("active" if @scope == 'notes')}
= link_to search_filter_path(scope: 'notes') do
%i.fa.fa-comments
Comments
.pull-right
= @search_results.notes_count
%li{class: ("active" if @scope == 'wiki_blobs')}
= link_to search_filter_path(scope: 'wiki_blobs') do
%i.fa.fa-book
Wiki
.pull-right
= @search_results.wiki_blobs_count
%h4 .search-results
#{@search_results.total_count} results found - if @search_results.empty?
- unless @show_snippets = render partial: "search/results/empty", locals: { message: "We couldn't find any matching results" }
- if @project - else
for #{link_to @project.name_with_namespace, [@project.namespace.becomes(Namespace), @project]} = render partial: "search/results/#{@scope.singularize}", collection: @objects
- elsif @group = paginate @objects, theme: 'gitlab'
for #{link_to @group.name, @group}
%hr
.row
.col-sm-3
- if @project
= render "project_filter"
- elsif @show_snippets
= render 'snippet_filter'
- else
= render "global_filter"
.col-sm-9
.search-results
- if @search_results.empty?
= render partial: "search/results/empty", locals: { message: "We couldn't find any matching results" }
- else
= render partial: "search/results/#{@scope.singularize}", collection: @objects
= paginate @objects, theme: 'gitlab'
:javascript :javascript
$(".search-results .term").highlight("#{escape_javascript(params[:search])}"); $(".search-results .term").highlight("#{escape_javascript(params[:search])}");
%ul.nav.nav-pills.nav-stacked.search-filter
%li{class: ("active" if @scope == 'snippet_blobs')}
= link_to search_filter_path(scope: 'snippet_blobs', snippets: true, group_id: nil, project_id: nil) do
%i.fa.fa-code
Snippet Contents
.pull-right
= @search_results.snippet_blobs_count
%li{class: ("active" if @scope == 'snippet_titles')}
= link_to search_filter_path(scope: 'snippet_titles', snippets: true, group_id: nil, project_id: nil) do
%i.fa.fa-book
Titles and Filenames
.pull-right
= @search_results.snippet_titles_count
= form_tag search_path, method: :get, class: 'form-horizontal' do |f| - if @search_term
.search-holder.clearfix .lead
.form-group Search for
= label_tag :search, class: 'control-label' do %code
%span Looking for = @search_term
.col-sm-6 - unless @show_snippets
= search_field_tag :search, params[:search], placeholder: "issue 143", class: "form-control search-text-input", id: "dashboard_search" - if @project
.col-sm-4 in project #{link_to @project.name_with_namespace, [@project.namespace.becomes(Namespace), @project]}
= button_tag 'Search', class: "btn btn-create" - elsif @group
.form-group in group #{link_to @group.name, @group}
.col-sm-2
- unless params[:snippets].eql? 'true'
.col-sm-10
= render 'filter', f: f
= hidden_field_tag :project_id, params[:project_id]
= hidden_field_tag :group_id, params[:group_id]
= hidden_field_tag :snippets, params[:snippets]
= hidden_field_tag :scope, params[:scope]
.pull-right
= render 'filter'
%hr
.results.prepend-top-10 .results.prepend-top-10
- if params[:search].present? = render 'search/results'
= render 'search/results' - else
wow
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