ransack_memory 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +10 -0
- data/app/controllers/concerns/ransack_memory.rb +56 -0
- data/app/helpers/ransack_memory_helper.rb +5 -0
- data/app/views/shared/_ransack_memory_clear_filter.html.haml +2 -0
- data/lib/generators/ransack_memory_generator.rb +11 -0
- data/lib/ransack_memory.rb +9 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 10e3fba05938906e50d390712345e76dbd704390
|
4
|
+
data.tar.gz: ecd1d5cd30a20f5e5b9768df2d1795b0f18a560f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 397f29e47cd222fe96ca649b9a1019dd9e414f917744860851a0aac790d3f8cb11dc5ff471eb4dfb57352931cf8f4cf7fc1b32f87d122154284fb008b6a39301
|
7
|
+
data.tar.gz: f23736495ce5aab52fdf3ce2879e307a5d8ddeee649544a593e918e4811206a3109a15df7acc422630085b3ebadd8ea89d6a4419dc8eec4756af930379b4052c
|
data/README.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Ransack Memory
|
2
|
+
|
3
|
+
This Gem provides automatic saving your filtered Ransack gem params into Rails session. It also autoloads params from session to your search forms.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'ransack_memory'
|
10
|
+
```
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Concerns
|
2
|
+
module RansackMemory
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
def save_and_load_filters
|
6
|
+
|
7
|
+
# 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
|
12
|
+
end
|
13
|
+
|
14
|
+
if user_signed_in?
|
15
|
+
# search term saving
|
16
|
+
session["#{controller_name}_#{action_name}_#{request.xhr?}"] = params[RansackMemory.config[:param]] if params[RansackMemory.config[:param]].present?
|
17
|
+
|
18
|
+
# page number saving
|
19
|
+
session["#{controller_name}_#{action_name}_#{request.xhr?}_page"] = params[:page] if params[:page].present?
|
20
|
+
|
21
|
+
# per page saving
|
22
|
+
session["#{controller_name}_#{action_name}_#{request.xhr?}_per_page"] = params[:per_page] if params[:per_page].present?
|
23
|
+
end
|
24
|
+
|
25
|
+
if user_signed_in?
|
26
|
+
# search term load
|
27
|
+
if session["#{controller_name}_#{action_name}_#{request.xhr?}"]
|
28
|
+
params[RansackMemory.config[:param]] = session["#{controller_name}_#{action_name}_#{request.xhr?}"]
|
29
|
+
else
|
30
|
+
params[RansackMemory.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.config[:param]] && session[:last_q_params] != params[RansackMemory.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.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
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
if defined?(Rails)
|
2
|
+
|
3
|
+
# Rails3 generator invoked with 'rails generate ransack_memory'
|
4
|
+
class RansackMemoryGenerator < Rails::Generators::Base
|
5
|
+
source_root(File.expand_path(File.dirname(__FILE__) + "/../../generators/ransack_memory/templates"))
|
6
|
+
def copy_initializer
|
7
|
+
copy_file 'ransack_memory.rb', 'config/initializers/ransack_memory.rb'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ransack_memory
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Richard Lapiš
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-06 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Automatically save and load ransack's filtered params into session
|
14
|
+
email: richard.lapis@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- README.md
|
20
|
+
- app/controllers/concerns/ransack_memory.rb
|
21
|
+
- app/helpers/ransack_memory_helper.rb
|
22
|
+
- app/views/shared/_ransack_memory_clear_filter.html.haml
|
23
|
+
- lib/generators/ransack_memory_generator.rb
|
24
|
+
- lib/ransack_memory.rb
|
25
|
+
homepage: https://github.com/richardrails/ransack_memory
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.9.3
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.4.8
|
46
|
+
signing_key:
|
47
|
+
specification_version: 3
|
48
|
+
summary: Automatically save and load ransack's filtered params into session
|
49
|
+
test_files: []
|