datagrid 1.1.1 → 1.1.2
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 +5 -5
- data/lib/datagrid/columns.rb +24 -13
- data/lib/datagrid/drivers/abstract_driver.rb +1 -1
- data/lib/datagrid/drivers/active_record.rb +2 -6
- data/lib/datagrid/drivers/array.rb +2 -2
- data/lib/datagrid/drivers/mongo_mapper.rb +3 -4
- data/lib/datagrid/drivers/mongoid.rb +3 -4
- data/spec/datagrid/columns_spec.rb +38 -23
- data/spec/datagrid/drivers/active_record_spec.rb +1 -1
- data/spec/datagrid/form_builder_spec.rb +1 -1
- data/spec/datagrid_spec.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44f9ec4967241697a3299e94ea4c112eee7976a0
|
4
|
+
data.tar.gz: 704336e23cb2865df032a9842a0c74797a43b19b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef2563a325877ffa13f721b5903e5381e064804a35d007e15d5ad279691504886e157c956a56698594351232782a9b9be45afb52038eacfad59f9e3553e31307
|
7
|
+
data.tar.gz: f30f96c8b933c2cc71636f0183615a47c6fe25a0658ea6c4cfd0a6ca738babaf4a1606be3b32071bfc93a505f4d58975327231759f6e70dba57e16830781bfd2
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.2
|
data/datagrid.gemspec
CHANGED
@@ -2,15 +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.1.
|
5
|
+
# stub: datagrid 1.1.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "datagrid"
|
9
|
-
s.version = "1.1.
|
9
|
+
s.version = "1.1.2"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
12
13
|
s.authors = ["Bogdan Gusiev"]
|
13
|
-
s.date = "2014-03-
|
14
|
+
s.date = "2014-03-17"
|
14
15
|
s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters"
|
15
16
|
s.email = "agresso@gmail.com"
|
16
17
|
s.extra_rdoc_files = [
|
@@ -110,8 +111,7 @@ Gem::Specification.new do |s|
|
|
110
111
|
]
|
111
112
|
s.homepage = "http://github.com/bogdan/datagrid"
|
112
113
|
s.licenses = ["MIT"]
|
113
|
-
s.
|
114
|
-
s.rubygems_version = "2.1.10"
|
114
|
+
s.rubygems_version = "2.2.2"
|
115
115
|
s.summary = "Ruby gem to create datagrids"
|
116
116
|
|
117
117
|
if s.respond_to? :specification_version then
|
data/lib/datagrid/columns.rb
CHANGED
@@ -16,7 +16,6 @@ module Datagrid
|
|
16
16
|
self.default_column_options = {}
|
17
17
|
|
18
18
|
class_attribute :batch_size
|
19
|
-
self.batch_size = 1000
|
20
19
|
|
21
20
|
end
|
22
21
|
base.send :include, InstanceMethods
|
@@ -259,18 +258,11 @@ module Datagrid
|
|
259
258
|
# grid.to_csv(:col_sep => ';')
|
260
259
|
def to_csv(*column_names)
|
261
260
|
options = column_names.extract_options!
|
262
|
-
|
263
|
-
require 'csv'
|
264
|
-
CSV
|
265
|
-
else
|
266
|
-
require "fastercsv"
|
267
|
-
FasterCSV
|
268
|
-
end
|
269
|
-
klass.generate(
|
261
|
+
csv_class.generate(
|
270
262
|
{:headers => self.header(*column_names), :write_headers => true}.merge(options)
|
271
263
|
) do |csv|
|
272
|
-
|
273
|
-
csv <<
|
264
|
+
each_with_batches do |asset|
|
265
|
+
csv << row_for(asset, *column_names)
|
274
266
|
end
|
275
267
|
end
|
276
268
|
end
|
@@ -358,10 +350,29 @@ module Datagrid
|
|
358
350
|
protected
|
359
351
|
|
360
352
|
def map_with_batches(&block)
|
353
|
+
result = []
|
354
|
+
each_with_batches do |asset|
|
355
|
+
result << block.call(asset)
|
356
|
+
end
|
357
|
+
result
|
358
|
+
end
|
359
|
+
|
360
|
+
def each_with_batches(&block)
|
361
361
|
if batch_size && batch_size > 0
|
362
|
-
driver.
|
362
|
+
driver.batch_each(assets, batch_size, &block)
|
363
|
+
else
|
364
|
+
assets.each(&block)
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
|
369
|
+
def csv_class
|
370
|
+
if RUBY_VERSION >= "1.9"
|
371
|
+
require 'csv'
|
372
|
+
CSV
|
363
373
|
else
|
364
|
-
|
374
|
+
require "fastercsv"
|
375
|
+
FasterCSV
|
365
376
|
end
|
366
377
|
end
|
367
378
|
|
@@ -101,12 +101,8 @@ module Datagrid
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
def
|
105
|
-
|
106
|
-
scope.find_each(batch_size ? { :batch_size => batch_size} : {}) do |record|
|
107
|
-
result << yield(record)
|
108
|
-
end
|
109
|
-
result
|
104
|
+
def batch_each(scope, batch_size, &block)
|
105
|
+
scope.find_each(batch_size ? { :batch_size => batch_size} : {}, &block)
|
110
106
|
end
|
111
107
|
|
112
108
|
protected
|
@@ -56,14 +56,13 @@ module Datagrid
|
|
56
56
|
[] # TODO: implement support
|
57
57
|
end
|
58
58
|
|
59
|
-
def
|
59
|
+
def batch_each(scope, batch_size, &block)
|
60
60
|
current_page = 0
|
61
|
-
result = []
|
62
61
|
loop do
|
63
62
|
batch = scope.skip(current_page * batch_size).limit(batch_size).to_a
|
64
|
-
return
|
63
|
+
return if batch.empty?
|
65
64
|
scope.skip(current_page * batch_size).limit(batch_size).each do |item|
|
66
|
-
|
65
|
+
yield(item)
|
67
66
|
end
|
68
67
|
current_page+=1
|
69
68
|
end
|
@@ -79,14 +79,13 @@ module Datagrid
|
|
79
79
|
return :string
|
80
80
|
end
|
81
81
|
|
82
|
-
def
|
82
|
+
def batch_each(scope, batch_size, &block)
|
83
83
|
current_page = 0
|
84
|
-
result = []
|
85
84
|
loop do
|
86
85
|
batch = scope.skip(current_page * batch_size).limit(batch_size).to_a
|
87
|
-
return
|
86
|
+
return if batch.empty?
|
88
87
|
scope.skip(current_page * batch_size).limit(batch_size).each do |item|
|
89
|
-
|
88
|
+
yield(item)
|
90
89
|
end
|
91
90
|
current_page+=1
|
92
91
|
end
|
@@ -83,28 +83,6 @@ describe Datagrid::Columns do
|
|
83
83
|
subject.to_csv(:col_sep => ";").should == "Shipping date;Group;Name;Access level;Pet\n#{date};Pop;Star;admin;ROTTWEILER\n"
|
84
84
|
end
|
85
85
|
|
86
|
-
it "should support defining a query for a column" do
|
87
|
-
report = test_report do
|
88
|
-
scope {Entry}
|
89
|
-
filter(:name)
|
90
|
-
column(:id)
|
91
|
-
column(:sum_group_id, 'sum(group_id)')
|
92
|
-
end
|
93
|
-
report.assets.first.sum_group_id.should == group.id
|
94
|
-
end
|
95
|
-
it "should support hidding columns through if and unless" do
|
96
|
-
report = test_report do
|
97
|
-
scope {Entry}
|
98
|
-
column(:id, :if => :show?)
|
99
|
-
column(:name, :unless => proc {|grid| !grid.show? })
|
100
|
-
|
101
|
-
def show?
|
102
|
-
false
|
103
|
-
end
|
104
|
-
end
|
105
|
-
report.columns(:id).should == []
|
106
|
-
report.columns(:name).should == []
|
107
|
-
end
|
108
86
|
end
|
109
87
|
|
110
88
|
it "should support columns with model and report arguments" do
|
@@ -139,6 +117,43 @@ describe Datagrid::Columns do
|
|
139
117
|
child.column_by_name(:name).should_not be_nil
|
140
118
|
child.column_by_name(:group_id).should_not be_nil
|
141
119
|
end
|
120
|
+
it "should support defining a query for a column" do
|
121
|
+
report = test_report do
|
122
|
+
scope {Entry}
|
123
|
+
filter(:name)
|
124
|
+
column(:id)
|
125
|
+
column(:sum_group_id, 'sum(group_id)')
|
126
|
+
end
|
127
|
+
Entry.create!(:group => group)
|
128
|
+
report.assets.first.sum_group_id.should == group.id
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should support post formatting for column defined with query" do
|
132
|
+
report = test_report do
|
133
|
+
scope {Group.joins(:entries).group("groups.id")}
|
134
|
+
filter(:name)
|
135
|
+
column(:entries_count, 'count(entries.id)') do |model|
|
136
|
+
format("(#{model.entries_count})") do |value|
|
137
|
+
content_tag(:span, value)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
3.times { Entry.create!(group: group) }
|
142
|
+
report.rows.should == [["(3)"]]
|
143
|
+
end
|
144
|
+
it "should support hidding columns through if and unless" do
|
145
|
+
report = test_report do
|
146
|
+
scope {Entry}
|
147
|
+
column(:id, :if => :show?)
|
148
|
+
column(:name, :unless => proc {|grid| !grid.show? })
|
149
|
+
|
150
|
+
def show?
|
151
|
+
false
|
152
|
+
end
|
153
|
+
end
|
154
|
+
report.columns(:id).should == []
|
155
|
+
report.columns(:name).should == []
|
156
|
+
end
|
142
157
|
|
143
158
|
describe ".column_names attributes" do
|
144
159
|
let(:grid) do
|
@@ -224,7 +239,7 @@ describe Datagrid::Columns do
|
|
224
239
|
fake_assets = double(:assets)
|
225
240
|
|
226
241
|
report.should_receive(:assets) { fake_assets }
|
227
|
-
fake_assets.should_receive(:
|
242
|
+
fake_assets.should_receive(:each)
|
228
243
|
fake_assets.should_not_receive(:find_each)
|
229
244
|
report.rows
|
230
245
|
end
|
@@ -18,6 +18,6 @@ describe Datagrid::Drivers::ActiveRecord do
|
|
18
18
|
|
19
19
|
it "should support append_column_queries" do
|
20
20
|
scope = subject.append_column_queries(Entry.scoped, [Datagrid::Columns::Column.new(SimpleReport, :sum_group_id, 'sum(entries.group_id)')])
|
21
|
-
scope.to_sql.should == 'SELECT "entries".*, sum(entries.group_id) AS sum_group_id FROM "entries"
|
21
|
+
scope.to_sql.strip.should == 'SELECT "entries".*, sum(entries.group_id) AS sum_group_id FROM "entries"'
|
22
22
|
end
|
23
23
|
end
|
@@ -247,7 +247,7 @@ describe Datagrid::FormBuilder do
|
|
247
247
|
end
|
248
248
|
end
|
249
249
|
let(:_filter) { :category }
|
250
|
-
if
|
250
|
+
if Rails.version >= "4.1"
|
251
251
|
it { should equal_to_dom(
|
252
252
|
'
|
253
253
|
<label class="category enum_filter checkboxes" for="report_category_first"><input id="report_category_first" name="report[category][]" type="checkbox" value="first" />first</label>
|
data/spec/datagrid_spec.rb
CHANGED
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.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdan Gusiev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -324,7 +324,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
324
324
|
version: '0'
|
325
325
|
requirements: []
|
326
326
|
rubyforge_project:
|
327
|
-
rubygems_version: 2.
|
327
|
+
rubygems_version: 2.2.2
|
328
328
|
signing_key:
|
329
329
|
specification_version: 4
|
330
330
|
summary: Ruby gem to create datagrids
|