Fixes #4095 - Trigger autocomplete when clicking the "Tags" field also without a search term.
This commit is contained in:
parent
08934daaf3
commit
757a9b274e
5 changed files with 35 additions and 4 deletions
|
@ -15,10 +15,15 @@ PreCommit:
|
||||||
on_warn: fail
|
on_warn: fail
|
||||||
CoffeeLint:
|
CoffeeLint:
|
||||||
# .coffeelint/rules/* not supported in YAML, specify all rules separately.
|
# .coffeelint/rules/* not supported in YAML, specify all rules separately.
|
||||||
flags: ['--reporter=csv', '--rules', './.coffeelint/rules/detect_translatable_string.coffee']
|
flags:
|
||||||
|
[
|
||||||
|
'--reporter=csv',
|
||||||
|
'--rules',
|
||||||
|
'./.coffeelint/rules/detect_translatable_string.coffee',
|
||||||
|
]
|
||||||
enabled: true
|
enabled: true
|
||||||
on_warn: fail
|
on_warn: fail
|
||||||
exclude: public/assets/chat/**/*
|
exclude: 'public/assets/chat/**/*'
|
||||||
CustomScript:
|
CustomScript:
|
||||||
enabled: true
|
enabled: true
|
||||||
description: 'Check if translation catalog is up-to-date'
|
description: 'Check if translation catalog is up-to-date'
|
||||||
|
|
|
@ -57,7 +57,7 @@ class App.WidgetTag extends App.Controller
|
||||||
source = "#{App.Config.get('api_path')}/tag_search"
|
source = "#{App.Config.get('api_path')}/tag_search"
|
||||||
@$('.js-newTagInput').autocomplete(
|
@$('.js-newTagInput').autocomplete(
|
||||||
source: source
|
source: source
|
||||||
minLength: 1
|
minLength: 0
|
||||||
response: (e, ui) =>
|
response: (e, ui) =>
|
||||||
return if !ui
|
return if !ui
|
||||||
return if !ui.content
|
return if !ui.content
|
||||||
|
|
|
@ -6,7 +6,8 @@ class TagsController < ApplicationController
|
||||||
|
|
||||||
# GET /api/v1/tag_search?term=abc
|
# GET /api/v1/tag_search?term=abc
|
||||||
def search
|
def search
|
||||||
list = Tag::Item.where('name_downcase LIKE ?', "%#{params[:term].strip.downcase}%").order(name: :asc).limit(params[:limit] || 10)
|
list = get_tag_list(params[:term], params[:limit] || 10)
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
list.each do |item|
|
list.each do |item|
|
||||||
result = {
|
result = {
|
||||||
|
@ -95,4 +96,13 @@ class TagsController < ApplicationController
|
||||||
render json: {}
|
render json: {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def get_tag_list(term, limit)
|
||||||
|
if term.blank?
|
||||||
|
return Tag::Item.left_outer_joins(:tags).group(:id).order('COUNT(tags.tag_item_id) DESC, name ASC').limit(limit)
|
||||||
|
end
|
||||||
|
|
||||||
|
Tag::Item.where('name_downcase LIKE ?', "%#{term.strip.downcase}%").order(name: :asc).limit(limit)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,10 @@ class Tag::Item < ApplicationModel
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
before_save :fill_namedowncase
|
before_save :fill_namedowncase
|
||||||
|
|
||||||
|
has_many :tags, foreign_key: 'tag_item_id',
|
||||||
|
inverse_of: :tag_item,
|
||||||
|
dependent: :destroy
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
lookup by name and create tag item
|
lookup by name and create tag item
|
||||||
|
|
|
@ -100,6 +100,18 @@ RSpec.describe Tag, type: :request do
|
||||||
include_examples 'no tag found using', search_term: '1foobar'
|
include_examples 'no tag found using', search_term: '1foobar'
|
||||||
include_examples 'no tag found using', search_term: 'foobar2'
|
include_examples 'no tag found using', search_term: 'foobar2'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'without search term' do
|
||||||
|
before do
|
||||||
|
create_list(:tag, 2, tag_item: tags.last)
|
||||||
|
create_list(:tag, 1, tag_item: tags.first)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'most used is on first place without search term' do
|
||||||
|
get '/api/v1/tag_search', params: { term: '' }
|
||||||
|
expect(json_response.first['value']).to eq(tags.last.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue