diff options
author | Alexis Reigel <alexis.reigel.ext@siemens.com> | 2018-11-15 18:10:10 +0300 |
---|---|---|
committer | Alexis Reigel <alexis.reigel.ext@siemens.com> | 2019-02-27 22:19:49 +0300 |
commit | 2e05292562e71deeff9b76bd3c696eca2a65a491 (patch) | |
tree | 3cceb216c54d7c55376b53421d273147d03b06ba /app/finders/autocomplete | |
parent | 315361e025f5e490631d611b0f43b1814d1b0edc (diff) |
use lazy ajax filter dropdown for runner tags
the potential number of available runner tags is too large to load it
statically to a dropdown. we use the same lazy loaded dropdown as is
used for the users dropdown already.
Diffstat (limited to 'app/finders/autocomplete')
-rw-r--r-- | app/finders/autocomplete/acts_as_taggable_on/tags_finder.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/app/finders/autocomplete/acts_as_taggable_on/tags_finder.rb b/app/finders/autocomplete/acts_as_taggable_on/tags_finder.rb new file mode 100644 index 00000000000..65ae90c08b4 --- /dev/null +++ b/app/finders/autocomplete/acts_as_taggable_on/tags_finder.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +module Autocomplete + module ActsAsTaggableOn + class TagsFinder + LIMIT = 20 + + def initialize(taggable_type:, params:) + @taggable_type = taggable_type + @params = params + end + + def execute + @tags = @taggable_type.all_tags + + search! + limit! + + @tags + end + + def search! + search = @params[:search] + + return unless search + + if search.empty? + @tags = @taggable_type.none + return + end + + @tags = + if search.length >= Gitlab::SQL::Pattern::MIN_CHARS_FOR_PARTIAL_MATCHING + @tags.named_like(search) + else + @tags.named(search) + end + end + + def limit! + @tags = @tags.limit(LIMIT) # rubocop: disable CodeReuse/ActiveRecord + end + end + end +end |