effective_datatables 4.8.1 → 4.8.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/app/assets/javascripts/effective_datatables/initialize.js.coffee +6 -1
- data/app/assets/stylesheets/dataTables/dataTables.bootstrap4.scss +1 -3
- data/app/models/effective/datatable.rb +27 -1
- data/app/models/effective/effective_datatable/attributes.rb +1 -0
- data/app/models/effective/effective_datatable/cookie.rb +2 -0
- data/app/models/effective/effective_datatable/params.rb +5 -0
- data/app/models/effective/effective_datatable/resource.rb +5 -6
- data/app/views/effective/datatables/_active_storage_column.html.haml +1 -1
- data/lib/effective_datatables/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64345f34ef800279082231d6d9e9949c4b68be37c0aa4069e5f435d3d1b1832a
|
4
|
+
data.tar.gz: 67ee557d89223e17b4b083f80eeef98ef4df108227a4c185f4973345fd302c58
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a75374172bd3387fe55c22a21db2fe3f44314c9ab4137ccfe2d8223a179d15e8172b5c8b9898419417fbfe05867c76a77b8fe166bf11d067b3f707d9b44c0e2
|
7
|
+
data.tar.gz: 41de743a61cbddf14cfe85055210767bd7a732d23c5df6e0c618e5359560e5764977adc305f1d43789ed13e37c9ef7c93ddc248567a1761a497eb093fb9cbe6e
|
data/README.md
CHANGED
@@ -1155,6 +1155,22 @@ def finalize(collection)
|
|
1155
1155
|
end
|
1156
1156
|
```
|
1157
1157
|
|
1158
|
+
## Render outside of view
|
1159
|
+
|
1160
|
+
You can render a datatable outside the view.
|
1161
|
+
|
1162
|
+
Anything you pass to the `rendered` method is treated as view/request params.
|
1163
|
+
|
1164
|
+
You can test filters and scopes by passing them here.
|
1165
|
+
|
1166
|
+
```
|
1167
|
+
post = Post.create!
|
1168
|
+
datatable = PostsDatatable.new.rendered(end_date: Time.zone.now+2.days, current_user_id: 1)
|
1169
|
+
|
1170
|
+
assert_equal 1, datatable.collection.count
|
1171
|
+
assert_equal [post], datatable.collection
|
1172
|
+
```
|
1173
|
+
|
1158
1174
|
## Authorization
|
1159
1175
|
|
1160
1176
|
All authorization checks are handled via the config.authorization_method found in the `config/initializers/effective_datatables.rb` file.
|
@@ -5,6 +5,9 @@ initializeDataTables = (target) ->
|
|
5
5
|
buttons_export_columns = options['buttons_export_columns'] || ':not(.col-actions)'
|
6
6
|
reorder = datatable.data('reorder')
|
7
7
|
|
8
|
+
if datatable.data('inline') && datatable.closest('form').length > 0
|
9
|
+
console.error('inline datatable cannot work inside a form')
|
10
|
+
|
8
11
|
if options['buttons'] == false
|
9
12
|
options['buttons'] = []
|
10
13
|
|
@@ -172,7 +175,9 @@ initializeDataTables = (target) ->
|
|
172
175
|
|
173
176
|
value = $input.val()
|
174
177
|
|
175
|
-
if
|
178
|
+
if Array.isArray(value)
|
179
|
+
# Nothing
|
180
|
+
else if value.startsWith('"') && value.endsWith('"')
|
176
181
|
value = value.substring(1, value.length-1)
|
177
182
|
else
|
178
183
|
value = $.trim(value)
|
@@ -162,9 +162,7 @@ div.dataTables_scrollFoot > .dataTables_scrollFootInner > table {
|
|
162
162
|
text-align: center;
|
163
163
|
}
|
164
164
|
}
|
165
|
-
|
166
|
-
padding-right: 20px;
|
167
|
-
}
|
165
|
+
|
168
166
|
table.dataTable.table-sm .sorting:before,
|
169
167
|
table.dataTable.table-sm .sorting_asc:before,
|
170
168
|
table.dataTable.table-sm .sorting_desc:before {
|
@@ -53,10 +53,36 @@ module Effective
|
|
53
53
|
self.view = view if view
|
54
54
|
end
|
55
55
|
|
56
|
+
def rendered(params = {})
|
57
|
+
raise('expected a hash of params') unless params.kind_of?(Hash)
|
58
|
+
|
59
|
+
view = ApplicationController.renderer.controller.helpers
|
60
|
+
|
61
|
+
view.class_eval do
|
62
|
+
attr_accessor :rendered_params
|
63
|
+
|
64
|
+
def current_user
|
65
|
+
rendered_params[:current_user]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
if params[:current_user_id]
|
70
|
+
params[:current_user] = User.find(params[:current_user_id])
|
71
|
+
end
|
72
|
+
|
73
|
+
view.rendered_params = params
|
74
|
+
|
75
|
+
self.view = view
|
76
|
+
self
|
77
|
+
end
|
78
|
+
|
56
79
|
# Once the view is assigned, we initialize everything
|
57
80
|
def view=(view)
|
58
81
|
@view = (view.respond_to?(:view_context) ? view.view_context : view)
|
59
|
-
|
82
|
+
|
83
|
+
unless @view.respond_to?(:params) || @view.respond_to?(:rendered_params)
|
84
|
+
raise 'expected view to respond to params'
|
85
|
+
end
|
60
86
|
|
61
87
|
assert_attributes!
|
62
88
|
load_attributes!
|
@@ -10,6 +10,7 @@ module Effective
|
|
10
10
|
|
11
11
|
def load_cookie!
|
12
12
|
return unless EffectiveDatatables.save_state
|
13
|
+
return unless view.respond_to?(:cookies)
|
13
14
|
|
14
15
|
@dt_cookie = view.cookies.signed['_effective_dt']
|
15
16
|
|
@@ -33,6 +34,7 @@ module Effective
|
|
33
34
|
|
34
35
|
def save_cookie!
|
35
36
|
return unless EffectiveDatatables.save_state
|
37
|
+
return unless view.respond_to?(:cookies)
|
36
38
|
|
37
39
|
@dt_cookie ||= []
|
38
40
|
@dt_cookie << [cookie_key, cookie_payload]
|
@@ -6,18 +6,23 @@ module Effective
|
|
6
6
|
|
7
7
|
def datatables_ajax_request?
|
8
8
|
return @_datatables_ajax_request unless @_datatables_ajax_request.nil?
|
9
|
+
return unless view.respond_to?(:params)
|
9
10
|
|
10
11
|
@_datatables_ajax_request = (view.present? && view.params.key?(:draw) && view.params.key?(:columns))
|
11
12
|
end
|
12
13
|
|
13
14
|
def datatables_inline_request?
|
14
15
|
return @_datatables_inline_request unless @_datatables_inline_request.nil?
|
16
|
+
return unless view.respond_to?(:params)
|
15
17
|
|
16
18
|
@_datatables_inline_request = (view.present? && view.params[:_datatable_id].to_s.split('-')[0...-1] == to_param.split('-')[0...-1])
|
17
19
|
end
|
18
20
|
|
19
21
|
def params
|
20
22
|
return {} unless view.present?
|
23
|
+
return view.rendered_params if view.respond_to?(:rendered_params)
|
24
|
+
return {} unless view.respond_to?(:request)
|
25
|
+
|
21
26
|
@params ||= {}.tap do |params|
|
22
27
|
Rack::Utils.parse_query(URI(view.request.referer.presence || '/').query).each { |k, v| params[k.to_sym] = v }
|
23
28
|
view.params.each { |k, v| params[k.to_sym] = v }
|
@@ -4,7 +4,7 @@ module Effective
|
|
4
4
|
AGGREGATE_SQL_FUNCTIONS = ['ARRAY_AGG(', 'AVG(', 'COUNT(', 'MAX(', 'MIN(', 'STRING_AGG(', 'SUM(']
|
5
5
|
|
6
6
|
def admin_namespace?
|
7
|
-
|
7
|
+
[:admin, 'admin'].include?(controller_namespace)
|
8
8
|
end
|
9
9
|
|
10
10
|
def controller_namespace
|
@@ -200,6 +200,7 @@ module Effective
|
|
200
200
|
|
201
201
|
def load_resource_belongs_tos!
|
202
202
|
return unless active_record_collection?
|
203
|
+
return unless @_collection_apply_belongs_to
|
203
204
|
|
204
205
|
changed = attributes.select do |attribute, value|
|
205
206
|
attribute = attribute.to_s
|
@@ -210,7 +211,7 @@ module Effective
|
|
210
211
|
next unless columns[associated]
|
211
212
|
|
212
213
|
if columns[associated][:as] == :belongs_to
|
213
|
-
|
214
|
+
unless @_collection.where_values_hash.include?(attribute)
|
214
215
|
@_collection = @_collection.where(attribute => value)
|
215
216
|
end
|
216
217
|
|
@@ -218,10 +219,8 @@ module Effective
|
|
218
219
|
elsif columns[associated][:as] == :belongs_to_polymorphic
|
219
220
|
associated_type = attributes["#{associated}_type".to_sym] || raise("Expected #{associated}_type attribute to be present when #{associated}_id is present on a polymorphic belongs to")
|
220
221
|
|
221
|
-
|
222
|
-
|
223
|
-
@_collection = @_collection.where(attribute => value).where("#{associated}_type" => associated_type)
|
224
|
-
end
|
222
|
+
unless @_collection.where_values_hash.include?(attribute) || @_collection.where_values_hash.include?("#{associated}_type")
|
223
|
+
@_collection = @_collection.where(attribute => value).where("#{associated}_type" => associated_type)
|
225
224
|
end
|
226
225
|
|
227
226
|
columns.delete(associated)
|
@@ -1,4 +1,4 @@
|
|
1
1
|
- Array(resource.public_send(column[:name])).each do |file|
|
2
2
|
.col-resource_item
|
3
3
|
- title = [file.content_type, number_to_human_size(file.byte_size)].map(&:presence).compact
|
4
|
-
= link_to(file.filename, url_for(file), title: title)
|
4
|
+
= link_to(file.filename, url_for(file), title: title, target: '_blank')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_datatables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.8.
|
4
|
+
version: 4.8.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -178,7 +178,7 @@ homepage: https://github.com/code-and-effect/effective_datatables
|
|
178
178
|
licenses:
|
179
179
|
- MIT
|
180
180
|
metadata: {}
|
181
|
-
post_install_message:
|
181
|
+
post_install_message:
|
182
182
|
rdoc_options: []
|
183
183
|
require_paths:
|
184
184
|
- lib
|
@@ -193,8 +193,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
requirements: []
|
196
|
-
rubygems_version: 3.
|
197
|
-
signing_key:
|
196
|
+
rubygems_version: 3.1.2
|
197
|
+
signing_key:
|
198
198
|
specification_version: 4
|
199
199
|
summary: Uniquely powerful server-side searching, sorting and filtering of any ActiveRecord
|
200
200
|
or Array collection as well as post-rendered content displayed as a frontend jQuery
|