diff options
author | Jacopo <beschi.jacopo@gmail.com> | 2019-01-17 15:35:23 +0100 |
---|---|---|
committer | Jacopo <beschi.jacopo@gmail.com> | 2019-01-24 18:44:09 +0100 |
commit | 22eb2e4c227b060981bb37708222cdd07e825542 (patch) | |
tree | c02c037a5877e1f7075a99806336fef8cb3b03bc /app/models | |
parent | e520a946410ca0007a2a562f2c2a7c6f8c6f1dab (diff) | |
download | gitlab-ce-22eb2e4c227b060981bb37708222cdd07e825542.tar.gz |
Adds milestone search
Adds to search ILIKE search for milestones title in:
- Milestones dashboard
- Group milestones page
- Project milestones page
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/dashboard_group_milestone.rb | 7 | ||||
-rw-r--r-- | app/models/global_milestone.rb | 1 | ||||
-rw-r--r-- | app/models/group_milestone.rb | 3 | ||||
-rw-r--r-- | app/models/milestone.rb | 13 |
4 files changed, 19 insertions, 5 deletions
diff --git a/app/models/dashboard_group_milestone.rb b/app/models/dashboard_group_milestone.rb index 9bcc95e35a5..74aa04ab7d0 100644 --- a/app/models/dashboard_group_milestone.rb +++ b/app/models/dashboard_group_milestone.rb @@ -11,11 +11,12 @@ class DashboardGroupMilestone < GlobalMilestone @group_name = milestone.group.full_name end - def self.build_collection(groups) - Milestone.of_groups(groups.select(:id)) + def self.build_collection(groups, params) + milestones = Milestone.of_groups(groups.select(:id)) .reorder_by_due_date_asc .order_by_name_asc .active - .map { |m| new(m) } + milestones = milestones.search_title(params[:search_title]) if params[:search_title].present? + milestones.map { |m| new(m) } end end diff --git a/app/models/global_milestone.rb b/app/models/global_milestone.rb index 4e82f3fed27..fd17745b035 100644 --- a/app/models/global_milestone.rb +++ b/app/models/global_milestone.rb @@ -27,6 +27,7 @@ class GlobalMilestone items = Milestone.of_projects(projects) .reorder_by_due_date_asc .order_by_name_asc + items = items.search_title(params[:search_title]) if params[:search_title].present? Milestone.filter_by_state(items, params[:state]).map { |m| new(m) } end diff --git a/app/models/group_milestone.rb b/app/models/group_milestone.rb index a58537de319..97cb26c6ea9 100644 --- a/app/models/group_milestone.rb +++ b/app/models/group_milestone.rb @@ -5,9 +5,10 @@ class GroupMilestone < GlobalMilestone def self.build_collection(group, projects, params) params = - { state: params[:state] } + { state: params[:state], search_title: params[:search_title] } project_milestones = Milestone.of_projects(projects) + project_milestones = project_milestones.search_title(params[:search_title]) if params[:search_title].present? child_milestones = Milestone.filter_by_state(project_milestones, params[:state]) grouped_milestones = child_milestones.group_by(&:title) diff --git a/app/models/milestone.rb b/app/models/milestone.rb index b21edce3aad..7ee7da99606 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -77,7 +77,7 @@ class Milestone < ActiveRecord::Base alias_attribute :name, :title class << self - # Searches for milestones matching the given query. + # Searches for milestones with a matching title or description. # # This method uses ILIKE on PostgreSQL and LIKE on MySQL. # @@ -88,6 +88,17 @@ class Milestone < ActiveRecord::Base fuzzy_search(query, [:title, :description]) end + # Searches for milestones with a matching title. + # + # This method uses ILIKE on PostgreSQL and LIKE on MySQL. + # + # query - The search query as a String + # + # Returns an ActiveRecord::Relation. + def search_title(query) + fuzzy_search(query, [:title]) + end + def filter_by_state(milestones, state) case state when 'closed' then milestones.closed |