easy_filter 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +11 -11
- data/app/views/easy_filter/_buttons.html.erb +1 -1
- data/app/views/easy_filter/_sort_field.html.erb +1 -1
- data/easy_filter.gemspec +2 -2
- data/lib/easy_filter/version.rb +1 -1
- data/lib/easy_filter/view_helpers.rb +47 -19
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 586866917848c0737f4cee36ad8651f512b4f12e
|
4
|
+
data.tar.gz: a27d5d81b98bceb88ea7be9bc6467a3a0d8fe58d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd796bf841dc16766a28db674a4353955b107ed79ba8ba2a7fed6314b00f0a5a9ee6c5456fe1898828e369834aa01fbde755b5ec95301e98e7e0fb37ed986dd8
|
7
|
+
data.tar.gz: c24cf86bbf1440c56b0affd17a36d47033b1b47c384044bb5fc9d30ca9eebf4249dc83fc166f9e47eaf17c02b16bdf6e935803265a667df2d99458a1a84cca4e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## V0.3.0
|
2
|
+
* Correct XSS problem and add default config to view helper
|
3
|
+
* correct typeo in gemspec
|
4
|
+
* Define jquery-ui version numbers based on Hakiri warnings
|
5
|
+
* Update README.md
|
6
|
+
|
1
7
|
## V0.2.0
|
2
8
|
* Correct Rubocop ABC errors with refactoring
|
3
9
|
* RSpec tests for field with more underscores
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
By [Peter Kepes](https://github.com/kepes)
|
4
4
|
|
5
|
-
[![Build Status](https://travis-ci.org/kepes/easy-filter.svg?branch=master)](https://travis-ci.org/kepes/easy-filter)
|
5
|
+
[![Build Status](https://travis-ci.org/kepes/easy-filter.svg?branch=master)](https://travis-ci.org/kepes/easy-filter) [![Gem Version](https://badge.fury.io/rb/easy_filter.svg)](http://badge.fury.io/rb/easy_filter) [![Code Climate](https://codeclimate.com/github/kepes/easy-filter/badges/gpa.svg)](https://codeclimate.com/github/kepes/easy-filter)
|
6
6
|
|
7
7
|
Filter and sort `ActiveRecord` model for Rails app with [Bootstrap](http://getbootstrap.com/) view helpers.
|
8
8
|
|
@@ -92,18 +92,18 @@ Default view helper templates generates [Bootstrap](http://getbootstrap.com/) co
|
|
92
92
|
app/views/easy_filter/_form_field_close.html.erb
|
93
93
|
app/views/easy_filter/_form_open.html.erb
|
94
94
|
|
95
|
-
####
|
96
|
-
|
97
|
-
View helpers provide paramters to define HTML input field names.
|
98
|
-
|
99
|
-
def easy_filter(model_class, filters, prefixes = { main: 'filter_', from: 'from_', to: 'to_', exact: 'exact_' })
|
100
|
-
|
101
|
-
def easy_sort(column, title = nil, sort = 'sort', direction = 'direction')
|
102
|
-
|
103
|
-
All default templates will use specified prefixes for input fields. If you have to use different names just use this parameters to redefine it.
|
95
|
+
#### Configuration
|
104
96
|
|
105
|
-
|
97
|
+
You can configure input field names used by EasyFilter in environments
|
106
98
|
|
99
|
+
Rails.application.configure do
|
100
|
+
config.easy_filter_defaults = {
|
101
|
+
prefixes: { main: 'filter_', from: 'from_', to: 'to_', exact: 'exact_' },
|
102
|
+
allowed_params: %w(sort direction),
|
103
|
+
sort_params: { field: 'sort', direction: 'direction' }
|
104
|
+
}
|
105
|
+
end
|
106
|
+
|
107
107
|
## Contributing
|
108
108
|
|
109
109
|
1. Fork it
|
@@ -1,2 +1,2 @@
|
|
1
1
|
<%= button_tag(t(:filter), name: "#{filter_prefixes[:main]}button", value: :filter, class: 'btn btn-default') %>
|
2
|
-
<%= link_to t(:clear_filter),
|
2
|
+
<%= link_to t(:clear_filter), cleaned_params.select { |k,v| !k.to_s.starts_with?(filter_prefixes[:main])}, class: 'btn btn-default' %>
|
@@ -1,2 +1,2 @@
|
|
1
1
|
<% icon = "<span class=\"glyphicon glyphicon-chevron-#{direction == "asc" ? "up" : "down"}\"></span>" %>
|
2
|
-
<%= link_to "#{title} #{column ==
|
2
|
+
<%= link_to "#{title} #{column == cleaned_params[sort_param_name] ? icon : ''}".html_safe, cleaned_params.merge(sort_param_name => column, direction_param_name => direction) %>
|
data/easy_filter.gemspec
CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency 'rubocop'
|
24
24
|
spec.add_development_dependency 'activerecord', '~> 3.2'
|
25
25
|
spec.add_development_dependency 'sqlite3'
|
26
|
-
spec.add_runtime_dependency 'jquery-rails'
|
27
|
-
spec.add_runtime_dependency 'jquery-ui-rails'
|
26
|
+
spec.add_runtime_dependency 'jquery-rails', '~> 3.1.4'
|
27
|
+
spec.add_runtime_dependency 'jquery-ui-rails', '~> 5.0.5'
|
28
28
|
end
|
data/lib/easy_filter/version.rb
CHANGED
@@ -1,37 +1,58 @@
|
|
1
1
|
module EasyFilter
|
2
2
|
# View helpers for EasyFilter
|
3
3
|
module ViewHelpers
|
4
|
-
def easy_sort(column, title = nil
|
4
|
+
def easy_sort(column, title = nil)
|
5
|
+
config = easy_filter_defaults
|
6
|
+
cleaned_params = clean_params params, config
|
5
7
|
title ||= column.titleize
|
6
|
-
dir =
|
8
|
+
dir = sort_direction column, config
|
7
9
|
|
8
10
|
render partial: 'easy_filter/sort_field',
|
9
|
-
locals:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
locals:
|
12
|
+
{ column: column.to_s,
|
13
|
+
title: title,
|
14
|
+
sort_param_name: config[:sort_params][:field],
|
15
|
+
direction: dir,
|
16
|
+
direction_param_name: config[:sort_params][:direction],
|
17
|
+
cleaned_params: cleaned_params
|
18
|
+
}
|
14
19
|
end
|
15
20
|
|
16
|
-
def easy_filter(model_class, filters
|
17
|
-
|
21
|
+
def easy_filter(model_class, filters)
|
22
|
+
config = easy_filter_defaults
|
23
|
+
cleaned_params = clean_params params, config
|
24
|
+
form = render_easy 'form_open', config, cleaned_params
|
18
25
|
|
19
26
|
filters.each do |filter|
|
20
27
|
f = determine_column filter, model_class
|
21
|
-
form += render_field f,
|
28
|
+
form += render_field f, config, cleaned_params
|
22
29
|
end
|
23
30
|
|
24
|
-
form += render_easy 'buttons',
|
25
|
-
form += render_easy 'form_close',
|
31
|
+
form += render_easy 'buttons', config, cleaned_params
|
32
|
+
form += render_easy 'form_close', config, cleaned_params
|
26
33
|
end
|
27
34
|
|
28
35
|
private
|
29
36
|
|
30
|
-
def
|
31
|
-
|
37
|
+
def easy_filter_defaults
|
38
|
+
rails_defaults = Rails.configuration.easy_filter_defaults if defined? Rails.configuration.easy_filter_defaults
|
39
|
+
rails_defaults ||= {}
|
40
|
+
{
|
41
|
+
prefixes: { main: 'filter_', from: 'from_', to: 'to_', exact: 'exact_' },
|
42
|
+
allowed_params: %w(sort direction),
|
43
|
+
sort_params: { field: 'sort', direction: 'direction' }
|
44
|
+
}.deep_merge rails_defaults
|
45
|
+
end
|
46
|
+
|
47
|
+
def sort_direction(column, config)
|
48
|
+
(column.to_s == params[config[:sort_params][:field]] && params[config[:sort_params][:direction]] == 'asc') ? 'desc' : 'asc'
|
49
|
+
end
|
50
|
+
|
51
|
+
def render_field(filter, config, cleaned_params)
|
52
|
+
form = render_easy 'form_field_open', config, cleaned_params
|
32
53
|
view = column_view filter[:col_type]
|
33
|
-
form += render_easy view,
|
34
|
-
form + render_easy('form_field_close',
|
54
|
+
form += render_easy view, config, cleaned_params, filter
|
55
|
+
form + render_easy('form_field_close', config, cleaned_params)
|
35
56
|
end
|
36
57
|
|
37
58
|
def column_view(col_type)
|
@@ -78,10 +99,17 @@ module EasyFilter
|
|
78
99
|
filter
|
79
100
|
end
|
80
101
|
|
81
|
-
def render_easy(name,
|
102
|
+
def render_easy(name, config, cleaned_params, filter = nil)
|
82
103
|
render partial: "easy_filter/#{name}",
|
83
|
-
locals: {
|
84
|
-
|
104
|
+
locals: {
|
105
|
+
filter_prefixes: config[:prefixes],
|
106
|
+
filter: filter,
|
107
|
+
cleaned_params: cleaned_params
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
def clean_params(params, config)
|
112
|
+
params.select { |k| k.to_s.starts_with?(config[:prefixes][:main]) || config[:allowed_params].include?(k) }
|
85
113
|
end
|
86
114
|
|
87
115
|
def boolean_array
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_filter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Kepes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -98,30 +98,30 @@ dependencies:
|
|
98
98
|
name: jquery-rails
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 3.1.4
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 3.1.4
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: jquery-ui-rails
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 5.0.5
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: 5.0.5
|
125
125
|
description: Filter and sort ActiveRecord model for Rails app with Bootstrap view
|
126
126
|
helpers
|
127
127
|
email:
|