auto_awesomplete 0.0.3 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of auto_awesomplete might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/auto_awesomplete.gemspec +0 -3
- data/lib/auto_awesomplete/search_adapter/base.rb +24 -8
- data/lib/auto_awesomplete/search_adapter/default.rb +38 -6
- data/lib/auto_awesomplete/version.rb +1 -1
- data/lib/generators/auto_awesomplete/search_adapter_generator.rb +52 -0
- data/lib/generators/auto_awesomplete/templates/search_adapter.rb.erb +6 -0
- data/vendor/assets/javascripts/auto_awesomplete/ajax.js.coffee +8 -2
- metadata +12 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c4c1c1e95701e96cdfdef28682b43a4e2ea6e3939cc98d11ad803e141d2040ae
|
4
|
+
data.tar.gz: 2e586493d22897ff21e53b160491655c0141d0028d24ac2d1c7256221e2ec4d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9e6ef99fc9b320edfe3931212ea0e01837492cc1480dbb764ad9e3a7f4f4072aba3dd3f42014ff08abb7f190dd078fc3f5b26d983d8b4483a20f7d27e0a4081
|
7
|
+
data.tar.gz: 0241d0b052aa83e38a5ef8b60cf7e6b3b10f971c3b17a6881a42b7ea0dfb075cb3b09dd3848de8c9c120693fb045573c756a1bc3433ad3528f157e0ec6f31048
|
data/auto_awesomplete.gemspec
CHANGED
@@ -17,8 +17,14 @@ module AutoAwesomplete
|
|
17
17
|
private
|
18
18
|
|
19
19
|
def default_finder(searched_class, term, options)
|
20
|
-
columns = options[:
|
21
|
-
conditions =
|
20
|
+
columns = options[:columns].present? ? options[:columns] : 'name'
|
21
|
+
conditions =
|
22
|
+
default_search_conditions(
|
23
|
+
term,
|
24
|
+
options[:basic_conditions],
|
25
|
+
columns,
|
26
|
+
options.slice(:case_sensitive)
|
27
|
+
)
|
22
28
|
|
23
29
|
if term.nil?
|
24
30
|
[ searched_class.where(options[:basic_conditions]) ]
|
@@ -30,7 +36,7 @@ module AutoAwesomplete
|
|
30
36
|
end
|
31
37
|
end
|
32
38
|
|
33
|
-
def default_search_conditions(term, basic_conditions, columns)
|
39
|
+
def default_search_conditions(term, basic_conditions, columns, options = {})
|
34
40
|
term_filter = ''
|
35
41
|
conditions = []
|
36
42
|
|
@@ -45,25 +51,35 @@ module AutoAwesomplete
|
|
45
51
|
|
46
52
|
columns.each_with_index do |column, idx|
|
47
53
|
term_filter += ' OR ' if idx > 0
|
48
|
-
|
54
|
+
|
55
|
+
if options[:case_sensitive]
|
56
|
+
term_filter += "#{column} LIKE ?"
|
57
|
+
else
|
58
|
+
term_filter += "LOWER(#{column}) LIKE LOWER(?)"
|
59
|
+
end
|
60
|
+
|
49
61
|
conditions << "%#{word}%"
|
50
62
|
end
|
51
63
|
end
|
52
64
|
|
53
65
|
term_filter = term_filter.empty? ? nil : "(#{term_filter})"
|
54
66
|
basic_conditions_part = basic_conditions.present? ? "(#{basic_conditions }) " : nil
|
55
|
-
|
67
|
+
term_and_basic_conditions = [term_filter, basic_conditions_part].compact.join(' AND ')
|
68
|
+
conditions.unshift(term_and_basic_conditions) if term_and_basic_conditions.present?
|
56
69
|
end
|
57
70
|
end
|
58
71
|
|
59
72
|
def get_awesomplete_label(item, options)
|
60
73
|
label_method = options[:label_method]
|
61
|
-
|
74
|
+
text_columns = options[:default_text_columns]
|
75
|
+
if text_columns.is_a?(String)
|
76
|
+
text_columns = text_columns.split(',').map(&:squish)
|
77
|
+
end
|
62
78
|
|
63
79
|
if label_method.present? && item.respond_to?(label_method)
|
64
80
|
item.public_send(label_method)
|
65
|
-
elsif
|
66
|
-
item.attributes[
|
81
|
+
elsif text_columns.present?
|
82
|
+
text_columns.map { |attr| item.attributes[attr.to_s] }.join(' ')
|
67
83
|
else
|
68
84
|
item.to_s
|
69
85
|
end
|
@@ -3,17 +3,49 @@ module AutoAwesomplete
|
|
3
3
|
class Default < Base
|
4
4
|
class << self
|
5
5
|
def search_default(term, page, options)
|
6
|
-
|
7
|
-
|
8
|
-
rescue NameError
|
9
|
-
return {error: "not found class '#{options[:default_class_name]}'"}
|
6
|
+
if !@searchable || @text_columns.blank?
|
7
|
+
raise_not_implemented
|
10
8
|
end
|
11
9
|
|
12
|
-
default_values =
|
10
|
+
default_values =
|
11
|
+
default_finder(
|
12
|
+
@searchable,
|
13
|
+
term,
|
14
|
+
page: page,
|
15
|
+
columns: @text_columns,
|
16
|
+
case_sensitive: @case_sensitive.nil? ? options[:case_sensitive] : @case_sensitive
|
17
|
+
)
|
13
18
|
default_values.map do |default_value|
|
14
|
-
get_awesomplete_label(
|
19
|
+
get_awesomplete_label(
|
20
|
+
default_value,
|
21
|
+
default_text_columns: @text_columns,
|
22
|
+
label_method: @label_method
|
23
|
+
)
|
15
24
|
end
|
16
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def searchable(class_or_relation)
|
30
|
+
@searchable = class_or_relation
|
31
|
+
end
|
32
|
+
|
33
|
+
def text_columns(*column_names)
|
34
|
+
@text_columns = column_names
|
35
|
+
end
|
36
|
+
|
37
|
+
def label_method(method_sym)
|
38
|
+
@label_method = method_sym
|
39
|
+
end
|
40
|
+
|
41
|
+
def case_sensitive(casi)
|
42
|
+
@case_sensitive = casi
|
43
|
+
end
|
44
|
+
|
45
|
+
def raise_not_implemented
|
46
|
+
raise NotImplementedError,
|
47
|
+
'You should implement your own SearchAdapter. Use: `rails generate auto_awesomplete:search_adapter`'
|
48
|
+
end
|
17
49
|
end
|
18
50
|
end
|
19
51
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module AutoAwesomplete
|
2
|
+
module Generators
|
3
|
+
class SearchAdapterGenerator < Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
class_option :destination_path,
|
7
|
+
type: :string,
|
8
|
+
default: 'app/awesomplete_search_adapters',
|
9
|
+
desc: 'Path for storing SearchAdapter classes',
|
10
|
+
banner: 'lib/search_adapters'
|
11
|
+
class_option :text_columns,
|
12
|
+
type: :array,
|
13
|
+
desc: 'Column for searching by',
|
14
|
+
banner: 'lastname firstname',
|
15
|
+
required: true
|
16
|
+
class_option :label_method,
|
17
|
+
type: :string,
|
18
|
+
desc: 'Instance method of model for converting into Hash for transporting into awesomplete',
|
19
|
+
banner: 'to_awesomplete'
|
20
|
+
class_option :case_sensitive,
|
21
|
+
type: :boolean,
|
22
|
+
desc: 'Is adapter request case sensitive or not',
|
23
|
+
banner: 'case_sensitive'
|
24
|
+
|
25
|
+
desc 'Creates SearchAdapter classes for your models'
|
26
|
+
def create_search_adapter
|
27
|
+
template 'search_adapter.rb.erb',
|
28
|
+
"#{options[:destination_path]}/#{class_path.push(file_name).join('/')}_search_adapter.rb"
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def text_columns
|
34
|
+
options[:text_columns].map do |c|
|
35
|
+
if c.underscore == c
|
36
|
+
":#{c}"
|
37
|
+
else
|
38
|
+
"\"#{c}\""
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def label_method
|
44
|
+
options[:label_method]
|
45
|
+
end
|
46
|
+
|
47
|
+
def case_sensitive
|
48
|
+
options[:case_sensitive]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
class <%= name.classify %>SearchAdapter < AutoAwesomplete::SearchAdapter::Default
|
2
|
+
searchable <%= name.classify %>
|
3
|
+
text_columns <%= text_columns.join(', ') %>
|
4
|
+
<% if label_method.present? %>label_method :<%= label_method %><% end %>
|
5
|
+
<% if case_sensitive.present? %>case_sensitive <%= case_sensitive %><% end %>
|
6
|
+
end
|
@@ -17,7 +17,13 @@
|
|
17
17
|
$inputs = $(':not(.awesomplete) > input.auto-ajax-awesomplete')
|
18
18
|
$inputs.each ->
|
19
19
|
$input = $(this)
|
20
|
-
awesomplete = new Awesomplete(
|
20
|
+
awesomplete = new Awesomplete(
|
21
|
+
this,
|
22
|
+
{
|
23
|
+
filter: ->
|
24
|
+
true
|
25
|
+
}
|
26
|
+
)
|
21
27
|
$input.on 'input', ->
|
22
28
|
$textInput = $(this)
|
23
29
|
path = $textInput.data('awesomplete-href')
|
@@ -32,7 +38,7 @@
|
|
32
38
|
jQuery ($) ->
|
33
39
|
autoAwesomplete.ajaxInit()
|
34
40
|
|
35
|
-
$body = $(
|
41
|
+
$body = $(document)
|
36
42
|
$body.on 'ajaxSuccess', ->
|
37
43
|
autoAwesomplete.ajaxInit()
|
38
44
|
return
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_awesomplete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Lisichkin
|
@@ -9,64 +9,36 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-04-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '3.1'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '3.1'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: coffee-rails
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '0'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: bundler
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - ~>
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: '1.5'
|
49
|
-
type: :development
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - ~>
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: '1.5'
|
56
|
-
- !ruby/object:Gem::Dependency
|
57
|
-
name: rails
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
59
|
-
requirements:
|
60
|
-
- - ~>
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: 3.2.12
|
63
|
-
type: :development
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - ~>
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: 3.2.12
|
70
42
|
description: |2
|
71
43
|
Gem provide scripts and helpers for initialize different awesomplete elements:
|
72
44
|
static and ajax. Moreover this gem is foundation for other gems.
|
@@ -78,7 +50,7 @@ executables: []
|
|
78
50
|
extensions: []
|
79
51
|
extra_rdoc_files: []
|
80
52
|
files:
|
81
|
-
- .gitignore
|
53
|
+
- ".gitignore"
|
82
54
|
- Gemfile
|
83
55
|
- LICENSE.txt
|
84
56
|
- README.md
|
@@ -93,6 +65,8 @@ files:
|
|
93
65
|
- lib/auto_awesomplete/search_adapter/base.rb
|
94
66
|
- lib/auto_awesomplete/search_adapter/default.rb
|
95
67
|
- lib/auto_awesomplete/version.rb
|
68
|
+
- lib/generators/auto_awesomplete/search_adapter_generator.rb
|
69
|
+
- lib/generators/auto_awesomplete/templates/search_adapter.rb.erb
|
96
70
|
- vendor/assets/javascripts/auto_awesomplete/ajax.js.coffee
|
97
71
|
homepage: https://github.com/Tab10id/auto_awesomplete
|
98
72
|
licenses:
|
@@ -104,19 +78,17 @@ require_paths:
|
|
104
78
|
- lib
|
105
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
106
80
|
requirements:
|
107
|
-
- -
|
81
|
+
- - ">="
|
108
82
|
- !ruby/object:Gem::Version
|
109
83
|
version: '0'
|
110
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
85
|
requirements:
|
112
|
-
- -
|
86
|
+
- - ">="
|
113
87
|
- !ruby/object:Gem::Version
|
114
88
|
version: '0'
|
115
89
|
requirements: []
|
116
|
-
|
117
|
-
rubygems_version: 2.0.2
|
90
|
+
rubygems_version: 3.0.3
|
118
91
|
signing_key:
|
119
92
|
specification_version: 4
|
120
93
|
summary: Base methods for wrapping a Awesomplete and easy initialize it.
|
121
94
|
test_files: []
|
122
|
-
has_rdoc:
|