datagrid 1.3.3 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/datagrid.gemspec +3 -3
- data/lib/datagrid/core.rb +7 -0
- data/lib/datagrid/filters/base_filter.rb +3 -3
- data/lib/datagrid/filters/ranged_filter.rb +16 -21
- data/lib/datagrid/filters/select_options.rb +3 -3
- data/lib/datagrid/rspec.rb +1 -2
- data/spec/datagrid/core_spec.rb +14 -0
- data/spec/datagrid/filters/enum_filter_spec.rb +6 -4
- data/spec/datagrid/filters/extended_boolean_filter_spec.rb +3 -2
- data/spec/datagrid/filters/integer_filter_spec.rb +51 -62
- 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: 3e94155c2af961e78d34637a09881263afa9b47d
|
4
|
+
data.tar.gz: a8573f7be208ac8d629e5a453a3ee52f899333ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c994fd4f81436a191195851226c4ff1dd11f1cf0ff17027ee2dd0fe04eed653475d2785e1c90e8765ea997249284fb30344f99e50c8fc5e271f8fb6fee25b3fb
|
7
|
+
data.tar.gz: 87bf1d14751e50059eb0414665608936f39002a42bb81021ca93e8b710eef37d231cdf6957fb9c032b9293bba598b270bd855f6339b5aca998a81f8d6cf88097
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.4
|
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.4 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.4"
|
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 = "
|
14
|
+
s.date = "2015-01-08"
|
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 = [
|
data/lib/datagrid/core.rb
CHANGED
@@ -98,6 +98,7 @@ module Datagrid
|
|
98
98
|
end
|
99
99
|
|
100
100
|
|
101
|
+
# Updates datagrid attributes with a passed hash argument
|
101
102
|
def assign_attributes(attributes)
|
102
103
|
attributes.each do |name, value|
|
103
104
|
self[name] = value
|
@@ -159,6 +160,12 @@ module Datagrid
|
|
159
160
|
self.class.send :check_scope_defined!, message
|
160
161
|
end
|
161
162
|
|
163
|
+
def inspect
|
164
|
+
attrs = attributes.map do |key, value|
|
165
|
+
"#{key}: #{value.inspect}"
|
166
|
+
end.join(", ")
|
167
|
+
"#<#{self.class} #{attrs}>"
|
168
|
+
end
|
162
169
|
|
163
170
|
end # InstanceMethods
|
164
171
|
end
|
@@ -33,13 +33,13 @@ class Datagrid::Filters::BaseFilter #:nodoc:
|
|
33
33
|
|
34
34
|
def parse_values(value)
|
35
35
|
if multiple?
|
36
|
+
return nil if value.nil?
|
36
37
|
normalize_multiple_value(value).map do |v|
|
37
38
|
parse(v)
|
38
39
|
end
|
40
|
+
elsif value.is_a?(Array)
|
41
|
+
raise Datagrid::ArgumentError, "#{grid_class}##{name} filter can not accept Array argument. Use :multiple option."
|
39
42
|
else
|
40
|
-
if value.is_a?(Array)
|
41
|
-
raise Datagrid::ArgumentError, "#{grid_class}##{name} filter can not accept Array argument. Use :multiple option."
|
42
|
-
end
|
43
43
|
parse(value)
|
44
44
|
end
|
45
45
|
end
|
@@ -10,31 +10,26 @@ module RangedFilter
|
|
10
10
|
|
11
11
|
def parse_values(value)
|
12
12
|
result = super(value)
|
13
|
-
if range?
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
else
|
28
|
-
raise ArgumentError, "Can not create a date range from array of more than two: #{result.inspect}"
|
29
|
-
end
|
13
|
+
return result if !range? || result.nil?
|
14
|
+
# Simulate single point range
|
15
|
+
return result..result unless result.is_a?(Array)
|
16
|
+
|
17
|
+
case result.size
|
18
|
+
when 0
|
19
|
+
nil
|
20
|
+
when 1
|
21
|
+
result.first
|
22
|
+
when 2
|
23
|
+
if result.first && result.last && result.first > result.last
|
24
|
+
# If wrong range is given - reverse it to be always valid
|
25
|
+
result.reverse
|
30
26
|
else
|
31
|
-
|
32
|
-
result..result
|
27
|
+
result
|
33
28
|
end
|
34
|
-
|
35
29
|
else
|
36
|
-
result
|
30
|
+
raise ArgumentError, "Can not create a date range from array of more than two: #{result.inspect}"
|
37
31
|
end
|
32
|
+
|
38
33
|
end
|
39
34
|
|
40
35
|
def range?
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Datagrid::Filters::SelectOptions
|
2
2
|
|
3
3
|
def select(object = nil)
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
unless object
|
5
|
+
Datagrid::Utils.warn_once("#{self.class.name}#select without argument is deprecated")
|
6
|
+
end
|
7
7
|
select = self.options[:select]
|
8
8
|
if select.is_a?(Symbol)
|
9
9
|
object.send(select)
|
data/lib/datagrid/rspec.rb
CHANGED
@@ -45,8 +45,7 @@ shared_examples_for "Datagrid" do
|
|
45
45
|
when :integer
|
46
46
|
1
|
47
47
|
when :enum
|
48
|
-
select = filter.select
|
49
|
-
select = select.call(subject) if select.respond_to?(:call)
|
48
|
+
select = filter.select(subject)
|
50
49
|
select.first.try(:last)
|
51
50
|
else
|
52
51
|
raise "unknown filter type: #{filter.class}"
|
data/spec/datagrid/core_spec.rb
CHANGED
@@ -48,4 +48,18 @@ describe Datagrid::Core do
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
|
+
|
52
|
+
describe ".inspect" do
|
53
|
+
it "should show all attribute values" do
|
54
|
+
class InspectTest
|
55
|
+
include Datagrid
|
56
|
+
scope {Entry}
|
57
|
+
filter(:created_at, :date, :range => true)
|
58
|
+
column(:name)
|
59
|
+
end
|
60
|
+
|
61
|
+
grid = InspectTest.new(:created_at => ['2014-01-01', '2014-08-05'], :descending => true, :order => 'name')
|
62
|
+
expect(grid.inspect).to eq('#<InspectTest order: :name, descending: true, created_at: [Wed, 01 Jan 2014, Tue, 05 Aug 2014]>')
|
63
|
+
end
|
64
|
+
end
|
51
65
|
end
|
@@ -3,17 +3,19 @@ require 'spec_helper'
|
|
3
3
|
describe Datagrid::Filters::EnumFilter do
|
4
4
|
|
5
5
|
it "should support select option" do
|
6
|
-
|
6
|
+
report = test_report do
|
7
7
|
scope {Entry}
|
8
8
|
filter(:group_id, :enum, :select => [1,2] )
|
9
|
-
end
|
9
|
+
end
|
10
|
+
expect(report.filter_by_name(:group_id).select(report)).to eq([1,2])
|
10
11
|
end
|
11
12
|
|
12
13
|
it "should support select option as proc" do
|
13
|
-
|
14
|
+
grid = test_report do
|
14
15
|
scope {Entry}
|
15
16
|
filter(:group_id, :enum, :select => proc { [1,2] })
|
16
|
-
end
|
17
|
+
end
|
18
|
+
expect(grid.filter_by_name(:group_id).select(grid)).to eq([1,2])
|
17
19
|
end
|
18
20
|
|
19
21
|
it "should support select option as proc with instace input" do
|
@@ -3,10 +3,11 @@ require 'spec_helper'
|
|
3
3
|
describe Datagrid::Filters::ExtendedBooleanFilter do
|
4
4
|
|
5
5
|
it "should support select option" do
|
6
|
-
|
6
|
+
grid = test_report do
|
7
7
|
scope {Entry}
|
8
8
|
filter(:disabled, :xboolean)
|
9
|
-
end
|
9
|
+
end
|
10
|
+
expect(grid.filter_by_name(:disabled).select(grid)).to eq([["Yes", "YES"], ["No", "NO"]])
|
10
11
|
end
|
11
12
|
|
12
13
|
it "should generate pass boolean value to filter block" do
|
@@ -2,83 +2,73 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Datagrid::Filters::IntegerFilter do
|
4
4
|
|
5
|
+
|
6
|
+
let(:entry1) { Entry.create!(:group_id => 1) }
|
7
|
+
let(:entry2) { Entry.create!(:group_id => 2) }
|
8
|
+
let(:entry3) { Entry.create!(:group_id => 3) }
|
9
|
+
let(:entry4) { Entry.create!(:group_id => 4) }
|
10
|
+
let(:entry5) { Entry.create!(:group_id => 5) }
|
11
|
+
let(:entry7) { Entry.create!(:group_id => 7) }
|
12
|
+
|
5
13
|
it "should support integer range argument" do
|
6
|
-
e1 = Entry.create!(:group_id => 1)
|
7
|
-
e2 = Entry.create!(:group_id => 4)
|
8
|
-
e3 = Entry.create!(:group_id => 7)
|
9
14
|
report = test_report(:group_id => 3..5) do
|
10
15
|
scope { Entry }
|
11
16
|
filter(:group_id, :integer)
|
12
17
|
end
|
13
|
-
expect(report.assets).not_to include(
|
14
|
-
expect(report.assets).to include(
|
15
|
-
expect(report.assets).not_to include(
|
18
|
+
expect(report.assets).not_to include(entry1)
|
19
|
+
expect(report.assets).to include(entry4)
|
20
|
+
expect(report.assets).not_to include(entry7)
|
16
21
|
end
|
17
22
|
|
18
23
|
it "should support integer range given as array argument" do
|
19
|
-
e1 = Entry.create!(:group_id => 7)
|
20
|
-
e2 = Entry.create!(:group_id => 4)
|
21
|
-
e3 = Entry.create!(:group_id => 1)
|
22
24
|
report = test_report(:group_id => [3.to_s, 5.to_s]) do
|
23
25
|
scope { Entry }
|
24
26
|
filter(:group_id, :integer, :range => true)
|
25
27
|
end
|
26
|
-
expect(report.assets).not_to include(
|
27
|
-
expect(report.assets).to include(
|
28
|
-
expect(report.assets).not_to include(
|
28
|
+
expect(report.assets).not_to include(entry7)
|
29
|
+
expect(report.assets).to include(entry4)
|
30
|
+
expect(report.assets).not_to include(entry1)
|
29
31
|
end
|
30
32
|
|
31
33
|
it "should support minimum integer argument" do
|
32
|
-
e1 = Entry.create!(:group_id => 1)
|
33
|
-
e2 = Entry.create!(:group_id => 4)
|
34
|
-
e3 = Entry.create!(:group_id => 7)
|
35
34
|
report = test_report(:group_id => [5.to_s, nil]) do
|
36
35
|
scope { Entry }
|
37
36
|
filter(:group_id, :integer, :range => true)
|
38
37
|
end
|
39
|
-
expect(report.assets).not_to include(
|
40
|
-
expect(report.assets).not_to include(
|
41
|
-
expect(report.assets).to include(
|
38
|
+
expect(report.assets).not_to include(entry1)
|
39
|
+
expect(report.assets).not_to include(entry4)
|
40
|
+
expect(report.assets).to include(entry7)
|
42
41
|
end
|
43
42
|
|
44
43
|
it "should support maximum integer argument" do
|
45
|
-
e1 = Entry.create!(:group_id => 1)
|
46
|
-
e2 = Entry.create!(:group_id => 4)
|
47
|
-
e3 = Entry.create!(:group_id => 7)
|
48
44
|
report = test_report(:group_id => [nil, 5.to_s]) do
|
49
45
|
scope { Entry }
|
50
46
|
filter(:group_id, :integer, :range => true)
|
51
47
|
end
|
52
|
-
expect(report.assets).to include(
|
53
|
-
expect(report.assets).to include(
|
54
|
-
expect(report.assets).not_to include(
|
48
|
+
expect(report.assets).to include(entry1)
|
49
|
+
expect(report.assets).to include(entry4)
|
50
|
+
expect(report.assets).not_to include(entry7)
|
55
51
|
end
|
56
52
|
|
57
53
|
it "should find something in one integer interval" do
|
58
54
|
|
59
|
-
e1 = Entry.create!(:group_id => 7)
|
60
|
-
e2 = Entry.create!(:group_id => 4)
|
61
|
-
e3 = Entry.create!(:group_id => 1)
|
62
55
|
report = test_report(:group_id => (4..4)) do
|
63
56
|
scope { Entry }
|
64
57
|
filter(:group_id, :integer, :range => true)
|
65
58
|
end
|
66
|
-
expect(report.assets).not_to include(
|
67
|
-
expect(report.assets).to include(
|
68
|
-
expect(report.assets).not_to include(
|
59
|
+
expect(report.assets).not_to include(entry7)
|
60
|
+
expect(report.assets).to include(entry4)
|
61
|
+
expect(report.assets).not_to include(entry1)
|
69
62
|
end
|
70
63
|
it "should support invalid range" do
|
71
64
|
|
72
|
-
e1 = Entry.create!(:group_id => 7)
|
73
|
-
e2 = Entry.create!(:group_id => 4)
|
74
|
-
e3 = Entry.create!(:group_id => 1)
|
75
65
|
report = test_report(:group_id => (7..1)) do
|
76
66
|
scope { Entry }
|
77
67
|
filter(:group_id, :integer, :range => true)
|
78
68
|
end
|
79
|
-
expect(report.assets).not_to include(
|
80
|
-
expect(report.assets).not_to include(
|
81
|
-
expect(report.assets).not_to include(
|
69
|
+
expect(report.assets).not_to include(entry7)
|
70
|
+
expect(report.assets).not_to include(entry4)
|
71
|
+
expect(report.assets).not_to include(entry1)
|
82
72
|
end
|
83
73
|
|
84
74
|
|
@@ -89,8 +79,8 @@ describe Datagrid::Filters::IntegerFilter do
|
|
89
79
|
where("group_id >= ?", value)
|
90
80
|
end
|
91
81
|
end
|
92
|
-
expect(report.assets).not_to include(
|
93
|
-
expect(report.assets).to include(
|
82
|
+
expect(report.assets).not_to include(entry1)
|
83
|
+
expect(report.assets).to include(entry5)
|
94
84
|
end
|
95
85
|
|
96
86
|
|
@@ -99,6 +89,7 @@ describe Datagrid::Filters::IntegerFilter do
|
|
99
89
|
scope { Entry.joins(:group) }
|
100
90
|
filter(:rating, :integer, :range => true)
|
101
91
|
end
|
92
|
+
expect(report.rating).to eq([4,nil])
|
102
93
|
expect(report.assets).not_to include(Entry.create!(:group => Group.create!(:rating => 3)))
|
103
94
|
expect(report.assets).to include(Entry.create!(:group => Group.create!(:rating => 5)))
|
104
95
|
end
|
@@ -106,39 +97,37 @@ describe Datagrid::Filters::IntegerFilter do
|
|
106
97
|
it "should support multiple values" do
|
107
98
|
report = test_report(:group_id => "1,2") do
|
108
99
|
scope {Entry}
|
109
|
-
filter(:group_id, :
|
100
|
+
filter(:group_id, :integer, :multiple => true)
|
110
101
|
end
|
111
|
-
expect(report.
|
112
|
-
expect(report.assets).to include(
|
113
|
-
expect(report.assets).
|
102
|
+
expect(report.group_id).to eq([1,2])
|
103
|
+
expect(report.assets).to include(entry1)
|
104
|
+
expect(report.assets).to include(entry2)
|
105
|
+
expect(report.assets).not_to include(entry3)
|
114
106
|
end
|
115
107
|
it "should support custom separator multiple values" do
|
116
108
|
report = test_report(:group_id => "1|2") do
|
117
109
|
scope {Entry}
|
118
|
-
filter(:group_id, :
|
110
|
+
filter(:group_id, :integer, :multiple => '|')
|
119
111
|
end
|
120
|
-
expect(report.
|
121
|
-
expect(report.assets).to include(
|
122
|
-
expect(report.assets).
|
112
|
+
expect(report.group_id).to eq([1,2])
|
113
|
+
expect(report.assets).to include(entry1)
|
114
|
+
expect(report.assets).to include(entry2)
|
115
|
+
expect(report.assets).not_to include(entry3)
|
123
116
|
end
|
124
117
|
|
125
|
-
it "should support multiple
|
126
|
-
report
|
127
|
-
scope {Entry}
|
128
|
-
filter(:group_id, :string, :multiple => true)
|
129
|
-
end
|
130
|
-
expect(report.assets).to include(Entry.create!( :group_id => 1))
|
131
|
-
expect(report.assets).to include(Entry.create!( :group_id => 2))
|
132
|
-
expect(report.assets).not_to include(Entry.create!( :group_id => 3))
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should support custom separator multiple values" do
|
136
|
-
report = test_report(:group_id => "1|2") do
|
118
|
+
it "should support multiple with allow_blank allow_nil options" do
|
119
|
+
report = test_report do
|
137
120
|
scope {Entry}
|
138
|
-
filter(:group_id, :
|
121
|
+
filter(:group_id, :integer, :multiple => true, :allow_nil => false, :allow_blank => true )
|
139
122
|
end
|
140
|
-
|
141
|
-
expect(report.assets).
|
142
|
-
expect(report.assets).
|
123
|
+
report.group_id = []
|
124
|
+
expect(report.assets).to_not include(entry1)
|
125
|
+
expect(report.assets).to_not include(entry2)
|
126
|
+
report.group_id = [1]
|
127
|
+
expect(report.assets).to include(entry1)
|
128
|
+
expect(report.assets).to_not include(entry2)
|
129
|
+
report.group_id = nil
|
130
|
+
expect(report.assets).to include(entry1)
|
131
|
+
expect(report.assets).to include(entry2)
|
143
132
|
end
|
144
133
|
end
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdan Gusiev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|