filterrific 2.0.4 → 2.0.5

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: 36dc749c095650e566eacee010e3021ee5aad1c3
4
- data.tar.gz: dedcfb34441effe7dfde8fbb610b0dedcfcab461
3
+ metadata.gz: a5979a704b32638ef10a22bd4fd751df14a61b61
4
+ data.tar.gz: c3061aa6b0a62f45be9f3a8596dbc2832e7f4e7b
5
5
  SHA512:
6
- metadata.gz: c92f6d1eae2d2a91ad1b00bc9cfb5c6bc2e84ea0889748042b4b295ede9a9741a14232e565b8ffad66a9ac7fd897f3f5e9e8140762649bbb6f155b99967845d1
7
- data.tar.gz: caf3aca751fbc4d9dbe894530ac03ef4024d2d69ca1569fa29081ed89ddd361cb3e40c4f09738204a6c0a73a7f6898595242c6475a7d9493eca5338578055e7d
6
+ metadata.gz: 411881a8695384b3f9e1edc9f9c9db7ad8ccb4afb9416693f36d29a4861b6901e2896145f07a29aef51b20734449b568fd2c7bbeaf1e14c71a30f360e1ecd6b1
7
+ data.tar.gz: fe163f9cfc3fd45760522877415395f594e664d1f20726ae62a192584bedc1deba5c9aaafae4ce6dbec966736864bbba63d7388f257409b17a0375ef1ecf8bf9
@@ -39,6 +39,15 @@
39
39
  },
40
40
  )
41
41
 
42
+ ### 2.0.5
43
+
44
+ * Feature: Allow disabling of session persistence by passing `false` as
45
+ `:persistence_id` option.
46
+ * Fix: Direction indicators on sortable headers are now correct.
47
+ * Fix: Make JS event observers work with TurboLinks.
48
+ * Fix: Make reset_filterrific_url available in controller.
49
+
50
+
42
51
 
43
52
  ### 2.0.4
44
53
 
