filter_form 0.0.3 → 0.0.4
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/README.md +12 -2
- data/lib/filter_form/input_builder.rb +20 -12
- data/lib/filter_form/inputs/base.rb +4 -4
- data/lib/filter_form/inputs/select/base.rb +26 -0
- data/lib/filter_form/inputs/select/belongs_to_eq.rb +25 -0
- data/lib/filter_form/inputs/string/base.rb +21 -0
- data/lib/filter_form/inputs/{date_eq.rb → string/date_eq.rb} +1 -1
- data/lib/filter_form/inputs/string/integer_eq.rb +6 -0
- data/lib/filter_form/inputs/string/string_cont.rb +6 -0
- data/lib/filter_form/simple_form/form_builder.rb +1 -1
- data/lib/filter_form/version.rb +1 -1
- metadata +7 -6
- data/lib/filter_form/inputs/belongs_to_eq.rb +0 -36
- data/lib/filter_form/inputs/integer_eq.rb +0 -6
- data/lib/filter_form/inputs/string.rb +0 -19
- data/lib/filter_form/inputs/string_cont.rb +0 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a5c64e1aac94322bc5abb235cab80a8d4247b2db
|
|
4
|
+
data.tar.gz: f8e50efe3a8d295b9e0365e39d73554f7454ecf5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ac4df24288cf564c677c9bbebcf5e7f3879600abb93fa6d02d891b053fabd61f67506e7e320b1c9dc59e434a338ec238b5931969123b7a551da80f5abe1dafb7
|
|
7
|
+
data.tar.gz: 5280ac3c9afb28987196dd4cc2676c069075a0f8525ac2a2d9650008eaf5e1027dd634ae7e8afd609e0ba6b42116524b62442cd86796ac93d067844fbedcc902
|
data/README.md
CHANGED
|
@@ -35,7 +35,7 @@ In your view file:
|
|
|
35
35
|
<%= filter_form_for @q do |f| %>
|
|
36
36
|
<%= f.filter_input :name %>
|
|
37
37
|
<%= f.filter_input :age %>
|
|
38
|
-
<%= f.filter_input :
|
|
38
|
+
<%= f.filter_input :city %>
|
|
39
39
|
<%= f.filter_input :birthday %>
|
|
40
40
|
<%= f.button :submit %>
|
|
41
41
|
<% end %>
|
|
@@ -45,7 +45,7 @@ For `string` attribute (like name) it will automatically create a text input wit
|
|
|
45
45
|
|
|
46
46
|
For `integer` type (age) it will set predicate `eq`.
|
|
47
47
|
|
|
48
|
-
For association
|
|
48
|
+
For association `belongs_to` (city) it will automatically build a select tag.
|
|
49
49
|
|
|
50
50
|
For `date` and `datetime` (birthday) it will automatically add jQuery [datepicker](http://jqueryui.com/datepicker/) and set predicate `eq`.
|
|
51
51
|
|
|
@@ -63,6 +63,16 @@ And application.css:
|
|
|
63
63
|
*= require jquery.ui.datepicker
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
+
And also you can customize your filter, like:
|
|
67
|
+
|
|
68
|
+
```erb
|
|
69
|
+
<%= filter_form_for @q do |f| %>
|
|
70
|
+
<%= f.filter_input :year, as: :select, collection: ((Date.today.year - 3)..(Date.today.year + 3)).to_a, predicate: :eq %>
|
|
71
|
+
<%= f.button :submit %>
|
|
72
|
+
<% end %>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
|
|
66
76
|
For more information about predicates visit [ransack](https://github.com/ernie/ransack).
|
|
67
77
|
|
|
68
78
|
If you want to customize your form visit [simple_form](https://github.com/plataformatec/simple_form).
|
|
@@ -1,25 +1,33 @@
|
|
|
1
1
|
require 'filter_form/inputs/base'
|
|
2
|
-
require 'filter_form/inputs/string'
|
|
3
2
|
|
|
4
|
-
require 'filter_form/inputs/
|
|
5
|
-
require 'filter_form/inputs/
|
|
6
|
-
|
|
7
|
-
require 'filter_form/inputs/
|
|
3
|
+
require 'filter_form/inputs/select/base'
|
|
4
|
+
require 'filter_form/inputs/select/belongs_to_eq'
|
|
5
|
+
|
|
6
|
+
require 'filter_form/inputs/string/base'
|
|
7
|
+
require 'filter_form/inputs/string/string_cont'
|
|
8
|
+
require 'filter_form/inputs/string/integer_eq'
|
|
9
|
+
require 'filter_form/inputs/string/date_eq'
|
|
8
10
|
|
|
9
11
|
module FilterForm
|
|
10
12
|
class InputBuilder
|
|
11
13
|
include ActiveModel::Model
|
|
12
14
|
|
|
13
|
-
attr_accessor :attribute_name, :object
|
|
15
|
+
attr_accessor :attribute_name, :object, :options
|
|
14
16
|
|
|
15
17
|
def build
|
|
16
|
-
"FilterForm::Inputs::#{ input_type.camelize }".constantize.new
|
|
18
|
+
"FilterForm::Inputs::#{ input_type.camelize }".constantize.new attribute_name: attribute_name,
|
|
19
|
+
object: object,
|
|
20
|
+
predicate: options[:predicate]
|
|
17
21
|
end
|
|
18
22
|
|
|
19
23
|
private
|
|
20
24
|
|
|
21
25
|
def input_type
|
|
22
|
-
|
|
26
|
+
if options[:as]
|
|
27
|
+
"#{ options[:as] }/base"
|
|
28
|
+
else
|
|
29
|
+
"#{ type }_#{ predicate }"
|
|
30
|
+
end
|
|
23
31
|
end
|
|
24
32
|
|
|
25
33
|
def predicate
|
|
@@ -34,13 +42,13 @@ module FilterForm
|
|
|
34
42
|
def type
|
|
35
43
|
case attribute_type
|
|
36
44
|
when :string
|
|
37
|
-
|
|
45
|
+
'string/string'
|
|
38
46
|
when :integer
|
|
39
|
-
|
|
47
|
+
'string/integer'
|
|
40
48
|
when :datetime, :date
|
|
41
|
-
|
|
49
|
+
'string/date'
|
|
42
50
|
when :belongs_to
|
|
43
|
-
|
|
51
|
+
'select/belongs_to'
|
|
44
52
|
end
|
|
45
53
|
end
|
|
46
54
|
|
|
@@ -3,7 +3,7 @@ module FilterForm
|
|
|
3
3
|
class Base
|
|
4
4
|
include ActiveModel::Model
|
|
5
5
|
|
|
6
|
-
attr_accessor :attribute_name, :object
|
|
6
|
+
attr_accessor :attribute_name, :object, :predicate
|
|
7
7
|
|
|
8
8
|
def options
|
|
9
9
|
{
|
|
@@ -15,15 +15,15 @@ module FilterForm
|
|
|
15
15
|
private
|
|
16
16
|
|
|
17
17
|
def input_name
|
|
18
|
-
"q[#{ attribute_name }_#{
|
|
18
|
+
"q[#{ attribute_name }_#{ predicate_name }]"
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def input_value
|
|
22
22
|
object_condition.values.first.value if object_condition
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
def
|
|
26
|
-
self.class.to_s.underscore.split('_').last
|
|
25
|
+
def predicate_name
|
|
26
|
+
predicate || self.class.to_s.underscore.split('_').last
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def object_condition
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module FilterForm
|
|
2
|
+
module Inputs
|
|
3
|
+
module Select
|
|
4
|
+
class Base < FilterForm::Inputs::Base
|
|
5
|
+
def options
|
|
6
|
+
super.merge(additional_options)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def additional_options
|
|
12
|
+
{
|
|
13
|
+
as: :select,
|
|
14
|
+
collection: collection,
|
|
15
|
+
include_blank: true,
|
|
16
|
+
selected: input_value
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def collection
|
|
21
|
+
[]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module FilterForm
|
|
2
|
+
module Inputs
|
|
3
|
+
module Select
|
|
4
|
+
class BelongsToEq < FilterForm::Inputs::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
|
+
attribute_name.to_s.camelize.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
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module FilterForm
|
|
2
|
+
module Inputs
|
|
3
|
+
module String
|
|
4
|
+
class Base < FilterForm::Inputs::Base
|
|
5
|
+
def options
|
|
6
|
+
result = super.merge(as: :string)
|
|
7
|
+
result[:input_html].merge!(additional_input_options)
|
|
8
|
+
result
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def additional_input_options
|
|
14
|
+
{
|
|
15
|
+
value: input_value
|
|
16
|
+
}
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -3,7 +3,7 @@ require 'filter_form/input_builder'
|
|
|
3
3
|
module SimpleForm
|
|
4
4
|
class FormBuilder < ActionView::Helpers::FormBuilder
|
|
5
5
|
def filter_input(attribute_name, options = {}, &block)
|
|
6
|
-
filter_form_input = FilterForm::InputBuilder.new(attribute_name: attribute_name, object: object).build
|
|
6
|
+
filter_form_input = FilterForm::InputBuilder.new(attribute_name: attribute_name, options: options, object: object).build
|
|
7
7
|
|
|
8
8
|
options.reverse_merge!(filter_form_input.options)
|
|
9
9
|
|
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.0.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Evgeny Li
|
|
@@ -97,11 +97,12 @@ files:
|
|
|
97
97
|
- lib/filter_form/form_helper.rb
|
|
98
98
|
- lib/filter_form/input_builder.rb
|
|
99
99
|
- lib/filter_form/inputs/base.rb
|
|
100
|
-
- lib/filter_form/inputs/
|
|
101
|
-
- lib/filter_form/inputs/
|
|
102
|
-
- lib/filter_form/inputs/
|
|
103
|
-
- lib/filter_form/inputs/string.rb
|
|
104
|
-
- lib/filter_form/inputs/
|
|
100
|
+
- lib/filter_form/inputs/select/base.rb
|
|
101
|
+
- lib/filter_form/inputs/select/belongs_to_eq.rb
|
|
102
|
+
- lib/filter_form/inputs/string/base.rb
|
|
103
|
+
- lib/filter_form/inputs/string/date_eq.rb
|
|
104
|
+
- lib/filter_form/inputs/string/integer_eq.rb
|
|
105
|
+
- lib/filter_form/inputs/string/string_cont.rb
|
|
105
106
|
- lib/filter_form/simple_form/form_builder.rb
|
|
106
107
|
- lib/filter_form/version.rb
|
|
107
108
|
homepage: https://github.com/exAspArk/filter_form
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
module FilterForm
|
|
2
|
-
module Inputs
|
|
3
|
-
class BelongsToEq < FilterForm::Inputs::Base
|
|
4
|
-
def options
|
|
5
|
-
super.merge(additional_options)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
private
|
|
9
|
-
|
|
10
|
-
def additional_options
|
|
11
|
-
{
|
|
12
|
-
as: :select,
|
|
13
|
-
collection: collection,
|
|
14
|
-
include_blank: true,
|
|
15
|
-
selected: input_value
|
|
16
|
-
}
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def object_condition
|
|
20
|
-
object.base.conditions.select { |c| c.a.first.name == custom_attribute_name }.first
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def collection
|
|
24
|
-
attribute_name.to_s.camelize.constantize.all
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def input_name
|
|
28
|
-
"q[#{ custom_attribute_name }_#{ predicate }]"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def custom_attribute_name
|
|
32
|
-
"#{ attribute_name }_id"
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module FilterForm
|
|
2
|
-
module Inputs
|
|
3
|
-
class String < FilterForm::Inputs::Base
|
|
4
|
-
def options
|
|
5
|
-
result = super.merge(as: :string)
|
|
6
|
-
result[:input_html].merge!(additional_input_options)
|
|
7
|
-
result
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
private
|
|
11
|
-
|
|
12
|
-
def additional_input_options
|
|
13
|
-
{
|
|
14
|
-
value: input_value
|
|
15
|
-
}
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|