datagrid 1.6.3 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -1
  3. data/Readme.markdown +11 -11
  4. data/app/views/datagrid/_enum_checkboxes.html.erb +2 -2
  5. data/app/views/datagrid/_form.html.erb +2 -3
  6. data/app/views/datagrid/_order_for.html.erb +2 -2
  7. data/app/views/datagrid/_range_filter.html.erb +3 -3
  8. data/datagrid.gemspec +10 -14
  9. data/lib/datagrid/active_model.rb +25 -29
  10. data/lib/datagrid/column_names_attribute.rb +11 -9
  11. data/lib/datagrid/columns/column.rb +10 -8
  12. data/lib/datagrid/columns.rb +142 -176
  13. data/lib/datagrid/configuration.rb +6 -1
  14. data/lib/datagrid/core.rb +63 -30
  15. data/lib/datagrid/drivers/abstract_driver.rb +2 -1
  16. data/lib/datagrid/drivers/active_record.rb +4 -3
  17. data/lib/datagrid/drivers/array.rb +2 -1
  18. data/lib/datagrid/drivers/mongo_mapper.rb +2 -1
  19. data/lib/datagrid/drivers/mongoid.rb +3 -2
  20. data/lib/datagrid/drivers/sequel.rb +8 -3
  21. data/lib/datagrid/drivers.rb +2 -1
  22. data/lib/datagrid/engine.rb +3 -2
  23. data/lib/datagrid/filters/base_filter.rb +8 -4
  24. data/lib/datagrid/filters/boolean_filter.rb +2 -1
  25. data/lib/datagrid/filters/composite_filters.rb +8 -12
  26. data/lib/datagrid/filters/dynamic_filter.rb +1 -1
  27. data/lib/datagrid/filters/extended_boolean_filter.rb +2 -1
  28. data/lib/datagrid/filters/select_options.rb +34 -1
  29. data/lib/datagrid/filters.rb +52 -30
  30. data/lib/datagrid/form_builder.rb +53 -35
  31. data/lib/datagrid/helper.rb +43 -61
  32. data/lib/datagrid/locale/en.yml +5 -1
  33. data/lib/datagrid/ordering.rb +15 -15
  34. data/lib/datagrid/renderer.rb +71 -15
  35. data/lib/datagrid/rspec.rb +4 -4
  36. data/lib/datagrid/scaffold.rb +1 -1
  37. data/lib/datagrid/utils.rb +1 -0
  38. data/lib/datagrid/version.rb +1 -1
  39. data/lib/datagrid.rb +2 -1
  40. data/templates/grid.rb.erb +1 -1
  41. data/templates/index.html.erb +1 -1
  42. metadata +8 -9
  43. data/lib/datagrid/filters/boolean_enum_filter.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5f1043a8a905be92c309d00b6c0b107ebec35939c89b5766f5d7c43dbe2c584
4
- data.tar.gz: 8b4bd8b0130ef2fa83cebe7012386ffcdb4d9ba32d3e803080e4345d6eb74dee
3
+ metadata.gz: 6b7756de5445c9c99d265a897b609b9f3dcf6dbf0b03e32455ca96518bf01eea
4
+ data.tar.gz: 7f748c1a7075331672e749d582145deacc1d38977ada1770b6d7b548d9bb17c9
5
5
  SHA512:
