Commit add099b0 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'milestone_search' into 'master'

Ability to search milestones

https://dev.gitlab.org/gitlab/gitlabhq/issues/2473

See merge request !1158
parents 24b282ae 56527b63
...@@ -11,6 +11,7 @@ v 8.0.0 (unreleased) ...@@ -11,6 +11,7 @@ v 8.0.0 (unreleased)
- Allow configuration of import sources for new projects (Artem Sidorenko) - Allow configuration of import sources for new projects (Artem Sidorenko)
- Search for comments should be case insensetive - Search for comments should be case insensetive
- Create cross-reference for closing references on commits pushed to non-default branches (Maël Valais) - Create cross-reference for closing references on commits pushed to non-default branches (Maël Valais)
- Ability to search milestones
v 7.14.0 v 7.14.0
- Fix bug where non-project members of the target project could set labels on new merge requests. - Fix bug where non-project members of the target project could set labels on new merge requests.
......
...@@ -23,7 +23,7 @@ class SearchController < ApplicationController ...@@ -23,7 +23,7 @@ class SearchController < ApplicationController
@search_results = @search_results =
if @project if @project
unless %w(blobs notes issues merge_requests wiki_blobs). unless %w(blobs notes issues merge_requests milestones wiki_blobs).
include?(@scope) include?(@scope)
@scope = 'blobs' @scope = 'blobs'
end end
...@@ -36,7 +36,7 @@ class SearchController < ApplicationController ...@@ -36,7 +36,7 @@ class SearchController < ApplicationController
Search::SnippetService.new(current_user, params).execute Search::SnippetService.new(current_user, params).execute
else else
unless %w(projects issues merge_requests).include?(@scope) unless %w(projects issues merge_requests milestones).include?(@scope)
@scope = 'projects' @scope = 'projects'
end end
Search::GlobalService.new(current_user, params).execute Search::GlobalService.new(current_user, params).execute
......
...@@ -47,6 +47,13 @@ class Milestone < ActiveRecord::Base ...@@ -47,6 +47,13 @@ class Milestone < ActiveRecord::Base
state :active state :active
end end
class << self
def search(query)
query = "%#{query}%"
where("title like ? or description like ?", query, query)
end
end
def expired? def expired?
if due_date if due_date
due_date.past? due_date.past?
......
...@@ -21,6 +21,13 @@ ...@@ -21,6 +21,13 @@
Merge requests Merge requests
%span.badge %span.badge
= @search_results.merge_requests_count = @search_results.merge_requests_count
%li{class: ("active" if @scope == 'milestones')}
= link_to search_filter_path(scope: 'milestones') do
= icon('clock-o fw')
%span
Milestones
%span.badge
= @search_results.milestones_count
%li{class: ("active" if @scope == 'notes')} %li{class: ("active" if @scope == 'notes')}
= link_to search_filter_path(scope: 'notes') do = link_to search_filter_path(scope: 'notes') do
= icon('comments fw') = icon('comments fw')
...@@ -74,4 +81,11 @@ ...@@ -74,4 +81,11 @@
Merge requests Merge requests
%span.badge %span.badge
= @search_results.merge_requests_count = @search_results.merge_requests_count
%li{class: ("active" if @scope == 'milestones')}
= link_to search_filter_path(scope: 'milestones') do
= icon('clock-o fw')
%span
Milestones
%span.badge
= @search_results.milestones_count
.search-result-row
%h4
= link_to [milestone.project.namespace.becomes(Namespace), milestone.project, milestone] do
%span.term.str-truncated= milestone.title
- if milestone.description.present?
.description.term
= preserve do
= search_md_sanitize(markdown(milestone.description))
\ No newline at end of file
...@@ -23,6 +23,13 @@ Feature: Search ...@@ -23,6 +23,13 @@ Feature: Search
Then I should see "Foo" link in the search results Then I should see "Foo" link in the search results
And I should not see "Bar" link in the search results And I should not see "Bar" link in the search results
Scenario: I should see milestones I am looking for
And project has milestones
When I search for "Foo"
When I click "Milestones" link
Then I should see "Foo" link in the search results
And I should not see "Bar" link in the search results
Scenario: I should see project code I am looking for Scenario: I should see project code I am looking for
When I click project "Shop" link When I click project "Shop" link
And I search for "rspec" And I search for "rspec"
...@@ -44,6 +51,14 @@ Feature: Search ...@@ -44,6 +51,14 @@ Feature: Search
Then I should see "Foo" link in the search results Then I should see "Foo" link in the search results
And I should not see "Bar" link in the search results And I should not see "Bar" link in the search results
Scenario: I should see project milestones
And project has milestones
When I click project "Shop" link
And I search for "Foo"
And I click "Milestones" link
Then I should see "Foo" link in the search results
And I should not see "Bar" link in the search results
Scenario: I should see Wiki blobs Scenario: I should see Wiki blobs
And project has Wiki content And project has Wiki content
When I click project "Shop" link When I click project "Shop" link
......
...@@ -41,6 +41,12 @@ class Spinach::Features::Search < Spinach::FeatureSteps ...@@ -41,6 +41,12 @@ class Spinach::Features::Search < Spinach::FeatureSteps
end end
end end
step 'I click "Milestones" link' do
page.within '.search-filter' do
click_link 'Milestones'
end
end
step 'I click "Wiki" link' do step 'I click "Wiki" link' do
page.within '.search-filter' do page.within '.search-filter' do
click_link 'Wiki' click_link 'Wiki'
...@@ -72,6 +78,11 @@ class Spinach::Features::Search < Spinach::FeatureSteps ...@@ -72,6 +78,11 @@ class Spinach::Features::Search < Spinach::FeatureSteps
create(:merge_request, :simple, title: "Bar", source_project: project, target_project: project) create(:merge_request, :simple, title: "Bar", source_project: project, target_project: project)
end end
step 'project has milestones' do
create(:milestone, title: "Foo", project: project)
create(:milestone, title: "Bar", project: project)
end
step 'I should see "Foo" link in the search results' do step 'I should see "Foo" link in the search results' do
page.within('.results') do page.within('.results') do
find(:css, '.search-results').should have_link 'Foo' find(:css, '.search-results').should have_link 'Foo'
......
...@@ -19,13 +19,15 @@ module Gitlab ...@@ -19,13 +19,15 @@ module Gitlab
issues.page(page).per(per_page) issues.page(page).per(per_page)
when 'merge_requests' when 'merge_requests'
merge_requests.page(page).per(per_page) merge_requests.page(page).per(per_page)
when 'milestones'
milestones.page(page).per(per_page)
else else
Kaminari.paginate_array([]).page(page).per(per_page) Kaminari.paginate_array([]).page(page).per(per_page)
end end
end end
def total_count def total_count
@total_count ||= projects_count + issues_count + merge_requests_count @total_count ||= projects_count + issues_count + merge_requests_count + milestones_count
end end
def projects_count def projects_count
...@@ -40,6 +42,10 @@ module Gitlab ...@@ -40,6 +42,10 @@ module Gitlab
@merge_requests_count ||= merge_requests.count @merge_requests_count ||= merge_requests.count
end end
def milestones_count
@milestones_count ||= milestones.count
end
def empty? def empty?
total_count.zero? total_count.zero?
end end
...@@ -60,6 +66,12 @@ module Gitlab ...@@ -60,6 +66,12 @@ module Gitlab
issues.order('updated_at DESC') issues.order('updated_at DESC')
end end
def milestones
milestones = Milestone.where(project_id: limit_project_ids)
milestones = milestones.search(query)
milestones.order('updated_at DESC')
end
def merge_requests def merge_requests
merge_requests = MergeRequest.in_projects(limit_project_ids) merge_requests = MergeRequest.in_projects(limit_project_ids)
if query =~ /[#!](\d+)\z/ if query =~ /[#!](\d+)\z/
......
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