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 +4 -4
- data/Gemfile.lock +31 -29
- data/README.md +44 -5
- data/ajax-datatables-rails-alt-api.gemspec +1 -1
- data/lib/ajax-datatables-rails/alt-api/datatable/column_def.rb +6 -10
- data/lib/ajax-datatables-rails/alt-api/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60ea4c776910c30aa006d1999efc5e75c9c0ef166a91c11e4c3e6710bd8b943e
|
4
|
+
data.tar.gz: e263427704c12d6f9edfdaf815296250a02f35b84fbdd27c055e15a3abc0a790
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 (
|
11
|
-
actionview (=
|
12
|
-
activesupport (=
|
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
|
17
|
-
actionview (
|
18
|
-
activesupport (=
|
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.
|
23
|
-
activesupport (
|
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.
|
31
|
+
builder (3.2.4)
|
31
32
|
byebug (11.0.1)
|
32
33
|
coderay (1.1.2)
|
33
|
-
concurrent-ruby (1.1.
|
34
|
-
crass (1.0.
|
34
|
+
concurrent-ruby (1.1.6)
|
35
|
+
crass (1.0.6)
|
35
36
|
diff-lcs (1.3)
|
36
|
-
erubi (1.
|
37
|
-
i18n (1.
|
37
|
+
erubi (1.9.0)
|
38
|
+
i18n (1.8.2)
|
38
39
|
concurrent-ruby (~> 1.0)
|
39
|
-
loofah (2.
|
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.
|
45
|
-
nokogiri (1.10.
|
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.
|
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
|
60
|
-
loofah (~> 2.
|
61
|
-
railties (
|
62
|
-
actionpack (=
|
63
|
-
activesupport (=
|
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.
|
67
|
-
rake (
|
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.
|
82
|
+
thor (1.0.1)
|
82
83
|
thread_safe (0.3.6)
|
83
|
-
tzinfo (1.2.
|
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 (~>
|
96
|
+
rake (~> 13.0)
|
95
97
|
rspec (~> 3.0)
|
96
98
|
|
97
99
|
BUNDLED WITH
|
98
|
-
2.0.
|
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.
|
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
|
-
#
|
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
|
-
|
55
|
-
|
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", "~>
|
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
|
-
|
56
|
-
|
57
|
-
|
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
|
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:
|
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:
|
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: '
|
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: '
|
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
|
-
|
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.
|