ajax-datatables-rails 0.4.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +120 -0
  3. data/.rubocop.yml +17 -7
  4. data/Appraisals +15 -20
  5. data/CHANGELOG.md +56 -4
  6. data/Gemfile +0 -5
  7. data/Guardfile +16 -0
  8. data/README.md +223 -97
  9. data/Rakefile +1 -0
  10. data/ajax-datatables-rails.gemspec +24 -20
  11. data/bin/_guard-core +29 -0
  12. data/bin/appraisal +29 -0
  13. data/bin/guard +29 -0
  14. data/bin/rake +29 -0
  15. data/bin/rspec +29 -0
  16. data/bin/rubocop +29 -0
  17. data/doc/migrate.md +97 -0
  18. data/doc/webpack.md +7 -2
  19. data/gemfiles/{rails_5.2.0.gemfile → rails_5.2.4.gemfile} +3 -5
  20. data/gemfiles/{rails_5.0.7.gemfile → rails_6.0.3.gemfile} +4 -6
  21. data/gemfiles/{rails_5.1.6.gemfile → rails_6.1.0.gemfile} +4 -6
  22. data/lib/ajax-datatables-rails.rb +12 -1
  23. data/lib/ajax-datatables-rails/active_record.rb +7 -0
  24. data/lib/ajax-datatables-rails/base.rb +47 -46
  25. data/lib/ajax-datatables-rails/datatable.rb +6 -0
  26. data/lib/ajax-datatables-rails/datatable/column.rb +65 -20
  27. data/lib/ajax-datatables-rails/datatable/column/date_filter.rb +12 -21
  28. data/lib/ajax-datatables-rails/datatable/column/order.rb +1 -1
  29. data/lib/ajax-datatables-rails/datatable/column/search.rb +36 -23
  30. data/lib/ajax-datatables-rails/datatable/datatable.rb +16 -6
  31. data/lib/ajax-datatables-rails/datatable/simple_order.rb +23 -10
  32. data/lib/ajax-datatables-rails/datatable/simple_search.rb +2 -0
  33. data/lib/ajax-datatables-rails/error.rb +9 -0
  34. data/lib/ajax-datatables-rails/orm.rb +6 -0
  35. data/lib/ajax-datatables-rails/orm/active_record.rb +11 -12
  36. data/lib/ajax-datatables-rails/version.rb +13 -1
  37. data/lib/generators/rails/templates/datatable.rb +1 -1
  38. data/spec/ajax-datatables-rails/base_spec.rb +95 -79
  39. data/spec/ajax-datatables-rails/datatable/column_spec.rb +83 -12
  40. data/spec/ajax-datatables-rails/datatable/datatable_spec.rb +62 -24
  41. data/spec/ajax-datatables-rails/datatable/simple_order_spec.rb +32 -12
  42. data/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +329 -221
  43. data/spec/ajax-datatables-rails/orm/active_record_paginate_records_spec.rb +5 -6
  44. data/spec/ajax-datatables-rails/orm/active_record_sort_records_spec.rb +12 -11
  45. data/spec/ajax-datatables-rails/orm/active_record_spec.rb +3 -4
  46. data/spec/install_oracle.sh +9 -3
  47. data/spec/spec_helper.rb +10 -21
  48. data/spec/support/datatables/complex_datatable.rb +29 -0
  49. data/spec/support/datatables/complex_datatable_array.rb +14 -0
  50. data/spec/support/{datatable_cond_date.rb → datatables/datatable_cond_date.rb} +0 -0
  51. data/spec/support/{datatable_cond_numeric.rb → datatables/datatable_cond_numeric.rb} +1 -1
  52. data/spec/support/{datatable_cond_proc.rb → datatables/datatable_cond_proc.rb} +0 -0
  53. data/spec/support/datatables/datatable_cond_string.rb +41 -0
  54. data/spec/support/datatables/datatable_cond_unknown.rb +5 -0
  55. data/spec/support/{datatable_order_nulls_last.rb → datatables/datatable_order_nulls_last.rb} +0 -0
  56. data/spec/support/{test_helpers.rb → helpers/params.rb} +14 -41
  57. data/spec/support/{test_models.rb → models/user.rb} +0 -0
  58. metadata +75 -74
  59. data/.travis.yml +0 -80
  60. data/gemfiles/rails_4.0.13.gemfile +0 -14
  61. data/gemfiles/rails_4.1.16.gemfile +0 -14
  62. data/gemfiles/rails_4.2.10.gemfile +0 -14
  63. data/lib/ajax-datatables-rails/config.rb +0 -31
  64. data/lib/ajax_datatables_rails.rb +0 -15
  65. data/lib/generators/datatable/config_generator.rb +0 -19
  66. data/lib/generators/datatable/templates/ajax_datatables_rails_config.rb +0 -12
  67. data/spec/ajax-datatables-rails/configuration_spec.rb +0 -43
  68. data/spec/ajax-datatables-rails/extended_spec.rb +0 -20
  69. data/spec/support/datatable_cond_string.rb +0 -23
