filterrific 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -6
- data/lib/filterrific/action_view_extension.rb +98 -96
- data/lib/filterrific/active_record_extension.rb +2 -4
- data/lib/filterrific/engine.rb +11 -17
- data/lib/filterrific/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 818d80584a2a4db43f268028613b856a6ef52528
|
4
|
+
data.tar.gz: 3744f644a940ddccbb6233027a7a4b919e009547
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7e1fe41394af2fc4e59e9daa1f0523d3b67a1d93288b047f5b76b8962adb84c7d0f61645639fa28d8cca5e6a2ed133fd01b927c7feea182040a4b9d35e0cc08
|
7
|
+
data.tar.gz: 61bf2d0d764c43a252b637ade5b0f4161541d9aeb8ed9b4623acf07a1a96e9dd67023bb8dcc1820df3a8d97c78ba2e15daf7bc5d41281a1be20dfd395473b238
|
data/CHANGELOG.md
CHANGED
@@ -8,15 +8,16 @@ API changes
|
|
8
8
|
filterrific(
|
9
9
|
default_settings: { sorted_by: 'name_asc' },
|
10
10
|
search_query: {
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
match_terms: :any, # [:all]
|
12
|
+
auto_wildcard: :suffix, # [:prefix, :both, :none]
|
13
|
+
columns: [:first_name, :email, :last_name],
|
14
|
+
case_sensitive: false, # [true]
|
14
15
|
},
|
15
16
|
sorted_by: {
|
16
17
|
name_asc: 'Name (A-Z)',
|
17
|
-
name_desc: 'Name (Z-A)'
|
18
|
+
name_desc: 'Name (Z-A)',
|
18
19
|
},
|
19
|
-
|
20
|
+
scopes: [
|
20
21
|
:with_country,
|
21
22
|
...
|
22
23
|
]
|
@@ -32,7 +33,7 @@ API changes
|
|
32
33
|
filter_names: [],
|
33
34
|
params_key: :filterrific,
|
34
35
|
select_options: {},
|
35
|
-
|
36
|
+
session_persistence_key: 'asdf',
|
36
37
|
)
|
37
38
|
@students = @filterrific.find
|
38
39
|
|
@@ -46,6 +47,12 @@ API changes
|
|
46
47
|
bug fixes in 3.1, and use of asset pipeline)
|
47
48
|
|
48
49
|
|
50
|
+
### 1.4.2
|
51
|
+
|
52
|
+
* Updated initialization of ActiveRecord and ActionView extensions again
|
53
|
+
|
54
|
+
|
55
|
+
|
49
56
|
### 1.4.1
|
50
57
|
|
51
58
|
* Updated initialization of ActiveRecord and ActionView extensions
|
@@ -3,108 +3,110 @@
|
|
3
3
|
#
|
4
4
|
# Adds view helpers to ActionView
|
5
5
|
#
|
6
|
-
module Filterrific
|
6
|
+
module Filterrific
|
7
|
+
module ActionViewExtension
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
# Sets all options on form_for to defaults if called with Filterrific object
|
10
|
+
def form_for(record, options = {}, &block)
|
11
|
+
if record.is_a?(Filterrific::ParamSet)
|
12
|
+
options[:as] ||= :filterrific
|
13
|
+
options[:html] ||= {}
|
14
|
+
options[:html][:method] ||= :get
|
15
|
+
options[:html][:id] ||= :filterrific_filter
|
16
|
+
options[:url] ||= url_for(:controller => controller.controller_name, :action => controller.action_name)
|
17
|
+
end
|
18
|
+
super
|
16
19
|
end
|
17
|
-
|
18
|
-
end
|
19
|
-
# TODO: change this to form_for_filterrific!
|
20
|
+
# TODO: change this to form_for_filterrific!
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
# Renders a spinner while the list is being updated
|
23
|
+
def render_filterrific_spinner
|
24
|
+
%(
|
25
|
+
<span class="filterrific_spinner" style="display:none;">
|
26
|
+
#{ image_tag('filterrific/filterrific-spinner.gif') }
|
27
|
+
</span>
|
28
|
+
).html_safe
|
29
|
+
end
|
30
|
+
#alias: filterrific_spinner
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
32
|
+
# Renders a link which indicates the current sorting and which can be used to
|
33
|
+
# toggle the list sorting (set column and direction).
|
34
|
+
# NOTE: Make sure that this is used in the list partial that is re-rendered
|
35
|
+
# when the filterrific params are changed, so that the filterrific params in
|
36
|
+
# the URL are always current.
|
37
|
+
# @param[Filterrific::ParamSet] filterrific the current filterrific instance
|
38
|
+
# @param[String, Symbol] sort_key the key to sort by, without direction.
|
39
|
+
# Example: 'name', 'created_at'
|
40
|
+
# @param[Hash, optional] options:
|
41
|
+
# * active_column_class: CSS class applied to current sort column.
|
42
|
+
# Default: 'filterrific_current_sort_column'
|
43
|
+
# * ascending_indicator: HTML string to indicate ascending sort direction.
|
44
|
+
# Default: Triangle pointing up.
|
45
|
+
# * default_sort_direction: override the default sorting when selecting
|
46
|
+
# a new sort column. Default: 'asc'.
|
47
|
+
# * descending_indicator: HTML string to indicate descending sort direction.
|
48
|
+
# Default: Triangle pointing down.
|
49
|
+
# * html_attrs: HTML attributes to be added to the sorting link. Default: {}
|
50
|
+
# * label: override label. Default: `sort_key.humanize`.
|
51
|
+
# * sorting_scope_name: override the name of the scope used for sorting.
|
52
|
+
# Default: `:sorted_by`
|
53
|
+
# * url_for_attrs: override the target URL attributes to be used for `url_for`.
|
54
|
+
# Default: {} (current URL).
|
55
|
+
# TODO: update documentation
|
56
|
+
# TODO: update demo app
|
57
|
+
# TODO: synchronize with sorting select in filter
|
58
|
+
def filterrific_sorting_link(filterrific, sort_key, options = {})
|
59
|
+
options = {
|
60
|
+
:active_column_class => 'filterrific_current_sort_column',
|
61
|
+
:ascending_indicator => '⬆',
|
62
|
+
:default_sort_direction => 'asc',
|
63
|
+
:descending_indicator => '⬇',
|
64
|
+
:html_attrs => {},
|
65
|
+
:label => sort_key.to_s.humanize,
|
66
|
+
:sorting_scope_name => :sorted_by,
|
67
|
+
:url_for_attrs => {},
|
68
|
+
}.merge(options)
|
69
|
+
options[:html_attrs] = options[:html_attrs].with_indifferent_access
|
70
|
+
current_sorting = filterrific.send(options[:sorting_scope_name])
|
71
|
+
current_sort_key = current_sorting ? current_sorting.gsub(/_asc|_desc/, '') : nil
|
72
|
+
current_sort_direction = current_sorting ? (current_sorting =~ /_desc\z/ ? 'desc' : 'asc') : nil
|
73
|
+
new_sort_key = sort_key.to_s
|
74
|
+
if new_sort_key == current_sort_key
|
75
|
+
# current sort column, toggle search_direction
|
76
|
+
new_sort_direction, current_sort_direction_indicator = if 'asc' == current_sort_direction
|
77
|
+
['desc', options[:ascending_indicator]]
|
78
|
+
else
|
79
|
+
['asc', options[:descending_indicator]]
|
80
|
+
end
|
81
|
+
new_sorting = [new_sort_key, new_sort_direction].join('_')
|
82
|
+
css_classes = [
|
83
|
+
options[:active_column_class],
|
84
|
+
options[:html_attrs].delete(:class)
|
85
|
+
].compact.join(' ')
|
86
|
+
new_filterrific_params = filterrific.to_hash
|
87
|
+
.with_indifferent_access
|
88
|
+
.merge(options[:sorting_scope_name] => new_sorting)
|
89
|
+
url_for_attrs = options[:url_for_attrs].merge(:filterrific => new_filterrific_params)
|
90
|
+
link_to(
|
91
|
+
[options[:label], current_sort_direction_indicator].join(' '),
|
92
|
+
url_for(url_for_attrs),
|
93
|
+
options[:html_attrs].reverse_merge(:class => css_classes, :method => :get, :remote => true)
|
94
|
+
)
|
77
95
|
else
|
78
|
-
|
96
|
+
# new sort column, change sort column
|
97
|
+
new_sort_direction = options[:default_sort_direction]
|
98
|
+
new_sorting = [new_sort_key, new_sort_direction].join('_')
|
99
|
+
new_filterrific_params = filterrific.to_hash
|
100
|
+
.with_indifferent_access
|
101
|
+
.merge(options[:sorting_scope_name] => new_sorting)
|
102
|
+
url_for_attrs = options[:url_for_attrs].merge(:filterrific => new_filterrific_params)
|
103
|
+
link_to(
|
104
|
+
options[:label],
|
105
|
+
url_for(url_for_attrs),
|
106
|
+
options[:html_attrs].reverse_merge(:method => :get, :remote => true)
|
107
|
+
)
|
79
108
|
end
|
80
|
-
new_sorting = [new_sort_key, new_sort_direction].join('_')
|
81
|
-
css_classes = [
|
82
|
-
options[:active_column_class],
|
83
|
-
options[:html_attrs].delete(:class)
|
84
|
-
].compact.join(' ')
|
85
|
-
new_filterrific_params = filterrific.to_hash
|
86
|
-
.with_indifferent_access
|
87
|
-
.merge(options[:sorting_scope_name] => new_sorting)
|
88
|
-
url_for_attrs = options[:url_for_attrs].merge(:filterrific => new_filterrific_params)
|
89
|
-
link_to(
|
90
|
-
[options[:label], current_sort_direction_indicator].join(' '),
|
91
|
-
url_for(url_for_attrs),
|
92
|
-
options[:html_attrs].reverse_merge(:class => css_classes, :method => :get, :remote => true)
|
93
|
-
)
|
94
|
-
else
|
95
|
-
# new sort column, change sort column
|
96
|
-
new_sort_direction = options[:default_sort_direction]
|
97
|
-
new_sorting = [new_sort_key, new_sort_direction].join('_')
|
98
|
-
new_filterrific_params = filterrific.to_hash
|
99
|
-
.with_indifferent_access
|
100
|
-
.merge(options[:sorting_scope_name] => new_sorting)
|
101
|
-
url_for_attrs = options[:url_for_attrs].merge(:filterrific => new_filterrific_params)
|
102
|
-
link_to(
|
103
|
-
options[:label],
|
104
|
-
url_for(url_for_attrs),
|
105
|
-
options[:html_attrs].reverse_merge(:method => :get, :remote => true)
|
106
|
-
)
|
107
109
|
end
|
108
|
-
end
|
109
110
|
|
111
|
+
end
|
110
112
|
end
|
@@ -3,9 +3,8 @@
|
|
3
3
|
#
|
4
4
|
require 'filterrific/param_set'
|
5
5
|
|
6
|
-
module Filterrific
|
7
|
-
|
8
|
-
module ClassMethods
|
6
|
+
module Filterrific
|
7
|
+
module ActiveRecordExtension
|
9
8
|
|
10
9
|
# Adds filterrific behavior to class when called like so:
|
11
10
|
#
|
@@ -84,5 +83,4 @@ module Filterrific::ActiveRecordExtension
|
|
84
83
|
end
|
85
84
|
|
86
85
|
end
|
87
|
-
|
88
86
|
end
|
data/lib/filterrific/engine.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require 'filterrific/param_set'
|
2
|
+
require 'filterrific/action_view_extension'
|
3
|
+
require 'filterrific/active_record_extension'
|
4
|
+
|
1
5
|
module Filterrific
|
2
6
|
class Engine < ::Rails::Engine
|
3
7
|
|
@@ -6,26 +10,16 @@ module Filterrific
|
|
6
10
|
|
7
11
|
isolate_namespace Filterrific
|
8
12
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
ActiveSupport.on_load :active_record do
|
14
|
-
require 'filterrific/active_record_extension'
|
15
|
-
class ::ActiveRecord::Base
|
16
|
-
extend Filterrific::ActiveRecordExtension::ClassMethods
|
17
|
-
end
|
18
|
-
end
|
13
|
+
ActiveSupport.on_load :active_record do
|
14
|
+
extend Filterrific::ActiveRecordExtension
|
15
|
+
end
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
include Filterrific::ActionViewExtension
|
24
|
-
end
|
25
|
-
end
|
17
|
+
ActiveSupport.on_load :action_view do
|
18
|
+
include Filterrific::ActionViewExtension
|
19
|
+
end
|
26
20
|
|
21
|
+
initializer "filterrific" do |app|
|
27
22
|
app.config.assets.precompile += %w(filterrific-spinner.gif)
|
28
|
-
|
29
23
|
end
|
30
24
|
|
31
25
|
end
|
data/lib/filterrific/version.rb
CHANGED
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: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jo Hund
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|