datagrid 1.6.0 → 1.6.1

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
  SHA256:
3
- metadata.gz: bd828dc639436b3eedd26fad706bb0ba844b62229209dc941019a09e63301d77
4
- data.tar.gz: 05c04ebc0ecd2f7b780964ea08677c451ac5c00353dda901af57cc8a447b18ec
3
+ metadata.gz: 76bece54343c202c79e7ca4d5e90ae1cc91d2c5a77b965a175b36df801e10bd1
4
+ data.tar.gz: 68e58ec9dec5f010b43a7e078fdbf2c3c1b0923c9f2ab38c327d3665570d08fa
5
5
  SHA512:
6
- metadata.gz: a7f7d6ab72a350bf5f88b5e41707204fa0d1791cc1b382b66d704b2380bffb96280e508b68896ac4e8bf158d7e36bf030c3aa4744134b07c3c0f41651c7fe256
7
- data.tar.gz: b07edf4527a83375d94b5cb9d1730c855e595f029bcdd77e9a311e0745a14acc3797b2e9af2d0335977f2718a7e9756bf753a468280511920d2908a385283878
6
+ metadata.gz: 9aeb7a29ea7df278090a6417e1f940dfe9f8b1aa57dd907f9f739c4d2bc3e613be66be28635c5cf51a70b9067a7f7da4a00e7adaf09ae8ddea0247c7f34a56b1
7
+ data.tar.gz: 8660381aa1d508c624b0bc6d1c6e71ca3e6c1e89cad518733aeaee31d1968dc6382c45d1d06cbb60cd33ea1407d3e79e92e5920d93483bdfd47a31ffa1e23cef
@@ -1,10 +1,12 @@
1
1
  language: ruby
2
2
  #bundler_args: --without development
3
3
  rvm:
4
- - 2.2.2
5
- - 2.3.0
6
- - 2.4.1
7
- - 2.5.1
4
+ - 2.2
5
+ - 2.3
6
+ - 2.4
7
+ - 2.5
8
+ - 2.6
9
+ - 2.7
8
10
  #- jruby
9
11
  #- jruby-head
10
12
  #env: JRUBY_OPTS="--server -J-Xms512m -J-Xmx1024m"
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ 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, :ruby_25, :ruby_26], git: 'git@github.com:technicalpickles/jeweler.git'
9
+ gem "jeweler", ">= 2.1.2", platform: :mri, github: 'technicalpickles/jeweler'
10
10
  end
11
11
 
12
12
 
@@ -17,7 +17,7 @@ group :development do
17
17
  gem "nokogiri" # used to test html output
18
18
 
19
19
  if RUBY_VERSION >= "2.5"
20
- gem "sqlite3", "~> 1.4", platform: [:ruby_25, :ruby_26]
20
+ gem "sqlite3", "~> 1.4", platform: :mri
21
21
  else
22
22
  gem "sqlite3", "~> 1.3.6"
23
23
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.0
1
+ 1.6.1
@@ -11,7 +11,7 @@ Local variables:
11
11
  </thead>
12
12
  <tbody>
13
13
  <% if assets.any? %>
14
- <%= datagrid_rows(grid, assets, options) %>
14
+ <%= datagrid_rows(grid, assets, **options) %>
15
15
  <% else %>
16
16
  <tr><td class="noresults" colspan="100%"><%= I18n.t('datagrid.no_results').html_safe %></td></tr>
17
17
  <% end %>
@@ -2,20 +2,21 @@
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.6.0 ruby lib
5
+ # stub: datagrid 1.6.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "datagrid".freeze
9
- s.version = "1.6.0"
9
+ s.version = "1.6.1"
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 = "2020-03-31"
14
+ s.date = "2020-09-07"
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 = [
18
- "LICENSE.txt"
18
+ "LICENSE.txt",
19
+ "Readme.markdown"
19
20
  ]
