datagrid 1.8.1 → 2.0.0.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -7
  3. data/{Readme.markdown → README.md} +46 -29
  4. data/app/assets/stylesheets/datagrid.css +145 -0
  5. data/app/views/datagrid/_enum_checkboxes.html.erb +5 -3
  6. data/app/views/datagrid/_form.html.erb +4 -5
  7. data/app/views/datagrid/_head.html.erb +26 -3
  8. data/app/views/datagrid/_range_filter.html.erb +5 -3
  9. data/app/views/datagrid/_row.html.erb +12 -1
  10. data/app/views/datagrid/_table.html.erb +4 -4
  11. data/datagrid.gemspec +8 -8
  12. data/lib/datagrid/active_model.rb +9 -17
  13. data/lib/datagrid/base.rb +39 -0
  14. data/lib/datagrid/column_names_attribute.rb +12 -12
  15. data/lib/datagrid/columns/column.rb +155 -133
  16. data/lib/datagrid/columns.rb +495 -282
  17. data/lib/datagrid/configuration.rb +23 -10
  18. data/lib/datagrid/core.rb +184 -150
  19. data/lib/datagrid/deprecated_object.rb +20 -0
  20. data/lib/datagrid/drivers/abstract_driver.rb +13 -25
  21. data/lib/datagrid/drivers/active_record.rb +24 -26
  22. data/lib/datagrid/drivers/array.rb +26 -17
  23. data/lib/datagrid/drivers/mongo_mapper.rb +15 -14
  24. data/lib/datagrid/drivers/mongoid.rb +16 -18
  25. data/lib/datagrid/drivers/sequel.rb +14 -19
  26. data/lib/datagrid/drivers.rb +2 -1
  27. data/lib/datagrid/engine.rb +11 -3
  28. data/lib/datagrid/filters/base_filter.rb +166 -142
  29. data/lib/datagrid/filters/boolean_filter.rb +19 -5
  30. data/lib/datagrid/filters/date_filter.rb +33 -35
  31. data/lib/datagrid/filters/date_time_filter.rb +24 -16
  32. data/lib/datagrid/filters/default_filter.rb +9 -3
  33. data/lib/datagrid/filters/dynamic_filter.rb +151 -105
  34. data/lib/datagrid/filters/enum_filter.rb +43 -19
  35. data/lib/datagrid/filters/extended_boolean_filter.rb +39 -27
  36. data/lib/datagrid/filters/float_filter.rb +16 -5
  37. data/lib/datagrid/filters/integer_filter.rb +21 -10
  38. data/lib/datagrid/filters/ranged_filter.rb +66 -45
  39. data/lib/datagrid/filters/select_options.rb +58 -49
  40. data/lib/datagrid/filters/string_filter.rb +9 -4
  41. data/lib/datagrid/filters.rb +234 -106
  42. data/lib/datagrid/form_builder.rb +116 -128
  43. data/lib/datagrid/generators/scaffold.rb +185 -0
  44. data/lib/datagrid/generators/views.rb +20 -0
  45. data/lib/datagrid/helper.rb +397 -22
  46. data/lib/datagrid/ordering.rb +81 -87
  47. data/lib/datagrid/rspec.rb +8 -12
  48. data/lib/datagrid/utils.rb +42 -38
  49. data/lib/datagrid/version.rb +3 -1
  50. data/lib/datagrid.rb +18 -28
  51. data/templates/base.rb.erb +33 -7
  52. data/templates/grid.rb.erb +1 -1
  53. metadata +18 -19
  54. data/app/assets/stylesheets/datagrid.sass +0 -134
  55. data/lib/datagrid/filters/composite_filters.rb +0 -49
  56. data/lib/datagrid/renderer.rb +0 -157
  57. data/lib/datagrid/scaffold.rb +0 -129
  58. data/lib/tasks/datagrid_tasks.rake +0 -15
  59. data/templates/controller.rb.erb +0 -6
  60. data/templates/index.html.erb +0 -5
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.8.1
4
+ version: 2.0.0.pre.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-05 00:00:00.000000000 Z
11
+ date: 2024-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -16,27 +16,27 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '6.0'
19
+ version: '7.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '6.0'
27
- description: This allows you to easily build datagrid aka data tables with sortable
28
- columns and filters
26
+ version: '7.0'
27
+ description: The library allows you to easily build datagrid aka data tables with
28
+ sortable columns and filters
29
29
  email: agresso@gmail.com