data/Rakefile CHANGED
@@ -10,6 +10,7 @@ task :console do
10
10
  require 'pry'
11
11
  require 'rails'
12
12
  require 'ajax-datatables-rails'
13
+ puts 'Loaded AjaxDatatablesRails'
13
14
  ARGV.clear
14
15
  Pry.start
15
16
  end
@@ -1,12 +1,10 @@
1
1
  # frozen_string_literal: true
2
- # coding: utf-8
3
2
 
4
- $LOAD_PATH.push File.expand_path('../lib', __FILE__)
5
- require 'ajax-datatables-rails/version'
3
+ require_relative 'lib/ajax-datatables-rails/version'
6
4
 
7
5
  Gem::Specification.new do |s|
8
6
  s.name = 'ajax-datatables-rails'
9
- s.version = AjaxDatatablesRails::VERSION
7
+ s.version = AjaxDatatablesRails::VERSION::STRING
10
8
  s.platform = Gem::Platform::RUBY
11
9
  s.authors = ['Joel Quenneville', 'Antonio Antillon']
12
10
  s.email = ['joel.quenneville@collegeplus.org', 'antillas21@gmail.com']
@@ -14,26 +12,32 @@ Gem::Specification.new do |s|
14
12
  s.summary = 'A gem that simplifies using datatables and hundreds of records via ajax'
15
13
  s.description = "A wrapper around datatable's ajax methods that allow synchronization with server-side pagination in a rails app"
16
14
  s.license = 'MIT'
15
+ s.metadata = {
16
+ 'homepage_uri' => 'https://github.com/jbox-web/ajax-datatables-rails',
17
+ 'changelog_uri' => 'https://github.com/jbox-web/ajax-datatables-rails/blob/master/CHANGELOG.md',
18
+ 'source_code_uri' => 'https://github.com/jbox-web/ajax-datatables-rails',
19
+ 'bug_tracker_uri' => 'https://github.com/jbox-web/ajax-datatables-rails/issues',
20
+ }
17
21
 
18
- s.add_dependency 'railties', '>= 4.0'
22
+ s.required_ruby_version = '>= 2.5.0'
23
+
24
+ s.files = `git ls-files`.split("\n")
25
+
26
+ s.add_runtime_dependency 'zeitwerk'
19
27
 
20
- s.add_development_dependency 'rails', '>= 4.0'
21
- s.add_development_dependency 'rake'
22
- s.add_development_dependency 'pg', '< 1.0'
23
- s.add_development_dependency 'mysql2'
24
- s.add_development_dependency 'sqlite3'
25
28
  s.add_development_dependency 'activerecord-oracle_enhanced-adapter'
26
- s.add_development_dependency 'rspec'
27
- s.add_development_dependency 'generator_spec'
28
- s.add_development_dependency 'pry'
29
- s.add_development_dependency 'simplecov'
29
+ s.add_development_dependency 'appraisal'
30
30
  s.add_development_dependency 'database_cleaner'
31
31
  s.add_development_dependency 'factory_bot'
32
32
  s.add_development_dependency 'faker'
