datagrid 1.5.5 → 1.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/app/views/datagrid/_form.html.erb +1 -1
- data/datagrid.gemspec +4 -3
- data/lib/datagrid/filters.rb +4 -1
- data/lib/datagrid/filters/base_filter.rb +0 -1
- data/lib/datagrid/filters/ranged_filter.rb +0 -1
- data/lib/datagrid/filters/string_filter.rb +3 -0
- data/lib/datagrid/form_builder.rb +5 -9
- data/lib/datagrid/scaffold.rb +13 -2
- data/lib/datagrid/utils.rb +3 -1
- data/spec/datagrid/columns_spec.rb +8 -0
- data/spec/datagrid/filters/string_filter_spec.rb +11 -2
- data/spec/datagrid/form_builder_spec.rb +6 -5
- data/templates/base.rb.erb +19 -0
- data/templates/grid.rb.erb +2 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de5cf9444ec74f75f3238dcdd239daf3fcf3782e
|
4
|
+
data.tar.gz: 026fd1c07e87df9f44d30ced49cfffb4e33c0775
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5a5ef91ad59f2cb24cde7ef914e2dbc85149f828983746563d27df21f3c5a5b1ee724924d512fa5b1feb8fda26beab0fab54239f12fadc8a106185e7d232234
|
7
|
+
data.tar.gz: 66b23c02db354d88e6128ac0eaaf8fcdba5d7a45699d024a67606371f13b4a27e052decc582b83c47b933d37ae766a7c0c3340fc4f6201fed7d0a24db7210be9
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.5.
|
1
|
+
1.5.6
|
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.6 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.6"
|
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-10-
|
14
|
+
s.date = "2017-10-30"
|
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 = [
|
@@ -122,6 +122,7 @@ Gem::Specification.new do |s|
|
|
122
122
|
"spec/support/test_partials/custom_checkboxes/_enum_checkboxes.html.erb",
|
123
123
|
"spec/support/test_partials/custom_form/_form.html.erb",
|
124
124
|
"spec/support/test_partials/custom_range/_range_filter.html.erb",
|
125
|
+
"templates/base.rb.erb",
|
125
126
|
"templates/controller.rb.erb",
|
126
127
|
"templates/grid.rb.erb",
|
127
128
|
"templates/index.html.erb"
|
data/lib/datagrid/filters.rb
CHANGED
@@ -72,8 +72,11 @@ module Datagrid
|
|
72
72
|
#
|
73
73
|
# * <tt>:header</tt> - determines the header of the filter
|
74
74
|
# * <tt>:default</tt> - the default filter value. Able to accept a <tt>Proc</tt> in case default should be recalculated
|
75
|
+
# * <tt>:range</tt> - if true, filter can accept two values that are treated as a range that will be used for filtering
|
76
|
+
# Not all of the filter types support this option. Here are the list of types that do:
|
77
|
+
# <tt>:integer</tt>, <tt>:float</tt>, <tt>:date</tt>, <tt>:datetime</tt>, <tt>:string</tt>
|
75
78
|
# * <tt>:multiple</tt> - if true multiple values can be assigned to this filter.
|
76
|
-
#
|
79
|
+
# If String is assigned as a filter value, it is parsed from string using a separator symbol (`,` by default).
|
77
80
|
# But you can specify a different separator as option value. Default: false.
|
78
81
|
# * <tt>:allow_nil</tt> - determines if the value can be nil
|
79
82
|
# * <tt>:allow_blank</tt> - determines if the value can be blank
|
@@ -8,7 +8,7 @@ module Datagrid
|
|
8
8
|
filter = datagrid_get_filter(filter_or_attribute)
|
9
9
|
options = add_html_classes(options, filter.name, datagrid_filter_html_class(filter))
|
10
10
|
# Prevent partials option from appearing in HTML attributes
|
11
|
-
options.delete(:partials)
|
11
|
+
options.delete(:partials) # Legacy option
|
12
12
|
self.send(filter.form_builder_helper_name, filter, options, &block)
|
13
13
|
end
|
14
14
|
|
@@ -48,7 +48,7 @@ module Datagrid
|
|
48
48
|
def datagrid_enum_filter(attribute_or_filter, options = {}, &block)
|
49
49
|
filter = datagrid_get_filter(attribute_or_filter)
|
50
50
|
if filter.checkboxes?
|
51
|
-
partial = partial_path(
|
51
|
+
partial = partial_path('enum_checkboxes')
|
52
52
|
options = add_html_classes(options, 'checkboxes')
|
53
53
|
elements = object.select_options(filter).map do |element|
|
54
54
|
text, value = @template.send(:option_text_and_value, element)
|
@@ -138,7 +138,7 @@ module Datagrid
|
|
138
138
|
def datagrid_range_filter(type, attribute_or_filter, options = {})
|
139
139
|
filter = datagrid_get_filter(attribute_or_filter)
|
140
140
|
if filter.range?
|
141
|
-
partial = partial_path(
|
141
|
+
partial = partial_path('range_filter')
|
142
142
|
options = options.merge(:multiple => true)
|
143
143
|
|
144
144
|
|
@@ -224,8 +224,8 @@ module Datagrid
|
|
224
224
|
Datagrid::Utils.add_html_classes(options, *classes)
|
225
225
|
end
|
226
226
|
|
227
|
-
def partial_path(
|
228
|
-
if partials = options
|
227
|
+
def partial_path(name)
|
228
|
+
if partials = self.options[:partials]
|
229
229
|
partial_name = File.join(partials, name)
|
230
230
|
# Second argument is []: no magical namespaces to lookup added from controller
|
231
231
|
if @template.lookup_context.template_exists?(partial_name, [], true)
|
@@ -235,10 +235,6 @@ module Datagrid
|
|
235
235
|
File.join('datagrid', name)
|
236
236
|
end
|
237
237
|
|
238
|
-
def supports_partial?(filter)
|
239
|
-
(filter.supports_range? && filter.range?) || (filter.type == :enum && filter.checkboxes?)
|
240
|
-
end
|
241
|
-
|
242
238
|
class Error < StandardError
|
243
239
|
end
|
244
240
|
end
|
data/lib/datagrid/scaffold.rb
CHANGED
@@ -8,8 +8,11 @@ class Datagrid::Scaffold < Rails::Generators::NamedBase
|
|
8
8
|
source_root File.expand_path(__FILE__ + "/../../../templates")
|
9
9
|
|
10
10
|
def create_scaffold
|
11
|
+
unless file_exists?(base_grid_file)
|
12
|
+
template "base.rb.erb", base_grid_file
|
13
|
+
end
|
11
14
|
template "grid.rb.erb", "app/grids/#{grid_class_name.underscore}.rb"
|
12
|
-
if
|
15
|
+
if file_exists?(grid_controller_file)
|
13
16
|
inject_into_file grid_controller_file, index_action, :after => %r{class .*#{grid_controller_class_name}.*\n}
|
14
17
|
else
|
15
18
|
template "controller.rb.erb", grid_controller_file
|
@@ -26,7 +29,7 @@ class Datagrid::Scaffold < Rails::Generators::NamedBase
|
|
26
29
|
"css.scss" => " *= require datagrid",
|
27
30
|
}.each do |extension, string|
|
28
31
|
file = "app/assets/stylesheets/application.#{extension}"
|
29
|
-
if
|
32
|
+
if file_exists?(file)
|
30
33
|
inject_into_file file, string + "\n", {:before => %r{.*require_self}} # before all
|
31
34
|
end
|
32
35
|
end
|
@@ -68,7 +71,10 @@ class Datagrid::Scaffold < Rails::Generators::NamedBase
|
|
68
71
|
# Kaminari is default
|
69
72
|
"paginate(@grid.assets)"
|
70
73
|
end
|
74
|
+
end
|
71
75
|
|
76
|
+
def base_grid_file
|
77
|
+
"app/grids/base_grid.rb"
|
72
78
|
end
|
73
79
|
|
74
80
|
def grid_route_name
|
@@ -109,4 +115,9 @@ RUBY
|
|
109
115
|
# Combine the 3 parts to generate complete route entry
|
110
116
|
namespace_ladder + route + "\n" + end_ladder
|
111
117
|
end
|
118
|
+
|
119
|
+
def file_exists?(name)
|
120
|
+
name = Rails.root.join(name) unless name.to_s.first == "/"
|
121
|
+
File.exists?(name)
|
122
|
+
end
|
112
123
|
end
|
data/lib/datagrid/utils.rb
CHANGED
@@ -146,8 +146,10 @@ module Datagrid
|
|
146
146
|
option.call(grid)
|
147
147
|
when Symbol, String
|
148
148
|
grid.send(option.to_sym)
|
149
|
+
when TrueClass, FalseClass
|
150
|
+
option
|
149
151
|
else
|
150
|
-
raise Datagrid::ConfigurationError, "Incorrect column availability option: #{option.
|
152
|
+
raise Datagrid::ConfigurationError, "Incorrect column availability option: #{option.inspect}"
|
151
153
|
end
|
152
154
|
end
|
153
155
|
end
|
@@ -229,6 +229,14 @@ describe Datagrid::Columns do
|
|
229
229
|
expect(report.available_columns.map(&:name)).to eq([:category])
|
230
230
|
end
|
231
231
|
|
232
|
+
it "raises when incorrect unless option is given" do
|
233
|
+
expect do
|
234
|
+
test_report do
|
235
|
+
column(:id, if: Object.new)
|
236
|
+
end
|
237
|
+
end.to raise_error(Datagrid::ConfigurationError)
|
238
|
+
end
|
239
|
+
|
232
240
|
it "raises when :before and :after used together" do
|
233
241
|
expect do
|
234
242
|
test_report do
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
1
|
+
require "spec_helper"
|
3
2
|
|
4
3
|
describe Datagrid::Filters::StringFilter do
|
5
4
|
|
@@ -23,4 +22,14 @@ describe Datagrid::Filters::StringFilter do
|
|
23
22
|
expect(report.assets).not_to include(Entry.create!( :name => "two"))
|
24
23
|
end
|
25
24
|
|
25
|
+
it "supports range" do
|
26
|
+
report = test_report(:name => ['ab', 'lm']) do
|
27
|
+
scope {Entry}
|
28
|
+
filter(:name, :string, range: true)
|
29
|
+
end
|
30
|
+
expect(report.assets).to include(Entry.create!( :name => "ac"))
|
31
|
+
expect(report.assets).to include(Entry.create!( :name => "kl"))
|
32
|
+
expect(report.assets).not_to include(Entry.create!( :name => "aa"))
|
33
|
+
expect(report.assets).not_to include(Entry.create!( :name => "mn"))
|
34
|
+
end
|
26
35
|
end
|
@@ -18,7 +18,8 @@ describe Datagrid::FormBuilder do
|
|
18
18
|
v.view_paths << File.expand_path("../../support/test_partials", __FILE__)
|
19
19
|
end
|
20
20
|
end
|
21
|
-
let(:view) { ActionView::Helpers::FormBuilder.new(:report, _grid, template,
|
21
|
+
let(:view) { ActionView::Helpers::FormBuilder.new(:report, _grid, template, view_options)}
|
22
|
+
let(:view_options) { {} }
|
22
23
|
|
23
24
|
|
24
25
|
describe ".datagrid_filter" do
|
@@ -60,7 +61,7 @@ describe Datagrid::FormBuilder do
|
|
60
61
|
)}
|
61
62
|
|
62
63
|
context "when partials option is passed for filter that don't support range" do
|
63
|
-
let(:
|
64
|
+
let(:view_options) { {partials: 'anything' } }
|
64
65
|
it { should equal_to_dom(
|
65
66
|
'<input class="group_id integer_filter" type="text" name="report[group_id]" id="report_group_id"/>'
|
66
67
|
)}
|
@@ -138,7 +139,7 @@ describe Datagrid::FormBuilder do
|
|
138
139
|
end
|
139
140
|
|
140
141
|
context "with custom partials option and template exists" do
|
141
|
-
let(:
|
142
|
+
let(:view_options) { { :partials => 'custom_range' } }
|
142
143
|
let(:_range) { nil }
|
143
144
|
it { should equal_to_dom(
|
144
145
|
"custom_range_partial"
|
@@ -146,7 +147,7 @@ describe Datagrid::FormBuilder do
|
|
146
147
|
end
|
147
148
|
|
148
149
|
context "when custom partial doesn't exist" do
|
149
|
-
let(:
|
150
|
+
let(:view_options) { { :partials => 'not_existed' } }
|
150
151
|
let(:_range) { nil }
|
151
152
|
it { should equal_to_dom(
|
152
153
|
'<input class="group_id integer_filter from" multiple type="text" name="report[group_id][]"><span class="separator integer"> - </span><input class="group_id integer_filter to" multiple type="text" name="report[group_id][]">'
|
@@ -361,7 +362,7 @@ describe Datagrid::FormBuilder do
|
|
361
362
|
end
|
362
363
|
|
363
364
|
context "when partials option passed and partial exists" do
|
364
|
-
let(:
|
365
|
+
let(:view_options) { {partials: 'custom_checkboxes'} }
|
365
366
|
it { should equal_to_dom('custom_enum_checkboxes') }
|
366
367
|
end
|
367
368
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class BaseGrid
|
2
|
+
|
3
|
+
include Datagrid
|
4
|
+
|
5
|
+
self.default_column_options = {
|
6
|
+
# Uncomment to disable the default order
|
7
|
+
# order: false,
|
8
|
+
# Uncomment to make all columns HTML by default
|
9
|
+
# html: true,
|
10
|
+
}
|
11
|
+
|
12
|
+
def self.date_column(name, *args)
|
13
|
+
column(name, *args) do |model|
|
14
|
+
format(block_given? ? yield : model.send(name)) do |date|
|
15
|
+
date.strftime("%m/%d/%Y")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/templates/grid.rb.erb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
class <%= grid_class_name %>
|
2
|
-
|
3
|
-
include Datagrid
|
1
|
+
class <%= grid_class_name %> < BaseGrid
|
4
2
|
|
5
3
|
scope do
|
6
4
|
<%= grid_model_name %>
|
@@ -11,7 +9,5 @@ class <%= grid_class_name %>
|
|
11
9
|
|
12
10
|
column(:id)
|
13
11
|
column(:name)
|
14
|
-
|
15
|
-
model.created_at.to_date
|
16
|
-
end
|
12
|
+
date_column(:created_at)
|
17
13
|
end
|
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.6
|
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-10-
|
11
|
+
date: 2017-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -276,6 +276,7 @@ files:
|
|
276
276
|
- spec/support/test_partials/custom_checkboxes/_enum_checkboxes.html.erb
|
277
277
|
- spec/support/test_partials/custom_form/_form.html.erb
|
278
278
|
- spec/support/test_partials/custom_range/_range_filter.html.erb
|
279
|
+
- templates/base.rb.erb
|
279
280
|
- templates/controller.rb.erb
|
280
281
|
- templates/grid.rb.erb
|
281
282
|
- templates/index.html.erb
|