ajax-datatables-rails-alt-api 0.2 → 0.2.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: 3971b13b37243068c00ebb38f21cdccb1730fa5301e1dc1a450cee5302fea7de
4
- data.tar.gz: 15fbd2322f5babc6f65e12a7a65635cf913c114013ad690e5d97845126514840
3
+ metadata.gz: 60ea4c776910c30aa006d1999efc5e75c9c0ef166a91c11e4c3e6710bd8b943e
4
+ data.tar.gz: e263427704c12d6f9edfdaf815296250a02f35b84fbdd27c055e15a3abc0a790
5
5
  SHA512:
6
- metadata.gz: 26f58dca1f65952fcffd063275c2ed4b4eb01fcf5cac5b863fc9b551a2f6ca8c1c3ec33b9b5682a4d448df2e1be1cba2b856c09ec427d3347b80842f0f424449
7
- data.tar.gz: debc041cdd0f37d3ec3174047efbc45f9e191c75ab4c62f86922d5b864023ad676993470ea4c4d1183b31f78cb21b64cb682f987bf78ec6742708353891cfb8c
6
+ metadata.gz: 86f40e4929a4a2e61d475bcf857d9c6edf63fffd64104386f8a8d03fed1b9d38012d7a3ad616bd41fff6bab74f663d487627f72763a8a216d1f1c0660233f593
7
+ data.tar.gz: d352f4dffae86ec49e23c4729e6c1b1a8ad102245110de6876bd4559be74173422f8ba3934398e1d751cf112cbd54182393403f981e655b2089134fbc263907e
data/Gemfile.lock CHANGED
@@ -7,42 +7,43 @@ PATH
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actionpack (5.2.3)
11
- actionview (= 5.2.3)
12
- activesupport (= 5.2.3)
13
- rack (~> 2.0)
10
+ actionpack (6.0.2.2)
11
+ actionview (= 6.0.2.2)
12
+ activesupport (= 6.0.2.2)
13
+ rack (~> 2.0, >= 2.0.8)
14
14
  rack-test (>= 0.6.3)
15
15
  rails-dom-testing (~> 2.0)
16
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
17
- actionview (5.2.3)
18
- activesupport (= 5.2.3)
16
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
17
+ actionview (6.0.2.2)
18
+ activesupport (= 6.0.2.2)
19
19
  builder (~> 3.1)
20
20
  erubi (~> 1.4)
21
21
  rails-dom-testing (~> 2.0)
22
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
23
- activesupport (5.2.3)
22
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
23
+ activesupport (6.0.2.2)
24
24
  concurrent-ruby (~> 1.0, >= 1.0.2)
25
25
  i18n (>= 0.7, < 2)
26
26
  minitest (~> 5.1)
27
27
  tzinfo (~> 1.1)
28
+ zeitwerk (~> 2.2)
28
29
  ajax-datatables-rails (1.0.0)
29
30
  railties (>= 4.2)
30
- builder (3.2.3)
31
+ builder (3.2.4)
31
32
  byebug (11.0.1)
32
33
  coderay (1.1.2)
33
- concurrent-ruby (1.1.5)
34
- crass (1.0.4)
34
+ concurrent-ruby (1.1.6)
35
+ crass (1.0.6)
35
36
  diff-lcs (1.3)
36
- erubi (1.8.0)
37
- i18n (1.6.0)
37
+ erubi (1.9.0)
38
+ i18n (1.8.2)
38
39
  concurrent-ruby (~> 1.0)
39
- loofah (2.2.3)
40
+ loofah (2.4.0)
40
41
  crass (~> 1.0.2)
41
42
  nokogiri (>= 1.5.9)
42
43
  method_source (0.9.2)
43
44
  mini_portile2 (2.4.0)
44
- minitest (5.11.3)
45
- nokogiri (1.10.3)
45
+ minitest (5.14.0)
46
+ nokogiri (1.10.9)
46
47
  mini_portile2 (~> 2.4.0)
47
48
  pry (0.12.2)
48
49
  coderay (~> 1.1.0)
@@ -50,21 +51,21 @@ GEM
50
51
  pry-byebug (3.7.0)
51
52
  byebug (~> 11.0)
52
53
  pry (~> 0.10)
53
- rack (2.0.7)
54
+ rack (2.2.2)
54
55
  rack-test (1.1.0)
55
56
  rack (>= 1.0, < 3)
