filter_form 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/filter_form/input_options/select/collection.rb +25 -0
- data/lib/filter_form/input_options_builder.rb +9 -0
- data/lib/filter_form/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a83442fb7f60aefce93393a49763bb4d66495b6e
|
4
|
+
data.tar.gz: 2ded8529b6e92cecce469d4b33b5153627e8a3b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a5c647796b8f95a916084c1ebe3268677c26a496e106576ef6634b45eb72782e22a502aeeabfd37e9fc716f43cbf457dae5447338ef9786b27a9e59bdc326b3
|
7
|
+
data.tar.gz: b3982e9af2e8457750805d14a0be2418aa1e2419eeac7e7d8ffc61f85cb4b0b2a3a5d24875fff1911224c593e59298d7f0680c0eaaba27a2f3c6fabde5fe7647
|
data/README.md
CHANGED
@@ -36,6 +36,7 @@ In your view file:
|
|
36
36
|
<%= f.filter_input :name # string %>
|
37
37
|
<%= f.filter_input :age # integer %>
|
38
38
|
<%= f.filter_input :city # belongs_to %>
|
39
|
+
<%= f.filter_input :parents # collection %>
|
39
40
|
<%= f.filter_input :birthday # date %>
|
40
41
|
<%= f.filter_input :amount # money %>
|
41
42
|
<%= f.button :submit %>
|
@@ -51,6 +52,7 @@ In your view file:
|
|
51
52
|
`datetime` | `datetime` | `eq` | `input[type=text]` |
|
52
53
|
`date` | `date` | `eq` | `input[type=text]` |
|
53
54
|
`belongs_to` | `belongs_to` association | `eq` | `select` |
|
55
|
+
`collection` | `has_many` or `has_and_belongs_to_many` association | `eq` | `select` |
|
54
56
|
`money` | `money` [monetized](https://github.com/RubyMoney/money-rails) attribute | `eq` | `input[type=text]` |
|
55
57
|
|
56
58
|
### Customization
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module FilterForm
|
2
|
+
module InputOptions
|
3
|
+
module Select
|
4
|
+
class Collection < FilterForm::InputOptions::Select::Base
|
5
|
+
private
|
6
|
+
|
7
|
+
def object_condition
|
8
|
+
object.base.conditions.select { |c| c.a.first.name == custom_attribute_name }.first
|
9
|
+
end
|
10
|
+
|
11
|
+
def collection
|
12
|
+
options[:collection] || attribute_name.to_s.camelize.singularize.constantize.all
|
13
|
+
end
|
14
|
+
|
15
|
+
def input_name
|
16
|
+
"q[#{ custom_attribute_name }_#{ predicate }]"
|
17
|
+
end
|
18
|
+
|
19
|
+
def custom_attribute_name
|
20
|
+
"#{ attribute_name }_id"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -2,6 +2,7 @@ require 'filter_form/input_options/base'
|
|
2
2
|
|
3
3
|
require 'filter_form/input_options/select/base'
|
4
4
|
require 'filter_form/input_options/select/belongs_to'
|
5
|
+
require 'filter_form/input_options/select/collection'
|
5
6
|
|
6
7
|
require 'filter_form/input_options/string/base'
|
7
8
|
require 'filter_form/input_options/string/date'
|
@@ -56,6 +57,8 @@ module FilterForm
|
|
56
57
|
'string/money'
|
57
58
|
when :belongs_to
|
58
59
|
'select/belongs_to'
|
60
|
+
when :collection
|
61
|
+
'select/collection'
|
59
62
|
when :select2
|
60
63
|
'select/select2'
|
61
64
|
else
|
@@ -67,6 +70,10 @@ module FilterForm
|
|
67
70
|
object.klass.reflections[attribute_name] && object.klass.reflections[attribute_name].belongs_to?
|
68
71
|
end
|
69
72
|
|
73
|
+
def collection?
|
74
|
+
object.klass.reflections[attribute_name] && object.klass.reflections[attribute_name].collection?
|
75
|
+
end
|
76
|
+
|
70
77
|
def money?
|
71
78
|
object.klass.columns_hash["#{ attribute_name }_cents"].present?
|
72
79
|
end
|
@@ -74,6 +81,8 @@ module FilterForm
|
|
74
81
|
def attribute_type
|
75
82
|
if belongs_to?
|
76
83
|
:belongs_to
|
84
|
+
elsif collection?
|
85
|
+
:collection
|
77
86
|
elsif money?
|
78
87
|
:money
|
79
88
|
else
|
data/lib/filter_form/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filter_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeny Li
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/filter_form/input_options/base.rb
|
114
114
|
- lib/filter_form/input_options/select/base.rb
|
115
115
|
- lib/filter_form/input_options/select/belongs_to.rb
|
116
|
+
- lib/filter_form/input_options/select/collection.rb
|
116
117
|
- lib/filter_form/input_options/string/base.rb
|
117
118
|
- lib/filter_form/input_options/string/date.rb
|
118
119
|
- lib/filter_form/input_options/string/money.rb
|