Commit 8114d36c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #1720 from coagulant/wiki_search

Wiki search
parents d6a5e3da e6524a91
...@@ -13,6 +13,7 @@ class SearchContext ...@@ -13,6 +13,7 @@ class SearchContext
result[:projects] = Project.where(id: project_ids).search(query).limit(10) result[:projects] = Project.where(id: project_ids).search(query).limit(10)
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)
result[:wiki_pages] = Wiki.where(project_id: project_ids).search(query).limit(10)
result result
end end
...@@ -20,7 +21,8 @@ class SearchContext ...@@ -20,7 +21,8 @@ class SearchContext
@result ||= { @result ||= {
projects: [], projects: [],
merge_requests: [], merge_requests: [],
issues: [] issues: [],
wiki_pages: []
} }
end end
end end
......
...@@ -5,5 +5,6 @@ class SearchController < ApplicationController ...@@ -5,5 +5,6 @@ class SearchController < ApplicationController
@projects = result[:projects] @projects = result[:projects]
@merge_requests = result[:merge_requests] @merge_requests = result[:merge_requests]
@issues = result[:issues] @issues = result[:issues]
@wiki_pages = result[:wiki_pages]
end end
end end
...@@ -15,6 +15,12 @@ class Wiki < ActiveRecord::Base ...@@ -15,6 +15,12 @@ class Wiki < ActiveRecord::Base
slug slug
end end
class << self
def search(query)
where("title like :query OR content like :query", query: "%#{query}%")
end
end
protected protected
def self.regenerate_from wiki def self.regenerate_from wiki
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
%br %br
%h3 %h3
Search results Search results
%small (#{@projects.count + @merge_requests.count + @issues.count}) %small (#{@projects.count + @merge_requests.count + @issues.count + @wiki_pages.count})
%hr %hr
.search_results .search_results
.row .row
...@@ -69,6 +69,23 @@ ...@@ -69,6 +69,23 @@
%tr %tr
%td %td
%h4.nothing_here_message No Issues %h4.nothing_here_message No Issues
.span6
%table
%thead
%tr
%th Wiki
%tbody
- @wiki_pages.each do |wiki_page|
%tr
%td
= link_to project_wiki_path(wiki_page.project, wiki_page) do
%strong.term= truncate wiki_page.title, length: 40
%strong.right
%span.label= wiki_page.project.name
- if @wiki_pages.blank?
%tr
%td
%h4.nothing_here_message No wiki pages
:javascript :javascript
$(function() { $(function() {
$(".search_results .term").highlight("#{params[:search]}"); $(".search_results .term").highlight("#{params[:search]}");
......
...@@ -2,8 +2,13 @@ Feature: Dashboard Search ...@@ -2,8 +2,13 @@ Feature: Dashboard Search
Background: Background:
Given I sign in as a user Given I sign in as a user
And I own project "Shop" And I own project "Shop"
And Project "Shop" has wiki page "Contibuting guide"
And I visit dashboard search page And I visit dashboard search page
Scenario: I should see project I am looking for Scenario: I should see project I am looking for
Given I search for "Sho" Given I search for "Sho"
Then I should see "Shop" project link Then I should see "Shop" project link
Scenario: I should see wiki page I am looking for
Given I search for "Contibuting"
Then I should see "Contibuting guide" wiki link
\ No newline at end of file
...@@ -15,4 +15,21 @@ class DashboardSearch < Spinach::FeatureSteps ...@@ -15,4 +15,21 @@ class DashboardSearch < Spinach::FeatureSteps
@project = Factory :project, :name => "Shop" @project = Factory :project, :name => "Shop"
@project.add_access(@user, :admin) @project.add_access(@user, :admin)
end end
Given 'I search for "Contibuting"' do
fill_in "dashboard_search", :with => "Contibuting"
click_button "Search"
end
And 'Project "Shop" has wiki page "Contibuting guide"' do
@wiki_page = Factory :wiki, :project => @project,
:title => "Contibuting guide",
:slug => "contributing"
end
Then 'I should see "Contibuting guide" wiki link' do
page.should have_link "Contibuting guide"
end
end end
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