56
57
  rails-dom-testing (2.0.3)
57
58
  activesupport (>= 4.2.0)
58
59
  nokogiri (>= 1.6)
59
- rails-html-sanitizer (1.0.4)
60
- loofah (~> 2.2, >= 2.2.2)
61
- railties (5.2.3)
62
- actionpack (= 5.2.3)
63
- activesupport (= 5.2.3)
60
+ rails-html-sanitizer (1.3.0)
61
+ loofah (~> 2.3)
62
+ railties (6.0.2.2)
63
+ actionpack (= 6.0.2.2)
64
+ activesupport (= 6.0.2.2)
64
65
  method_source
65
66
  rake (>= 0.8.7)
66
- thor (>= 0.19.0, < 2.0)
67
- rake (10.5.0)
67
+ thor (>= 0.20.3, < 2.0)
68
+ rake (13.0.1)
68
69
  rspec (3.8.0)
69
70
  rspec-core (~> 3.8.0)
70
71
  rspec-expectations (~> 3.8.0)
@@ -78,10 +79,11 @@ GEM
78
79
  diff-lcs (>= 1.2.0, < 2.0)
79
80
  rspec-support (~> 3.8.0)
80
81
  rspec-support (3.8.0)
81
- thor (0.20.3)
82
+ thor (1.0.1)
82
83
  thread_safe (0.3.6)
83
- tzinfo (1.2.5)
84
+ tzinfo (1.2.6)
84
85
  thread_safe (~> 0.1)
86
+ zeitwerk (2.3.0)
85
87
 
86
88
  PLATFORMS
87
89
  ruby
@@ -91,8 +93,8 @@ DEPENDENCIES
91
93
  bundler (~> 2.0)
92
94
  pry (~> 0.12)
93
95
  pry-byebug (~> 3)
94
- rake (~> 10.0)
96
+ rake (~> 13.0)
95
97
  rspec (~> 3.0)
96
98
 
97
99
  BUNDLED WITH
