activeadmin-ajax_filter 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 623bc73b23aeeffb17a649881dd93aac161501e7
4
- data.tar.gz: 20c10cfbdf0e62cf2c4a9398e1b347c4607bf86f
3
+ metadata.gz: 0615541e8662246ec0d547129a2429e9a4a43d50
4
+ data.tar.gz: 28c1e167ae37b2893b37e58e6de7ed1cc40d7e87
5
5
  SHA512:
6
- metadata.gz: 332257481022b85e17431c08bd7dd30535c56ae3fec0bdbe4161583089bbe44643515e4bebe18741b59ae88c666c815af15219bb3e224abb375f817fbfff7468
7
- data.tar.gz: 3d2a382207e390bdba1ecbf104e48751d4511414c254ce706bb3309ebf4553ca80fbee3f6ad580c4e05501691eb4ec72cb3fc4c9f632c03843449b85862a9117
6
+ metadata.gz: 681e7958936fa07a57f811621b0358c2f16c479a17d4d4fc755ba10d5042574c91ed3d441eeeb5020b625fe71b8f8e69c0f6ab920e27e8a769ac31ba059ff159
7
+ data.tar.gz: 86b64b3ee8d2d5ba8b638421a7e720ec7fd001465a4666dfb6940dc5afc2d9990e6b699ce2f6e0466daaa77a7e453756626a9c6d9117bcdcf9f03346a1cd3ec9
data/.travis.yml CHANGED
@@ -3,5 +3,11 @@ rvm:
3
3
  - 2.1.5
4
4
  - 2.2.4
5
5
  - 2.3.0
6
- - ruby-head
7
6
  before_install: gem install bundler -v 1.10.6
7
+
8
+ script:
9
+ - bundle exec rspec
10
+
11
+ addons:
12
+ code_climate:
13
+ repo_token: 9c938a047651a943393f0f52bfc1d03d71fce0f19bf0f8c1265033af9b09a56e
data/README.md CHANGED
@@ -1,3 +1,8 @@
1
+ [![Build Status](https://travis-ci.org/holyketzer/activeadmin-ajax_filter.svg?branch=master)](https://travis-ci.org/holyketzer/activeadmin-ajax_filter)
2
+ [![Code Climate](https://codeclimate.com/github/holyketzer/activeadmin-ajax_filter/badges/gpa.svg)](https://codeclimate.com/github/holyketzer/activeadmin-ajax_filter)
3
+ [![Test Coverage](https://codeclimate.com/github/holyketzer/activeadmin-ajax_filter/badges/coverage.svg)](https://codeclimate.com/github/holyketzer/activeadmin-ajax_filter/coverage)
4
+ [![Gem Version](https://badge.fury.io/rb/activeadmin-ajax_filter.svg)](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
- #= require activeadmin-ajax_filter
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
- @import "activeadmin-ajax_filter";
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
- # Relation-resource
43
- ActiveAdmin.register User do
44
- include ActiveAdmin::AjaxFilter
45
- ...
46
-
47
- # Main resource
48
- ActiveAdmin.register Invoice do
49
- filter :user, as: :ajax_select, data: { search_fields: [:email, :customer_uid], limit: 7 }
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 parameter
57
- * 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`
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, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
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(:created_at).limit(params[:limit] || 10)
17
+ render json: scope.order(params[:order]).limit(params[:limit] || 10)
18
18
  end
19
19
  end
20
20
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveAdmin
2
2
  module AjaxFilter
3
- VERSION = '0.1.1'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  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.1.1
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-01 00:00:00.000000000 Z
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: