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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a86d3d1a93e184496486be98659d834991d87789
4
- data.tar.gz: 04571cb15dee9f818907c3832bdecbe65d3a1002
3
+ metadata.gz: 9a695cb0107f631edef6c8ff40d794e88559dfca
4
+ data.tar.gz: 49b8de0521a68a356134ae23b529a162756fa117
5
5
  SHA512:
6
- metadata.gz: 520a31aecb53d6afedd645e0442504b0f9d581a6e3d076e5f0cd3cc1629c3b5dd88c0aa9dc49046c483d78ab5227131e1f7eeb64b7f9c90aa638ed1b20fd5372
7
- data.tar.gz: acb8a306c7f666a4cab3a7d31a78264ca351b754ae2aded735feaf9e7feddf8675d77e2a31515d846c3ad1c90866517d93e563abf2cf1150ad9cec33e1abab65
6
+ metadata.gz: 899d48d0a4a15e09463284d1f724191f59e005e4333bd27c33497f6c410ad679244d8e33b69a1d45b92587459349b35f1bfe72bf88c6e3b05b6bd6e3dd1365a7
7
+ data.tar.gz: 5f4463260e920a12e4f1f04f2414c6391dd87c8a697523a53aaf307e213b3a01989d57801460a6bfa89d4c1833172838e9bc43b8713c802cfadf2cf9ff7150e9
@@ -1,9 +1,9 @@
1
1
  language: ruby
2
2
  #bundler_args: --without development
3
3
  rvm:
4
- - 2.0.0
5
- - 2.1.1
6
- - 2.2.0
4
+ - 2.2.2
5
+ - 2.3.0
6
+ - 2.4.0
7
7
  #- jruby
8
8
  #- jruby-head
9
9
  #env: JRUBY_OPTS="--server -J-Xms512m -J-Xmx1024m"
data/Gemfile CHANGED
@@ -1,13 +1,16 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "rails", ">= 3.2.22.2"
3
+ gem "rails", ">= 4.0"
4
4
 
5
5
  group :development do
6
6
 
7
7
  gem "bundler"