33
- s.add_development_dependency 'appraisal'
34
-
35
- s.files = `git ls-files`.split("\n")
36
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
37
- s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
38
- s.require_paths = ['lib']
33
+ s.add_development_dependency 'generator_spec'
34
+ s.add_development_dependency 'guard-rspec'
35
+ s.add_development_dependency 'pg'
36
+ s.add_development_dependency 'pry'
37
+ s.add_development_dependency 'rails', '>= 5.2'
38
+ s.add_development_dependency 'rake'
39
+ s.add_development_dependency 'rspec'
40
+ s.add_development_dependency 'rspec-retry'
41
+ s.add_development_dependency 'rubocop'
42
+ s.add_development_dependency 'simplecov'
39
43
  end
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application '_guard-core' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("guard", "_guard-core")
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'appraisal' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("appraisal", "appraisal")
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'guard' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("guard", "guard")
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rubocop", "rubocop")
@@ -0,0 +1,97 @@
1
+ ## To migrate from `v1.0.x` to `v1.3.0`
2
+
3
+ The *v1.3.0* version has some breaking changes :
4
+
5
+ * `AjaxDatatablesRails.config.db_adapter=` is removed and is configured per datatable class now. It defaults to Rails DB adapter. (fixes [#364](https://github.com/jbox-web/ajax-datatables-rails/issues/364))
6
+
7
+ This change is transparent for everyone. Just remove `AjaxDatatablesRails.config.db_adapter=` from your configuration (if exists) and it should work fine.
8
+
9
+ Now you can use AjaxDatatablesRails in multi-db environments.
10
+
11
+ * `AjaxDatatablesRails.config.nulls_last=` is removed and is configured per datatable class now (or by column). It defaults to false.
12
+
13
+ This change is easy to mitigate : add `self.nulls_last = true` in [`ApplicationDatatable`](https://github.com/jbox-web/ajax-datatables-rails#create-a-master-parent-class-easy) and remove `AjaxDatatablesRails.config.nulls_last=`
14
+
15
+ ```ruby
16
+ class ApplicationDatatable < AjaxDatatablesRails::ActiveRecord
17
+ self.nulls_last = true
18
+ # puts commonly used methods here
19
+ end
20
+ ```
21
+
22
+ * `AjaxDatatablesRails.config` is removed with no replacement
23
+
24
+ Fix the two changes above and remove any configuration file about AjaxDatatablesRails. The gem is now configless :)
25
+
26
+ ## To migrate from `v0.4.x` to `v1.0.0`
27
+
28
+ The *v1.0.0* version is a **major break** from *v0.4*.
29
+
30
+ * Datatables no longer inherits from `AjaxDatatablesRails::Base` but from `AjaxDatatablesRails::ActiveRecord` (this solves [#228](https://github.com/jbox-web/ajax-datatables-rails/issues/228))
31
+ * The `view_context` is no longer injected in Datatables but only the `params` hash (see the [example](#4-setup-the-controller-action)). This will break calls to helpers methods.
32
+
33
+ 1) To mitigate the first change (Datatables no longer inherits from `AjaxDatatablesRails::Base` but from `AjaxDatatablesRails::ActiveRecord`)
34
+
35
+ Create a new `ApplicationDatatable` class and make all your classes inherits from it :
36
+
37
+ ```ruby
38
+ class ApplicationDatatable < AjaxDatatablesRails::ActiveRecord
39
+ end
40
+
41
+ class PostDatatable < ApplicationDatatable
42
+ end
43
+ ```
44
+
45
+ **Note :** This is now in the [ProTips™](https://github.com/jbox-web/ajax-datatables-rails#protips) section of the documentation.
46
+
47
+ 2) To mitigate the second change (The `view_context` is no longer injected in Datatables)
48
+
49
+ Update the `ApplicationDatatable` class :
50
+
51
+ ```ruby
52
+ class ApplicationDatatable < AjaxDatatablesRails::ActiveRecord
53
+ extend Forwardable
54
+ attr_reader :view
55
+ def initialize(params, opts = {})
56
+ @view = opts[:view_context]
57
+ super
58
+ end
59
+ end
60
+ ```
61
+
62
+ and update your controllers :
63
+
64
+ ```ruby
65
+ # before
66
+ respond_to do |format|
67
+ format.json { render json: UserDatatable.new(view_context) }
68
+ end
69
+
70
+ # after
71
+ respond_to do |format|
72
+ format.json { render json: UserDatatable.new(params, view_context: view_context) }
73
+ end
74
+
75
+ # if you need to inject some options
76
+ respond_to do |format|
77
+ format.json { render json: UserDatatable.new(params, view_context: view_context, my: 'options') }
78
+ end
79
+ ```
80
+
81
+ This way, you can still use `def_delegators` in your datatables [as in the documentation](https://github.com/jbox-web/ajax-datatables-rails#using-view-helpers).
82
+
83
+ Note that the recommanded way is to use [Draper gem](https://github.com/drapergem/draper) to separate filtering logic from view/presentation logic [as in the documentation](https://github.com/jbox-web/ajax-datatables-rails#using-view-decorators).
84
+
85
+ ## To migrate from `v0.3.x` to `v0.4.x`
86
+
87
+ The *v0.4* version is a **major break** from *v0.3*.
88
+
89
+ The core has been rewriten to remove dependency on [Kaminari](https://github.com/kaminari/kaminari) or [WillPaginate](https://github.com/mislav/will_paginate).
90
+
91
+ It also brings a new (more natural) way of defining columns, based on hash definitions (and not arrays) and add some filtering options for column search.
92
+
93
+ To migrate on the v0.4 you'll need to :
94
+
95
+ * update your DataTables classes to remove all the `extend` directives
96
+ * switch to hash definitions of `view_columns`
97
+ * update your views to declare your columns bindings ([See here](https://github.com/jbox-web/ajax-datatables-rails#5-wire-up-the-javascript))
@@ -5,7 +5,9 @@ We assume here that Bootstrap and FontAwesome are already installed with Webpack
5
5
  Inspired by https://datatables.net/download and completed :
6
6
 
7
7
  Add npm packages :
8
-
8
+ ```sh
9
+ $ yarn add imports-loader
10
+ ```
9
11
  ```sh
10
12
  $ yarn add datatables.net
11
13
  $ yarn add datatables.net-bs
@@ -22,7 +24,10 @@ In `config/webpack/loaders/datatables.js` :
22
24
  ```js
23
25
  module.exports = {
24
26
  test: /datatables\.net.*/,
25
- loader: 'imports-loader?define=>false'
27
+ loader: 'imports-loader',
28
+ options: {
29
+ additionalCode: 'var define = false;'
30
+ }
26
31
  }
27
32
  ```
28
33
 
@@ -2,12 +2,10 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "5.2.0"
5
+ gem "rails", "5.2.4"
6
6
  gem "activerecord-oracle_enhanced-adapter", "~> 5.2.0"
7
+ gem "sqlite3", "~> 1.3.0"
8
+ gem "mysql2"
7
9
  gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced"
8
10
 
9
- group :test do
10
- gem "codeclimate-test-reporter", "~> 1.0.0"
11
- end
12
-
13
11
  gemspec path: "../"
@@ -2,12 +2,10 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "5.0.7"
6
- gem "activerecord-oracle_enhanced-adapter", "~> 1.7.0"
5
+ gem "rails", "6.0.3"
6
+ gem "activerecord-oracle_enhanced-adapter", "~> 6.0.0"
7
+ gem "sqlite3", "~> 1.4.0"
8
+ gem "mysql2"
7
9
  gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced"
8
10
 
9
- group :test do
10
- gem "codeclimate-test-reporter", "~> 1.0.0"
11
- end
12
-
13
11
  gemspec path: "../"
@@ -2,12 +2,10 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "5.1.6"
6
- gem "activerecord-oracle_enhanced-adapter", "~> 1.8.0"
5
+ gem "rails", "6.1.0"
6
+ gem "activerecord-oracle_enhanced-adapter", "~> 6.1.0"
7
+ gem "sqlite3", "~> 1.4.0"
8
+ gem "mysql2"
7
9
  gem "ruby-oci8" if ENV["DB_ADAPTER"] == "oracle_enhanced"
8
10
 
9
- group :test do
10
- gem "codeclimate-test-reporter", "~> 1.0.0"
11
- end
12
-
13
11
  gemspec path: "../"
@@ -1,3 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ajax_datatables_rails'
3
+ require 'zeitwerk'
4
+ loader = Zeitwerk::Loader.for_gem
5
+ generators = "#{__dir__}/generators"
6
+ loader.ignore(generators)
7
+ loader.inflector.inflect(
8
+ 'orm' => 'ORM',
9
+ 'ajax-datatables-rails' => 'AjaxDatatablesRails'
10
+ )
11
+ loader.setup
12
+
13
+ module AjaxDatatablesRails
14
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AjaxDatatablesRails
4
+ class ActiveRecord < AjaxDatatablesRails::Base
5
+ include AjaxDatatablesRails::ORM::ActiveRecord
6
+ end
7
+ end