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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 012d1468059f7ed2bc98a58b26d982960eb40c9c
4
- data.tar.gz: 6bd2b6019015f43c84e372fd27a5472e7f72d115
3
+ metadata.gz: de5cf9444ec74f75f3238dcdd239daf3fcf3782e
4
+ data.tar.gz: 026fd1c07e87df9f44d30ced49cfffb4e33c0775
5
5
  SHA512:
6
- metadata.gz: 430016e9d03c4f09f0d8e0efec3faac6ec8c9428aa77a98679de546e3c52f7325aad22aae6a7aaed04b5bdb5be1048f2a9df73df43101bdb3178cdf1a57888c9
7
- data.tar.gz: bdeb1423e1bdbf3ef66d2e4656ff565c50ec1a3e2cd18dc5d076e3b364528618cec623b20b528b8b98399a9f15ebbd1cb9f0bdbb7de8a35993ccc174f389ca08
6
+ metadata.gz: f5a5ef91ad59f2cb24cde7ef914e2dbc85149f828983746563d27df21f3c5a5b1ee724924d512fa5b1feb8fda26beab0fab54239f12fadc8a106185e7d232234
7
+ data.tar.gz: 66b23c02db354d88e6128ac0eaaf8fcdba5d7a45699d024a67606371f13b4a27e052decc582b83c47b933d37ae766a7c0c3340fc4f6201fed7d0a24db7210be9
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.5.5
1
+ 1.5.6
@@ -2,7 +2,7 @@
2
2
  <% grid.filters.each do |filter| %>
3
3
  <div class="datagrid-filter filter">
4
4
  <%= f.datagrid_label filter %>
5
- <%= f.datagrid_filter filter, partials: options[:partials] %>
5
+ <%= f.datagrid_filter filter %>
6
6
  </div>
7
7
  <% end %>
8
8
  <div class="datagrid-actions">
@@ -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 ruby lib
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.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-03"
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"
@@ -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
- # By default multiple values are parsed from string using `,` separator.
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
@@ -154,7 +154,6 @@ class Datagrid::Filters::BaseFilter #:nodoc:
154
154
  def normalize_multiple_value(value)
155
155
  case value
156
156
  when String
157
- #TODO: write tests and doc
158
157
  value.split(separator)
159
158
  when Range
160
159
  [value.first, value.last]
@@ -1,6 +1,5 @@
1
1
  module Datagrid::Filters::RangedFilter
2
2
 
3
-
4
3
  def initialize(grid, name, options, &block)
5
4
  super(grid, name, options, &block)
6
5
  if range?
@@ -1,4 +1,7 @@
1
1
  class Datagrid::Filters::StringFilter < Datagrid::Filters::BaseFilter
2
+
3
+ include Datagrid::Filters::RangedFilter
4
+
2
5
  def parse(value)
3
6
  value.nil? ? nil : value.to_s
4
7
  end
@@ -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) unless supports_partial?(filter)
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(options, 'enum_checkboxes')
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(options, 'range_filter')
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(options, name)
228
- if partials = options.delete(:partials)
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
@@ -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 File.exists?(grid_controller_file)
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 File.exists?(Rails.root.join(file))
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
@@ -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.insepct}"
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(:_filter_options) { {partials: 'anything' } }
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(:_filter_options) { { :partials => 'custom_range' } }
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(:_filter_options) { { :partials => 'not_existed' } }
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(:_filter_options) { {partials: 'custom_checkboxes'} }
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
@@ -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
- column(:created_at) do |model|
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.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-03 00:00:00.000000000 Z
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