active_admin_auto_select 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +64 -23
- data/active_admin_auto_select.gemspec +2 -1
- data/lib/active_admin_auto_select.rb +11 -2
- data/lib/active_admin_auto_select/rails.rb +2 -0
- data/lib/active_admin_auto_select/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f67a66ea734c425a23696088c318f40203046088
|
4
|
+
data.tar.gz: f54bc1ec07043c15a41b7808a9a8c5b2d8e5acdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80c8f878690641ae60a7ba90f635971a695eca263a9d66ce3b4e563b2f2f33c3a8cd9851aa4e0d1b582f23a45f0f2845c5c6eb7d73c1b758f6db05f23148eea5
|
7
|
+
data.tar.gz: c4950f69e39152d7a8346fbaf48cc27e016673122fcd967a55a9fb4e57b8a0106d11588fcc4cd7c2d746d41d7a34e4b34aa98be2afaed2b43b2e1a668b7db594
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# ActiveAdminAutoSelect
|
2
2
|
|
3
|
-
This gem is a
|
3
|
+
This gem is a nifty UI widget, which combines the Select2 library, PostgeSQL and ActiveAdmin,
|
4
|
+
for helping you filter records in ActiveAdmin using auto-completion, based on certain database
|
5
|
+
columns of your choice.
|
4
6
|
|
5
7
|
![Image of AutoSelect](http://i.imgur.com/lEJmaQC.png)
|
6
8
|
![Image of AutoSelect](http://i.imgur.com/6s0Xnco.png)
|
@@ -10,50 +12,89 @@ This gem is a little widget which combines Select2, PostgeSQL and ActiveAdmin an
|
|
10
12
|
Add this line to your application's Gemfile:
|
11
13
|
|
12
14
|
```ruby
|
13
|
-
gem '
|
15
|
+
gem 'active_admin_auto_select'
|
14
16
|
```
|
15
17
|
|
18
|
+
Currently, [Select2 3.5](http://select2.github.io/select2/) is required. Select2 versions 4+
|
19
|
+
are not compatible as the API contains [breaking changes](https://select2.org/upgrading/new-in-40).
|
20
|
+
We are looking to remedy this as soon as possible.
|
21
|
+
|
16
22
|
And then execute:
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
24
|
+
```console
|
25
|
+
> bundle
|
26
|
+
```
|
27
|
+
|
28
|
+
Add the following directives to your Javascript manifest file:
|
21
29
|
|
22
|
-
|
30
|
+
```javascript
|
31
|
+
//= require select2
|
32
|
+
//= require underscore
|
23
33
|
//= require autoselect
|
24
|
-
|
34
|
+
```
|
25
35
|
|
26
|
-
|
36
|
+
Or for Coffeescript flavor, add this:
|
37
|
+
|
38
|
+
```coffeescript
|
39
|
+
#= require select2
|
40
|
+
#= require underscore
|
41
|
+
#= require autoselect
|
42
|
+
```
|
27
43
|
|
28
|
-
|
29
|
-
For example, if you want to add the widget to the users id filter:
|
44
|
+
Add the following directive to your Stylesheet manifest file:
|
30
45
|
|
31
|
-
|
46
|
+
```scss
|
47
|
+
@import "select2";
|
48
|
+
```
|
49
|
+
|
50
|
+
## Usage
|
51
|
+
|
52
|
+
After installing the gem, you have to add some lines into the ActiveAdmin controller you want to auto_select.
|
53
|
+
For example, say you want to add the widget in order to filter to the users' `id` filter, by searching in their full names or emails:
|
32
54
|
|
33
|
-
|
55
|
+
### Call the `auto_select` method in order to create the collection_action
|
34
56
|
|
35
57
|
```ruby
|
36
|
-
|
58
|
+
auto_select :first_name, :last_name, :email,
|
59
|
+
{
|
60
|
+
'users_with_properties' => ->{ User.joins(:properties).uniq }
|
61
|
+
}
|
37
62
|
```
|
38
63
|
|
39
|
-
|
64
|
+
In the example above, `first_name`, `:last_name` and `:email` are the database columns that help you find the desired user.
|
65
|
+
Anything that is typed into the autocomplete field will be lookup in the columns specified here. Last argument is a Hash of
|
66
|
+
scopes that will make sense by reading through the next example.
|
40
67
|
|
41
|
-
|
42
|
-
data-scope is the desired scope which will be used by the widget in order to fetch the similar users.
|
43
|
-
data-url is also necessary and is the url generated by the action which is defined in the module.
|
68
|
+
### Define the relevant `filter` in your controller
|
44
69
|
|
45
70
|
```ruby
|
46
|
-
|
47
|
-
|
48
|
-
|
71
|
+
filter :id_eq, label: 'User',
|
72
|
+
input_html: {
|
73
|
+
data: {
|
74
|
+
scope: 'users_with_properties',
|
75
|
+
url: 'users/autoselect',
|
76
|
+
placeholder: 'Select a user'
|
77
|
+
}
|
78
|
+
}
|
49
79
|
```
|
50
80
|
|
51
|
-
####
|
81
|
+
#### Notice
|
52
82
|
|
53
|
-
|
54
|
-
|
83
|
+
- `:id_eq` (required) is the column being filtered `id` + the `_eq` suffix (Ransack style).
|
84
|
+
- `data-scope` option is the desired scope that will be used by the widget in order to fetch the similar users.
|
85
|
+
- `data-url` (required) is the url generated by the action, which is defined in the ActiveAdmin controller.
|
86
|
+
|
87
|
+
### Instantiate the `AutoSelect` Javascript class in your active_admin's javascript file.
|
88
|
+
|
89
|
+
```javascript
|
90
|
+
$(document).ready ->
|
91
|
+
newAutoSelect = new AutoSelect(input: $('#q_id_eq'))
|
92
|
+
newAutoSelect.init()
|
55
93
|
```
|
56
94
|
|
95
|
+
Where `#q_user_id_eq` use the generated input's `id` of the filter you added. For instance,
|
96
|
+
if your filter's name in the ActiveAdmin controller is defined as `id_eq`, then the `id`
|
97
|
+
attribute of the generated input will be `q_id_eq`.
|
57
98
|
|
58
99
|
## Contributing
|
59
100
|
|
@@ -15,6 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.require_paths = ["lib"]
|
16
16
|
spec.add_development_dependency "bundler", "~> 1.10"
|
17
17
|
spec.add_development_dependency "rake", "~> 10.0"
|
18
|
-
spec.add_dependency "select2-rails"
|
18
|
+
spec.add_dependency "select2-rails", "3.5.2"
|
19
|
+
spec.add_dependency "underscore-rails"
|
19
20
|
spec.add_dependency "pg"
|
20
21
|
end
|
@@ -4,7 +4,12 @@ require 'active_admin_auto_select/rails'
|
|
4
4
|
module AutoSelectable
|
5
5
|
def auto_select(*fields)
|
6
6
|
options = fields.extract_options!
|
7
|
-
|
7
|
+
|
8
|
+
# The @resource instance variable seems unavailable in versions
|
9
|
+
# later than 1.0.0.pre1 of the ActiveAdmin.
|
10
|
+
resource = @resource || self.config.resource_class_name.constantize
|
11
|
+
|
12
|
+
create_collection_action(fields, options, resource)
|
8
13
|
end
|
9
14
|
|
10
15
|
def create_collection_action(fields, options, resource)
|
@@ -27,7 +32,11 @@ module AutoSelectable
|
|
27
32
|
resources = effective_scope.call.
|
28
33
|
where("#{resource.table_name}.id IN (?)", params[:ids]).
|
29
34
|
select(select_fields)
|
30
|
-
|
35
|
+
if resources.size == 1
|
36
|
+
resources = resources.first
|
37
|
+
else
|
38
|
+
resources = resources.sort_by { |r| params[:ids].index(r.id.to_s) }
|
39
|
+
end
|
31
40
|
render json: resources and return
|
32
41
|
else
|
33
42
|
concat_fields = fields.join(" || ' '::text || ")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_admin_auto_select
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- spyrbri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -40,6 +40,20 @@ dependencies:
|
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: select2-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.5.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.5.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: underscore-rails
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - ">="
|
@@ -107,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
121
|
version: '0'
|
108
122
|
requirements: []
|
109
123
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.2
|
124
|
+
rubygems_version: 2.5.2
|
111
125
|
signing_key:
|
112
126
|
specification_version: 4
|
113
127
|
summary: This gem helps you select a row of a column in a model with autocomplete
|