8
- gem "jeweler", ">= 2.1.2"
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", "3.1.7"
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
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "datagrid"
18
- gem.homepage = "http://github.com/bogdan/datagrid"
19
- gem.license = "MIT"
20
- gem.summary = %Q{Ruby gem to create datagrids}
21
- gem.description = %Q{This allows you to easily build datagrid aka data tables with sortable columns and filters}
22
- gem.email = "agresso@gmail.com"
23
- gem.authors = ["Bogdan Gusiev"]
24
- gem.required_ruby_version = '>= 2.0'
25
- # dependencies defined in Gemfile
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
+ 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, form.datagrid_extra_checkbox_options.merge(:multiple => true, :id => id, :checked => checked), value.to_s, nil) -%>
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 -%>
@@ -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.1 ruby lib
5
+ # stub: datagrid 1.5.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
- s.name = "datagrid".freeze
9
- s.version = "1.5.1"
8
+ s.name = "datagrid"
9
+ s.version = "1.5.2"
10
10
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib".freeze]
13
- s.authors = ["Bogdan Gusiev".freeze]
14
- s.date = "2016-10-25"
15
- s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters".freeze
16
- s.email = "agresso@gmail.com".freeze
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".freeze
130
- s.licenses = ["MIT".freeze]
131
- s.required_ruby_version = Gem::Requirement.new(">= 2.0".freeze)
132
- s.rubygems_version = "2.6.7".freeze
133
- s.summary = "Ruby gem to create datagrids".freeze
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>.freeze, [">= 3.2.22.2"])
140
- s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
141
- s.add_development_dependency(%q<jeweler>.freeze, [">= 2.1.2"])
142
- s.add_development_dependency(%q<pry-byebug>.freeze, [">= 0"])
143
- s.add_development_dependency(%q<rspec>.freeze, [">= 3"])
144
- s.add_development_dependency(%q<nokogiri>.freeze, [">= 0"])
145
- s.add_development_dependency(%q<sqlite3>.freeze, [">= 0"])
146
- s.add_development_dependency(%q<sequel>.freeze, [">= 0"])
147
- s.add_development_dependency(%q<mongoid>.freeze, ["= 3.1.7"])
148
- s.add_development_dependency(%q<mongo_mapper>.freeze, ["~> 0.13.0"])
149
- s.add_development_dependency(%q<bson>.freeze, [">= 0"])
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>.freeze, [">= 3.2.22.2"])
153
- s.add_dependency(%q<bundler>.freeze, [">= 0"])
154
- s.add_dependency(%q<jeweler>.freeze, [">= 2.1.2"])
155
- s.add_dependency(%q<pry-byebug>.freeze, [">= 0"])
156
- s.add_dependency(%q<rspec>.freeze, [">= 3"])
157
- s.add_dependency(%q<nokogiri>.freeze, [">= 0"])
158
- s.add_dependency(%q<sqlite3>.freeze, [">= 0"])
159
- s.add_dependency(%q<sequel>.freeze, [">= 0"])
160
- s.add_dependency(%q<mongoid>.freeze, ["= 3.1.7"])
161
- s.add_dependency(%q<mongo_mapper>.freeze, ["~> 0.13.0"])
162
- s.add_dependency(%q<bson>.freeze, [">= 0"])
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>.freeze, [">= 3.2.22.2"])
167
- s.add_dependency(%q<bundler>.freeze, [">= 0"])
168
- s.add_dependency(%q<jeweler>.freeze, [">= 2.1.2"])
169
- s.add_dependency(%q<pry-byebug>.freeze, [">= 0"])
170
- s.add_dependency(%q<rspec>.freeze, [">= 3"])
171
- s.add_dependency(%q<nokogiri>.freeze, [">= 0"])
172
- s.add_dependency(%q<sqlite3>.freeze, [">= 0"])
173
- s.add_dependency(%q<sequel>.freeze, [">= 0"])
174
- s.add_dependency(%q<mongoid>.freeze, ["= 3.1.7"])
175
- s.add_dependency(%q<mongo_mapper>.freeze, ["~> 0.13.0"])
176
- s.add_dependency(%q<bson>.freeze, [">= 0"])
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
 
@@ -15,10 +15,10 @@ module Datagrid
15
15
 
16
16
  autoload :Helper
17
17
  ActionView::Base.send(:include, Datagrid::Helper)
18
-
18
+
19
19
  autoload :FormBuilder
20
20
  ActionView::Helpers::FormBuilder.send(:include, Datagrid::FormBuilder)
21
-
21
+
22
22
  autoload :Renderer
23
23
 
24
24
  autoload :Engine
@@ -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
@@ -171,6 +171,12 @@ module Datagrid
171
171
  "#<#{self.class} #{attrs}>"
172
172
  end
173
173
 
174
+ def ==(other)
175
+ self.class == other.class &&
176
+ attributes == other.attributes &&
177
+ scope == other.scope
178
+ end
179
+
174
180
  end # InstanceMethods
175
181
  end
176
182
  end
@@ -63,7 +63,7 @@ module Datagrid
63
63
  end
64
64
 
65
65
  def is_timestamp?(scope, field)
66
- raise NotImplementedError
66
+ normalized_column_type(scope, field) == :timestamp
67
67
  end
68
68
 
69
69
  def contains(scope, field, value)
@@ -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
- type = column_type(scope, field)
95
- return nil unless type
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?(type)
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
@@ -32,6 +32,10 @@ module Datagrid
32
32
  column_name
33
33
  end
34
34
 
35
+ def reverse_order(scope)
36
+ scope.reverse
37
+ end
38
+
35
39
  def greater_equal(scope, field, value)
36
40
  scope.select do |object|
37
41
  compare_value = object.send(field)
@@ -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] => :fload,
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] => :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] = [YES, NO].map do |key, value|
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) ? options[:include_blank] : !multiple?
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