datagrid 0.3.6 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +14 -14
- data/Gemfile.lock +13 -5
- data/Rakefile +0 -9
- data/Readme.markdown +13 -4
- data/VERSION +1 -1
- data/datagrid.gemspec +42 -33
- data/lib/datagrid/columns/column.rb +1 -1
- data/lib/datagrid/core.rb +8 -5
- data/lib/datagrid/drivers.rb +9 -0
- data/lib/datagrid/drivers/abstract_driver.rb +24 -0
- data/lib/datagrid/drivers/active_record.rb +40 -0
- data/lib/datagrid/drivers/mongoid.rb +35 -0
- data/lib/datagrid/filters.rb +2 -1
- data/lib/datagrid/filters/composite_filters.rb +1 -1
- data/lib/datagrid/helper.rb +3 -3
- data/lib/datagrid/ordering.rb +3 -11
- data/spec/datagrid/drivers/active_record_spec.rb +13 -0
- data/spec/datagrid/drivers/mongoid_spec.rb +56 -0
- data/spec/datagrid/helper_spec.rb +24 -6
- data/spec/datagrid_spec.rb +1 -1
- data/spec/spec_helper.rb +9 -1
- data/spec/support/mongoid.rb +47 -0
- data/spec/support/schema.rb +1 -3
- metadata +102 -82
data/Gemfile
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
2
|
|
6
|
-
|
7
|
-
# Include everything needed to run rake, tests, features, etc.
|
8
|
-
|
9
|
-
gem "rails"
|
3
|
+
gem "rails", ">= 3.0"
|
10
4
|
|
11
5
|
|
12
6
|
|
13
7
|
group :development do
|
14
|
-
|
15
|
-
gem "
|
16
|
-
gem "rspec", "2.6.0"
|
8
|
+
|
9
|
+
gem "rake"
|
17
10
|
gem "bundler", "~> 1.0.0"
|
18
11
|
gem "jeweler", "~> 1.6.0"
|
19
|
-
|
12
|
+
|
20
13
|
gem "ruby-debug", :platform => "mri_18"
|
21
14
|
#gem "ruby-debug19", :platform => "mri_19"
|
15
|
+
|
16
|
+
gem "mocha"
|
17
|
+
gem "rspec", "2.6.0"
|
18
|
+
gem "accept_values_for"
|
19
|
+
gem "nokogiri" # used to test html output
|
20
|
+
|
22
21
|
gem "sqlite3-ruby"
|
23
|
-
gem "fastercsv"
|
24
|
-
gem "nokogiri"
|
25
22
|
gem 'will_paginate', '2.3.15'
|
26
|
-
gem "accept_values_for"
|
27
23
|
|
24
|
+
gem "mongoid", "2.2.3"
|
25
|
+
gem "bson_ext"
|
26
|
+
|
27
|
+
gem "fastercsv", :platform => "mri_18"
|
28
28
|
end
|
data/Gemfile.lock
CHANGED
@@ -32,6 +32,8 @@ GEM
|
|
32
32
|
activesupport (= 3.0.7)
|
33
33
|
activesupport (3.0.7)
|
34
34
|
arel (2.0.10)
|
35
|
+
bson (1.4.1)
|
36
|
+
bson_ext (1.4.1)
|
35
37
|
builder (2.1.2)
|
36
38
|
columnize (0.3.2)
|
37
39
|
diff-lcs (1.1.2)
|
@@ -52,6 +54,12 @@ GEM
|
|
52
54
|
treetop (~> 1.4.8)
|
53
55
|
mime-types (1.16)
|
54
56
|
mocha (0.9.12)
|
57
|
+
mongo (1.4.1)
|
58
|
+
bson (= 1.4.1)
|
59
|
+
mongoid (2.2.3)
|
60
|
+
activemodel (~> 3.0)
|
61
|
+
mongo (~> 1.3)
|
62
|
+
tzinfo (~> 0.3.22)
|
55
63
|
nokogiri (1.4.4)
|
56
64
|
polyglot (0.3.1)
|
57
65
|
rack (1.2.3)
|
@@ -72,8 +80,7 @@ GEM
|
|
72
80
|
activesupport (= 3.0.7)
|
73
81
|
rake (>= 0.8.7)
|
74
82
|
thor (~> 0.14.4)
|
75
|
-
rake (0.
|
76
|
-
rcov (0.9.9)
|
83
|
+
rake (0.9.2.2)
|
77
84
|
rspec (2.6.0)
|
78
85
|
rspec-core (~> 2.6.0)
|
79
86
|
rspec-expectations (~> 2.6.0)
|
@@ -101,14 +108,15 @@ PLATFORMS
|
|
101
108
|
|
102
109
|
DEPENDENCIES
|
103
110
|
accept_values_for
|
111
|
+
bson_ext
|
104
112
|
bundler (~> 1.0.0)
|
105
113
|
fastercsv
|
106
114
|
jeweler (~> 1.6.0)
|
107
115
|
mocha
|
116
|
+
mongoid (= 2.2.3)
|
108
117
|
nokogiri
|
109
|
-
rails
|
110
|
-
rake
|
111
|
-
rcov
|
118
|
+
rails (>= 3.0)
|
119
|
+
rake
|
112
120
|
rspec (= 2.6.0)
|
113
121
|
ruby-debug
|
114
122
|
sqlite3-ruby
|
data/Rakefile
CHANGED
@@ -38,12 +38,3 @@ end
|
|
38
38
|
|
39
39
|
task :default => :spec
|
40
40
|
|
41
|
-
require 'rake/rdoctask'
|
42
|
-
Rake::RDocTask.new do |rdoc|
|
43
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
-
|
45
|
-
rdoc.rdoc_dir = 'rdoc'
|
46
|
-
rdoc.title = "datagrid #{version}"
|
47
|
-
rdoc.rdoc_files.include('README*')
|
48
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
-
end
|
data/Readme.markdown
CHANGED
@@ -13,16 +13,25 @@ Ruby library that helps you to build and represent table-like data with:
|
|
13
13
|
|
14
14
|
In order to create a report, you need to define:
|
15
15
|
|
16
|
-
* scope of
|
16
|
+
* scope of objects to look through
|
17
17
|
* filters that will be used to filter data
|
18
18
|
* columns that should be displayed and sortable (if possible)
|
19
19
|
|
20
20
|
|
21
|
-
###
|
21
|
+
### ORM Support
|
22
|
+
|
23
|
+
* ActiveRecord
|
24
|
+
* Mongoid (beta)
|
25
|
+
|
26
|
+
[Create an issue](https://github.com/bogdan/datagrid/issues/new) if you want more.
|
27
|
+
|
28
|
+
### Live Demo
|
22
29
|
|
23
30
|
[Datagrid DEMO application](http://datagrid.heroku.com) is available live!
|
24
31
|
[Demo source code](https://github.com/bogdan/datagrid-demo).
|
25
32
|
|
33
|
+
### Example
|
34
|
+
|
26
35
|
In order to create a grid:
|
27
36
|
|
28
37
|
``` ruby
|
@@ -83,7 +92,7 @@ report.to_csv # => Yes, it is
|
|
83
92
|
### Scope
|
84
93
|
|
85
94
|
Default scope of objects to filter and display.
|
86
|
-
In common case it is `ActiveRecord::Base` subclass with some generic scopes like in example above:
|
95
|
+
In common case it is `ActiveRecord::Base` (or any other supported ORM) subclass with some generic scopes like in example above:
|
87
96
|
|
88
97
|
``` ruby
|
89
98
|
scope do
|
@@ -164,7 +173,7 @@ end
|
|
164
173
|
```
|
165
174
|
|
166
175
|
There is a simple helper set of helpers that allows you display report:
|
167
|
-
(require
|
176
|
+
(require any pagination gem, will\_paginate is used as an example)
|
168
177
|
|
169
178
|
``` haml
|
170
179
|
- assets = @report.assets.paginate(:page => params[:page])
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/datagrid.gemspec
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.
|
7
|
+
s.name = "datagrid"
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Bogdan Gusiev"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2011-11-03"
|
13
|
+
s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters"
|
14
|
+
s.email = "agresso@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt"
|
17
17
|
]
|
@@ -30,6 +30,10 @@ Gem::Specification.new do |s|
|
|
30
30
|
"lib/datagrid/columns.rb",
|
31
31
|
"lib/datagrid/columns/column.rb",
|
32
32
|
"lib/datagrid/core.rb",
|
33
|
+
"lib/datagrid/drivers.rb",
|
34
|
+
"lib/datagrid/drivers/abstract_driver.rb",
|
35
|
+
"lib/datagrid/drivers/active_record.rb",
|
36
|
+
"lib/datagrid/drivers/mongoid.rb",
|
33
37
|
"lib/datagrid/filters.rb",
|
34
38
|
"lib/datagrid/filters/base_filter.rb",
|
35
39
|
"lib/datagrid/filters/boolean_enum_filter.rb",
|
@@ -48,6 +52,8 @@ Gem::Specification.new do |s|
|
|
48
52
|
"lib/datagrid/utils.rb",
|
49
53
|
"spec/datagrid/active_model_spec.rb",
|
50
54
|
"spec/datagrid/columns_spec.rb",
|
55
|
+
"spec/datagrid/drivers/active_record_spec.rb",
|
56
|
+
"spec/datagrid/drivers/mongoid_spec.rb",
|
51
57
|
"spec/datagrid/filters/composite_filters_spec.rb",
|
52
58
|
"spec/datagrid/filters/enum_filter_spec.rb",
|
53
59
|
"spec/datagrid/filters_spec.rb",
|
@@ -57,62 +63,65 @@ Gem::Specification.new do |s|
|
|
57
63
|
"spec/datagrid_spec.rb",
|
58
64
|
"spec/spec_helper.rb",
|
59
65
|
"spec/support/equal_to_dom.rb",
|
66
|
+
"spec/support/mongoid.rb",
|
60
67
|
"spec/support/schema.rb",
|
61
68
|
"spec/support/simple_report.rb"
|
62
69
|
]
|
63
|
-
s.homepage =
|
70
|
+
s.homepage = "http://github.com/bogdan/datagrid"
|
64
71
|
s.licenses = ["MIT"]
|
65
72
|
s.require_paths = ["lib"]
|
66
|
-
s.rubygems_version =
|
67
|
-
s.summary =
|
73
|
+
s.rubygems_version = "1.8.11"
|
74
|
+
s.summary = "Ruby gem to create datagrids"
|
68
75
|
|
69
76
|
if s.respond_to? :specification_version then
|
70
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
71
77
|
s.specification_version = 3
|
72
78
|
|
73
79
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
74
|
-
s.add_runtime_dependency(%q<rails>, [">= 0"])
|
75
|
-
s.add_development_dependency(%q<rake>, ["
|
76
|
-
s.add_development_dependency(%q<mocha>, [">= 0"])
|
77
|
-
s.add_development_dependency(%q<rspec>, ["= 2.6.0"])
|
80
|
+
s.add_runtime_dependency(%q<rails>, [">= 3.0"])
|
81
|
+
s.add_development_dependency(%q<rake>, [">= 0"])
|
78
82
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
79
83
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
|
80
|
-
s.add_development_dependency(%q<rcov>, [">= 0"])
|
81
84
|
s.add_development_dependency(%q<ruby-debug>, [">= 0"])
|
82
|
-
s.add_development_dependency(%q<
|
83
|
-
s.add_development_dependency(%q<
|
85
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
86
|
+
s.add_development_dependency(%q<rspec>, ["= 2.6.0"])
|
87
|
+
s.add_development_dependency(%q<accept_values_for>, [">= 0"])
|
84
88
|
s.add_development_dependency(%q<nokogiri>, [">= 0"])
|
89
|
+
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
|
85
90
|
s.add_development_dependency(%q<will_paginate>, ["= 2.3.15"])
|
86
|
-
s.add_development_dependency(%q<
|
91
|
+
s.add_development_dependency(%q<mongoid>, ["= 2.2.3"])
|
92
|
+
s.add_development_dependency(%q<bson_ext>, [">= 0"])
|
93
|
+
s.add_development_dependency(%q<fastercsv>, [">= 0"])
|
87
94
|
else
|
88
|
-
s.add_dependency(%q<rails>, [">= 0"])
|
89
|
-
s.add_dependency(%q<rake>, ["
|
90
|
-
s.add_dependency(%q<mocha>, [">= 0"])
|
91
|
-
s.add_dependency(%q<rspec>, ["= 2.6.0"])
|
95
|
+
s.add_dependency(%q<rails>, [">= 3.0"])
|
96
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
92
97
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
93
98
|
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
94
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
95
99
|
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
96
|
-
s.add_dependency(%q<
|
97
|
-
s.add_dependency(%q<
|
100
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
101
|
+
s.add_dependency(%q<rspec>, ["= 2.6.0"])
|
102
|
+
s.add_dependency(%q<accept_values_for>, [">= 0"])
|
98
103
|
s.add_dependency(%q<nokogiri>, [">= 0"])
|
104
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
99
105
|
s.add_dependency(%q<will_paginate>, ["= 2.3.15"])
|
100
|
-
s.add_dependency(%q<
|
106
|
+
s.add_dependency(%q<mongoid>, ["= 2.2.3"])
|
107
|
+
s.add_dependency(%q<bson_ext>, [">= 0"])
|
108
|
+
s.add_dependency(%q<fastercsv>, [">= 0"])
|
101
109
|
end
|
102
110
|
else
|
103
|
-
s.add_dependency(%q<rails>, [">= 0"])
|
104
|
-
s.add_dependency(%q<rake>, ["
|
105
|
-
s.add_dependency(%q<mocha>, [">= 0"])
|
106
|
-
s.add_dependency(%q<rspec>, ["= 2.6.0"])
|
111
|
+
s.add_dependency(%q<rails>, [">= 3.0"])
|
112
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
107
113
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
108
114
|
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
109
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
110
115
|
s.add_dependency(%q<ruby-debug>, [">= 0"])
|
111
|
-
s.add_dependency(%q<
|
112
|
-
s.add_dependency(%q<
|
116
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
117
|
+
s.add_dependency(%q<rspec>, ["= 2.6.0"])
|
118
|
+
s.add_dependency(%q<accept_values_for>, [">= 0"])
|
113
119
|
s.add_dependency(%q<nokogiri>, [">= 0"])
|
120
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
114
121
|
s.add_dependency(%q<will_paginate>, ["= 2.3.15"])
|
115
|
-
s.add_dependency(%q<
|
122
|
+
s.add_dependency(%q<mongoid>, ["= 2.2.3"])
|
123
|
+
s.add_dependency(%q<bson_ext>, [">= 0"])
|
124
|
+
s.add_dependency(%q<fastercsv>, [">= 0"])
|
116
125
|
end
|
117
126
|
end
|
118
127
|
|
data/lib/datagrid/core.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "datagrid/drivers"
|
2
2
|
|
3
3
|
module Datagrid
|
4
4
|
module Core
|
@@ -42,6 +42,9 @@ module Datagrid
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
def driver
|
46
|
+
@driver ||= Drivers::AbstractDriver.guess_driver(scope).new
|
47
|
+
end
|
45
48
|
|
46
49
|
protected
|
47
50
|
def check_scope_defined!(message = "Scope not defined")
|
@@ -77,7 +80,7 @@ module Datagrid
|
|
77
80
|
end
|
78
81
|
|
79
82
|
def assets
|
80
|
-
|
83
|
+
driver.to_scope(scope)
|
81
84
|
end
|
82
85
|
|
83
86
|
def attributes=(attributes)
|
@@ -94,9 +97,9 @@ module Datagrid
|
|
94
97
|
self.class.scope
|
95
98
|
end
|
96
99
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
+
def driver
|
101
|
+
self.class.driver
|
102
|
+
end
|
100
103
|
|
101
104
|
def check_scope_defined!(message)
|
102
105
|
self.class.check_scope_defined!(message)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Datagrid
|
2
|
+
module Drivers
|
3
|
+
class AbstractDriver
|
4
|
+
|
5
|
+
class_attribute :subclasses
|
6
|
+
|
7
|
+
def self.inherited(base)
|
8
|
+
super(base)
|
9
|
+
self.subclasses ||= []
|
10
|
+
self.subclasses << base
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.guess_driver(scope)
|
14
|
+
klass = self.subclasses.find do |driver_class|
|
15
|
+
driver_class.match?(scope)
|
16
|
+
end || raise(Datagrid::ConfigurationError, "ORM Driver not found for scope: #{scope.inspect}.")
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
#TODO api declaration
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Datagrid
|
2
|
+
module Drivers
|
3
|
+
class ActiveRecord < AbstractDriver
|
4
|
+
|
5
|
+
def self.match?(scope)
|
6
|
+
if scope.is_a?(Class)
|
7
|
+
scope.ancestors.include?(::ActiveRecord::Base)
|
8
|
+
else
|
9
|
+
scope.is_a?(::ActiveRecord::Relation)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_scope(scope)
|
14
|
+
scope.scoped({})
|
15
|
+
end
|
16
|
+
|
17
|
+
def where(scope, condition)
|
18
|
+
scope.where(condition)
|
19
|
+
end
|
20
|
+
|
21
|
+
def asc(scope, order)
|
22
|
+
# Rails 3.x.x don't able to override already applied order
|
23
|
+
# Using #reorder instead
|
24
|
+
scope.reorder(order)
|
25
|
+
end
|
26
|
+
|
27
|
+
def desc(scope, order)
|
28
|
+
scope.reorder(order).reverse_order
|
29
|
+
end
|
30
|
+
|
31
|
+
def table_name(scope)
|
32
|
+
scope.table_name
|
33
|
+
end
|
34
|
+
|
35
|
+
def default_order(scope, column_name)
|
36
|
+
scope.column_names.include?(column_name.to_s) ? [scope.table_name, column_name].join(".") : nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Datagrid
|
2
|
+
module Drivers
|
3
|
+
class Mongoid < AbstractDriver
|
4
|
+
|
5
|
+
def self.match?(scope)
|
6
|
+
if scope.is_a?(Class)
|
7
|
+
scope.ancestors.include?(::Mongoid::Document)
|
8
|
+
else
|
9
|
+
scope.is_a?(::Mongoid::Criteria)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_scope(scope)
|
14
|
+
scope.where
|
15
|
+
end
|
16
|
+
|
17
|
+
def where(scope, condition)
|
18
|
+
scope.where(condition)
|
19
|
+
end
|
20
|
+
|
21
|
+
def asc(scope, order)
|
22
|
+
scope.asc(order)
|
23
|
+
end
|
24
|
+
|
25
|
+
def desc(scope, order)
|
26
|
+
scope.desc(order)
|
27
|
+
end
|
28
|
+
|
29
|
+
def default_order(scope, column_name)
|
30
|
+
column_name
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/datagrid/filters.rb
CHANGED
@@ -67,8 +67,9 @@ module Datagrid
|
|
67
67
|
protected
|
68
68
|
def default_filter(attribute)
|
69
69
|
check_scope_defined!("Scope should be defined before filters")
|
70
|
+
grid = self
|
70
71
|
lambda do |value|
|
71
|
-
|
72
|
+
grid.driver.where(grid.scope, attribute => value)
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
data/lib/datagrid/helper.rb
CHANGED
@@ -21,7 +21,7 @@ module Datagrid
|
|
21
21
|
options = args.extract_options!
|
22
22
|
html = options[:html] || {}
|
23
23
|
html[:class] ||= "datagrid"
|
24
|
-
assets = report.assets
|
24
|
+
assets = args.any? ? args.shift : report.assets
|
25
25
|
paginate = options[:paginate]
|
26
26
|
assets = assets.paginate(paginate) if paginate
|
27
27
|
content = content_tag(:tr, datagrid_header(report, options)) + datagrid_rows(report, assets, options)
|
@@ -37,7 +37,7 @@ module Datagrid
|
|
37
37
|
if options[:order] && column.order
|
38
38
|
data << datagrid_order_for(grid, column)
|
39
39
|
end
|
40
|
-
header << content_tag(:th, data)
|
40
|
+
header << content_tag(:th, data, :class => column.name)
|
41
41
|
end
|
42
42
|
header
|
43
43
|
end
|
@@ -46,7 +46,7 @@ module Datagrid
|
|
46
46
|
columns = report.columns
|
47
47
|
result = assets.map do |asset|
|
48
48
|
content = columns.map do |column|
|
49
|
-
content_tag(:td, datagrid_format_value(report, column, asset))
|
49
|
+
content_tag(:td, datagrid_format_value(report, column, asset), :class => column.name)
|
50
50
|
end.join(empty_string)
|
51
51
|
content_tag(:tr, _safe(content), :class => options[:cycle] && cycle(*options[:cycle]))
|
52
52
|
end.join(empty_string)
|
data/lib/datagrid/ordering.rb
CHANGED
@@ -61,23 +61,15 @@ module Datagrid
|
|
61
61
|
|
62
62
|
def apply_order(assets, column)
|
63
63
|
|
64
|
-
# Rails 3.0.x don't able to override already applied order
|
65
|
-
# Using #reorder instead
|
66
|
-
order_method = assets.respond_to?(:reorder) ? :reorder : :order # Rails 3?
|
67
|
-
|
68
64
|
order = column.order
|
69
65
|
if self.descending?
|
70
66
|
if column.order_desc
|
71
|
-
|
67
|
+
driver.asc(assets, column.order_desc)
|
72
68
|
else
|
73
|
-
|
74
|
-
assets.reorder(order).reverse_order
|
75
|
-
else
|
76
|
-
assets.order(ActiveRecord::Base.send(:reverse_sql_order, order))
|
77
|
-
end
|
69
|
+
driver.desc(assets, order)
|
78
70
|
end
|
79
71
|
else
|
80
|
-
|
72
|
+
driver.asc(assets, order)
|
81
73
|
end
|
82
74
|
end
|
83
75
|
|
@@ -0,0 +1,56 @@
|
|
1
|
+
describe Datagrid::Drivers::Mongoid do
|
2
|
+
|
3
|
+
describe ".match?" do
|
4
|
+
|
5
|
+
subject { described_class }
|
6
|
+
|
7
|
+
it {should be_match(MongoidEntry)}
|
8
|
+
it {should be_match(MongoidEntry.scoped)}
|
9
|
+
it {should_not be_match(Entry.scoped)}
|
10
|
+
|
11
|
+
end
|
12
|
+
describe "api" do
|
13
|
+
|
14
|
+
subject do
|
15
|
+
MongoidGrid.new(
|
16
|
+
defined?(_attributes) ? _attributes : {}
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
let!(:first) do
|
21
|
+
MongoidEntry.create!(
|
22
|
+
:group_id => 2,
|
23
|
+
:name => "Main First",
|
24
|
+
:disabled => false
|
25
|
+
)
|
26
|
+
end
|
27
|
+
let!(:second) do
|
28
|
+
MongoidEntry.create!(
|
29
|
+
:group_id => 3,
|
30
|
+
:name => "Main Second",
|
31
|
+
:disabled => true
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
its(:assets) {should include(first, second)}
|
37
|
+
|
38
|
+
its(:"assets.size") {should == 2}
|
39
|
+
its(:rows) {should == [["Main First", 2, false], ["Main Second", 3, true]]}
|
40
|
+
its(:header) {should ==[ "Name", "Group", "Disabled"]}
|
41
|
+
|
42
|
+
its(:data) {should == [[ "Name", "Group", "Disabled"], ["Main First", 2, false], ["Main Second", 3, true]]}
|
43
|
+
|
44
|
+
|
45
|
+
describe "when some filters specified" do
|
46
|
+
let(:_attributes) { {:group_id => 2} }
|
47
|
+
its(:assets) {should include(first)}
|
48
|
+
its(:assets) {should_not include(second)}
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "when reverse ordering is specified" do
|
52
|
+
let(:_attributes) { {:order => :name, :descending => true} }
|
53
|
+
its(:rows) {should == [["Main Second", 3, true], ["Main First", 2, false]]}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -28,15 +28,33 @@ describe Datagrid::Helper do
|
|
28
28
|
subject.datagrid_table(grid).should equal_to_dom(<<-HTML)
|
29
29
|
<table class="datagrid">
|
30
30
|
<tr>
|
31
|
-
<th>Group<div class="order"></div>
|
31
|
+
<th class="group">Group<div class="order"></div>
|
32
32
|
</th>
|
33
|
-
<th>Name<div class="order"></div>
|
33
|
+
<th class="name">Name<div class="order"></div>
|
34
34
|
</th>
|
35
35
|
</tr>
|
36
36
|
|
37
37
|
<tr>
|
38
|
-
<td>Pop</td>
|
39
|
-
<td>Star</td>
|
38
|
+
<td class="group">Pop</td>
|
39
|
+
<td class="name">Star</td>
|
40
|
+
</tr>
|
41
|
+
</table>
|
42
|
+
HTML
|
43
|
+
end
|
44
|
+
it "should support giving assets explicitly" do
|
45
|
+
other_entry = Entry.create!(entry.attributes)
|
46
|
+
subject.datagrid_table(grid, [entry]).should equal_to_dom(<<-HTML)
|
47
|
+
<table class="datagrid">
|
48
|
+
<tr>
|
49
|
+
<th class="group">Group<div class="order"></div>
|
50
|
+
</th>
|
51
|
+
<th class="name">Name<div class="order"></div>
|
52
|
+
</th>
|
53
|
+
</tr>
|
54
|
+
|
55
|
+
<tr>
|
56
|
+
<td class="group">Pop</td>
|
57
|
+
<td class="name">Star</td>
|
40
58
|
</tr>
|
41
59
|
</table>
|
42
60
|
HTML
|
@@ -45,8 +63,8 @@ HTML
|
|
45
63
|
it "should support cycle option" do
|
46
64
|
subject.datagrid_rows(grid, [entry], :cycle => ["odd", "even"]).should equal_to_dom(<<-HTML)
|
47
65
|
<tr class="odd">
|
48
|
-
<td>Pop</td>
|
49
|
-
<td>Star</td>
|
66
|
+
<td class="group">Pop</td>
|
67
|
+
<td class="name">Star</td>
|
50
68
|
</tr>
|
51
69
|
HTML
|
52
70
|
end
|
data/spec/datagrid_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler'
|
3
|
+
|
3
4
|
begin
|
4
5
|
Bundler.setup(:default, :development)
|
5
6
|
rescue Bundler::BundlerError => e
|
@@ -7,19 +8,24 @@ rescue Bundler::BundlerError => e
|
|
7
8
|
$stderr.puts "Run `bundle install` to install missing gems"
|
8
9
|
exit e.status_code
|
9
10
|
end
|
11
|
+
|
10
12
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
11
13
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
12
14
|
|
13
15
|
require "active_record"
|
14
16
|
require "will_paginate"
|
17
|
+
require "mongoid"
|
15
18
|
require 'datagrid'
|
16
19
|
require "discover"
|
17
20
|
begin
|
18
|
-
|
21
|
+
require 'ruby-debug'
|
19
22
|
rescue
|
20
23
|
end
|
21
24
|
require 'rspec'
|
25
|
+
require "logger"
|
22
26
|
|
27
|
+
File.open('spec.log', "w").close
|
28
|
+
TEST_LOGGER = Logger.new('spec.log')
|
23
29
|
|
24
30
|
RSpec.configure do |config|
|
25
31
|
|
@@ -28,6 +34,7 @@ RSpec.configure do |config|
|
|
28
34
|
#TODO better database truncation
|
29
35
|
Group.delete_all
|
30
36
|
Entry.delete_all
|
37
|
+
MongoidEntry.delete_all
|
31
38
|
|
32
39
|
end
|
33
40
|
|
@@ -39,4 +46,5 @@ end
|
|
39
46
|
# Requires supporting files with custom matchers and macros, etc,
|
40
47
|
# in ./support/ and its subdirectories.
|
41
48
|
Dir["#{File.dirname(__FILE__)}/support/schema.rb"].each {|f| require f}
|
49
|
+
Dir["#{File.dirname(__FILE__)}/support/mongoid.rb"].each {|f| require f}
|
42
50
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require 'mongoid'
|
3
|
+
|
4
|
+
|
5
|
+
Mongoid.from_hash({
|
6
|
+
"host" => "localhost",
|
7
|
+
"database" =>"datagrid_mongoid",
|
8
|
+
"autocreate_indexes" => true,
|
9
|
+
})
|
10
|
+
|
11
|
+
#Mongoid.logger = TEST_LOGGER #TODO: understand why still output to STDOUT
|
12
|
+
Mongoid.logger = nil
|
13
|
+
|
14
|
+
|
15
|
+
class MongoidEntry
|
16
|
+
|
17
|
+
include Mongoid::Document
|
18
|
+
include Mongoid::Timestamps
|
19
|
+
|
20
|
+
field :group_id, :type => Integer
|
21
|
+
field :name, :type => String
|
22
|
+
field :category, :type => String
|
23
|
+
field :disabled, :default => false, :type => Boolean
|
24
|
+
field :confirmed, :default => false, :type => Boolean
|
25
|
+
field :shipping_date, :type => DateTime
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
class MongoidGrid
|
30
|
+
include ::Datagrid
|
31
|
+
|
32
|
+
scope do
|
33
|
+
MongoidEntry
|
34
|
+
end
|
35
|
+
|
36
|
+
filter :name
|
37
|
+
filter :group_id do |value|
|
38
|
+
where(:group_id => value)
|
39
|
+
end
|
40
|
+
filter :disabled, :eboolean
|
41
|
+
|
42
|
+
column :name
|
43
|
+
column :group_id
|
44
|
+
column :disabled
|
45
|
+
|
46
|
+
end
|
47
|
+
|
data/spec/support/schema.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
require "logger"
|
2
1
|
|
3
2
|
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
4
3
|
ActiveRecord::Base.configurations = true
|
5
4
|
|
6
|
-
|
7
|
-
ActiveRecord::Base.logger = Logger.new('spec.log')
|
5
|
+
ActiveRecord::Base.logger = TEST_LOGGER
|
8
6
|
|
9
7
|
|
10
8
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datagrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bogdan Gusiev
|
@@ -15,41 +15,26 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-11-03 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
21
|
+
type: :runtime
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
23
|
none: false
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
hash:
|
27
|
+
hash: 7
|
28
28
|
segments:
|
29
|
+
- 3
|
29
30
|
- 0
|
30
|
-
version: "0"
|
31
|
-
requirement: *id001
|
32
|
-
type: :runtime
|
33
|
-
name: rails
|
31
|
+
version: "3.0"
|
34
32
|
prerelease: false
|
33
|
+
name: rails
|
34
|
+
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
version_requirements: &id002 !ruby/object:Gem::Requirement
|
37
|
-
none: false
|
38
|
-
requirements:
|
39
|
-
- - "="
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
hash: 49
|
42
|
-
segments:
|
43
|
-
- 0
|
44
|
-
- 8
|
45
|
-
- 7
|
46
|
-
version: 0.8.7
|
47
|
-
requirement: *id002
|
48
36
|
type: :development
|
49
|
-
|
50
|
-
prerelease: false
|
51
|
-
- !ruby/object:Gem::Dependency
|
52
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
53
38
|
none: false
|
54
39
|
requirements:
|
55
40
|
- - ">="
|
@@ -58,28 +43,12 @@ dependencies:
|
|
58
43
|
segments:
|
59
44
|
- 0
|
60
45
|
version: "0"
|
61
|
-
requirement: *id003
|
62
|
-
type: :development
|
63
|
-
name: mocha
|
64
46
|
prerelease: false
|
47
|
+
name: rake
|
48
|
+
version_requirements: *id002
|
65
49
|
- !ruby/object:Gem::Dependency
|
66
|
-
version_requirements: &id004 !ruby/object:Gem::Requirement
|
67
|
-
none: false
|
68
|
-
requirements:
|
69
|
-
- - "="
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
hash: 23
|
72
|
-
segments:
|
73
|
-
- 2
|
74
|
-
- 6
|
75
|
-
- 0
|
76
|
-
version: 2.6.0
|
77
|
-
requirement: *id004
|
78
50
|
type: :development
|
79
|
-
|
80
|
-
prerelease: false
|
81
|
-
- !ruby/object:Gem::Dependency
|
82
|
-
version_requirements: &id005 !ruby/object:Gem::Requirement
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
83
52
|
none: false
|
84
53
|
requirements:
|
85
54
|
- - ~>
|
@@ -90,12 +59,12 @@ dependencies:
|
|
90
59
|
- 0
|
91
60
|
- 0
|
92
61
|
version: 1.0.0
|
93
|
-
requirement: *id005
|
94
|
-
type: :development
|
95
|
-
name: bundler
|
96
62
|
prerelease: false
|
63
|
+
name: bundler
|
64
|
+
version_requirements: *id003
|
97
65
|
- !ruby/object:Gem::Dependency
|
98
|
-
|
66
|
+
type: :development
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
99
68
|
none: false
|
100
69
|
requirements:
|
101
70
|
- - ~>
|
@@ -106,12 +75,12 @@ dependencies:
|
|
106
75
|
- 6
|
107
76
|
- 0
|
108
77
|
version: 1.6.0
|
109
|
-
requirement: *id006
|
110
|
-
type: :development
|
111
|
-
name: jeweler
|
112
78
|
prerelease: false
|
79
|
+
name: jeweler
|
80
|
+
version_requirements: *id004
|
113
81
|
- !ruby/object:Gem::Dependency
|
114
|
-
|
82
|
+
type: :development
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
115
84
|
none: false
|
116
85
|
requirements:
|
117
86
|
- - ">="
|
@@ -120,12 +89,12 @@ dependencies:
|
|
120
89
|
segments:
|
121
90
|
- 0
|
122
91
|
version: "0"
|
123
|
-
requirement: *id007
|
124
|
-
type: :development
|
125
|
-
name: rcov
|
126
92
|
prerelease: false
|
93
|
+
name: ruby-debug
|
94
|
+
version_requirements: *id005
|
127
95
|
- !ruby/object:Gem::Dependency
|
128
|
-
|
96
|
+
type: :development
|
97
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
129
98
|
none: false
|
130
99
|
requirements:
|
131
100
|
- - ">="
|
@@ -134,12 +103,28 @@ dependencies:
|
|
134
103
|
segments:
|
135
104
|
- 0
|
136
105
|
version: "0"
|
137
|
-
|
106
|
+
prerelease: false
|
107
|
+
name: mocha
|
108
|
+
version_requirements: *id006
|
109
|
+
- !ruby/object:Gem::Dependency
|
138
110
|
type: :development
|
139
|
-
|
111
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - "="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
hash: 23
|
117
|
+
segments:
|
118
|
+
- 2
|
119
|
+
- 6
|
120
|
+
- 0
|
121
|
+
version: 2.6.0
|
140
122
|
prerelease: false
|
123
|
+
name: rspec
|
124
|
+
version_requirements: *id007
|
141
125
|
- !ruby/object:Gem::Dependency
|
142
|
-
|
126
|
+
type: :development
|
127
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
143
128
|
none: false
|
144
129
|
requirements:
|
145
130
|
- - ">="
|
@@ -148,12 +133,12 @@ dependencies:
|
|
148
133
|
segments:
|
149
134
|
- 0
|
150
135
|
version: "0"
|
151
|
-
requirement: *id009
|
152
|
-
type: :development
|
153
|
-
name: sqlite3-ruby
|
154
136
|
prerelease: false
|
137
|
+
name: accept_values_for
|
138
|
+
version_requirements: *id008
|
155
139
|
- !ruby/object:Gem::Dependency
|
156
|
-
|
140
|
+
type: :development
|
141
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
157
142
|
none: false
|
158
143
|
requirements:
|
159
144
|
- - ">="
|
@@ -162,12 +147,12 @@ dependencies:
|
|
162
147
|
segments:
|
163
148
|
- 0
|
164
149
|
version: "0"
|
165
|
-
requirement: *id010
|
166
|
-
type: :development
|
167
|
-
name: fastercsv
|
168
150
|
prerelease: false
|
151
|
+
name: nokogiri
|
152
|
+
version_requirements: *id009
|
169
153
|
- !ruby/object:Gem::Dependency
|
170
|
-
|
154
|
+
type: :development
|
155
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
171
156
|
none: false
|
172
157
|
requirements:
|
173
158
|
- - ">="
|
@@ -176,12 +161,12 @@ dependencies:
|
|
176
161
|
segments:
|
177
162
|
- 0
|
178
163
|
version: "0"
|
179
|
-
requirement: *id011
|
180
|
-
type: :development
|
181
|
-
name: nokogiri
|
182
164
|
prerelease: false
|
165
|
+
name: sqlite3-ruby
|
166
|
+
version_requirements: *id010
|
183
167
|
- !ruby/object:Gem::Dependency
|
184
|
-
|
168
|
+
type: :development
|
169
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
185
170
|
none: false
|
186
171
|
requirements:
|
187
172
|
- - "="
|
@@ -192,12 +177,28 @@ dependencies:
|
|
192
177
|
- 3
|
193
178
|
- 15
|
194
179
|
version: 2.3.15
|
195
|
-
|
196
|
-
type: :development
|
180
|
+
prerelease: false
|
197
181
|
name: will_paginate
|
182
|
+
version_requirements: *id011
|
183
|
+
- !ruby/object:Gem::Dependency
|
184
|
+
type: :development
|
185
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
186
|
+
none: false
|
187
|
+
requirements:
|
188
|
+
- - "="
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
hash: 1
|
191
|
+
segments:
|
192
|
+
- 2
|
193
|
+
- 2
|
194
|
+
- 3
|
195
|
+
version: 2.2.3
|
198
196
|
prerelease: false
|
197
|
+
name: mongoid
|
198
|
+
version_requirements: *id012
|
199
199
|
- !ruby/object:Gem::Dependency
|
200
|
-
|
200
|
+
type: :development
|
201
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
201
202
|
none: false
|
202
203
|
requirements:
|
203
204
|
- - ">="
|
@@ -206,10 +207,23 @@ dependencies:
|
|
206
207
|
segments:
|
207
208
|
- 0
|
208
209
|
version: "0"
|
209
|
-
|
210
|
+
prerelease: false
|
211
|
+
name: bson_ext
|
212
|
+
version_requirements: *id013
|
213
|
+
- !ruby/object:Gem::Dependency
|
210
214
|
type: :development
|
211
|
-
|
215
|
+
requirement: &id014 !ruby/object:Gem::Requirement
|
216
|
+
none: false
|
217
|
+
requirements:
|
218
|
+
- - ">="
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
hash: 3
|
221
|
+
segments:
|
222
|
+
- 0
|
223
|
+
version: "0"
|
212
224
|
prerelease: false
|
225
|
+
name: fastercsv
|
226
|
+
version_requirements: *id014
|
213
227
|
description: This allows you to easily build datagrid aka data tables with sortable columns and filters
|
214
228
|
email: agresso@gmail.com
|
215
229
|
executables: []
|
@@ -233,6 +247,10 @@ files:
|
|
233
247
|
- lib/datagrid/columns.rb
|
234
248
|
- lib/datagrid/columns/column.rb
|
235
249
|
- lib/datagrid/core.rb
|
250
|
+
- lib/datagrid/drivers.rb
|
251
|
+
- lib/datagrid/drivers/abstract_driver.rb
|
252
|
+
- lib/datagrid/drivers/active_record.rb
|
253
|
+
- lib/datagrid/drivers/mongoid.rb
|
236
254
|
- lib/datagrid/filters.rb
|
237
255
|
- lib/datagrid/filters/base_filter.rb
|
238
256
|
- lib/datagrid/filters/boolean_enum_filter.rb
|
@@ -251,6 +269,8 @@ files:
|
|
251
269
|
- lib/datagrid/utils.rb
|
252
270
|
- spec/datagrid/active_model_spec.rb
|
253
271
|
- spec/datagrid/columns_spec.rb
|
272
|
+
- spec/datagrid/drivers/active_record_spec.rb
|
273
|
+
- spec/datagrid/drivers/mongoid_spec.rb
|
254
274
|
- spec/datagrid/filters/composite_filters_spec.rb
|
255
275
|
- spec/datagrid/filters/enum_filter_spec.rb
|
256
276
|
- spec/datagrid/filters_spec.rb
|
@@ -260,9 +280,9 @@ files:
|
|
260
280
|
- spec/datagrid_spec.rb
|
261
281
|
- spec/spec_helper.rb
|
262
282
|
- spec/support/equal_to_dom.rb
|
283
|
+
- spec/support/mongoid.rb
|
263
284
|
- spec/support/schema.rb
|
264
285
|
- spec/support/simple_report.rb
|
265
|
-
has_rdoc: true
|
266
286
|
homepage: http://github.com/bogdan/datagrid
|
267
287
|
licenses:
|
268
288
|
- MIT
|
@@ -292,7 +312,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
292
312
|
requirements: []
|
293
313
|
|
294
314
|
rubyforge_project:
|
295
|
-
rubygems_version: 1.
|
315
|
+
rubygems_version: 1.8.11
|
296
316
|
signing_key:
|
297
317
|
specification_version: 3
|
298
318
|
summary: Ruby gem to create datagrids
|