datagrid 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/Gemfile +7 -4
- data/Rakefile +15 -13
- data/VERSION +1 -1
- data/app/views/datagrid/_enum_checkboxes.html.erb +1 -1
- data/datagrid.gemspec +47 -50
- data/lib/datagrid.rb +2 -2
- data/lib/datagrid/columns/column.rb +1 -5
- data/lib/datagrid/core.rb +6 -0
- data/lib/datagrid/drivers/abstract_driver.rb +1 -1
- data/lib/datagrid/drivers/active_record.rb +3 -11
- data/lib/datagrid/drivers/array.rb +4 -0
- data/lib/datagrid/drivers/mongoid.rb +1 -6
- data/lib/datagrid/drivers/sequel.rb +1 -5
- data/lib/datagrid/filters/base_filter.rb +1 -5
- data/lib/datagrid/filters/extended_boolean_filter.rb +10 -5
- data/lib/datagrid/filters/integer_filter.rb +4 -0
- data/lib/datagrid/filters/select_options.rb +4 -3
- data/lib/datagrid/form_builder.rb +5 -9
- data/lib/datagrid/utils.rb +4 -0
- data/spec/datagrid/core_spec.rb +26 -1
- data/spec/datagrid/drivers/active_record_spec.rb +2 -2
- data/spec/datagrid/drivers/mongo_mapper_spec.rb +77 -75
- data/spec/datagrid/filters/enum_filter_spec.rb +2 -2
- data/spec/datagrid/filters/integer_filter_spec.rb +19 -10
- data/spec/datagrid/form_builder_spec.rb +87 -81
- data/spec/datagrid/helper_spec.rb +4 -4
- data/spec/spec_helper.rb +22 -11
- data/spec/support/active_record.rb +2 -2
- data/spec/support/mongo_mapper.rb +23 -23
- metadata +9 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a695cb0107f631edef6c8ff40d794e88559dfca
|
4
|
+
data.tar.gz: 49b8de0521a68a356134ae23b529a162756fa117
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 899d48d0a4a15e09463284d1f724191f59e005e4333bd27c33497f6c410ad679244d8e33b69a1d45b92587459349b35f1bfe72bf88c6e3b05b6bd6e3dd1365a7
|
7
|
+
data.tar.gz: 5f4463260e920a12e4f1f04f2414c6391dd87c8a697523a53aaf307e213b3a01989d57801460a6bfa89d4c1833172838e9bc43b8713c802cfadf2cf9ff7150e9
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
|
-
gem "rails", ">=
|
3
|
+
gem "rails", ">= 4.0"
|
4
4
|
|
5
5
|
group :development do
|
6
6
|
|
7
7
|
gem "bundler"
|
8
|
-
|
8
|
+
if RUBY_VERSION >= "2.3"
|
9
|
+
gem "jeweler", ">= 2.1.2", platform: [:ruby_23, :ruby_24]
|
10
|
+
end
|
9
11
|
|
10
12
|
|
13
|
+
#gem "json", ">= 1.9"
|
11
14
|
gem "pry-byebug", :platform => [:ruby_20, :ruby_21, :ruby_22, :ruby_23] & Bundler::Dsl::VALID_PLATFORMS
|
12
15
|
|
13
16
|
gem "rspec", ">= 3"
|
@@ -17,8 +20,8 @@ group :development do
|
|
17
20
|
gem "sequel"
|
18
21
|
|
19
22
|
group :mongo do
|
20
|
-
gem "mongoid"
|
21
|
-
gem "mongo_mapper", "~> 0.13.0"
|
23
|
+
gem "mongoid"
|
24
|
+
#gem "mongo_mapper", "~> 0.13.0"
|
22
25
|
gem "bson"
|
23
26
|
gem "bson_ext"
|
24
27
|
end
|
data/Rakefile
CHANGED
@@ -11,20 +11,22 @@ rescue Bundler::BundlerError => e
|
|
11
11
|
end
|
12
12
|
require 'rake'
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
14
|
+
if RUBY_VERSION >= "2.3"
|
15
|
+
require 'jeweler'
|
16
|
+
Jeweler::Tasks.new do |gem|
|
17
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
|
+
gem.name = "datagrid"
|
19
|
+
gem.homepage = "http://github.com/bogdan/datagrid"
|
20
|
+
gem.license = "MIT"
|
21
|
+
gem.summary = %Q{Ruby gem to create datagrids}
|
22
|
+
gem.description = %Q{This allows you to easily build datagrid aka data tables with sortable columns and filters}
|
23
|
+
gem.email = "agresso@gmail.com"
|
24
|
+
gem.authors = ["Bogdan Gusiev"]
|
25
|
+
gem.required_ruby_version = '>= 2.0'
|
26
|
+
# dependencies defined in Gemfile
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
26
29
|
end
|
27
|
-
Jeweler::RubygemsDotOrgTasks.new
|
28
30
|
|
29
31
|
require 'rspec/core'
|
30
32
|
require 'rspec/core/rake_task'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.5.
|
1
|
+
1.5.2
|
@@ -5,7 +5,7 @@ You can add indent if whitespace doesn't matter for you
|
|
5
5
|
<%- elements.each do |value, text, checked| -%>
|
6
6
|
<%- id = [form.object_name, filter.name, value].join('_').underscore -%>
|
7
7
|
<%= form.label filter.name, options.merge(:for => id) do -%>
|
8
|
-
<%= form.check_box(filter.name,
|
8
|
+
<%= form.check_box(filter.name, {:multiple => true, :id => id, :checked => checked, :include_hidden => false}, value.to_s, nil) -%>
|
9
9
|
<%= text -%>
|
10
10
|
<%- end -%>
|
11
11
|
<%- end -%>
|
data/datagrid.gemspec
CHANGED
@@ -2,18 +2,18 @@
|
|
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.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
|
-
s.name = "datagrid"
|
9
|
-
s.version = "1.5.
|
8
|
+
s.name = "datagrid"
|
9
|
+
s.version = "1.5.2"
|
10
10
|
|
11
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0"
|
12
|
-
s.require_paths = ["lib"
|
13
|
-
s.authors = ["Bogdan Gusiev"
|
14
|
-
s.date = "
|
15
|
-
s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters"
|
16
|
-
s.email = "agresso@gmail.com"
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Bogdan Gusiev"]
|
14
|
+
s.date = "2017-02-28"
|
15
|
+
s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters"
|
16
|
+
s.email = "agresso@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
18
18
|
"LICENSE.txt"
|
19
19
|
]
|
@@ -126,55 +126,52 @@ Gem::Specification.new do |s|
|
|
126
126
|
"templates/grid.rb.erb",
|
127
127
|
"templates/index.html.erb"
|
128
128
|
]
|
129
|
-
s.homepage = "http://github.com/bogdan/datagrid"
|
130
|
-
s.licenses = ["MIT"
|
131
|
-
s.required_ruby_version = Gem::Requirement.new(">= 2.0"
|
132
|
-
s.rubygems_version = "2.
|
133
|
-
s.summary = "Ruby gem to create datagrids"
|
129
|
+
s.homepage = "http://github.com/bogdan/datagrid"
|
130
|
+
s.licenses = ["MIT"]
|
131
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.0")
|
132
|
+
s.rubygems_version = "2.5.1"
|
133
|
+
s.summary = "Ruby gem to create datagrids"
|
134
134
|
|
135
135
|
if s.respond_to? :specification_version then
|
136
136
|
s.specification_version = 4
|
137
137
|
|
138
138
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
139
|
-
s.add_runtime_dependency(%q<rails
|
140
|
-
s.add_development_dependency(%q<bundler
|
141
|
-
s.add_development_dependency(%q<jeweler
|
142
|
-
s.add_development_dependency(%q<pry-byebug
|
143
|
-
s.add_development_dependency(%q<rspec
|
144
|
-
s.add_development_dependency(%q<nokogiri
|
145
|
-
s.add_development_dependency(%q<sqlite3
|
146
|
-
s.add_development_dependency(%q<sequel
|
147
|
-
s.add_development_dependency(%q<mongoid
|
148
|
-
s.add_development_dependency(%q<
|
149
|
-
s.add_development_dependency(%q<
|
150
|
-
s.add_development_dependency(%q<bson_ext>.freeze, [">= 0"])
|
139
|
+
s.add_runtime_dependency(%q<rails>, [">= 4.0"])
|
140
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
141
|
+
s.add_development_dependency(%q<jeweler>, [">= 2.1.2"])
|
142
|
+
s.add_development_dependency(%q<pry-byebug>, [">= 0"])
|
143
|
+
s.add_development_dependency(%q<rspec>, [">= 3"])
|
144
|
+
s.add_development_dependency(%q<nokogiri>, [">= 0"])
|
145
|
+
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
146
|
+
s.add_development_dependency(%q<sequel>, [">= 0"])
|
147
|
+
s.add_development_dependency(%q<mongoid>, [">= 0"])
|
148
|
+
s.add_development_dependency(%q<bson>, [">= 0"])
|
149
|
+
s.add_development_dependency(%q<bson_ext>, [">= 0"])
|
151
150
|
else
|
152
|
-
s.add_dependency(%q<rails
|
153
|
-
s.add_dependency(%q<bundler
|
154
|
-
s.add_dependency(%q<jeweler
|
155
|
-
s.add_dependency(%q<pry-byebug
|
156
|
-
s.add_dependency(%q<rspec
|
157
|
-
s.add_dependency(%q<nokogiri
|
158
|
-
s.add_dependency(%q<sqlite3
|
159
|
-
s.add_dependency(%q<sequel
|
160
|
-
s.add_dependency(%q<mongoid
|
161
|
-
s.add_dependency(%q<
|
162
|
-
s.add_dependency(%q<
|
163
|
-
s.add_dependency(%q<bson_ext>.freeze, [">= 0"])
|
151
|
+
s.add_dependency(%q<rails>, [">= 4.0"])
|
152
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
153
|
+
s.add_dependency(%q<jeweler>, [">= 2.1.2"])
|
154
|
+
s.add_dependency(%q<pry-byebug>, [">= 0"])
|
155
|
+
s.add_dependency(%q<rspec>, [">= 3"])
|
156
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
157
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
158
|
+
s.add_dependency(%q<sequel>, [">= 0"])
|
159
|
+
s.add_dependency(%q<mongoid>, [">= 0"])
|
160
|
+
s.add_dependency(%q<bson>, [">= 0"])
|
161
|
+
s.add_dependency(%q<bson_ext>, [">= 0"])
|
164
162
|
end
|
165
163
|
else
|
166
|
-
s.add_dependency(%q<rails
|
167
|
-
s.add_dependency(%q<bundler
|
168
|
-
s.add_dependency(%q<jeweler
|
169
|
-
s.add_dependency(%q<pry-byebug
|
170
|
-
s.add_dependency(%q<rspec
|
171
|
-
s.add_dependency(%q<nokogiri
|
172
|
-
s.add_dependency(%q<sqlite3
|
173
|
-
s.add_dependency(%q<sequel
|
174
|
-
s.add_dependency(%q<mongoid
|
175
|
-
s.add_dependency(%q<
|
176
|
-
s.add_dependency(%q<
|
177
|
-
s.add_dependency(%q<bson_ext>.freeze, [">= 0"])
|
164
|
+
s.add_dependency(%q<rails>, [">= 4.0"])
|
165
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
166
|
+
s.add_dependency(%q<jeweler>, [">= 2.1.2"])
|
167
|
+
s.add_dependency(%q<pry-byebug>, [">= 0"])
|
168
|
+
s.add_dependency(%q<rspec>, [">= 3"])
|
169
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
170
|
+
s.add_dependency(%q<sqlite3>, [">= 0"])
|
171
|
+
s.add_dependency(%q<sequel>, [">= 0"])
|
172
|
+
s.add_dependency(%q<mongoid>, [">= 0"])
|
173
|
+
s.add_dependency(%q<bson>, [">= 0"])
|
174
|
+
s.add_dependency(%q<bson_ext>, [">= 0"])
|
178
175
|
end
|
179
176
|
end
|
180
177
|
|
data/lib/datagrid.rb
CHANGED
@@ -59,7 +59,7 @@ class Datagrid::Columns::Column
|
|
59
59
|
|
60
60
|
def header
|
61
61
|
if header = options[:header]
|
62
|
-
callable(header)
|
62
|
+
Datagrid::Utils.callable(header)
|
63
63
|
else
|
64
64
|
Datagrid::Utils.translate_from_namespace(:columns, grid_class, name)
|
65
65
|
end
|
@@ -157,10 +157,6 @@ class Datagrid::Columns::Column
|
|
157
157
|
|
158
158
|
end
|
159
159
|
|
160
|
-
def callable(value)
|
161
|
-
value.respond_to?(:call) ? value.call : value
|
162
|
-
end
|
163
|
-
|
164
160
|
def driver
|
165
161
|
grid_class.driver
|
166
162
|
end
|
data/lib/datagrid/core.rb
CHANGED
@@ -81,18 +81,14 @@ module Datagrid
|
|
81
81
|
scope.column_names
|
82
82
|
end
|
83
83
|
|
84
|
-
def is_timestamp?(scope, field)
|
85
|
-
column_type(scope, field) == :datetime
|
86
|
-
end
|
87
|
-
|
88
84
|
def contains(scope, field, value)
|
89
85
|
field = prefix_table_name(scope, field)
|
90
86
|
scope.where("#{field} #{contains_predicate} ?", "%#{value}%")
|
91
87
|
end
|
92
88
|
|
93
89
|
def normalized_column_type(scope, field)
|
94
|
-
|
95
|
-
|
90
|
+
return nil unless has_column?(scope, field)
|
91
|
+
builtin_type = scope.columns_hash[field.to_s].type
|
96
92
|
{
|
97
93
|
[:string, :text, :time, :binary] => :string,
|
98
94
|
[:integer, :primary_key] => :integer,
|
@@ -101,7 +97,7 @@ module Datagrid
|
|
101
97
|
[:datetime, :timestamp] => :timestamp,
|
102
98
|
[:boolean] => :boolean
|
103
99
|
}.each do |keys, value|
|
104
|
-
return value if keys.include?(
|
100
|
+
return value if keys.include?(builtin_type)
|
105
101
|
end
|
106
102
|
end
|
107
103
|
|
@@ -135,10 +131,6 @@ module Datagrid
|
|
135
131
|
::ActiveRecord::Base.connection.is_a?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) ?
|
136
132
|
'ilike' : 'like'
|
137
133
|
end
|
138
|
-
|
139
|
-
def column_type(scope, field)
|
140
|
-
has_column?(scope, field) ? scope.columns_hash[field.to_s].type : nil
|
141
|
-
end
|
142
134
|
end
|
143
135
|
end
|
144
136
|
end
|
@@ -46,11 +46,6 @@ module Datagrid
|
|
46
46
|
column_names(scope).include?(column_name.to_s)
|
47
47
|
end
|
48
48
|
|
49
|
-
def is_timestamp?(scope, column_name)
|
50
|
-
has_column?(scope, column_name) &&
|
51
|
-
timestamp_class?(to_scope(scope).klass.fields[column_name.to_s].type)
|
52
|
-
end
|
53
|
-
|
54
49
|
def contains(scope, field, value)
|
55
50
|
scope.where(field => Regexp.compile(Regexp.escape(value)))
|
56
51
|
end
|
@@ -70,7 +65,7 @@ module Datagrid
|
|
70
65
|
|
71
66
|
TIMESTAMP_CLASSES => :timestamp,
|
72
67
|
|
73
|
-
[Float] => :
|
68
|
+
[Float] => :float,
|
74
69
|
|
75
70
|
[Integer] => :integer,
|
76
71
|
}.each do |keys, value|
|
@@ -56,10 +56,6 @@ module Datagrid
|
|
56
56
|
scope.columns
|
57
57
|
end
|
58
58
|
|
59
|
-
def is_timestamp?(scope, column_name)
|
60
|
-
column_type(scope, column_name) == :datetime
|
61
|
-
end
|
62
|
-
|
63
59
|
def contains(scope, field, value)
|
64
60
|
field = prefix_table_name(scope, field)
|
65
61
|
scope.where(Sequel.like(field, "%#{value}%"))
|
@@ -73,7 +69,7 @@ module Datagrid
|
|
73
69
|
[:integer, :primary_key] => :integer,
|
74
70
|
[:float, :decimal] => :float,
|
75
71
|
[:date] => :date,
|
76
|
-
[:datetime] => :
|
72
|
+
[:datetime] => :timestamp,
|
77
73
|
[:boolean] => :boolean
|
78
74
|
}.each do |keys, value|
|
79
75
|
return value if keys.include?(type)
|
@@ -55,7 +55,7 @@ class Datagrid::Filters::BaseFilter #:nodoc:
|
|
55
55
|
|
56
56
|
def header
|
57
57
|
if header = options[:header]
|
58
|
-
callable(header)
|
58
|
+
Datagrid::Utils.callable(header)
|
59
59
|
else
|
60
60
|
Datagrid::Utils.translate_from_namespace(:filters, grid_class, name)
|
61
61
|
end
|
@@ -167,10 +167,6 @@ class Datagrid::Filters::BaseFilter #:nodoc:
|
|
167
167
|
','
|
168
168
|
end
|
169
169
|
|
170
|
-
def callable(value)
|
171
|
-
value.respond_to?(:call) ? value.call : value
|
172
|
-
end
|
173
|
-
|
174
170
|
def driver
|
175
171
|
grid_class.driver
|
176
172
|
end
|
@@ -1,16 +1,14 @@
|
|
1
|
-
class Datagrid::Filters::ExtendedBooleanFilter < Datagrid::Filters::EnumFilter #:nodoc:
|
1
|
+
class Datagrid::Filters::ExtendedBooleanFilter < Datagrid::Filters::EnumFilter #:nodoc:
|
2
2
|
|
3
3
|
YES = "YES"
|
4
4
|
NO = "NO"
|
5
5
|
|
6
6
|
def initialize(report, attribute, options = {}, &block)
|
7
|
-
options[:select] =
|
8
|
-
[I18n.t("datagrid.filters.xboolean.#{key.downcase}"), key]
|
9
|
-
end
|
7
|
+
options[:select] = -> { boolean_select }
|
10
8
|
super(report, attribute, options, &block)
|
11
9
|
end
|
12
10
|
|
13
|
-
def execute(value, scope, grid_object)
|
11
|
+
def execute(value, scope, grid_object)
|
14
12
|
value = value.blank? ? nil : ::Datagrid::Utils.booleanize(value)
|
15
13
|
super(value, scope, grid_object)
|
16
14
|
end
|
@@ -28,4 +26,11 @@ class Datagrid::Filters::ExtendedBooleanFilter < Datagrid::Filters::EnumFilter #
|
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
29
|
+
protected
|
30
|
+
|
31
|
+
def boolean_select
|
32
|
+
[YES, NO].map do |key, value|
|
33
|
+
[I18n.t("datagrid.filters.xboolean.#{key.downcase}"), key]
|
34
|
+
end
|
35
|
+
end
|
31
36
|
end
|
@@ -6,6 +6,10 @@ class Datagrid::Filters::IntegerFilter < Datagrid::Filters::BaseFilter
|
|
6
6
|
|
7
7
|
def parse(value)
|
8
8
|
return nil if value.blank?
|
9
|
+
if defined?(ActiveRecord) && value.is_a?(ActiveRecord::Base) &&
|
10
|
+
value.respond_to?(:id) && value.id.is_a?(Integer)
|
11
|
+
return value.id
|
12
|
+
end
|
9
13
|
return value if value.is_a?(Range)
|
10
14
|
value.to_i
|
11
15
|
end
|
@@ -16,11 +16,12 @@ module Datagrid::Filters::SelectOptions
|
|
16
16
|
|
17
17
|
def include_blank
|
18
18
|
unless prompt
|
19
|
-
options.has_key?(:include_blank) ?
|
19
|
+
options.has_key?(:include_blank) ?
|
20
|
+
Datagrid::Utils.callable(options[:include_blank]) : !multiple?
|
20
21
|
end
|
21
22
|
end
|
22
|
-
|
23
|
+
|
23
24
|
def prompt
|
24
|
-
options.has_key?(:prompt) ? options[:prompt] : false
|
25
|
+
options.has_key?(:prompt) ? Datagrid::Utils.callable(options[:prompt]) : false
|
25
26
|
end
|
26
27
|
end
|