6
- metadata.gz: 4c42259fe4c806e235d10610ab4b3681319d8f5712c73addc1d54f61d6e6cbd0447a967464f878464da2b54f60dc376acef5238cce1467a097d7cbf799beb51d
7
- data.tar.gz: 1ac692930c8a269190bc36ecce7c50cf1c1696fe5b9b6dc0644adfa59eb15a2bab77f4dac70a29633693e707e53ef29ed874eda6f6c82533ed441afe72a5d304
6
+ metadata.gz: 8acee3003f7a9e63ec80808221667fa530f74d882c88d06ce20855b97bf75ec806a6eb5ddf89c9f47044d943238d74c33fcfd290c78d8d4e6e31a3081f4f6e83
7
+ data.tar.gz: 54d4cb553c0a82068d905e8367bffb18298d215b3a0ae09be4b09fa2f77dfe1cc299e019c080d3b689d897f2f38dba217bdef5200284bebadc8ccb1b9ce83644
data/CHANGELOG.md CHANGED
@@ -1,6 +1,24 @@
1
+ ## master
2
+
3
+ ## 1.8.0
4
+
5
+ * Support `input_options: {type: "textarea"}` as `<textarea/>` tag
6
+ * Remove deprecated `eboolean` filter
7
+ * Fixed scope wrapping to be universal
8
+ * Deprecated `integer_range_filters` and `date_range_filters`. Use `filter(name, type, range: true)` instead.
9
+ * Add `original_scope` method that returns scope as it was defined without any wrapping [#313](https://github.com/bogdan/datagrid/pull/313)
10
+ * Add ability to specify `columns` option for `datagrid_row`. [#314](https://github.com/bogdan/datagrid/pull/314)
11
+
12
+ ## 1.7.0
13
+
14
+ * Depend on `railties` instead of `rails` to prevent loading of unnecessary frameworks
15
+ * Bugfix `File.exist?` usage for ruby 3.0 [#307](https://github.com/bogdan/datagrid/issues/307)
16
+ * Drop support of old Ruby versions (< 2.7)
17
+ * Drop support of old Rails versions (< 6.0)
18
+
1
19
  ## 1.6.3
2
20
 
3
- * Fix usage of options spread operator for ruby 3.0 [#296](https://github.com/bogdan/datagrid/issues/296)
21
+ * Fix usage of options spread operator for Ruby 3.0 [#296](https://github.com/bogdan/datagrid/issues/296)
4
22
 
5
23
  ## 1.6.2
6
24
 
data/Readme.markdown CHANGED
@@ -1,12 +1,12 @@
1
1
  # Datagrid
2
2
 
3
- [![Build Status](https://travis-ci.org/bogdan/datagrid.svg?branch=master)](https://travis-ci.org/bogdan/datagrid)
3
+ [![Build Status](https://github.com/bogdan/datagrid/workflows/CI/badge.svg?branch=master)](https://github.com/bogdan/datagrid/actions)
4
4
 
5
5
  [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fbogdan%2Fdatagrid.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fbogdan%2Fdatagrid?ref=badge_shield)
6
6
 
7
- Ruby library that helps you to build and represent table-like data with:
7
+ A really mighty and flexible ruby library that generates reports including admin panels, analytics and data representation:
8
8
 
9
- * Customizable filtering
9
+ * Filtering
10
10
  * Columns
11
11
  * Sort order
12
12
  * Localization
@@ -27,7 +27,7 @@ Ruby library that helps you to build and represent table-like data with:
27
27
 
28
28
  * [Readme](/Readme.markdown) - this read-me for basic information
29
29
  * [Wiki](https://github.com/bogdan/datagrid/wiki) - general reference on how to use the gem
30
- * [Rdoc](https://rdoc.info/github/bogdan/datagrid) - API reference
30
+ * [Rdoc](https://rubydoc.info/gems/datagrid) - API reference
31
31
 
32
32
  ### Live Demo
33
33
 
@@ -54,7 +54,7 @@ class UsersGrid
54
54
  filter(:group_id, :integer, multiple: true)
55
55
  filter(:logins_count, :integer, range: true)
56
56
  filter(:group_name, :string, header: "Group") do |value|
57
- self.joins(:group).where(:groups => {:name => value})
57
+ self.joins(:group).where(groups: {name: value})
58
58
  end
59
59
 
60
60
  column(:name)
@@ -72,11 +72,11 @@ Basic grid api:
72
72
 
73
73
  ``` ruby
74
74
  report = UsersGrid.new(
75
- :group_id => [1,2],
76
- :logins_count => [1, nil],
77
- :category => "first",
78
- :order => :group,
79
- :descending => true
75
+ group_id: [1,2],
76
+ logins_count: [1, nil],
77
+ category: "first",
78
+ order: :group,
79
+ descending: true
80
80
  )
81
81
 
82
82
  report.assets # => Array of User instances:
@@ -145,7 +145,7 @@ Datagrid supports different type of filters including:
145
145
  Each column is represented by name and code block to calculate the value.
146
146
 
147
147
  ``` ruby
148
- column(:activated, :header => "Active", :order => "activated", :after => :name) do
148
+ column(:activated, header: "Active", order: "activated", after: :name) do
149
149
  self.activated?
150
150
  end
151
151
  ```
@@ -4,8 +4,8 @@ You can add indent if whitespace doesn't matter for you
4
4
  %>
5
5
  <%- elements.each do |value, text, checked| -%>
6
6
  <%- id = [form.object_name, filter.name, value].join('_').underscore -%>
7
- <%= form.label filter.name, options.merge(:for => id) do -%>
8
- <%= form.check_box(filter.name, {:multiple => true, :id => id, :checked => checked, :include_hidden => false}, value.to_s, nil) -%>
7
+ <%= form.label filter.name, options.merge(for: id) do -%>
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 -%>
@@ -6,9 +6,8 @@
6
6
  </div>
7
7
  <% end %>
8
8
  <div class="datagrid-actions">
9
- <%= f.submit I18n.t("datagrid.form.search").html_safe, :class => "datagrid-submit" %>
9
+ <%= f.submit I18n.t("datagrid.form.search").html_safe, class: "datagrid-submit" %>
10
10
  <%# https://github.com/rails/rails/pull/14949 -%>
11
- <% empty_parameter = Rails.version >= "4.1.0" && Rails.version <= '4.1.2' ? nil : {}-%>
12
- <%= link_to I18n.t('datagrid.form.reset').html_safe, url_for(grid.to_param => empty_parameter), :class => "datagrid-reset" %>
11
+ <%= link_to I18n.t('datagrid.form.reset').html_safe, url_for(grid.to_param => {}), class: "datagrid-reset" %>
13
12
  </div>
14
13
  <% end -%>
@@ -2,9 +2,9 @@
2
2
  <%= link_to(
3
3
  I18n.t("datagrid.table.order.asc").html_safe,
4
4
  datagrid_order_path(grid, column, false),
5
- :class => "asc") %>
5
+ class: "asc") %>
6
6
  <%= link_to(
7
7
  I18n.t("datagrid.table.order.desc").html_safe,
8
8
  datagrid_order_path(grid, column, true),
9
- :class => "desc") %>
9
+ class: "desc") %>
10
10
  </div>
@@ -1,3 +1,3 @@
1
- <%= form.text_field(filter.name, from_options) %>
2
- <span class="separator <%= filter.type %>"> - </span>
3
- <%= form.text_field(filter.name, to_options) %>
1
+ <%= form.datagrid_filter_input(filter, **from_options) %>
2
+ <span class="separator <%= filter.type %>"><%= I18n.t('datagrid.filters.range.separator') %></span>
3
+ <%= form.datagrid_filter_input(filter, **to_options) %>
data/datagrid.gemspec CHANGED
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "datagrid/version"
2
+
3
+ require_relative "lib/datagrid/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
6
  s.name = "datagrid"
8
7
  s.version = Datagrid::VERSION
9
8
  s.require_paths = ["lib"]
10
9
  s.authors = ["Bogdan Gusiev"]
11
- s.date = "2020-09-07"
12
10
  s.summary = "Ruby gem to create datagrids"
13
11
  s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters"
14
12
  s.email = "agresso@gmail.com"
@@ -23,19 +21,17 @@ Gem::Specification.new do |s|
23
21
  "datagrid.gemspec",
24
22
  ]
25
23
  s.files += `git ls-files | grep -E '^(app|lib|templates)'`.split("\n")
26
- s.homepage = "http://github.com/bogdan/datagrid"
24
+ s.homepage = "https://github.com/bogdan/datagrid"
27
25
  s.licenses = ["MIT"]
28
- s.required_ruby_version = Gem::Requirement.new(">= 2.0")
29
- s.rubygems_version = "3.0.8"
30
- url = 'https://github.com/bogdan/datagrid'
26
+ s.required_ruby_version = Gem::Requirement.new(">= 2.7")
31
27
  s.metadata = {
32
- "homepage_uri" => url,
33
- "bug_tracker_uri" => "#{url}/issues",
34
- "documentation_uri" => "#{url}/wiki",
35
- "changelog_uri" => "#{url}/blob/master/CHANGELOG.md",
36
- "source_code_uri" => url,
28
+ "homepage_uri" => s.homepage,
29
+ "bug_tracker_uri" => "#{s.homepage}/issues",
30
+ "documentation_uri" => "#{s.homepage}/wiki",
31
+ "changelog_uri" => "#{s.homepage}/blob/master/CHANGELOG.md",
32
+ "source_code_uri" => s.homepage,
37
33
  }
38
34
 
39
- s.add_dependency(%q<rails>, [">= 4.0"])
35
+ s.add_dependency "railties", ">= 6.0"
40
36
  end
41
37
 
@@ -1,10 +1,7 @@
1
-
2
1
  module Datagrid
3
-
4
2
  # Required to be ActiveModel compatible
5
- # @private
6
- module ActiveModel #:nodoc:
7
-
3
+ module ActiveModel
4
+ # @!visibility private
8
5
  def self.included(base)
9
6
  base.extend ClassMethods
10
7
  base.class_eval do
@@ -18,41 +15,40 @@ module Datagrid
18
15
  extend ::ActiveModel::AttributesAssignment
19
16
  rescue LoadError
20
17
  end
21
-
22
18
  end
23
- base.send :include, InstanceMethods
24
- end # self.included
19
+ end
25
20
 
26
21
  module ClassMethods
22
+ # @return [String] URL query parameter name of the grid class
27
23
  def param_name
28
24
  self.to_s.underscore.tr('/', '_')
29
25
  end
30
- end # ClassMethods
26
+ end
31
27
 
32
- module InstanceMethods
33
- def param_name
34
- self.class.param_name
35
- end
28
+ # @return [String] URL query parameter name of the grid class
29
+ def param_name
30
+ self.class.param_name
31
+ end
36
32
 
37
- def param_key
38
- param_name
39
- end
33
+ # @return [String] URL query parameter name of the grid class
34
+ def param_key
35
+ param_name
36
+ end
40
37
 
41
- def to_key
42
- [self.class.param_name]
43
- end
38
+ def to_key
39
+ [self.class.param_name]
40
+ end
44
41
 
45
- def persisted?
46
- false
47
- end
42
+ def persisted?
43
+ false
44
+ end
48
45
 
49
- def to_model
50
- self
51
- end
46
+ def to_model
47
+ self
48
+ end
52
49
 
53
- def to_param
54
- self.param_name
55
- end
56
- end # InstanceMethods
50
+ def to_param
51
+ self.param_name
52
+ end
57
53
  end
58
54
  end
@@ -17,15 +17,13 @@ module Datagrid
17
17
  # Adds a filter that acts like a column selection
18
18
  # All defined columns will be available to select/deselect
19
19
  # as a multi-select enum filter.
20
- # Columns with <tt>:mandatory => true</tt> option
20
+ # Columns with <tt>mandatory: true</tt> option
21
21
  # will always present in the grid table and won't be listed
22
22
  # in column names selection
23
23
  # Accepts same options as <tt>:enum</tt> filter
24
- #
25
- # Examples:
26
- #
24
+ # @example
27
25
  # column_names_filter(header: "Choose columns")
28
- #
26
+ # @see Datagrid::Filters::ClassMethods#filter
29
27
  def column_names_filter(**options)
30
28
  filter(
31
29
  :column_names, :enum,
@@ -37,24 +35,28 @@ module Datagrid
37
35
  end
38
36
  end
39
37
 
40
- def columns(*args, **options) #:nodoc:
38
+ # @!visibility private
39
+ def columns(*args, **options)
41
40
  super(*selected_column_names(*args), **options)
42
41
  end
43
42
 
44
- # Returns a list of enabled columns with <tt>:mandatory => true</tt> option
43
+ # Returns a list of enabled columns with <tt>mandatory: true</tt> option
45
44
  # If no mandatory columns specified than all of them considered mandatory
45
+ # @return [Array<Datagrid::Columns::Column>]
46
46
  def mandatory_columns
47
47
  available_columns.select {|c| c.mandatory? }
48
48
  end
49
49
 
50
- # Returns a list of enabled columns without <tt>:mandatory => true</tt> option
50
+ # Returns a list of enabled columns without <tt>mandatory: true</tt> option
51
+ # If no mandatory columns specified than all of them considered mandatory but not optional
52
+ # @return [Array<Datagrid::Columns::Column>]
51
53
  def optional_columns
52
54
  available_columns - mandatory_columns
53
55
  end
54
56
 
55
57
  protected
56
58
 
57
- def optional_columns_select #:nodoc:
59
+ def optional_columns_select
58
60
  optional_columns.map {|c| [c.header, c.name] }
59
61
  end
60
62
 
@@ -1,6 +1,8 @@
1
1
  class Datagrid::Columns::Column
2
2
 
3
- class ResponseFormat # :nodoc:
3
+ # Datagrid class holding an information of
4
+ # how a column should be rendered in data/console/csv format and HTML format
5
+ class ResponseFormat
4
6
 
5
7
  attr_accessor :data_block, :html_block
6
8
 
@@ -131,24 +133,24 @@ class Datagrid::Columns::Column
131
133
  grid.generic_value(self, model)
132
134
  end
133
135
 
134
- def append_preload(scope)
135
- return scope unless preload
136
+ def append_preload(relation)
137
+ return relation unless preload
136
138
  if preload.respond_to?(:call)
137
- return scope unless preload
139
+ return relation unless preload
138
140
  if preload.arity == 1
139
- preload.call(scope)
141
+ preload.call(relation)
140
142
  else
141
- scope.instance_exec(&preload)
143
+ relation.instance_exec(&preload)
142
144
  end
143
145
  else
144
- driver.default_preload(scope, preload)
146
+ driver.default_preload(relation, preload)
145
147
  end
146
148
  end
147
149
 
148
150
  def preload
149
151
  preload = options[:preload]
150
152
 
151
- if preload == true && driver.can_preload?(driver.to_scope(grid_class.scope), name)
153
+ if preload == true && driver.can_preload?(grid_class.scope, name)
152
154
  name
153
155
  else
154
156
  preload