effective_datatables 3.4.4 → 3.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/app/models/effective/datatable_dsl_tool.rb +11 -3
- data/app/models/effective/effective_datatable/compute.rb +2 -0
- data/app/models/effective/effective_datatable/cookie.rb +1 -1
- data/app/models/effective/effective_datatable/dsl/datatable.rb +3 -5
- data/app/models/effective/effective_datatable/format.rb +8 -18
- data/app/views/effective/datatables/_actions_column.html.haml +1 -8
- data/lib/effective_datatables.rb +2 -2
- data/lib/effective_datatables/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86d13c3823bb2ead08f5b0f149710589c150fd22
|
4
|
+
data.tar.gz: 8892b0cf84bd7f3e22e1381b6b32934e3f61b04d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f79b2cd9bdb8f4e498f0231502a5afdb002632603aa662ecd61951c2910b8a56ed155ded0d371137bbc6eac677196f53da4c2cf48c28f2379e950e3aeb5af99c
|
7
|
+
data.tar.gz: 14389f933ab9567434827750946dbf65b7ad760d0023b4e0edcf68d12d097a7883c086ec353df44be4e56781afe974b22d59b78a7b15634c78e08e4fed2c5701
|
data/README.md
CHANGED
@@ -91,7 +91,7 @@ We're going to display this DataTable on the posts#index action.
|
|
91
91
|
```ruby
|
92
92
|
class PostsController < ApplicationController
|
93
93
|
def index
|
94
|
-
@datatable = PostsDatatable.new
|
94
|
+
@datatable = PostsDatatable.new
|
95
95
|
end
|
96
96
|
end
|
97
97
|
```
|
@@ -255,7 +255,7 @@ In the above example, when `attributes[:user_id]` is present, the table displays
|
|
255
255
|
```ruby
|
256
256
|
class PostsController < ApplicationController
|
257
257
|
def index
|
258
|
-
@datatable = PostsDatatable.new(
|
258
|
+
@datatable = PostsDatatable.new(user_id: current_user.id)
|
259
259
|
end
|
260
260
|
end
|
261
261
|
```
|
@@ -311,7 +311,7 @@ Attributes cannot be changed by search, filter, or state in any way. They're gua
|
|
311
311
|
```ruby
|
312
312
|
class PostsController < ApplicationController
|
313
313
|
def index
|
314
|
-
@datatable = PostsDatatable.new(
|
314
|
+
@datatable = PostsDatatable.new(user_id: current_user.id, admin: true)
|
315
315
|
end
|
316
316
|
end
|
317
317
|
```
|
@@ -407,7 +407,7 @@ Sometimes it's handy to call `.reorder(nil)` on a scope.
|
|
407
407
|
|
408
408
|
The `datatable do ... end` block configures a table of data.
|
409
409
|
|
410
|
-
Initialize the datatable in your controller or view, `@datatable = PostsDatatable.new
|
410
|
+
Initialize the datatable in your controller or view, `@datatable = PostsDatatable.new`, and render it in your view `<%= render_datatable(@datatable) %>`
|
411
411
|
|
412
412
|
### col
|
413
413
|
|
@@ -608,7 +608,7 @@ Creates a single form with fields for each `filter` and a single radio input fie
|
|
608
608
|
|
609
609
|
The form is submitted by an AJAX POST action, or, in some advanced circumstances (see Dynamic Columns below) as a regular POST or even GET.
|
610
610
|
|
611
|
-
Initialize the datatable in your controller or view, `@datatable = PostsDatatable.new
|
611
|
+
Initialize the datatable in your controller or view, `@datatable = PostsDatatable.new`, and render its filters anywhere with `<%= render_datatable_filters(@datatable) %>`.
|
612
612
|
|
613
613
|
### scope
|
614
614
|
|
@@ -864,7 +864,7 @@ If you just want to render a datatable and nothing else, there is a quick way to
|
|
864
864
|
```ruby
|
865
865
|
class PostsController < ApplicationController
|
866
866
|
def index
|
867
|
-
render_datatable_index PostsDatatable.new
|
867
|
+
render_datatable_index PostsDatatable.new
|
868
868
|
end
|
869
869
|
end
|
870
870
|
```
|
@@ -16,16 +16,24 @@ module Effective
|
|
16
16
|
@view = datatable.view
|
17
17
|
end
|
18
18
|
|
19
|
-
def method_missing(method, *args)
|
19
|
+
def method_missing(method, *args, &block)
|
20
20
|
# Catch a common error
|
21
21
|
if [:bulk_actions, :charts, :collection, :filters].include?(method) && in_datatables_do_block
|
22
22
|
raise "#{method} block must be declared outside the datatable do ... end block"
|
23
23
|
end
|
24
24
|
|
25
25
|
if datatable.respond_to?(method)
|
26
|
-
|
26
|
+
if block_given?
|
27
|
+
datatable.send(method, *args) { yield }
|
28
|
+
else
|
29
|
+
datatable.send(method, *args)
|
30
|
+
end
|
27
31
|
elsif view.respond_to?(method)
|
28
|
-
|
32
|
+
if block_given?
|
33
|
+
view.send(method, *args) { yield }
|
34
|
+
else
|
35
|
+
view.send(method, *args)
|
36
|
+
end
|
29
37
|
else
|
30
38
|
super
|
31
39
|
end
|
@@ -97,7 +97,7 @@ module Effective
|
|
97
97
|
)
|
98
98
|
end
|
99
99
|
|
100
|
-
def actions_col(show:
|
100
|
+
def actions_col(show: nil, edit: nil, destroy: nil, col_class: nil, partial: nil, partial_as: nil, responsive: 5000, visible: true, &format)
|
101
101
|
raise 'You can only have one actions column' if datatable.columns[:_actions].present?
|
102
102
|
|
103
103
|
datatable._columns[:_actions] = Effective::DatatableColumn.new(
|
@@ -109,7 +109,7 @@ module Effective
|
|
109
109
|
index: nil,
|
110
110
|
label: '',
|
111
111
|
name: :actions,
|
112
|
-
partial: partial
|
112
|
+
partial: partial,
|
113
113
|
partial_as: partial_as,
|
114
114
|
responsive: responsive,
|
115
115
|
search: false,
|
@@ -119,9 +119,7 @@ module Effective
|
|
119
119
|
th_append: nil,
|
120
120
|
visible: visible,
|
121
121
|
|
122
|
-
show: show,
|
123
|
-
edit: edit,
|
124
|
-
destroy: destroy
|
122
|
+
actions: { show: show, edit: edit, destroy: destroy, partial: :glyphicons }.reject { |k, v| v.nil? }
|
125
123
|
)
|
126
124
|
end
|
127
125
|
|
@@ -15,7 +15,7 @@ module Effective
|
|
15
15
|
datatable: self,
|
16
16
|
column: columns[name],
|
17
17
|
controller_namespace: controller_namespace
|
18
|
-
}.merge(
|
18
|
+
}.merge(resource_col_locals(opts))
|
19
19
|
|
20
20
|
rendered[name] = (view.render(
|
21
21
|
partial: opts[:partial],
|
@@ -58,6 +58,8 @@ module Effective
|
|
58
58
|
end
|
59
59
|
|
60
60
|
case column[:as]
|
61
|
+
when :actions
|
62
|
+
view.render_resource_actions(value, **column[:actions].merge(effective_resource: resource))
|
61
63
|
when :boolean
|
62
64
|
case value
|
63
65
|
when true ; 'Yes'
|
@@ -101,23 +103,11 @@ module Effective
|
|
101
103
|
end
|
102
104
|
|
103
105
|
def actions_col_locals(opts)
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
EffectiveDatatables.authorized?(view.controller, :show, collection_class)
|
110
|
-
),
|
111
|
-
edit_action: (
|
112
|
-
active_record_collection? && opts[:edit] && resource.routes[:edit] &&
|
113
|
-
EffectiveDatatables.authorized?(view.controller, :edit, collection_class)
|
114
|
-
),
|
115
|
-
destroy_action: (
|
116
|
-
active_record_collection? && opts[:destroy] && resource.routes[:destroy] &&
|
117
|
-
EffectiveDatatables.authorized?(view.controller, :destroy, collection_class)
|
118
|
-
),
|
119
|
-
effective_resource: resource
|
120
|
-
}
|
106
|
+
if opts[:as] == :actions
|
107
|
+
{ actions_col_locals: opts[:actions].merge(effective_resource: resource) }
|
108
|
+
else
|
109
|
+
{}
|
110
|
+
end
|
121
111
|
end
|
122
112
|
|
123
113
|
def resource_col_locals(opts)
|
@@ -1,8 +1 @@
|
|
1
|
-
|
2
|
-
= show_icon_to effective_resource.action_path(:show, resource)
|
3
|
-
|
4
|
-
- if edit_action && EffectiveDatatables.authorized?(self, :edit, resource)
|
5
|
-
= edit_icon_to effective_resource.action_path(:edit, resource)
|
6
|
-
|
7
|
-
- if destroy_action && EffectiveDatatables.authorized?(self, :destroy, resource)
|
8
|
-
= destroy_icon_to effective_resource.action_path(:destroy, resource), data: { method: :delete, confirm: "Delete #{resource}?" }
|
1
|
+
= render_resource_actions(resource, **actions_col_locals)
|
data/lib/effective_datatables.rb
CHANGED
@@ -21,7 +21,7 @@ module EffectiveDatatables
|
|
21
21
|
@_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact
|
22
22
|
|
23
23
|
return !!authorization_method unless authorization_method.respond_to?(:call)
|
24
|
-
controller = controller.controller if controller.respond_to?(:controller)
|
24
|
+
controller = controller.controller if controller.respond_to?(:controller)
|
25
25
|
|
26
26
|
begin
|
27
27
|
!!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
|
@@ -31,7 +31,7 @@ module EffectiveDatatables
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.authorize!(controller, action, resource)
|
34
|
-
raise Effective::AccessDenied unless authorized?(controller, action, resource)
|
34
|
+
raise Effective::AccessDenied.new('Access Denied', action, resource) unless authorized?(controller, action, resource)
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
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: 3.4.
|
4
|
+
version: 3.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|