98
- 2.0.1
100
+ 2.0.2
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  This is an alternative API to the [ajax-datatables-rails](https://github.com/jbox-web/ajax-datatables-rails) gem. The motivation for this was that we had a lot of datatables written against an older version of ajax-datatables-rails. The newer version of ajax-datatables-rails was incompatible with our older implementation of datatables, so it required a major refactor effort. There were certain things in the recent ajax-datatables-rails API felt redundant, and if a major refactor was needed, a reimagined API started to be developed.
4
4
 
5
- This uses ajax-datatables-rails under the hood. Ideally, this or something similar may influence future versions of ajax-datatables-rails.
5
+ This uses ajax-datatables-rails under the hood. Perhaps, this or something similar may influence future versions of ajax-datatables-rails.
6
+
7
+ This is compatible with ajax-datatables-rails. This is intended to replace needing to define methods like: `view_columns`, `data`, defining `def_delgators`.
6
8
 
7
9
  ## Features
8
10
 
@@ -43,16 +45,24 @@ class UserDatatable < ApplicationDatatable
43
45
  column(:links, display_only: true) { link_to("Show", user_path(record)) }
44
46
 
45
47
 
46
- # assuming there is an address relationship to the user, you could expose searchable attrs this way
48
+ # Assuming there is an address relationship to the user, you can expose searchable attributes this way.
47
49
  search_only_attributes %w[Address.city
48
50
  Address.state_name
49
51
  Address.country
50
52
  Address.country_name
51
53
  Address.postal_code]
52
54
 
53
- # some method called by a cell renderer block
54
- def format_address(address)
55
- # makes the address pretty
55
+ # methods not available to the view some method called by a cell renderer block
56
+ module CellMethods
57
+ def format_address(address)
58
+ # makes the address pretty
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def get_raw_records
65
+ User.includes(:address)
56
66
  end
57
67
  end
58
68
  ```
@@ -94,11 +104,40 @@ end
94
104
  $table = $('#users-datatable');
95
105
  $table.DataTable({
96
106
  ajax: $table.data('ajax-url'),
107
+ processing: true,
108
+ serverSide: true,
97
109
  columns: $table.data('datatable-columns')
98
110
  })
99
111
  </script>
100
112
  ```
101
113
 
114
+ ### Column options
115
+
116
+ The `column` method can take the following arguments:
117
+
118
+ | option | type | required | default value | meaning |
119
+ |---------------|---------|----------|-------------------------|---------------------------------------------------------------------------------------------------------------|
120
+ | attr_name | String | yes | `nil` | Name of attr. This can be arbitrary, and not reflective of attributes on a model |
121
+ | source | Boolean | no | same attr on base model | Use this if the attr_name is not on the base_model and the column needs to be searchable or sortable |
122
+ | sortable | Boolean | no | `true` | Do you want the model to be sortable |
123
+ | visible | Boolean | no | `true` | Set to false if this should not be rendered |
124
+ | searchable | Boolean | no | `true` | Set to false if you don't want the column to be searched |
125
+ | condition | Proc | no | `true` | A truthy result of the proc will render the column. This is useful if you want to conditionally show a column |
126
+ | cond | Symbol | no | default of datatables | This is passed through to ajax-datatables-rails. It is the SQL matcher search will use |
127
+ | search_only | Boolean | no | `true` | Shorthand option for do not display but make attr searchable |
128
+ | display_only | Boolean | no | `true` | Shorthand option for display but exclude from search |
129
+ | cell_renderer | Block | no | `nil` | This block is what renders cells. More info below |
130
+
131
+ Cell rendering
132
+
133
+ There are two options for this. Let the `attr_name` return the value associated with the `base_model` attribute. Or you can provide a block. The block can take an argument:
134
+
135
+ `{ |current_record| current_record.name }` or no argument { name } will both behave the same. `method_missing` is used to seamlessly delegate to the `record`, `view`, or CellMethods defined on the datatable.
136
+
137
+ ## Testing
138
+
139
+ Tests are currently, non-existent 😕. It is something I'd like to change, but I doubt will have time. This was extracted from a rails project that had around 20 complex datatables. I feel that this has been put through its paces by working for the project this was extracted from. Tests were written against that project, but since datatables is closely tied with ActiveRecord. I'd like to write tests, but so far have not had the time.
140
+
102
141
  ## Development
103
142
 
104
143
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -38,7 +38,7 @@ Gem::Specification.new do |spec|
38
38
  spec.add_dependency "ajax-datatables-rails", "~> 1.0.0"
39
39
 
40
40
  spec.add_development_dependency "bundler", "~> 2.0"
41
- spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rake", "~> 13.0"
42
42
  spec.add_development_dependency "rspec", "~> 3.0"
43
43
  spec.add_development_dependency "pry", "~> 0.12"
44
44
  spec.add_development_dependency "pry-byebug", "~> 3"
@@ -45,16 +45,14 @@ module AjaxDatatablesRails
45
45
 
46
46
  # Used to serialize options passed to the JS datatable initializer columns
47
47
  def as_json
48
- if condition_met?
49
- {data: attr_name, visible: visible, sortable: sortable}
50
- end
48
+ { data: attr_name, visible: visible, sortable: sortable } if condition_met?
51
49
  end
52
50
 
53
51
  def view_column
54
- {source: search_source,
55
- orderable: to_bool(sortable),
56
- searchable: to_bool(searchable),
57
- cond: cond}
52
+ { source: search_source,
53
+ orderable: to_bool(sortable),
54
+ searchable: to_bool(searchable),
55
+ cond: cond }
58
56
  end
59
57
 
60
58
  def render?
@@ -85,9 +83,7 @@ module AjaxDatatablesRails
85
83
  base_model = datatable.base_model
86
84
  src = source
87
85
  src ||= "#{base_model}.#{attr_name}" if base_model
88
- unless src
89
- raise ColumnDefError, "Unable to infer source for column #{attr_name}"
90
- end
86
+ raise ColumnDefError, "Unable to infer source for column #{attr_name}" unless src
91
87
 
92
88
  src
93
89
  end
@@ -1,5 +1,5 @@
1
1
  module AjaxDatatablesRails
2
2
  module AltApi
3
- VERSION = '0.2'.freeze
3
+ VERSION = '0.2.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ajax-datatables-rails-alt-api
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean McCleary
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-30 00:00:00.000000000 Z
11
+ date: 2020-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ajax-datatables-rails
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -142,7 +142,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  - !ruby/object:Gem::Version
143
143
  version: '0'
144
144
  requirements: []
145
- rubygems_version: 3.0.1
145
+ rubyforge_project:
146
+ rubygems_version: 2.7.6.2
146
147
  signing_key:
147
148
  specification_version: 4
148
149
  summary: This is an alternate API to ajax-datatables-rails.