@@ -79,12 +79,12 @@ Filterrific.submitFilterForm = function(){
79
79
 
80
80
 
81
81
 
82
- // Initialize event observers on document ready
83
- jQuery(document).ready(function($) {
82
+ // Initialize event observers on document ready and turbolinks page:load
83
+ jQuery(document).on('ready page:load', function() {
84
84
  // Add change event handler to all Filterrific filter inputs.
85
- $(document).on(
85
+ $('#filterrific_filter').on(
86
86
  "change",
87
- "#filterrific_filter :input",
87
+ ":input",
88
88
  Filterrific.submitFilterForm
89
89
  );
90
90
 
@@ -3,6 +3,7 @@
3
3
  ## TODO
4
4
 
5
5
  * add check that no filter_name conflicts with existing methods on included ActiveRecord class (See https://github.com/jhund/filterrific/issues/17)
6
+ * fix reset url, make controller method, helper method
6
7
 
7
8
  ## Travis
8
9
 
@@ -5,6 +5,8 @@
5
5
  module Filterrific
6
6
  module ActionControllerExtension
7
7
 
8
+ include HasResetFilterrificUrlMixin
9
+
8
10
  protected
9
11
 
10
12
  # @param model_class [Class]
@@ -19,7 +21,7 @@ module Filterrific
19
21
  # @option opts [String, Symbol, optional] :persistence_id
20
22
  # defaults to "namespace/controller#action" string, used for session key
21
23
  # and saved searches to isolate different filters' persisted params from
22
- # each other.
24
+ # each other. Set to false to turn off session persistence.
23
25
  # @option opts [Hash, optional] :select_options
24
26
  # these are available in the view to populate select lists and other
25
27
  # dynamic values.
@@ -29,19 +31,23 @@ module Filterrific
29
31
  # went back to #stringify_keys which should be sufficient.
30
32
  f_params = (filterrific_params || {}).stringify_keys
31
33
  opts = opts.stringify_keys
32
- pi = opts['persistence_id'] || compute_default_persistence_id
34
+ pers_id = if false == opts['persistence_id']
35
+ nil
36
+ else
37
+ opts['persistence_id'] || compute_default_persistence_id
38
+ end
33
39
 
34
40
  if (f_params.delete('reset_filterrific'))
35
41
  # Reset query and session_persisted params
36
- session[pi] = nil
42
+ session[pers_id] = nil if pers_id
37
43
  redirect_to url_for({}) and return false # requires `or return` in calling action.
38
44
  end
39
45
 
40
- f_params = compute_filterrific_params(model_class, f_params, opts, pi)
46
+ f_params = compute_filterrific_params(model_class, f_params, opts, pers_id)
41
47
 
42
48
  filterrific = Filterrific::ParamSet.new(model_class, f_params)
43
49
  filterrific.select_options = opts['select_options']
44
- session[pi] = filterrific.to_hash
50
+ session[pers_id] = filterrific.to_hash if pers_id
45
51
  filterrific
46
52
  end
47
53
 
@@ -55,11 +61,11 @@ module Filterrific
55
61
  # @param model_class [ActiveRecord::Base]
56
62
  # @param filterrific_params [Hash]
57
63
  # @param opts [Hash]
58
- # @param persistence_id [String]
64
+ # @param persistence_id [String, nil]
59
65
  def compute_filterrific_params(model_class, filterrific_params, opts, persistence_id)
60
66
  r = (
61
67
  filterrific_params.presence || # start with passed in params
62
- session[persistence_id].presence || # then try session persisted params
68
+ (persistence_id && session[persistence_id].presence) || # then try session persisted params if persistence_id is present
63
69
  opts['default_filter_params'] || # then use passed in opts
64
70
  model_class.filterrific_default_filter_params # finally use model_class defaults
65
71
  ).stringify_keys
@@ -5,6 +5,8 @@
5
5
  module Filterrific
6
6
  module ActionViewExtension
7
7
 
8
+ include HasResetFilterrificUrlMixin
9
+
8
10
  # Sets all options on form_for to defaults that work with Filterrific
9
11
  # @param record [Filterrific] the @filterrific object
10
12
  # @param options [Hash] standard options for form_for
@@ -75,9 +77,10 @@ module Filterrific
75
77
  }.merge(opts)
76
78
  opts.merge!(
77
79
  :html_attrs => opts[:html_attrs].with_indifferent_access,
78
- :current_sorting => filterrific.send(opts[:sorting_scope_name]),
80
+ :current_sorting => (current_sorting = filterrific.send(opts[:sorting_scope_name])),
79
81
  :current_sort_key => current_sorting ? current_sorting.gsub(/_asc|_desc/, '') : nil,
80
82
  :current_sort_direction => current_sorting ? (current_sorting =~ /_desc\z/ ? 'desc' : 'asc') : nil,
83
+ :current_sort_direction_indicator => (current_sorting =~ /_desc\z/ ? opts[:descending_indicator] : opts[:ascending_indicator]),
81
84
  )
82
85
  new_sort_key = sort_key.to_s
83
86
  if new_sort_key == opts[:current_sort_key]
@@ -89,13 +92,6 @@ module Filterrific
89
92
  end
90
93
  end
91
94
 
92
- # Returns a url that can be used to reset the Filterrific params
93
- def reset_filterrific_url(opts = {})
94
- url_for(
95
- { filterrific: { reset_filterrific: true } }.merge(opts)
96
- )
97
- end
98
-
99
95
  protected
100
96
 
101
97
  # Renders HTML to reverse sort order on currently sorted column.
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'filterrific/param_set'
4
4
 
5
+ require 'filterrific/has_reset_filterrific_url_mixin'
6
+
5
7
  require 'filterrific/action_controller_extension'
6
8
  require 'filterrific/action_view_extension'
7
9
  require 'filterrific/active_record_extension'
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Adds reset_filterrific_url to controllers and views
4
+ #
5
+ module Filterrific
6
+ module HasResetFilterrificUrlMixin
7
+
8
+ # Returns a url that can be used to reset the Filterrific params
9
+ def reset_filterrific_url(opts = {})
10
+ url_for(
11
+ { filterrific: { reset_filterrific: true } }.merge(opts)
12
+ )
13
+ end
14
+
15
+ end
16
+ end
@@ -90,12 +90,12 @@ module Filterrific
90
90
  fp[key] = val.call
91
91
  when val.is_a?(Array)
92
92
  # type cast integers in the array
93
- fp[key] = fp[key].map { |e| e =~ /^[1-9]\d*$/ ? e.to_i : e }
93
+ fp[key] = fp[key].map { |e| e =~ /^[1-9\-]\d*$/ ? e.to_i : e }
94
94
  when val.is_a?(Hash)
95
95
  # type cast Hash to OpenStruct so that nested params render correctly
96
96
  # in the form
97
97
  fp[key] = OpenStruct.new(fp[key])
98
- when val =~ /^[1-9]\d*$/
98
+ when val =~ /^[1-9\-]\d*$/
99
99
  # type cast integer
100
100
  fp[key] = fp[key].to_i
101
101
  end
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Filterrific
4
- VERSION = "2.0.4"
4
+ VERSION = "2.0.5"
5
5
  end
@@ -102,5 +102,15 @@ module Filterrific
102
102
 
103
103
  end
104
104
 
105
+ describe '#reset_filterrific_url' do
106
+
107
+ it 'responds to #reset_filterrific_url' do
108
+ TestController.new.must_respond_to(:reset_filterrific_url)
109
+ end
110
+
111
+ end
112
+
105
113
  end
106
114
  end
115
+
116
+
@@ -13,6 +13,7 @@ module Filterrific
13
13
  filter_array_string
14
14
  filter_hash
15
15
  filter_int
16
+ filter_negative_int
16
17
  filter_proc
17
18
  filter_string
18
19
  ]
@@ -29,6 +30,7 @@ module Filterrific
29
30
  'filter_array_string' => %w[one two three],
30
31
  'filter_hash' => { a: 1, b: 2 },
31
32
  'filter_int' => '42',
33
+ 'filter_negative_int' => '-42',
32
34
  'filter_proc' => lambda { 1 + 1 },
33
35
  'filter_string' => 'forty-two',
34
36
  }
@@ -41,6 +43,7 @@ module Filterrific
41
43
  'filter_array_string' => %w[one two three],
42
44
  'filter_hash' => OpenStruct.new(a: 1, b: 2),
43
45
  'filter_int' => 42,
46
+ 'filter_negative_int' => -42,
44
47
  'filter_proc' => 2,
45
48
  'filter_string' => 'forty-two',
46
49
  }
@@ -53,6 +56,7 @@ module Filterrific
53
56
  'filter_array_string' => %w[one two three],
54
57
  'filter_hash' => { a: 1, b: 2 },
55
58
  'filter_int' => 42,
59
+ 'filter_negative_int' => -42,
56
60
  'filter_proc' => 2,
57
61
  'filter_string' => 'forty-two',
58
62
  }
@@ -167,6 +171,7 @@ module Filterrific
167
171
  [{ an_array: [1, 'a'] }, { an_array: [1, 'a'] }],
168
172
  [{ a_hash: { 'a' => 1, 'b' => 2 } }, { a_hash: OpenStruct.new({ 'a' => 1, 'b' => 2 }) }],
169
173
  [{ a_string_that_looks_like_int: '123' }, { a_string_that_looks_like_int: 123 }],
174
+ [{ a_string_that_looks_like_a_negative_int: '-123' }, { a_string_that_looks_like_a_negative_int: -123 }],
170
175
  [{ a_string_that_almost_looks_like_int: '0123' }, { a_string_that_almost_looks_like_int: '0123' }],
171
176
  [{ an_array_with_almost_int: ['0123', '123'] }, { an_array_with_almost_int: ['0123', 123] }],
172
177
  [{ a_string: 'abc' }, { a_string: 'abc' }],
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filterrific
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jo Hund
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-10 00:00:00.000000000 Z
11
+ date: 2015-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -107,6 +107,7 @@ files:
107
107
  - lib/filterrific/action_view_extension.rb
108
108
  - lib/filterrific/active_record_extension.rb
109
109
  - lib/filterrific/engine.rb
110
+ - lib/filterrific/has_reset_filterrific_url_mixin.rb
110
111
  - lib/filterrific/param_set.rb
111
112
  - lib/filterrific/version.rb
112
113
  - spec/filterrific/action_controller_extension_spec.rb