30
30
  executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files:
33
33
  - LICENSE.txt
34
- - Readme.markdown
34
+ - README.md
35
35
  files:
36
36
  - CHANGELOG.md
37
37
  - LICENSE.txt
38
- - Readme.markdown
39
- - app/assets/stylesheets/datagrid.sass
38
+ - README.md
39
+ - app/assets/stylesheets/datagrid.css
40
40
  - app/views/datagrid/_enum_checkboxes.html.erb
41
41
  - app/views/datagrid/_form.html.erb
42
42
  - app/views/datagrid/_head.html.erb
@@ -47,11 +47,13 @@ files:
47
47
  - datagrid.gemspec
48
48
  - lib/datagrid.rb
49
49
  - lib/datagrid/active_model.rb
50
+ - lib/datagrid/base.rb
50
51
  - lib/datagrid/column_names_attribute.rb
51
52
  - lib/datagrid/columns.rb
52
53
  - lib/datagrid/columns/column.rb
53
54
  - lib/datagrid/configuration.rb
54
55
  - lib/datagrid/core.rb
56
+ - lib/datagrid/deprecated_object.rb
55
57
  - lib/datagrid/drivers.rb
56
58
  - lib/datagrid/drivers/abstract_driver.rb
57
59
  - lib/datagrid/drivers/active_record.rb
@@ -63,7 +65,6 @@ files:
63
65
  - lib/datagrid/filters.rb
64
66
  - lib/datagrid/filters/base_filter.rb
65
67
  - lib/datagrid/filters/boolean_filter.rb
66
- - lib/datagrid/filters/composite_filters.rb
67
68
  - lib/datagrid/filters/date_filter.rb
68
69
  - lib/datagrid/filters/date_time_filter.rb
69
70
  - lib/datagrid/filters/default_filter.rb
@@ -76,19 +77,16 @@ files:
76
77
  - lib/datagrid/filters/select_options.rb
77
78
  - lib/datagrid/filters/string_filter.rb
78
79
  - lib/datagrid/form_builder.rb
80
+ - lib/datagrid/generators/scaffold.rb
81
+ - lib/datagrid/generators/views.rb
79
82
  - lib/datagrid/helper.rb
80
83
  - lib/datagrid/locale/en.yml
81
84
  - lib/datagrid/ordering.rb
82
- - lib/datagrid/renderer.rb
83
85
  - lib/datagrid/rspec.rb
84
- - lib/datagrid/scaffold.rb
85
86
  - lib/datagrid/utils.rb
86
87
  - lib/datagrid/version.rb
87
- - lib/tasks/datagrid_tasks.rake
88
88
  - templates/base.rb.erb
89
- - templates/controller.rb.erb
90
89
  - templates/grid.rb.erb
91
- - templates/index.html.erb
92
90
  homepage: https://github.com/bogdan/datagrid
93
91
  licenses:
94
92
  - MIT
@@ -96,8 +94,9 @@ metadata:
96
94
  homepage_uri: https://github.com/bogdan/datagrid
97
95
  bug_tracker_uri: https://github.com/bogdan/datagrid/issues
98
96
  documentation_uri: https://github.com/bogdan/datagrid/wiki
99
- changelog_uri: https://github.com/bogdan/datagrid/blob/master/CHANGELOG.md
97
+ changelog_uri: https://github.com/bogdan/datagrid/blob/main/CHANGELOG.md
100
98
  source_code_uri: https://github.com/bogdan/datagrid
