activeadmin-ajax_filter 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +7 -1
- data/README.md +24 -16
- data/activeadmin-ajax_filter.gemspec +1 -0
- data/app/assets/javascripts/activeadmin-ajax_filter.js.coffee +5 -0
- data/lib/active_admin/ajax_filter.rb +1 -1
- data/lib/active_admin/ajax_filter/version.rb +1 -1
- data/lib/active_admin/inputs/filters/ajax_select_input.rb +5 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0615541e8662246ec0d547129a2429e9a4a43d50
|
4
|
+
data.tar.gz: 28c1e167ae37b2893b37e58e6de7ed1cc40d7e87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 681e7958936fa07a57f811621b0358c2f16c479a17d4d4fc755ba10d5042574c91ed3d441eeeb5020b625fe71b8f8e69c0f6ab920e27e8a769ac31ba059ff159
|
7
|
+
data.tar.gz: 86b64b3ee8d2d5ba8b638421a7e720ec7fd001465a4666dfb6940dc5afc2d9990e6b699ce2f6e0466daaa77a7e453756626a9c6d9117bcdcf9f03346a1cd3ec9
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
[](https://travis-ci.org/holyketzer/activeadmin-ajax_filter)
|
2
|
+
[](https://codeclimate.com/github/holyketzer/activeadmin-ajax_filter)
|
3
|
+
[](https://codeclimate.com/github/holyketzer/activeadmin-ajax_filter/coverage)
|
4
|
+
[](https://badge.fury.io/rb/activeadmin-ajax_filter)
|
5
|
+
|
1
6
|
# Activeadmin::AjaxFilter
|
2
7
|
|
3
8
|
This gem extends ActiveAdmin so that your can use filters with AJAX-powered input.
|
@@ -27,34 +32,38 @@ Or install it yourself as:
|
|
27
32
|
Include this line in your JavaScript code (active_admin.js.coffee)
|
28
33
|
|
29
34
|
```coffeescript
|
30
|
-
|
35
|
+
#= require activeadmin-ajax_filter
|
31
36
|
```
|
32
37
|
|
33
38
|
Include this line in your CSS code (active_admin.scss)
|
34
39
|
|
35
40
|
```scss
|
36
|
-
|
41
|
+
@import "activeadmin-ajax_filter";
|
37
42
|
```
|
38
43
|
|
39
44
|
Include `ActiveAdmin::AjaxFilter` module to the ActiveAdmin relation resource for which you want to support filtering and add `ajax_select` filter to main resource. For example:
|
40
45
|
|
41
46
|
```ruby
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
# Relation-resource
|
48
|
+
ActiveAdmin.register User do
|
49
|
+
include ActiveAdmin::AjaxFilter
|
50
|
+
# ...
|
51
|
+
end
|
52
|
+
|
53
|
+
# Main resource
|
54
|
+
ActiveAdmin.register Invoice do
|
55
|
+
filter :user, as: :ajax_select, data: { search_fields: [:email, :customer_uid], limit: 7 }
|
56
|
+
# ...
|
57
|
+
end
|
50
58
|
```
|
51
59
|
|
52
60
|
You can use next parameters in `data` hash:
|
53
61
|
|
54
|
-
* limit - count of the items which will be requested by AJAX, by default `5`
|
55
|
-
* value_field - value field for html select element, by default `id`
|
56
|
-
* search_fields - fields by which AJAX search will be performed, required
|
57
|
-
*
|
62
|
+
* `limit` - count of the items which will be requested by AJAX, by default `5`
|
63
|
+
* `value_field` - value field for html select element, by default `id`
|
64
|
+
* `search_fields` - fields by which AJAX search will be performed, required
|
65
|
+
* `ordering` - sort string like `email ASC, customer_uid DESC`, by default it uses first value of `search_fields` with `ASC` direction
|
66
|
+
* `ransack` - ransack query which will be applied, by default it's builded from `search_fields` with `or` and `contains` clauses, e.g.: `email_or_customer_uid_cont`
|
58
67
|
|
59
68
|
## Development
|
60
69
|
|
@@ -64,8 +73,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
64
73
|
|
65
74
|
## Contributing
|
66
75
|
|
67
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/holyketzer/activeadmin-ajax_filter. This project is intended to be a safe, welcoming space for collaboration
|
68
|
-
|
76
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/holyketzer/activeadmin-ajax_filter. This project is intended to be a safe, welcoming space for collaboration.
|
69
77
|
|
70
78
|
## License
|
71
79
|
|
@@ -26,4 +26,5 @@ Gem::Specification.new do |gem|
|
|
26
26
|
gem.add_development_dependency 'rspec', '~> 3.3', '>= 3.3.0'
|
27
27
|
gem.add_development_dependency 'sqlite3', '~> 1.3', '>= 1.3.11'
|
28
28
|
gem.add_development_dependency 'temping', '~> 3.3', '>= 3.3.0'
|
29
|
+
gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
|
29
30
|
end
|
@@ -3,6 +3,7 @@ $ ->
|
|
3
3
|
select = $(select)
|
4
4
|
valueField = select.data('value-field')
|
5
5
|
searchFields = select.data('search-fields').split(' ')
|
6
|
+
ordering = select.data('ordering')
|
6
7
|
|
7
8
|
loadOptions = (q, callback) ->
|
8
9
|
$.ajax
|
@@ -12,6 +13,7 @@ $ ->
|
|
12
13
|
data:
|
13
14
|
q: q
|
14
15
|
limit: select.data('limit')
|
16
|
+
order: ordering
|
15
17
|
error: ->
|
16
18
|
callback()
|
17
19
|
success: (res) ->
|
@@ -21,6 +23,9 @@ $ ->
|
|
21
23
|
valueField: valueField
|
22
24
|
labelField: searchFields[0]
|
23
25
|
searchField: searchFields
|
26
|
+
sortField: ordering.split(',').map (clause)->
|
27
|
+
c = clause.trim().split(' ')
|
28
|
+
{ field: c[0], direction: c[1] }
|
24
29
|
options: []
|
25
30
|
create: false
|
26
31
|
render:
|
@@ -14,7 +14,7 @@ module ActiveAdmin
|
|
14
14
|
collection_action :filter, method: :get do
|
15
15
|
scope = collection.ransack(params[:q]).result
|
16
16
|
|
17
|
-
render json: scope.order(:
|
17
|
+
render json: scope.order(params[:order]).limit(params[:limit] || 10)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -17,6 +17,7 @@ module ActiveAdmin
|
|
17
17
|
'data-limit' => collection_limit,
|
18
18
|
'data-value-field' => value_field,
|
19
19
|
'data-search-fields' => search_fields,
|
20
|
+
'data-ordering' => ordering,
|
20
21
|
'data-ransack' => ransack,
|
21
22
|
'data-selected-value' => selected_value,
|
22
23
|
)
|
@@ -38,6 +39,10 @@ module ActiveAdmin
|
|
38
39
|
ajax_data[:search_fields] || raise(ArgumentError, 'search_fields in required')
|
39
40
|
end
|
40
41
|
|
42
|
+
def ordering
|
43
|
+
ajax_data[:ordering] || "#{search_fields.first} ASC"
|
44
|
+
end
|
45
|
+
|
41
46
|
def ransack
|
42
47
|
ajax_data[:ransack] || "#{search_fields.join('_or_')}_cont"
|
43
48
|
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.
|
4
|
+
version: 0.2.0
|
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-02-
|
11
|
+
date: 2016-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeadmin
|
@@ -132,6 +132,20 @@ dependencies:
|
|
132
132
|
- - ">="
|
133
133
|
- !ruby/object:Gem::Version
|
134
134
|
version: 3.3.0
|
135
|
+
- !ruby/object:Gem::Dependency
|
136
|
+
name: codeclimate-test-reporter
|
137
|
+
requirement: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - "~>"
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0.4'
|
142
|
+
type: :development
|
143
|
+
prerelease: false
|
144
|
+
version_requirements: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - "~>"
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0.4'
|
135
149
|
description: Allows to define filter by relation for ActiveAdmin resource pages using
|
136
150
|
Ransacker to dynamicaly load items while user is typing symbols in filter
|
137
151
|
email:
|