ransack_memory 0.0.4 → 0.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: abefb2da0c94c8caee92ef550ca93bc48538e8a9
4
- data.tar.gz: 442d357d0778cde47013f4f680721e0ff26bbe9a
3
+ metadata.gz: 53163621f241e9f3a29c0a8bffe48e32c5f3e60b
4
+ data.tar.gz: '0960d53e98ecbb53b8dd62589e4d277531d03978'
5
5
  SHA512:
6
- metadata.gz: ceb4da1cd2186094774fac35ff3e697a7d7e716f40d00b949a1a32d2d7fa65087360cd8969178ad3a159f82f50d9a8af507b330ebf87a21e74b244e6f453e05b
7
- data.tar.gz: 8b1bbacd8e909bb8746db3ffbc52dcbaa898764172339418c0ac6d79a05306d68978bd374f2b11e0b2d4c74cc40a8abff985605f18e0ec7f06edc178d28bef79
6
+ metadata.gz: c6844bd183a86491ab2f8f24538585ab557e1a00b9801ef03962342424e2df72e8077359a9e2a326c74e8aae60d37ca94b618a1eb5637aca2787d238a92bdb93
7
+ data.tar.gz: f4de744aac0b48d88d3e30f39d872d1854a1917677df5b5667d33bd168b06c250f96a8742cfdd73eadff3b500ce2880b2580b0ec52ea857cca8f75ae988519b2
@@ -3,54 +3,46 @@ module RansackMemory
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  def save_and_load_filters
6
+
7
+ session_key_base = "#{controller_name}_#{action_name}_#{request.xhr?}"
8
+
9
+ # permit search params
10
+ params[::RansackMemory::Core.config[:param]].permit! if params[::RansackMemory::Core.config[:param]].present? && params[::RansackMemory::Core.config[:param]].respond_to?(:permit)
6
11
 
7
12
  # cancel filter if button pressed
8
- if params[:cancel_filter].present? && params[:cancel_filter] == "true"
9
- @selected_filter = nil
10
- session["#{controller_name}_#{action_name}_#{request.xhr?}"] = nil
11
- session["#{controller_name}_#{action_name}_#{request.xhr?}_page"] = nil
13
+ if params[:cancel_filter] == "true"
14
+ session["#{session_key_base}"] = nil
15
+ session["#{session_key_base}_page"] = nil
16
+ session["#{session_key_base}_per_page"] = nil
12
17
  end
13
18
 
14
- if user_signed_in?
15
- # search term saving
16
- session["#{controller_name}_#{action_name}_#{request.xhr?}"] = params[::RansackMemory::Core.config[:param]] if params[::RansackMemory::Core.config[:param]].present?
19
+ # search term saving
20
+ session["#{session_key_base}"] = params[::RansackMemory::Core.config[:param]] if params[::RansackMemory::Core.config[:param]].present?
17
21
 
18
- # page number saving
19
- session["#{controller_name}_#{action_name}_#{request.xhr?}_page"] = params[:page] if params[:page].present?
22
+ # page number saving
23
+ session["#{session_key_base}_page"] = params[:page] if params[:page].present?
20
24
 
21
- # per page saving
22
- session["#{controller_name}_#{action_name}_#{request.xhr?}_per_page"] = params[:per_page] if params[:per_page].present?
23
- end
25
+ # per page saving
26
+ session["#{session_key_base}_per_page"] = params[:per_page] if params[:per_page].present?
27
+
28
+ # search term load
29
+ params[::RansackMemory::Core.config[:param]] = session["#{session_key_base}"].presence
30
+
31
+ # page number load
32
+ params[:page] = session["#{session_key_base}_page"].presence
24
33
 
25
- if user_signed_in?
26
- # search term load
27
- if session["#{controller_name}_#{action_name}_#{request.xhr?}"]
28
- params[::RansackMemory::Core.config[:param]] = session["#{controller_name}_#{action_name}_#{request.xhr?}"]
29
- else
30
- params[::RansackMemory::Core.config[:param]] = nil
31
- end
32
-
33
- # page number load
34
- if session["#{controller_name}_#{action_name}_#{request.xhr?}_page"]
35
- params[:page] = session["#{controller_name}_#{action_name}_#{request.xhr?}_page"]
36
- else
37
- params[:page] = nil
38
- end
39
-
40
- # set page number to 1 if filter has changed
41
- if (params[::RansackMemory::Core.config[:param]] && session[:last_q_params] != params[::RansackMemory::Core.config[:param]]) || (params[:cancel_filter].present? && session["#{controller_name}_#{action_name}_#{request.xhr?}_page"] != params[:page])
42
- params[:page] = nil
43
- session["#{controller_name}_#{action_name}_#{request.xhr?}_page"] = nil
44
- end
45
- session[:last_q_params] = params[::RansackMemory::Core.config[:param]]
46
-
47
- # per page load
48
- if session["#{controller_name}_#{action_name}_#{request.xhr?}_per_page"]
49
- params[:per_page] = session["#{controller_name}_#{action_name}_#{request.xhr?}_per_page"]
50
- else
51
- params[:per_page] = nil
52
- end
34
+ # per page load
35
+ params[:per_page] = session["#{session_key_base}_per_page"].presence
36
+
37
+ # set page number to 1 if filter has changed
38
+ if (params[::RansackMemory::Core.config[:param]].present? && session[:last_q_params] != params[::RansackMemory::Core.config[:param]]) || (params[:cancel_filter].present? && session["#{session_key_base}_page"] != params[:page])
39
+ params[:page] = nil
40
+ session["#{session_key_base}_page"] = nil
53
41
  end
42
+
43
+ session[:last_q_params] = params[::RansackMemory::Core.config[:param]]
44
+
45
+ # session[:last_page] = params[:page]
54
46
  end
55
47
  end
56
48
  end
@@ -1,3 +1,3 @@
1
1
  module RansackMemory
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack_memory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Lapiš
@@ -36,17 +36,17 @@ require_paths:
36
36
  - lib
37
37
  required_ruby_version: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: 1.9.3
42
42
  required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - '>='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  requirements: []
48
48
  rubyforge_project:
49
- rubygems_version: 2.4.8
49
+ rubygems_version: 2.6.13
50
50
  signing_key:
51
51
  specification_version: 3
52
52
  summary: Automatically save and load ransack's filtered params into session