Commit f42fe0b6 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add ability to filter labels by title or description

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 02e35a0d
...@@ -160,7 +160,10 @@ class Projects::LabelsController < Projects::ApplicationController ...@@ -160,7 +160,10 @@ class Projects::LabelsController < Projects::ApplicationController
def find_labels def find_labels
@available_labels ||= @available_labels ||=
LabelsFinder.new(current_user, project_id: @project.id, include_ancestor_groups: params[:include_ancestor_groups]).execute LabelsFinder.new(current_user,
project_id: @project.id,
include_ancestor_groups: params[:include_ancestor_groups],
search: params[:search]).execute
end end
def authorize_admin_labels! def authorize_admin_labels!
......
...@@ -14,6 +14,7 @@ class LabelsFinder < UnionFinder ...@@ -14,6 +14,7 @@ class LabelsFinder < UnionFinder
@skip_authorization = skip_authorization @skip_authorization = skip_authorization
items = find_union(label_ids, Label) || Label.none items = find_union(label_ids, Label) || Label.none
items = with_title(items) items = with_title(items)
items = by_search(items)
sort(items) sort(items)
end end
...@@ -63,6 +64,12 @@ class LabelsFinder < UnionFinder ...@@ -63,6 +64,12 @@ class LabelsFinder < UnionFinder
items.where(title: title) items.where(title: title)
end end
def by_search(labels)
return labels unless params[:search].present?
labels.search(params[:search])
end
# Gets redacted array of group ids # Gets redacted array of group ids
# which can include the ancestors and descendants of the requested group. # which can include the ancestors and descendants of the requested group.
def group_ids_for(group) def group_ids_for(group)
......
...@@ -2,6 +2,7 @@ class Label < ActiveRecord::Base ...@@ -2,6 +2,7 @@ class Label < ActiveRecord::Base
include CacheMarkdownField include CacheMarkdownField
include Referable include Referable
include Subscribable include Subscribable
include Gitlab::SQL::Pattern
# Represents a "No Label" state used for filtering Issues and Merge # Represents a "No Label" state used for filtering Issues and Merge
# Requests that have no label assigned. # Requests that have no label assigned.
...@@ -103,6 +104,17 @@ class Label < ActiveRecord::Base ...@@ -103,6 +104,17 @@ class Label < ActiveRecord::Base
nil nil
end end
# Searches for labels with a matching title or description.
#
# This method uses ILIKE on PostgreSQL and LIKE on MySQL.
#
# query - The search query as a String.
#
# Returns an ActiveRecord::Relation.
def self.search(query)
fuzzy_search(query, [:title, :description])
end
def open_issues_count(user = nil) def open_issues_count(user = nil)
issues_count(user, state: 'opened') issues_count(user, state: 'opened')
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