20
21
  s.files = [
21
22
  ".document",
@@ -316,9 +316,8 @@ module Datagrid
316
316
  def to_csv(*column_names)
317
317
  require "csv"
318
318
  options = column_names.extract_options!
319
- CSV.generate(
320
- {:headers => self.header(*column_names), :write_headers => true}.merge!(options)
321
- ) do |csv|
319
+ options = {:headers => self.header(*column_names), :write_headers => true}.merge!(options)
320
+ CSV.generate(**options) do |csv|
322
321
  each_with_batches do |asset|
323
322
  csv << row_for(asset, *column_names)
324
323
  end
@@ -407,7 +406,7 @@ module Datagrid
407
406
  # Defines a column at instance level
408
407
  #
409
408
  # See Datagrid::Columns::ClassMethods#column for more info
410
- def column(name, options_or_query = {}, options = {}, &block) #:nodoc:
409
+ def column(name, options_or_query = {}, options = {}, &block)
411
410
  self.class.define_column(columns_array, name, options_or_query, options, &block)
412
411
  end
413
412
 
@@ -416,7 +415,7 @@ module Datagrid
416
415
  super
417
416
  end
418
417
 
419
- # Returns all columns available for current grid configuration.
418
+ # Returns all columns that are possible to be displayed for the current grid object
420
419
  #
421
420
  # class MyGrid
422
421
  # filter(:search) {|scope, value| scope.full_text_search(value)}
@@ -536,6 +535,8 @@ module Datagrid
536
535
  def value_from_html_block(context, asset, column)
537
536
  args = []
538
537
  remaining_arity = column.html_block.arity
538
+ remaining_arity = 1 if remaining_arity < 0
539
+
539
540
  asset = decorate(asset)
540
541
 
541
542
  if column.data?
@@ -9,7 +9,7 @@ module Datagrid
9
9
  base.class_eval do
10
10
  class_attribute :scope_value
11
11
 
12
- class_attribute :datagrid_attributes
12
+ class_attribute :datagrid_attributes, instance_writer: false
13
13
  self.datagrid_attributes = []
14
14
 
15
15
  class_attribute :dynamic_block, :instance_writer => false
@@ -163,6 +163,9 @@ module Datagrid
163
163
  end
164
164
 
165
165
  # Returns serializable query arguments skipping all nil values
166
+ #
167
+ # grid = ProductsGrid.new(category: 'dresses', available: true)
168
+ # grid.as_query # => {category: 'dresses', available: true}
166
169
  def as_query
167
170
  attributes = self.attributes.clone
168
171
  attributes.each do |key, value|
@@ -171,6 +174,15 @@ module Datagrid
171
174
  attributes
172
175
  end
173
176
 
177
+ # Returns query parameters to link this grid from a page
178
+ #
179
+ # grid = ProductsGrid.new(category: 'dresses', available: true)
180
+ # Rails.application.routes.url_helpers.products_path(grid.query_params)
181
+ # # => "/products?products_grid[category]=dresses&products_grid[available]=true"
182
+ def query_params(attributes = {})
183
+ { param_name.to_sym => as_query.merge(attributes) }
184
+ end
185
+
174
186
  # Redefines scope at instance level
175
187
  #
176
188
  # class MyGrid
@@ -105,7 +105,8 @@ module Datagrid
105
105
  if scope.limit_value
106
106
  raise Datagrid::ConfigurationError, "ActiveRecord can not use batches in combination with SQL limit"
107
107
  end
108
- scope.find_each(batch_size ? { :batch_size => batch_size} : {}, &block)
108
+ options = batch_size ? { batch_size: batch_size } : {}
109
+ scope.find_each(**options, &block)
109
110
  end
110
111
 
111
112
  def default_cache_key(asset)
@@ -73,7 +73,7 @@ module Datagrid
73
73
  # %td= row.project_name
74
74
  # %td.project-status{class: row.status}= row.status
75
75
  def datagrid_rows(grid, assets = grid.assets, **options, &block)
76
- datagrid_renderer.rows(grid, assets, options, &block)
76
+ datagrid_renderer.rows(grid, assets, **options, &block)
77
77
  end
78
78
 
79
79
  # Renders ordering controls for the given column name
@@ -81,10 +81,9 @@ module Datagrid
81
81
  def order_path(grid, column, descending, request)
82
82
  column = grid.column_by_name(column)
83
83
  query = request ? request.query_parameters : {}
84
- order_parameter = {grid.param_name => grid.as_query.merge(:order => column.name, :descending => descending)}
85
84
  ActionDispatch::Http::URL.path_for(
86
85
  path: request ? request.path : '/',
87
- params: query.merge(order_parameter)
86
+ params: query.merge(grid.query_params(order: column.name, descending: descending))
88
87
  )
89
88
  end
90
89
 
@@ -72,12 +72,8 @@ module Datagrid
72
72
  end
73
73
 
74
74
  def apply_args(*args, &block)
75
- return block.call(*args) if block.arity < 0
76
- args = args.clone
77
- (args.size - block.arity).times do
78
- args.pop
79
- end
80
- block.call(*args)
75
+ size = block.arity < 0 ? args.size : block.arity
76
+ block.call(*args.slice(0, size))
81
77
  end
82
78
 
83
79
  def parse_date(value)
@@ -193,4 +193,18 @@ describe Datagrid::Core do
193
193
  }.to_not raise_error
194
194
  end
195
195
  end
