filter_form 0.0.8 → 0.1.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: 61af5ef0d5917e255602f6569418187119a6f180
4
- data.tar.gz: 1b30d938f722535d762a193b17463fc88a55d2b7
3
+ metadata.gz: b830a861ee39acd8f2c1b5ed04935ad77f3b509a
4
+ data.tar.gz: c311699b26fb7f0bca2ef57e6173287121735121
5
5
  SHA512:
6
- metadata.gz: c6751e3a4c26d7b2cb544e56153b7f0640bab894cefc0e04c3579e68a963573344b1fc3fb831f620a026f83615c74f8c95b8d881388dccd2563efc115058f464
7
- data.tar.gz: 6a0df1220993e23dc094cc829dcb0c272491bb636fccc0421837be3b0187462204390d97207e87821aa82fa226c843a8510211276e212b8f80a9fb00cf82279e
6
+ metadata.gz: 69267fd08e65bbb07f3757f1f37a2d4893c802fb12515a1043c864744d9ef8c7ec7d0f87b2251725c2edf243677fbd627cdce8c3dd337bc3b2271ff4bd97ad05
7
+ data.tar.gz: 72c09ffcc2dd31f588dd6866f3ad7a7655c3b1e6c414f7000a8879d936046e6784f70dcd86aafdfd4112b841b473ea578b4ad7c0c1244284d9cd7d5ac6bde616
data/README.md CHANGED
@@ -47,6 +47,7 @@ In your view file:
47
47
  Mapping | Database Column Type | Default predicate | Generated HTML Element |
48
48
  --------------- |:------------------------------------------------|:----------------------|:--------------------------|
49
49
  `string` | `string` | `cont` | `input[type=text]` |
50
+ `select2` | `string` | `eq` | `select` |
50
51
  `integer` | `integer` | `eq` | `input[type=text]` |
51
52
  `datetime` | `datetime` | `eq` | `input[type=text]` |
52
53
  `date` | `date` | `eq` | `input[type=text]` |
@@ -59,7 +60,8 @@ Of course you can customize your filter, like:
59
60
 
60
61
  ```erb
61
62
  <%= filter_form_for @q do |f| %>
62
- <%= f.filter_input :year, as: :select, collection: ((Date.today.year - 3)..(Date.today.year + 3)).to_a, predicate: :not_eq %>
63
+ <%= f.filter_input :title, as: :select2 %>
64
+ <%= f.filter_input :year, as: :select, collection: (2000..2013).to_a, predicate: :not_eq %>
63
65
  <%= f.button :submit %>
64
66
  <% end %>
65
67
  ```
@@ -3,5 +3,8 @@
3
3
  #= require select2
4
4
 
5
5
  $ ->
6
+ $('.filter_form_select2').select2()
7
+
6
8
  $('.filter_form_date').datepicker
7
9
  dateFormat: 'yy-mm-dd'
10
+
@@ -2,6 +2,7 @@ require 'filter_form/inputs/base'
2
2
 
3
3
  require 'filter_form/inputs/select/base'
4
4
  require 'filter_form/inputs/select/belongs_to'
5
+ require 'filter_form/inputs/select/select2'
5
6
 
6
7
  require 'filter_form/inputs/string/base'
7
8
  require 'filter_form/inputs/string/date'
@@ -30,7 +31,7 @@ module FilterForm
30
31
  def predicate
31
32
  return custom_predicate if custom_predicate
32
33
 
33
- case attribute_type
34
+ case type
34
35
  when :string
35
36
  :cont
36
37
  else
@@ -52,6 +53,8 @@ module FilterForm
52
53
  'string/money'
53
54
  when :belongs_to
54
55
  'select/belongs_to'
56
+ when :select2
57
+ 'select/select2'
55
58
  else
56
59
  _type
57
60
  end
@@ -3,16 +3,32 @@ module FilterForm
3
3
  class Base
4
4
  include ActiveModel::Model
5
5
 
6
+ INPUT_CLASS = ''
7
+
6
8
  attr_accessor :attribute_name, :object, :predicate
7
9
 
8
10
  def options
11
+ result = default_options.merge(additional_options)
12
+ result[:input_html].merge!(additional_input_options)
13
+ result
14
+ end
15
+
16
+ private
17
+
18
+ def default_options
9
19
  {
10
20
  required: false,
11
21
  input_html: { name: input_name }
12
22
  }
13
23
  end
14
24
 
15
- private
25
+ def additional_options
26
+ {}
27
+ end
28
+
29
+ def additional_input_options
30
+ { class: self.class::INPUT_CLASS }
31
+ end
16
32
 
17
33
  def input_name
18
34
  "q[#{ attribute_name }_#{ predicate }]"
@@ -2,11 +2,7 @@ module FilterForm
2
2
  module Inputs
3
3
  module Select
4
4
  class Base < FilterForm::Inputs::Base
5
- def options
6
- super.merge(additional_options)
7
- end
8
-
9
- private
5
+ private
10
6
 
11
7
  def additional_options
12
8
  {
@@ -18,7 +14,7 @@ module FilterForm
18
14
  end
19
15
 
20
16
  def collection
21
- []
17
+ object.klass.uniq.pluck(attribute_name)
22
18
  end
23
19
  end
24
20
  end
@@ -0,0 +1,9 @@
1
+ module FilterForm
2
+ module Inputs
3
+ module Select
4
+ class Select2 < FilterForm::Inputs::Select::Base
5
+ INPUT_CLASS = 'filter_form_select2'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -2,18 +2,14 @@ module FilterForm
2
2
  module Inputs
3
3
  module String
4
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
5
+ private
10
6
 
11
- private
7
+ def additional_options
8
+ { as: :string }
9
+ end
12
10
 
13
11
  def additional_input_options
14
- {
15
- value: input_value
16
- }
12
+ super.merge(value: input_value)
17
13
  end
18
14
  end
19
15
  end
@@ -2,13 +2,7 @@ module FilterForm
2
2
  module Inputs
3
3
  module String
4
4
  class Date < FilterForm::Inputs::String::Base
5
- DATE_CLASS = 'filter_form_date'
6
-
7
- private
8
-
9
- def additional_input_options
10
- super.merge(class: DATE_CLASS)
11
- end
5
+ INPUT_CLASS = 'filter_form_date'
12
6
  end
13
7
  end
14
8
  end
@@ -1,3 +1,3 @@
1
1
  module FilterForm
2
- VERSION = '0.0.8'
2
+ VERSION = '0.1.0'
3
3
  end
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.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeny Li
@@ -114,6 +114,7 @@ files:
114
114
  - lib/filter_form/inputs/base.rb
115
115
  - lib/filter_form/inputs/select/base.rb
116
116
  - lib/filter_form/inputs/select/belongs_to.rb
117
+ - lib/filter_form/inputs/select/select2.rb
117
118
  - lib/filter_form/inputs/string/base.rb
118
119
  - lib/filter_form/inputs/string/date.rb
119
120
  - lib/filter_form/inputs/string/money.rb