datagrid 1.5.4 → 1.5.5
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/app/views/datagrid/_order_for.html.erb +2 -2
- data/datagrid.gemspec +3 -3
- data/lib/datagrid/columns.rb +0 -39
- data/lib/datagrid/core.rb +43 -0
- data/lib/datagrid/filters.rb +0 -1
- data/lib/datagrid/filters/base_filter.rb +2 -0
- data/lib/datagrid/filters/ranged_filter.rb +1 -1
- data/lib/datagrid/helper.rb +5 -0
- data/lib/datagrid/renderer.rb +10 -0
- data/spec/datagrid/columns_spec.rb +0 -32
- data/spec/datagrid/core_spec.rb +49 -0
- data/spec/datagrid/filters/date_filter_spec.rb +7 -5
- data/spec/datagrid/filters/date_time_filter_spec.rb +8 -6
- data/spec/datagrid/filters/integer_filter_spec.rb +5 -3
- data/spec/datagrid/form_builder_spec.rb +4 -4
- data/spec/datagrid/helper_spec.rb +3 -0
- data/spec/support/matchers.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: 012d1468059f7ed2bc98a58b26d982960eb40c9c
|
4
|
+
data.tar.gz: 6bd2b6019015f43c84e372fd27a5472e7f72d115
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 430016e9d03c4f09f0d8e0efec3faac6ec8c9428aa77a98679de546e3c52f7325aad22aae6a7aaed04b5bdb5be1048f2a9df73df43101bdb3178cdf1a57888c9
|
7
|
+
data.tar.gz: bdeb1423e1bdbf3ef66d2e4656ff565c50ec1a3e2cd18dc5d076e3b364528618cec623b20b528b8b98399a9f15ebbd1cb9f0bdbb7de8a35993ccc174f389ca08
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.5.
|
1
|
+
1.5.5
|
@@ -1,10 +1,10 @@
|
|
1
1
|
<div class="order">
|
2
2
|
<%= link_to(
|
3
3
|
I18n.t("datagrid.table.order.asc").html_safe,
|
4
|
-
|
4
|
+
datagrid_order_path(grid, column, false),
|
5
5
|
:class => "asc") %>
|
6
6
|
<%= link_to(
|
7
7
|
I18n.t("datagrid.table.order.desc").html_safe,
|
8
|
-
|
8
|
+
datagrid_order_path(grid, column, true),
|
9
9
|
:class => "desc") %>
|
10
10
|
</div>
|
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.5.
|
5
|
+
# stub: datagrid 1.5.5 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "datagrid".freeze
|
9
|
-
s.version = "1.5.
|
9
|
+
s.version = "1.5.5"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Bogdan Gusiev".freeze]
|
14
|
-
s.date = "2017-
|
14
|
+
s.date = "2017-10-03"
|
15
15
|
s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters".freeze
|
16
16
|
s.email = "agresso@gmail.com".freeze
|
17
17
|
s.extra_rdoc_files = [
|
data/lib/datagrid/columns.rb
CHANGED
@@ -20,8 +20,6 @@ module Datagrid
|
|
20
20
|
class_attribute :columns_array
|
21
21
|
self.columns_array = []
|
22
22
|
|
23
|
-
class_attribute :dynamic_block, :instance_writer => false
|
24
|
-
|
25
23
|
class_attribute :cached
|
26
24
|
self.cached = false
|
27
25
|
|
@@ -163,42 +161,6 @@ module Datagrid
|
|
163
161
|
end
|
164
162
|
end
|
165
163
|
|
166
|
-
# Allows dynamic columns definition, that could not be defined at class level
|
167
|
-
#
|
168
|
-
# class MerchantsGrid
|
169
|
-
#
|
170
|
-
# scope { Merchant }
|
171
|
-
#
|
172
|
-
# column(:name)
|
173
|
-
#
|
174
|
-
# dynamic do
|
175
|
-
# PurchaseCategory.all.each do |category|
|
176
|
-
# column(:"#{category.name.underscore}_sales") do |merchant|
|
177
|
-
# merchant.purchases.where(:category_id => category.id).count
|
178
|
-
# end
|
179
|
-
# end
|
180
|
-
# end
|
181
|
-
# end
|
182
|
-
#
|
183
|
-
# grid = MerchantsGrid.new
|
184
|
-
# grid.data # => [
|
185
|
-
# # [ "Name", "Swimwear Sales", "Sportswear Sales", ... ]
|
186
|
-
# # [ "Reebok", 2083382, 8382283, ... ]
|
187
|
-
# # [ "Nike", 8372283, 18734783, ... ]
|
188
|
-
# # ]
|
189
|
-
def dynamic(&block)
|
190
|
-
previous_block = dynamic_block
|
191
|
-
self.dynamic_block =
|
192
|
-
if previous_block
|
193
|
-
proc {
|
194
|
-
instance_eval(&previous_block)
|
195
|
-
instance_eval(&block)
|
196
|
-
}
|
197
|
-
else
|
198
|
-
block
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
164
|
# Defines a model decorator that will be used to define a column value.
|
203
165
|
# All column blocks will be given a decorated version of the model.
|
204
166
|
#
|
@@ -450,7 +412,6 @@ module Datagrid
|
|
450
412
|
def initialize(*) #:nodoc:
|
451
413
|
self.columns_array = self.class.columns_array.clone
|
452
414
|
super
|
453
|
-
instance_eval(&dynamic_block) if dynamic_block
|
454
415
|
end
|
455
416
|
|
456
417
|
# Returns all columns available for current grid configuration.
|
data/lib/datagrid/core.rb
CHANGED
@@ -8,8 +8,14 @@ module Datagrid
|
|
8
8
|
base.extend ClassMethods
|
9
9
|
base.class_eval do
|
10
10
|
class_attribute :scope_value
|
11
|
+
|
11
12
|
class_attribute :datagrid_attributes
|
12
13
|
self.datagrid_attributes = []
|
14
|
+
|
15
|
+
class_attribute :dynamic_block, :instance_writer => false
|
16
|
+
if defined?(::ActiveModel::AttributeAssignment)
|
17
|
+
include ::ActiveModel::AttributeAssignment
|
18
|
+
end
|
13
19
|
end
|
14
20
|
base.send :include, InstanceMethods
|
15
21
|
end # self.included
|
@@ -50,6 +56,42 @@ module Datagrid
|
|
50
56
|
@driver ||= Drivers::AbstractDriver.guess_driver(scope).new
|
51
57
|
end
|
52
58
|
|
59
|
+
# Allows dynamic columns definition, that could not be defined at class level
|
60
|
+
#
|
61
|
+
# class MerchantsGrid
|
62
|
+
#
|
63
|
+
# scope { Merchant }
|
64
|
+
#
|
65
|
+
# column(:name)
|
66
|
+
#
|
67
|
+
# dynamic do
|
68
|
+
# PurchaseCategory.all.each do |category|
|
69
|
+
# column(:"#{category.name.underscore}_sales") do |merchant|
|
70
|
+
# merchant.purchases.where(:category_id => category.id).count
|
71
|
+
# end
|
72
|
+
# end
|
73
|
+
# end
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# grid = MerchantsGrid.new
|
77
|
+
# grid.data # => [
|
78
|
+
# # [ "Name", "Swimwear Sales", "Sportswear Sales", ... ]
|
79
|
+
# # [ "Reebok", 2083382, 8382283, ... ]
|
80
|
+
# # [ "Nike", 8372283, 18734783, ... ]
|
81
|
+
# # ]
|
82
|
+
def dynamic(&block)
|
83
|
+
previous_block = dynamic_block
|
84
|
+
self.dynamic_block =
|
85
|
+
if previous_block
|
86
|
+
proc {
|
87
|
+
instance_eval(&previous_block)
|
88
|
+
instance_eval(&block)
|
89
|
+
}
|
90
|
+
else
|
91
|
+
block
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
53
95
|
protected
|
54
96
|
def check_scope_defined!(message = nil)
|
55
97
|
message ||= "#{self}.scope is not defined"
|
@@ -72,6 +114,7 @@ module Datagrid
|
|
72
114
|
self.attributes = attributes
|
73
115
|
end
|
74
116
|
|
117
|
+
instance_eval(&dynamic_block) if dynamic_block
|
75
118
|
if block_given?
|
76
119
|
self.scope(&block)
|
77
120
|
end
|
data/lib/datagrid/filters.rb
CHANGED
@@ -12,7 +12,7 @@ module Datagrid::Filters::RangedFilter
|
|
12
12
|
result = super(value)
|
13
13
|
return result if !range? || result.nil?
|
14
14
|
# Simulate single point range
|
15
|
-
return result
|
15
|
+
return [result, result] unless result.is_a?(Array)
|
16
16
|
|
17
17
|
case result.size
|
18
18
|
when 0
|
data/lib/datagrid/helper.rb
CHANGED
@@ -116,6 +116,11 @@ module Datagrid
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
+
# Generates an ascending or descending order url for the given column
|
120
|
+
def datagrid_order_path(grid, column, descending)
|
121
|
+
datagrid_renderer.order_path(grid, column, descending, request)
|
122
|
+
end
|
123
|
+
|
119
124
|
# Represents a datagrid row that provides access to column values for the given asset
|
120
125
|
#
|
121
126
|
# row = datagrid_row(grid, user)
|
data/lib/datagrid/renderer.rb
CHANGED
@@ -78,6 +78,16 @@ module Datagrid
|
|
78
78
|
{ :grid => grid, :column => column })
|
79
79
|
end
|
80
80
|
|
81
|
+
def order_path(grid, column, descending, request)
|
82
|
+
column = grid.column_by_name(column)
|
83
|
+
query = request ? request.query_parameters : {}
|
84
|
+
order_parameter = {grid.param_name => grid.as_query.merge(:order => column.name, :descending => descending)}
|
85
|
+
ActionDispatch::Http::URL.path_for(
|
86
|
+
path: request ? request.path : '/',
|
87
|
+
params: query.merge(order_parameter)
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
81
91
|
private
|
82
92
|
|
83
93
|
def _safe(string)
|
@@ -459,38 +459,6 @@ describe Datagrid::Columns do
|
|
459
459
|
end
|
460
460
|
end
|
461
461
|
|
462
|
-
describe 'dynamic helper' do
|
463
|
-
it "should work" do
|
464
|
-
grid = test_report do
|
465
|
-
scope {Entry}
|
466
|
-
column(:id)
|
467
|
-
dynamic {
|
468
|
-
column(:name)
|
469
|
-
column(:category)
|
470
|
-
}
|
471
|
-
end
|
472
|
-
|
473
|
-
expect(grid.columns.map(&:name)).to eq([:id, :name, :category])
|
474
|
-
expect(grid.class.columns.map(&:name)).to eq([:id])
|
475
|
-
|
476
|
-
expect(grid.column_by_name(:id)).not_to be_nil
|
477
|
-
expect(grid.column_by_name(:name)).not_to be_nil
|
478
|
-
end
|
479
|
-
|
480
|
-
it "has access to attributes" do
|
481
|
-
grid = test_report(:attribute_name => 'value') do
|
482
|
-
scope {Entry}
|
483
|
-
datagrid_attribute :attribute_name
|
484
|
-
dynamic {
|
485
|
-
value = attribute_name
|
486
|
-
column(:name) { value }
|
487
|
-
}
|
488
|
-
end
|
489
|
-
|
490
|
-
expect(grid.data_value(:name, Entry.create!)).to eq('value')
|
491
|
-
end
|
492
|
-
end
|
493
|
-
|
494
462
|
describe ".data_value" do
|
495
463
|
it "should return value" do
|
496
464
|
grid = test_report do
|
data/spec/datagrid/core_spec.rb
CHANGED
@@ -109,4 +109,53 @@ describe Datagrid::Core do
|
|
109
109
|
expect(EqualTest.new).to_not eq(EqualTest.new {|s| s.reorder(:name)})
|
110
110
|
end
|
111
111
|
end
|
112
|
+
|
113
|
+
describe 'dynamic helper' do
|
114
|
+
it "should work" do
|
115
|
+
grid = test_report do
|
116
|
+
scope {Entry}
|
117
|
+
column(:id)
|
118
|
+
dynamic {
|
119
|
+
column(:name)
|
120
|
+
column(:category)
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
expect(grid.columns.map(&:name)).to eq([:id, :name, :category])
|
125
|
+
expect(grid.class.columns.map(&:name)).to eq([:id])
|
126
|
+
|
127
|
+
expect(grid.column_by_name(:id)).not_to be_nil
|
128
|
+
expect(grid.column_by_name(:name)).not_to be_nil
|
129
|
+
end
|
130
|
+
|
131
|
+
it "has access to attributes" do
|
132
|
+
grid = test_report(:attribute_name => 'value') do
|
133
|
+
scope {Entry}
|
134
|
+
datagrid_attribute :attribute_name
|
135
|
+
dynamic {
|
136
|
+
value = attribute_name
|
137
|
+
column(:name) { value }
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
141
|
+
expect(grid.data_value(:name, Entry.create!)).to eq('value')
|
142
|
+
end
|
143
|
+
|
144
|
+
it "applies before instance scope" do
|
145
|
+
klass = test_report_class do
|
146
|
+
scope {Entry}
|
147
|
+
dynamic do
|
148
|
+
scope do |s|
|
149
|
+
s.limit(1)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
grid = klass.new do |s|
|
155
|
+
s.limit(2)
|
156
|
+
end
|
157
|
+
|
158
|
+
expect(grid.assets.limit_value).to eq(2)
|
159
|
+
end
|
160
|
+
end
|
112
161
|
end
|
@@ -104,18 +104,20 @@ describe Datagrid::Filters::DateFilter do
|
|
104
104
|
expect(report.assets).to include(e2)
|
105
105
|
expect(report.assets).not_to include(e3)
|
106
106
|
end
|
107
|
-
it "should support invalid range" do
|
108
107
|
|
108
|
+
it "should invert invalid range" do
|
109
|
+
range = 1.days.ago..7.days.ago
|
109
110
|
e1 = Entry.create!(:created_at => 7.days.ago)
|
110
111
|
e2 = Entry.create!(:created_at => 4.days.ago)
|
111
112
|
e3 = Entry.create!(:created_at => 1.day.ago)
|
112
|
-
report = test_report(:created_at =>
|
113
|
+
report = test_report(:created_at => range) do
|
113
114
|
scope { Entry }
|
114
115
|
filter(:created_at, :date, :range => true)
|
115
116
|
end
|
116
|
-
expect(report.
|
117
|
-
expect(report.assets).
|
118
|
-
expect(report.assets).
|
117
|
+
expect(report.created_at).to eq([range.last.to_date, range.first.to_date])
|
118
|
+
expect(report.assets).to include(e1)
|
119
|
+
expect(report.assets).to include(e2)
|
120
|
+
expect(report.assets).to include(e3)
|
119
121
|
end
|
120
122
|
|
121
123
|
|
@@ -85,7 +85,7 @@ describe Datagrid::Filters::DateTimeFilter do
|
|
85
85
|
e1 = Entry.create!(:created_at => Time.new(2013, 1, 1, 1, 0))
|
86
86
|
e2 = Entry.create!(:created_at => Time.new(2013, 1, 1, 2, 0))
|
87
87
|
e3 = Entry.create!(:created_at => Time.new(2013, 1, 1, 3, 0))
|
88
|
-
report = test_report(:created_at =>
|
88
|
+
report = test_report(:created_at => Time.new(2013, 1, 1, 2, 0)..Time.new(2013, 1, 1, 2, 0)) do
|
89
89
|
scope { Entry }
|
90
90
|
filter(:created_at, :datetime, :range => true)
|
91
91
|
end
|
@@ -93,18 +93,20 @@ describe Datagrid::Filters::DateTimeFilter do
|
|
93
93
|
expect(report.assets).to include(e2)
|
94
94
|
expect(report.assets).not_to include(e3)
|
95
95
|
end
|
96
|
-
it "should
|
96
|
+
it "should reverse invalid range" do
|
97
97
|
|
98
|
+
range = Time.new(2013, 1, 1, 3, 0)..Time.new(2013, 1, 1, 1, 0)
|
98
99
|
e1 = Entry.create!(:created_at => Time.new(2013, 1, 1, 1, 0))
|
99
100
|
e2 = Entry.create!(:created_at => Time.new(2013, 1, 1, 2, 0))
|
100
101
|
e3 = Entry.create!(:created_at => Time.new(2013, 1, 1, 3, 0))
|
101
|
-
report = test_report(:created_at =>
|
102
|
+
report = test_report(:created_at => range) do
|
102
103
|
scope { Entry }
|
103
104
|
filter(:created_at, :datetime, :range => true)
|
104
105
|
end
|
105
|
-
expect(report.
|
106
|
-
expect(report.assets).
|
107
|
-
expect(report.assets).
|
106
|
+
expect(report.created_at).to eq([range.last, range.first])
|
107
|
+
expect(report.assets).to include(e1)
|
108
|
+
expect(report.assets).to include(e2)
|
109
|
+
expect(report.assets).to include(e3)
|
108
110
|
end
|
109
111
|
|
110
112
|
|
@@ -59,15 +59,17 @@ describe Datagrid::Filters::IntegerFilter do
|
|
59
59
|
expect(report.assets).to include(entry4)
|
60
60
|
expect(report.assets).not_to include(entry1)
|
61
61
|
end
|
62
|
+
|
62
63
|
it "should support invalid range" do
|
63
64
|
|
64
65
|
report = test_report(:group_id => (7..1)) do
|
65
66
|
scope { Entry }
|
66
67
|
filter(:group_id, :integer, :range => true)
|
67
68
|
end
|
68
|
-
expect(report.
|
69
|
-
expect(report.assets).
|
70
|
-
expect(report.assets).
|
69
|
+
expect(report.group_id).to eq([1,7])
|
70
|
+
expect(report.assets).to include(entry7)
|
71
|
+
expect(report.assets).to include(entry4)
|
72
|
+
expect(report.assets).to include(entry1)
|
71
73
|
end
|
72
74
|
|
73
75
|
|
@@ -131,9 +131,9 @@ describe Datagrid::FormBuilder do
|
|
131
131
|
context "with invalid range value" do
|
132
132
|
let(:_range) { 2..1 }
|
133
133
|
it { should equal_to_dom(
|
134
|
-
'<input class="group_id integer_filter from" multiple value="
|
134
|
+
'<input class="group_id integer_filter from" multiple value="1" type="text" name="report[group_id][]"/>' +
|
135
135
|
'<span class="separator integer"> - </span>' +
|
136
|
-
'<input class="group_id integer_filter to" multiple value="
|
136
|
+
'<input class="group_id integer_filter to" multiple value="2" type="text" name="report[group_id][]"/>'
|
137
137
|
)}
|
138
138
|
end
|
139
139
|
|
@@ -243,9 +243,9 @@ describe Datagrid::FormBuilder do
|
|
243
243
|
context "with invalid range value" do
|
244
244
|
let(:_range) { Date.parse('2012-01-02')..Date.parse('2012-01-01') }
|
245
245
|
it { should equal_to_dom(
|
246
|
-
'<input class="created_at date_filter from" multiple value="2012-01-
|
246
|
+
'<input class="created_at date_filter from" multiple value="2012-01-01" type="text" name="report[created_at][]"/>' +
|
247
247
|
'<span class="separator date"> - </span>' +
|
248
|
-
'<input class="created_at date_filter to" multiple value="2012-01-
|
248
|
+
'<input class="created_at date_filter to" multiple value="2012-01-02" type="text" name="report[created_at][]"/>'
|
249
249
|
)}
|
250
250
|
end
|
251
251
|
context "with blank range value" do
|
@@ -15,6 +15,9 @@ describe Datagrid::Helper do
|
|
15
15
|
|
16
16
|
before(:each) do
|
17
17
|
allow(subject).to receive(:params).and_return({})
|
18
|
+
allow(subject).to receive(:request) do
|
19
|
+
Struct.new(:path, :query_parameters).new("/location", {})
|
20
|
+
end
|
18
21
|
allow(subject).to receive(:url_for) do |options|
|
19
22
|
options.is_a?(String) ? options : ["/location", options.to_param.presence].compact.join('?')
|
20
23
|
end
|
data/spec/support/matchers.rb
CHANGED
@@ -70,7 +70,7 @@ class CssPattern
|
|
70
70
|
if !html.match(pattern_or_string)
|
71
71
|
return error!("#{css.inspect} did not match #{pattern_or_string.inspect}. It was \n:#{html.inspect}")
|
72
72
|
end
|
73
|
-
elsif amount_or_pattern_or_string_or_proc.is_a?
|
73
|
+
elsif amount_or_pattern_or_string_or_proc.is_a? Numeric
|
74
74
|
expected_amount = amount_or_pattern_or_string_or_proc
|
75
75
|
amount = path.size
|
76
76
|
if amount != expected_amount
|
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.5.
|
4
|
+
version: 1.5.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: 2017-
|
11
|
+
date: 2017-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|