datagrid 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/datagrid.gemspec +3 -3
- data/lib/datagrid/filters/dynamic_filter.rb +16 -4
- data/spec/datagrid/filters/dynamic_filter_spec.rb +27 -0
- data/spec/datagrid/form_builder_spec.rb +13 -0
- 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: 22ba5c3d97717d9f5d236b7f8559346d8e2255ad
|
4
|
+
data.tar.gz: 6f80355aafcb9f54870d42f458d8f8c4aa152cd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93798b31a87ed1c8f81e49da6293d996f3952f8db26eb387446f57d46c2507c00a78bd6e5fc6908c64b822f1cdfa175b13cdd875e3afb0021edba3f32c584c2a
|
7
|
+
data.tar.gz: 296aa0e6501289e986a9a0de697f1c2ae0fd068e631c358ce8dad7f7edae2e45a40881512199a37492d936ed0166503bbc46766bc258c40eb96a264fc0388a9e
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.5
|
data/datagrid.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: datagrid 1.3.
|
5
|
+
# stub: datagrid 1.3.5 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "datagrid"
|
9
|
-
s.version = "1.3.
|
9
|
+
s.version = "1.3.5"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Bogdan Gusiev"]
|
14
|
-
s.date = "2015-01-
|
14
|
+
s.date = "2015-01-21"
|
15
15
|
s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters"
|
16
16
|
s.email = "agresso@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -4,9 +4,12 @@ class Datagrid::Filters::DynamicFilter < Datagrid::Filters::BaseFilter
|
|
4
4
|
|
5
5
|
include Datagrid::Filters::SelectOptions
|
6
6
|
|
7
|
+
AVAILABLE_OPERATIONS = %w(= =~ >= <=)
|
8
|
+
|
7
9
|
def initialize(*)
|
8
10
|
super
|
9
11
|
options[:select] ||= default_select
|
12
|
+
options[:operations] ||= AVAILABLE_OPERATIONS
|
10
13
|
unless options.has_key?(:include_blank)
|
11
14
|
options[:include_blank] = false
|
12
15
|
end
|
@@ -19,13 +22,18 @@ class Datagrid::Filters::DynamicFilter < Datagrid::Filters::BaseFilter
|
|
19
22
|
end
|
20
23
|
|
21
24
|
def unapplicable_value?(filter)
|
22
|
-
|
23
|
-
|
25
|
+
_, _, value = filter
|
26
|
+
super(value)
|
24
27
|
end
|
25
28
|
|
26
29
|
def default_filter_where(driver, scope, filter)
|
27
30
|
field, operation, value = filter
|
28
31
|
date_conversion = value.is_a?(Date) && driver.is_timestamp?(scope, field)
|
32
|
+
|
33
|
+
return scope if field.blank? || operation.blank?
|
34
|
+
unless operations.include?(operation)
|
35
|
+
raise Datagrid::FilteringError, "Unknown operation: #{operation.inspect}. Available operations: #{operations.join(' ')}"
|
36
|
+
end
|
29
37
|
case operation
|
30
38
|
when '='
|
31
39
|
if date_conversion
|
@@ -52,12 +60,16 @@ class Datagrid::Filters::DynamicFilter < Datagrid::Filters::BaseFilter
|
|
52
60
|
end
|
53
61
|
driver.less_equal(scope, field, value)
|
54
62
|
else
|
55
|
-
raise "
|
63
|
+
raise Datagrid::FilteringError, "Unknown operation: #{operation.inspect}. Use filter block argument to implement operation"
|
56
64
|
end
|
57
65
|
end
|
58
66
|
|
67
|
+
def operations
|
68
|
+
options[:operations]
|
69
|
+
end
|
70
|
+
|
59
71
|
def operations_select
|
60
|
-
|
72
|
+
operations.map do |operation|
|
61
73
|
[I18n.t(operation, :scope => "datagrid.filters.dynamic.operations").html_safe, operation]
|
62
74
|
end
|
63
75
|
end
|
@@ -119,4 +119,31 @@ describe Datagrid::Filters::DynamicFilter do
|
|
119
119
|
expect(report.assets).not_to include(Entry.create!(:shipping_date => '1986-08-06'))
|
120
120
|
end
|
121
121
|
|
122
|
+
it "should support allow_nil and allow_blank options" do
|
123
|
+
grid = test_report do
|
124
|
+
scope {Entry}
|
125
|
+
filter(:condition, :dynamic, :allow_nil => true, :allow_blank => true, operations: ['>=', '<=']) do |(field, operation, value), scope|
|
126
|
+
if value.blank?
|
127
|
+
scope.where(disabled: false)
|
128
|
+
else
|
129
|
+
scope.where("#{field} #{operation} ?", value)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
expect(grid.assets).to_not include(Entry.create!(disabled: true))
|
135
|
+
expect(grid.assets).to include(Entry.create!(disabled: false))
|
136
|
+
|
137
|
+
grid.condition = [:group_id, '>=', 3]
|
138
|
+
expect(grid.assets).to include(Entry.create!(disabled: true, group_id: 4))
|
139
|
+
expect(grid.assets).to_not include(Entry.create!(disabled: false, group_id: 2))
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should raise if unknown operation" do
|
143
|
+
report.condition = [:shipping_date, "<>", '1996-08-05']
|
144
|
+
expect{
|
145
|
+
report.assets
|
146
|
+
}.to raise_error(Datagrid::FilteringError)
|
147
|
+
end
|
148
|
+
|
122
149
|
end
|
@@ -544,6 +544,19 @@ DOM
|
|
544
544
|
it {should equal_to_dom(expected_html)}
|
545
545
|
|
546
546
|
end
|
547
|
+
|
548
|
+
context "when operation options passed" do
|
549
|
+
let(:filter_options) do
|
550
|
+
{:operations => %w(>= <=), :select => [:id]}
|
551
|
+
end
|
552
|
+
let(:expected_html) do
|
553
|
+
<<-HTML
|
554
|
+
<select class="condition dynamic_filter field" id="report_condition" name="report[condition][]"><option value="id">id</option></select><select class="condition dynamic_filter operation" id="report_condition" name="report[condition][]"><option value=">=">≥</option>
|
555
|
+
<option value="<=">≤</option></select><input class="condition dynamic_filter value" id="report_condition" name="report[condition][]" size="30" type="text">
|
556
|
+
HTML
|
557
|
+
end
|
558
|
+
it {should equal_to_dom(expected_html)}
|
559
|
+
end
|
547
560
|
end
|
548
561
|
end
|
549
562
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datagrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdan Gusiev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|