summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-08-11 12:41:58 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-08-11 12:41:58 +0300
commitbdb9340e4d0fc0badb5202a5c910be8cdf2ba180 (patch)
tree62f3f7fd49fd4ee58e2c0d711fbed2c3fb95f6a2
parent7122a823f859a1201428791e32000c4a8bcc6787 (diff)
parentf361be9eca790c444c9a95c98fe8e5f95e1d7f95 (diff)
downloadgitlab-ce-bdb9340e4d0fc0badb5202a5c910be8cdf2ba180.tar.gz
Merge pull request #7385 from Razer6/fix_search_empty_project
Fix 500 on searching on empty project, restyle search page
-rw-r--r--app/assets/stylesheets/generic/common.scss15
-rw-r--r--app/services/search/project_service.rb8
-rw-r--r--app/views/search/_project_results.html.haml18
-rw-r--r--app/views/search/results/_empty.html.haml4
-rw-r--r--features/project/source/search_code.feature10
-rw-r--r--features/steps/project/search_code.rb12
-rw-r--r--features/steps/shared/project.rb7
7 files changed, 61 insertions, 13 deletions
diff --git a/app/assets/stylesheets/generic/common.scss b/app/assets/stylesheets/generic/common.scss
index 991561cd503..9d3c9f372a9 100644
--- a/app/assets/stylesheets/generic/common.scss
+++ b/app/assets/stylesheets/generic/common.scss
@@ -341,3 +341,18 @@ table {
.footer-links a {
margin-right: 15px;
}
+
+.search_box {
+ position: relative;
+ padding: 30px;
+ text-align: center;
+ background-color: #F9F9F9;
+ border: 1px solid #DDDDDD;
+ border-radius: 0px;
+}
+
+.search_glyph {
+ color: #555;
+ font-size: 42px;
+}
+
diff --git a/app/services/search/project_service.rb b/app/services/search/project_service.rb
index 493dee95f90..8aac18840e4 100644
--- a/app/services/search/project_service.rb
+++ b/app/services/search/project_service.rb
@@ -12,7 +12,13 @@ module Search
return result unless query.present?
if params[:search_code].present?
- blobs = project.repository.search_files(query, params[:repository_ref]) unless project.empty_repo?
+ if !@project.empty_repo?
+ blobs = project.repository.search_files(query,
+ params[:repository_ref])
+ else
+ blobs = Array.new
+ end
+
blobs = Kaminari.paginate_array(blobs).page(params[:page]).per(20)
result[:blobs] = blobs
result[:total_results] = blobs.total_count
diff --git a/app/views/search/_project_results.html.haml b/app/views/search/_project_results.html.haml
index af3b97879c7..751824dce4a 100644
--- a/app/views/search/_project_results.html.haml
+++ b/app/views/search/_project_results.html.haml
@@ -9,10 +9,16 @@
.search_results
- if params[:search_code].present?
.blob-results
- = render partial: "search/results/blob", collection: @search_results[:blobs]
- = paginate @search_results[:blobs], theme: 'gitlab'
+ - if !@search_results[:blobs].empty?
+ = render partial: "search/results/blob", collection: @search_results[:blobs]
+ = paginate @search_results[:blobs], theme: 'gitlab'
+ - else
+ = render partial: "search/results/empty", :locals => { message: "We couldn't find any matching code" }
- else
- %ul.bordered-list
- = render partial: "search/results/merge_request", collection: @search_results[:merge_requests]
- = render partial: "search/results/issue", collection: @search_results[:issues]
- = render partial: "search/results/note", collection: @search_results[:notes]
+ - if (@search_results[:merge_requests] || @search_results[:issues] || @search_results[:notes]).length > 0
+ %ul.bordered-list
+ = render partial: "search/results/merge_request", collection: @search_results[:merge_requests]
+ = render partial: "search/results/issue", collection: @search_results[:issues]
+ = render partial: "search/results/note", collection: @search_results[:notes]
+ - else
+ = render partial: "search/results/empty", :locals => { message: "We couldn't find any issues, merge requests or notes" }
diff --git a/app/views/search/results/_empty.html.haml b/app/views/search/results/_empty.html.haml
new file mode 100644
index 00000000000..3615f6ae52a
--- /dev/null
+++ b/app/views/search/results/_empty.html.haml
@@ -0,0 +1,4 @@
+.search_box
+ .search_glyph
+ %span.icon-search
+ %h4 #{message}
diff --git a/features/project/source/search_code.feature b/features/project/source/search_code.feature
index ad8a650d895..93b326696d0 100644
--- a/features/project/source/search_code.feature
+++ b/features/project/source/search_code.feature
@@ -1,9 +1,15 @@
Feature: Project Search code
Background:
Given I sign in as a user
- And I own project "Shop"
- Given I visit project source page
Scenario: Search for term "coffee"
+ Given I own project "Shop"
+ And I visit project source page
When I search for term "coffee"
Then I should see files from repository containing "coffee"
+
+ Scenario: Search on empty project
+ Given I own an empty project
+ And I visit my project's home page
+ When I search for term "coffee"
+ Then I should see empty result
diff --git a/features/steps/project/search_code.rb b/features/steps/project/search_code.rb
index 8d130a8ed0d..affa7d3b43b 100644
--- a/features/steps/project/search_code.rb
+++ b/features/steps/project/search_code.rb
@@ -3,14 +3,18 @@ class ProjectSearchCode < Spinach::FeatureSteps
include SharedProject
include SharedPaths
- When 'I search for term "coffee"' do
+ step 'I search for term "coffee"' do
fill_in "search", with: "coffee"
click_button "Go"
click_link 'Repository Code'
end
- Then 'I should see files from repository containing "coffee"' do
- page.should have_content "coffee"
- page.should have_content " CONTRIBUTING.md"
+ step 'I should see files from repository containing "coffee"' do
+ page.should have_content 'coffee'
+ page.should have_content 'CONTRIBUTING.md'
+ end
+
+ step 'I should see empty result' do
+ page.should have_content "We couldn't find any matching code"
end
end
diff --git a/features/steps/shared/project.rb b/features/steps/shared/project.rb
index 655840f447d..c131976614f 100644
--- a/features/steps/shared/project.rb
+++ b/features/steps/shared/project.rb
@@ -21,6 +21,13 @@ module SharedProject
@project.team << [@user, :master]
end
+ # Create an empty project without caring about the name
+ And 'I own an empty project' do
+ @project = create(:empty_project,
+ name: 'Empty Project', namespace: @user.namespace)
+ @project.team << [@user, :master]
+ end
+
And 'project "Shop" has push event' do
@project = Project.find_by(name: "Shop")