196
+
197
+
198
+ describe ".query_param" do
199
+ it "works" do
200
+ grid = test_report(name: 'value') do
201
+ scope {Entry}
202
+ filter(:name)
203
+ def param_name
204
+ 'grid'
205
+ end
206
+ end
207
+ expect(grid.query_params).to eq({grid: {name: 'value'}})
208
+ end
209
+ end
196
210
  end
@@ -124,7 +124,7 @@ describe Datagrid::Filters::DateFilter do
124
124
 
125
125
  it "should support block" do
126
126
  date = Date.new(2018, 01, 07)
127
- time = date.to_time + 2.hours + 2.minutes
127
+ time = Time.utc(2018, 01, 07, 2, 2)
128
128
  report = test_report(:created_at => date) do
129
129
  scope { Entry }
130
130
  filter(:created_at, :date, :range => true) do |value|
@@ -245,6 +245,17 @@ describe Datagrid::Helper do
245
245
  )
246
246
  end
247
247
 
248
+ it "should render columns with &:symbol block" do
249
+ rp = test_report do
250
+ scope { Entry }
251
+ column(:name, &:name)
252
+ end
253
+
254
+ expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
255
+ "tr td.name" => "Star"
256
+ )
257
+ end
258
+
248
259
  it "should render html columns" do
249
260
  rp = test_report do
250
261
  scope { Entry }
@@ -257,6 +268,41 @@ describe Datagrid::Helper do
257
268
  )
258
269
  end
259
270
 
271
+ it "should render :html columns with &:symbol block" do
272
+ rp = test_report do
273
+ scope { Entry }
274
+ column(:name, :html => true, &:name)
275
+ end
276
+
277
+ expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
278
+ "tr td.name" => "Star"
279
+ )
280
+ end
281
+
282
+ it "should render format columns with &:symbol block" do
283
+ rp = test_report do
284
+ scope { Entry }
285
+ column(:name) do |record|
286
+ format(record, &:name)
287
+ end
288
+ end
289
+
290
+ expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
291
+ "tr td.name" => "Star"
292
+ )
293
+ end
294
+
295
+ it "should render :html columns with &:symbol block with a data attribute" do
296
+ rp = test_report do
297
+ scope { Entry }
298
+ column(:name, :html => true, data: 'DATA', &:name)
299
+ end
300
+
301
+ expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
302
+ "tr td.name" => "Star"
303
+ )
304
+ end
305
+
260
306
  it "should render argument-based html columns" do
261
307
  rp = test_report do
262
308
  scope { Entry }
@@ -2,10 +2,10 @@
2
2
  <p>Namespaced order_for partial.</p>
3
3
  <%= link_to(
4
4
  I18n.t("datagrid.table.order.asc").html_safe,
5
- url_for(grid.param_name => grid.as_query.merge(:order => column.name, :descending => false)),
5
+ url_for(grid.query_params(order: column.name, descending: false)),
6
6
  :class => "asc") %>
7
7
  <%= link_to(
8
8
  I18n.t("datagrid.table.order.desc").html_safe,
9
- url_for(grid.param_name => grid.as_query.merge(:order => column.name, :descending => true )),
9
+ url_for(grid.query_params(order: column.name, descending: true)),
10
10
  :class => "desc") %>
11
11
  </div>
@@ -13,7 +13,7 @@ Local variables:
13
13
  <% if assets.empty? %>
14
14
  <tr><td class="noresults" colspan="100%"><%= I18n.t('datagrid.no_results').html_safe %></td></tr>
15
15
  <% else %>
16
- <%= datagrid_rows(grid, assets, options) %>
16
+ <%= datagrid_rows(grid, assets, **options) %>
17
17
  <% end %>
18
18
  </tbody>
19
19
  <% 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.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-31 00:00:00.000000000 Z
11
+ date: 2020-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -171,6 +171,7 @@ executables: []
171
171
  extensions: []
172
172
  extra_rdoc_files:
173
173
  - LICENSE.txt
174
+ - Readme.markdown
174
175
  files:
175
176
  - ".document"
176
177
  - ".rspec"
@@ -284,7 +285,7 @@ homepage: http://github.com/bogdan/datagrid
284
285
  licenses:
285
286
  - MIT
286
287
  metadata: {}
287
- post_install_message:
288
+ post_install_message:
288
289
  rdoc_options: []
289
290
  require_paths:
290
291
  - lib
@@ -300,7 +301,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
300
301
  version: '0'
301
302
  requirements: []
302
303
  rubygems_version: 3.0.8
303
- signing_key:
304
+ signing_key:
304
305
  specification_version: 4
305
306
  summary: Ruby gem to create datagrids
306
307
  test_files: []