activeadmin-ajax_filter 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/activeadmin-ajax_filter.js.coffee +96 -88
- data/lib/active_admin/ajax_filter.rb +1 -1
- data/lib/active_admin/ajax_filter/version.rb +1 -1
- data/lib/active_admin/inputs/ajax_core.rb +4 -4
- data/lib/active_admin/inputs/filters/ajax_select_input.rb +0 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3388e55ea6dd77ff8bd2a7431a5b4bb4f0c402bc
|
4
|
+
data.tar.gz: b950b9818a0edb6c6d37df9bc104fef3713dfa8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1f2c12fcd0bc4dd43f3f93803296056279284f976779965de57c93650a3a75c693d37ad6a2fdab3b402b0b3891b705a4d61d7f6ca85802c256c282b5aaa35cc
|
7
|
+
data.tar.gz: fa69bf317340e2905118a0f2d9b00e6a701b8c55c73f69e09fba59eebaecf4cdd788e82b1d8fb8ea942ed3dd4c33cd2e26d7c78a165fbee8857f1cbfe7b7b955
|
@@ -1,91 +1,99 @@
|
|
1
1
|
$ ->
|
2
|
-
|
3
|
-
select
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
2
|
+
apply_filter_ajax_select = () ->
|
3
|
+
$('.filter_ajax_select select, .ajax_select select').each (_, select) ->
|
4
|
+
select = $(select)
|
5
|
+
valueField = select.data('value-field')
|
6
|
+
searchFields = select.data('search-fields').split(' ')
|
7
|
+
staticRansack = select.data('static-ransack')
|
8
|
+
|
9
|
+
ajaxFields = select.data('ajax-search-fields')
|
10
|
+
if ajaxFields
|
11
|
+
ajaxFields = ajaxFields.split(' ')
|
12
|
+
else
|
13
|
+
ajaxFields = []
|
14
|
+
|
15
|
+
ordering = select.data('ordering')
|
16
|
+
url = select.data('url')
|
17
|
+
|
18
|
+
loadOptions = (q, callback) ->
|
19
|
+
$.ajax
|
20
|
+
url: url
|
21
|
+
type: 'GET'
|
22
|
+
dataType: 'json'
|
23
|
+
data:
|
24
|
+
q: q
|
25
|
+
limit: select.data('limit')
|
26
|
+
order: ordering
|
27
|
+
error: ->
|
28
|
+
callback()
|
29
|
+
success: (res) ->
|
30
|
+
callback(res)
|
31
|
+
|
32
|
+
relatedInput = (field) ->
|
33
|
+
$("[name*=#{field}]", select.parents('form'))
|
34
|
+
|
35
|
+
select.selectize
|
36
|
+
valueField: valueField
|
37
|
+
labelField: searchFields[0]
|
38
|
+
searchField: searchFields
|
39
|
+
sortField: ordering.split(',').map (clause)->
|
40
|
+
c = clause.trim().split(' ')
|
41
|
+
{ field: c[0], direction: c[1] }
|
42
|
+
options: []
|
43
|
+
create: false
|
44
|
+
render:
|
45
|
+
option: (item, escape) ->
|
46
|
+
html = searchFields.map (field, index)->
|
47
|
+
value = escape(item[field])
|
48
|
+
|
49
|
+
if index == 0
|
50
|
+
klass = 'primary'
|
51
|
+
else
|
52
|
+
klass = 'secondary'
|
53
|
+
|
54
|
+
"<span class='#{klass}'>#{value}</span>"
|
55
|
+
|
56
|
+
"<div class='item'>#{html.join('')}</div>"
|
57
|
+
|
58
|
+
load: (query, callback) ->
|
59
|
+
if query.length
|
60
|
+
q = {}
|
61
|
+
q[select.data('ransack')] = query
|
62
|
+
|
63
|
+
ajaxFields.forEach (field) ->
|
64
|
+
q["#{field}_eq"] = relatedInput(field).val()
|
65
|
+
# clear cache because it wrong with changing values of ajaxFields
|
66
|
+
select.loadedSearches = {}
|
67
|
+
|
68
|
+
for ransack, value of staticRansack
|
69
|
+
q[ransack] = value
|
70
|
+
|
71
|
+
loadOptions(q, callback)
|
72
|
+
else
|
73
|
+
callback()
|
74
|
+
|
75
|
+
onInitialize: ->
|
76
|
+
selectize = this
|
77
|
+
selectedValue = select.data('selected-value')
|
78
|
+
selectedRansack = "#{valueField}_eq"
|
79
|
+
|
80
|
+
if selectedValue
|
81
|
+
q = {}
|
82
|
+
q[selectedRansack] = selectedValue
|
83
|
+
|
84
|
+
loadOptions(q, (res)->
|
85
|
+
if res.length
|
86
|
+
selectize.addOption(res[0])
|
87
|
+
selectize.addItem(res[0][valueField])
|
88
|
+
)
|
61
89
|
|
62
90
|
ajaxFields.forEach (field) ->
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
callback()
|
73
|
-
|
74
|
-
onInitialize: ->
|
75
|
-
selectize = this
|
76
|
-
selectedValue = select.data('selected-value')
|
77
|
-
selectedRansack = "#{valueField}_eq"
|
78
|
-
|
79
|
-
if selectedValue
|
80
|
-
q = {}
|
81
|
-
q[selectedRansack] = selectedValue
|
82
|
-
|
83
|
-
loadOptions(q, (res)->
|
84
|
-
if res.length
|
85
|
-
selectize.addOption(res[0])
|
86
|
-
selectize.addItem(res[0][valueField])
|
87
|
-
)
|
88
|
-
|
89
|
-
ajaxFields.forEach (field) ->
|
90
|
-
relatedInput(field).change ->
|
91
|
-
selectize.clearOptions()
|
91
|
+
relatedInput(field).change ->
|
92
|
+
selectize.clearOptions()
|
93
|
+
|
94
|
+
# apply ajax filter to all static inputs
|
95
|
+
apply_filter_ajax_select()
|
96
|
+
|
97
|
+
# apply ajax filter on inputs inside has_many entries
|
98
|
+
$("form.formtastic .has_many_add").click ->
|
99
|
+
setTimeout((-> apply_filter_ajax_select()), 0)
|
@@ -16,7 +16,7 @@ module ActiveAdmin
|
|
16
16
|
collection_action :filter, method: :get do
|
17
17
|
scope = collection.ransack(params[:q]).result
|
18
18
|
|
19
|
-
render
|
19
|
+
render text: scope.order(params[:order]).limit(params[:limit] || 10).to_json
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -7,10 +7,6 @@ module ActiveAdmin
|
|
7
7
|
klass.reorder("#{method} asc").limit(collection_limit).uniq.pluck(method)
|
8
8
|
end
|
9
9
|
|
10
|
-
# def collection_from_association
|
11
|
-
# super.limit(collection_limit)
|
12
|
-
# end
|
13
|
-
|
14
10
|
def input_html_options
|
15
11
|
super.merge(
|
16
12
|
'data-limit' => collection_limit,
|
@@ -33,6 +29,10 @@ module ActiveAdmin
|
|
33
29
|
ajax_data[:limit] || DEFAULT_LIMIT
|
34
30
|
end
|
35
31
|
|
32
|
+
def collection_from_association
|
33
|
+
super.try(:limit, collection_limit)
|
34
|
+
end
|
35
|
+
|
36
36
|
def value_field
|
37
37
|
ajax_data[:value_field] || :id
|
38
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin-ajax_filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Emelyanov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeadmin
|