99
+ rubygems_mfa_required: 'true'
101
100
  post_install_message:
102
101
  rdoc_options: []
103
102
  require_paths:
@@ -106,15 +105,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
105
  requirements:
107
106
  - - ">="
108
107
  - !ruby/object:Gem::Version
109
- version: '2.7'
108
+ version: '3.0'
110
109
  required_rubygems_version: !ruby/object:Gem::Requirement
111
110
  requirements:
112
111
  - - ">="
113
112
  - !ruby/object:Gem::Version
114
113
  version: '0'
115
114
  requirements: []
116
- rubygems_version: 3.4.15
115
+ rubygems_version: 3.5.11
117
116
  signing_key:
118
117
  specification_version: 4
119
- summary: Ruby gem to create datagrids
118
+ summary: Library that provides DSL to present table like data
120
119
  test_files: []
@@ -1,134 +0,0 @@
1
- $dg-form-label: 150px
2
-
3
- = clearfix
4
- *zoom: 1
5
-
6
- &:before,
7
- &:after
8
- display: table
9
- content: ''
10
-
11
- &:after
12
- clear: both
13
-
14
- =inline-block
15
- display: inline-block
16
- zoom: 1
17
- *display: inline
18
-
19
- table.datagrid
20
- background-color: transparent
21
- border-collapse: collapse
22
- max-width: 100%
23
-
24
- th
25
- background-color: #eee
26
- text-align: left
27
-
28
- td,
29
- th
30
- border: 1px solid #d6d6d6
31
- padding: 5px 10px
32
-
33
- .order
34
- a.asc, a.desc
35
- text-decoration: none
36
- font-weight: normal
37
-
38
- &.ordered
39
- background-color: #fff7d5
40
-
41
- &.asc
42
- a.asc
43
- font-weight: bold
44
- color: #d00
45
-
46
- &.desc
47
- a.desc
48
- font-weight: bold
49
- color: #d00
50
- .noresults
51
- text-align: center
52
-
53
- .datagrid-form
54
- background-color: #f0f0f0
55
- border-radius: 5px
56
- padding: 20px
57
-
58
- .datagrid-filter
59
- margin: 10px
60
- +clearfix
61
-
62
- label
63
- width: $dg-form-label
64
- float: left
65
- a
66
- float: left
67
-
68
- input[class*='filter']
69
- border: 2px solid #ccc
70
- border-radius: 4px
71
- float: left
72
- padding: 5px 12px
73
- width: 207px
74
-
75
- &.from, &.to
76
- width: 83px
77
-
78
- select
79
- float: left
80
- width: 235px
81
-
82
- &[multiple]
83
- border: 2px solid #ccc
84
- border-radius: 5px
85
- height: 100px
86
- &.dynamic_filter
87
- &.field
88
- width: 178px
89
- &.operation
90
- margin-left: 7px
91
- width: 50px
92
- input.dynamic_filter.value
93
- margin: 10px 0 0 $dg-form-label
94
- clear: both
95
-
96
- .separator
97
- float: left
98
- margin: 6px 4px 0
99
- .enum_filter.checkboxes
100
- float: none
101
- display: block
102
- input
103
- margin: 7px
104
- margin-left: 150px
105
-
106
-
107
- .datagrid-actions
108
- padding-left: $dg-form-label +10
109
-
110
- input[type='submit']
111
- background-color: #555
112
- border: none
113
- border-radius: 5px
114
- color: white
115
- cursor: pointer
116
- font-size: 14px
117
- font-weight: bold
118
- line-height: normal
119
- padding: 7px 15px
120
- vertical-align: middle
121
- +inline-block
122
-
123
- &:hover,
124
- &:focus
125
- background-color: #333
126
-
127
- &:active
128
- background-color: #000
129
-
130
- > a
131
- font-size: 14px
132
- padding: 7px 15px
133
- vertical-align: middle
134
- +inline-block
@@ -1,49 +0,0 @@
1
- module Datagrid
2
- module Filters
3
- # @!visibility private
4
- module CompositeFilters
5
-
6
- def self.included(base)
7
- base.extend ClassMethods
8
- base.class_eval do
9
- end
10
- end
11
-
12
- # @!visibility private
13
- module ClassMethods
14
-
15
- def date_range_filters(field, from_options = {}, to_options = {})
16
- Utils.warn_once('date_range_filters is deprecated in favor of range option for date filter')
17
- from_options = normalize_composite_filter_options(from_options, field)
18
- to_options = normalize_composite_filter_options(to_options, field)
19
-
20
- filter(from_options[:name] || :"from_#{field.to_s.tr('.', '_')}", :date, **from_options) do |date, scope, grid|
21
- grid.driver.greater_equal(scope, field, date)
22
- end
23
- filter(to_options[:name] || :"to_#{field.to_s.tr('.', '_')}", :date, **to_options) do |date, scope, grid|
24
- grid.driver.less_equal(scope, field, date)
25
- end
26
- end
27
-
28
- def integer_range_filters(field, from_options = {}, to_options = {})
29
- Utils.warn_once('integer_range_filters is deprecated in favor of range option for integer filter')
30
- from_options = normalize_composite_filter_options(from_options, field)
31
- to_options = normalize_composite_filter_options(to_options, field)
32
- filter(from_options[:name] || :"from_#{field.to_s.tr('.', '_')}", :integer, **from_options) do |value, scope, grid|
33
- grid.driver.greater_equal(scope, field, value)
34
- end
35
- filter(to_options[:name] || :"to_#{field.to_s.tr('.', '_')}", :integer, **to_options) do |value, scope, grid|
36
- grid.driver.less_equal(scope, field, value)
37
- end
38
- end
39
-
40
- def normalize_composite_filter_options(options, field)
41
- if options.is_a?(String) || options.is_a?(Symbol)
42
- options = {name: options}
43
- end
44
- options
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,157 +0,0 @@
1
- require "action_view"
2
-
3
- module Datagrid
4
- # @!visibility private
5
- class Renderer
6
-
7
- def self.for(template)
8
- new(template)
9
- end
10
-
11
- def initialize(template)
12
- @template = template
13
- end
14
-
15
- def format_value(grid, column, asset)
16
- if column.is_a?(String) || column.is_a?(Symbol)
17
- column = grid.column_by_name(column)
18
- end
19
-
20
- value = grid.html_value(column, @template, asset)
21
-
22
- url = column.options[:url] && column.options[:url].call(asset)
23
- if url
24
- @template.link_to(value, url)
25
- else
26
- value
27
- end
28
- end
29
-
30
- def form_for(grid, options = {})
31
- options[:method] ||= :get
32
- options[:html] ||= {}
33
- options[:html][:class] ||= "datagrid-form #{@template.dom_class(grid)}"
34
- options[:as] ||= grid.param_name
35
- _render_partial('form', options[:partials], {:grid => grid, :options => options})
36
- end
37
-
38
- def table(grid, assets, **options)
39
- options[:html] ||= {}
40
- options[:html][:class] ||= "datagrid #{@template.dom_class(grid)}"
41
-
42
- _render_partial('table', options[:partials],
43
- {
44
- grid: grid,
45
- options: options,
46
- assets: assets
47
- })
48
- end
49
-
50
- def header(grid, options = {})
51
- options[:order] = true unless options.has_key?(:order)
52
-
53
- _render_partial('head', options[:partials],
54
- { :grid => grid, :options => options })
55
- end
56
-
57
- def rows(grid, assets = grid.assets, **options, &block)
58
- result = assets.map do |asset|
59
- row(grid, asset, **options, &block)
60
- end.to_a.join
61
-
62
- _safe(result)
63
- end
64
-
65
- def row(grid, asset, **options, &block)
66
- Datagrid::Helper::HtmlRow.new(self, grid, asset, options).tap do |row|
67
- if block_given?
68
- return @template.capture(row, &block)
69
- end
70
- end
71
- end
72
-
73
- def order_for(grid, column, options = {})
74
- _render_partial('order_for', options[:partials],
75
- { :grid => grid, :column => column })
76
- end
77
-
78
- def order_path(grid, column, descending, request)
79
- column = grid.column_by_name(column)
80
- query = request ? request.query_parameters : {}
81
- ActionDispatch::Http::URL.path_for(
82
- path: request ? request.path : '/',
83
- params: query.merge(grid.query_params(order: column.name, descending: descending))
84
- )
85
- end
86
-
87
- private
88
-
89
- def _safe(string)
90
- string.respond_to?(:html_safe) ? string.html_safe : string
91
- end
92
-
93
- def _render_partial(partial_name, partials_path, locals = {})
94
- @template.render({
95
- :partial => File.join(partials_path || 'datagrid', partial_name),
96
- :locals => locals
97
- })
98
- end
99
- end
100
-
101
- module Helper
102
- # Represents a datagrid row that provides access to column values for the given asset
103
- # @example
104
- # row = datagrid_row(grid, user)
105
- # row.class # => Datagrid::Helper::HtmlRow
106
- # row.first_name # => "<strong>Bogdan</strong>"
107
- # row.grid # => Grid object
108
- # row.asset # => User object
109
- # row.each do |value|
110
- # puts value
111
- # end
112
- class HtmlRow
113
-
114
- include Enumerable
115
-
116
- attr_reader :grid, :asset, :options
117
-
118
- # @!visibility private
119
- def initialize(renderer, grid, asset, options)
120
- @renderer = renderer
121
- @grid = grid
122
- @asset = asset
123
- @options = options
124
- end
125
-
126
- # @return [Object] a column value for given column name
127
- def get(column)
128
- @renderer.format_value(@grid, column, @asset)
129
- end
130
-
131
- # Iterates over all column values that are available in the row
132
- # param block [Proc] column value iterator
133
- def each(&block)
134
- (@options[:columns] || @grid.html_columns).each do |column|
135
- block.call(get(column))
136
- end
137
- end
138
-
139
- def to_s
140
- @renderer.send(:_render_partial, 'row', options[:partials], {
141
- :grid => grid,
142
- :options => options,
143
- :asset => asset
144
- })
145
- end
146
-
147
- protected
148
- def method_missing(method, *args, &blk)
149
- if column = @grid.column_by_name(method)
150
- get(column)
151
- else
152
- super
153
- end
154
- end
155
- end
156
- end
157
- end
@@ -1,129 +0,0 @@
1
- require "rails/generators"
2
-
3
- class Datagrid::Scaffold < Rails::Generators::NamedBase
4
-
5
- include Rails::Generators::ResourceHelpers
6
-
7
- check_class_collision :suffix => "Grid"
8
- source_root File.expand_path(__FILE__ + "/../../../templates")
9
-
10
- def create_scaffold
11
- unless file_exists?(base_grid_file)
12
- template "base.rb.erb", base_grid_file
13
- end
14
- template "grid.rb.erb", "app/grids/#{grid_class_name.underscore}.rb"
15
- if file_exists?(grid_controller_file)
16
- inject_into_file grid_controller_file, index_action, :after => %r{class .*#{grid_controller_class_name}.*\n}
17
- else
18
- template "controller.rb.erb", grid_controller_file
19
- end
20
- template "index.html.erb", view_file
21
- route(generate_routing_namespace("resources :#{grid_controller_short_name}"))
22
- unless defined?(::Kaminari) || defined?(::WillPaginate)
23
- gem 'kaminari'
24
- end
25
- in_root do
26
- {
27
- "css" => " *= require datagrid",
28
- "css.sass" => " *= require datagrid",
29
- "css.scss" => " *= require datagrid",
30
- }.each do |extension, string|
31
- file = "app/assets/stylesheets/application.#{extension}"
32
- if file_exists?(file)
33
- inject_into_file file, string + "\n", {:before => %r{.*require_self}} # before all
34
- end
35
- end
36
- end
37
- end
38
-
39
- def view_file
40
- Rails.root.join("app/views").join(controller_file_path).join("index.html.erb")
41
- end
42
-
43
- def grid_class_name
44
- file_name.camelize.pluralize + "Grid"
45
- end
46
-
47
- def grid_controller_class_name
48
- controller_class_name.camelize + "Controller"
49
- end
50
-
51
- def grid_controller_file
52
- Rails.root.join("app/controllers").join("#{grid_controller_class_name.underscore}.rb")
53
- end
54
-
55
- def grid_controller_short_name
56
- controller_file_name
57
- end
58
-
59
- def grid_model_name
60
- file_name.camelize.singularize
61
- end
62
-
63
- def grid_param_name
64
- grid_class_name.underscore
65
- end
66
-
67
- def pagination_helper_code
68
- if defined?(::WillPaginate)
69
- "will_paginate(@grid.assets)"
70
- else
71
- # Kaminari is default
72
- "paginate(@grid.assets)"
73
- end
74
- end
75
-
76
- def base_grid_file
77
- "app/grids/base_grid.rb"
78
- end
79
-
80
- def grid_route_name
81
- controller_class_name.underscore.gsub("/", "_") + "_path"
82
- end
83
-
84
- def index_action
85
- indent(<<-RUBY)
86
- def index
87
- @grid = #{grid_class_name}.new(grid_params) do |scope|
88
- scope.page(params[:page])
89
- end
90
- end
91
-
92
- protected
93
-
94
- def grid_params
95
- params.fetch(:#{grid_param_name}, {}).permit!
96
- end
97
- RUBY
98
- end
99
-
100
- protected
101
- def generate_routing_namespace(code)
102
- depth = regular_class_path.length
103
- # Create 'namespace' ladder
104
- # namespace :foo do
105
- # namespace :bar do
106
- namespace_ladder = regular_class_path.each_with_index.map do |ns, i|
107
- indent("namespace :#{ns} do\n", i * 2)
108
- end.join
109
-
110
- # Create route
111
- # get 'baz/index'
112
- route = indent(code, depth * 2)
113
-
114
- # Create `end` ladder
115
- # end
116
- # end
117
- end_ladder = (1..depth).reverse_each.map do |i|
118
- indent("end\n", i * 2)
119
- end.join
120
-
121
- # Combine the 3 parts to generate complete route entry
122
- namespace_ladder + route + "\n" + end_ladder
123
- end
124
-
125
- def file_exists?(name)
126
- name = Rails.root.join(name) unless name.to_s.first == "/"
127
- File.exist?(name)
128
- end
129
- end
@@ -1,15 +0,0 @@
1
- namespace :datagrid do
2
-
3
- desc "Copy table partials into rails application"
4
- task :copy_partials do
5
- require "fileutils"
6
- views_path = "app/views/datagrid"
7
- destination_dir = (Rails.root + views_path).to_s
8
- pattern = File.expand_path(File.dirname(__FILE__) + "/../../#{views_path}") + "/*"
9
- Dir[pattern].each do |template|
10
- puts "* copy #{template} => #{destination_dir}"
11
- FileUtils.mkdir_p destination_dir
12
- FileUtils.cp template, destination_dir
13
- end
14
- end
15
- end
@@ -1,6 +0,0 @@
1
- class <%= grid_controller_class_name %> < ApplicationController
2
-
3
- <%= index_action -%>
4
-
5
- end
6
-
@@ -1,5 +0,0 @@
1
- <%%= datagrid_form_for @grid, method: :get, url: <%= grid_route_name %> %>
2
-
3
- <%%= <%=pagination_helper_code%> %>
4
- <%%= datagrid_table @grid %>
5
- <%%= <%=pagination_helper_code%> %>