diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-08-24 12:53:39 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-08-24 12:53:39 +0000 |
commit | add099b024cc4155a5be494fdb9ae339fd073a14 (patch) | |
tree | 0ee484fe1bb0dbdae4333e30ad7c3c36251c1bcf | |
parent | 24b282aeeaf5ba41c6b73100051eb48428787770 (diff) | |
parent | 56527b63e8a09e0fe4967eabf08638d853e6b2b5 (diff) | |
download | gitlab-ce-add099b024cc4155a5be494fdb9ae339fd073a14.tar.gz |
Merge branch 'milestone_search' into 'master'
Ability to search milestones
https://dev.gitlab.org/gitlab/gitlabhq/issues/2473
See merge request !1158
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/controllers/search_controller.rb | 4 | ||||
-rw-r--r-- | app/models/milestone.rb | 9 | ||||
-rw-r--r-- | app/views/search/_category.html.haml | 14 | ||||
-rw-r--r-- | app/views/search/results/_milestone.html.haml | 9 | ||||
-rw-r--r-- | features/search.feature | 15 | ||||
-rw-r--r-- | features/steps/search.rb | 11 | ||||
-rw-r--r-- | lib/gitlab/search_results.rb | 14 |
8 files changed, 73 insertions, 4 deletions
diff --git a/CHANGELOG b/CHANGELOG index 7eb6ab81dd9..7ec1dabcf95 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,7 @@ v 8.0.0 (unreleased) - Allow configuration of import sources for new projects (Artem Sidorenko) - Search for comments should be case insensetive - Create cross-reference for closing references on commits pushed to non-default branches (Maƫl Valais) + - Ability to search milestones v 7.14.0 - Fix bug where non-project members of the target project could set labels on new merge requests. diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 4e2ea6c5710..eb0408a95e5 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -23,7 +23,7 @@ class SearchController < ApplicationController @search_results = if @project - unless %w(blobs notes issues merge_requests wiki_blobs). + unless %w(blobs notes issues merge_requests milestones wiki_blobs). include?(@scope) @scope = 'blobs' end @@ -36,7 +36,7 @@ class SearchController < ApplicationController Search::SnippetService.new(current_user, params).execute else - unless %w(projects issues merge_requests).include?(@scope) + unless %w(projects issues merge_requests milestones).include?(@scope) @scope = 'projects' end Search::GlobalService.new(current_user, params).execute diff --git a/app/models/milestone.rb b/app/models/milestone.rb index d28f3c8d3f9..c6aff6f709f 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -47,6 +47,13 @@ class Milestone < ActiveRecord::Base state :active end + class << self + def search(query) + query = "%#{query}%" + where("title like ? or description like ?", query, query) + end + end + def expired? if due_date due_date.past? @@ -54,7 +61,7 @@ class Milestone < ActiveRecord::Base false end end - + def open_items_count self.issues.opened.count + self.merge_requests.opened.count end diff --git a/app/views/search/_category.html.haml b/app/views/search/_category.html.haml index 154332cb9a9..a75cd7bd809 100644 --- a/app/views/search/_category.html.haml +++ b/app/views/search/_category.html.haml @@ -21,6 +21,13 @@ Merge requests %span.badge = @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')} = link_to search_filter_path(scope: 'notes') do = icon('comments fw') @@ -74,4 +81,11 @@ Merge requests %span.badge = @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 diff --git a/app/views/search/results/_milestone.html.haml b/app/views/search/results/_milestone.html.haml new file mode 100644 index 00000000000..e0b18733d74 --- /dev/null +++ b/app/views/search/results/_milestone.html.haml @@ -0,0 +1,9 @@ +.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 diff --git a/features/search.feature b/features/search.feature index 1608e824671..a9234c1a611 100644 --- a/features/search.feature +++ b/features/search.feature @@ -23,6 +23,13 @@ Feature: Search 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 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 When I click project "Shop" link And I search for "rspec" @@ -44,6 +51,14 @@ Feature: Search 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 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 And project has Wiki content When I click project "Shop" link diff --git a/features/steps/search.rb b/features/steps/search.rb index 87893aa0205..79273cbad9a 100644 --- a/features/steps/search.rb +++ b/features/steps/search.rb @@ -41,6 +41,12 @@ class Spinach::Features::Search < Spinach::FeatureSteps end end + step 'I click "Milestones" link' do + page.within '.search-filter' do + click_link 'Milestones' + end + end + step 'I click "Wiki" link' do page.within '.search-filter' do click_link 'Wiki' @@ -72,6 +78,11 @@ class Spinach::Features::Search < Spinach::FeatureSteps create(:merge_request, :simple, title: "Bar", source_project: project, target_project: project) 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 page.within('.results') do find(:css, '.search-results').should have_link 'Foo' diff --git a/lib/gitlab/search_results.rb b/lib/gitlab/search_results.rb index 06245374bc8..2ab2d4af797 100644 --- a/lib/gitlab/search_results.rb +++ b/lib/gitlab/search_results.rb @@ -19,13 +19,15 @@ module Gitlab issues.page(page).per(per_page) when 'merge_requests' merge_requests.page(page).per(per_page) + when 'milestones' + milestones.page(page).per(per_page) else Kaminari.paginate_array([]).page(page).per(per_page) end end def total_count - @total_count ||= projects_count + issues_count + merge_requests_count + @total_count ||= projects_count + issues_count + merge_requests_count + milestones_count end def projects_count @@ -40,6 +42,10 @@ module Gitlab @merge_requests_count ||= merge_requests.count end + def milestones_count + @milestones_count ||= milestones.count + end + def empty? total_count.zero? end @@ -60,6 +66,12 @@ module Gitlab issues.order('updated_at DESC') end + def milestones + milestones = Milestone.where(project_id: limit_project_ids) + milestones = milestones.search(query) + milestones.order('updated_at DESC') + end + def merge_requests merge_requests = MergeRequest.in_projects(limit_project_ids) if query =~ /[#!](\d+)\z/ |