effective_datatables 4.0.4 → 4.0.5
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.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/app/models/effective/datatable_column.rb +1 -0
- 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 +3 -21
- data/app/views/effective/datatables/_actions_column.html.haml +1 -10
- data/lib/effective_datatables.rb +1 -1
- 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: 04e0a6631353c2886a27998e81421932eab67e61
|
4
|
+
data.tar.gz: e8ebacdf2f46047dc0b1c83577c6fda40e8c28c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3b227fc1bc1fac6642c927ff68b0af939d35ffcc3ba307bf18793de924f34b0be5337cccec271efac3bcde5280880dc577fa7887e880156bf4247cb3edad60c
|
7
|
+
data.tar.gz: ea3164ff927280bc31f52b6d5d65c0a9b019f484aba9602d5249728e4dbb5397bcb2334857b6dc227d591e9fb257cb9342e61039fa4d5b4ce23baf407371af22
|
data/README.md
CHANGED
@@ -92,7 +92,7 @@ We're going to display this DataTable on the posts#index action.
|
|
92
92
|
```ruby
|
93
93
|
class PostsController < ApplicationController
|
94
94
|
def index
|
95
|
-
@datatable = PostsDatatable.new
|
95
|
+
@datatable = PostsDatatable.new
|
96
96
|
end
|
97
97
|
end
|
98
98
|
```
|
@@ -131,7 +131,7 @@ class PostsDatatable < Effective::Datatable
|
|
131
131
|
# Everything in the filters block ends up in a single form
|
132
132
|
# The form is submitted by datatables javascript as an AJAX post
|
133
133
|
filters do
|
134
|
-
# Scopes are rendered as a single radio button form field (works well with
|
134
|
+
# Scopes are rendered as a single radio button form field (works well with effective_bootstrap gem)
|
135
135
|
# The scopes only work when your collection is an ActiveRecord class, and they must exist on the model
|
136
136
|
# The current scope is automatically applied by effective_datatables to your collection
|
137
137
|
# You don't have to consider the current scope when writing your collection block
|
@@ -256,7 +256,7 @@ In the above example, when `attributes[:user_id]` is present, the table displays
|
|
256
256
|
```ruby
|
257
257
|
class PostsController < ApplicationController
|
258
258
|
def index
|
259
|
-
@datatable = PostsDatatable.new(
|
259
|
+
@datatable = PostsDatatable.new(user_id: current_user.id)
|
260
260
|
end
|
261
261
|
end
|
262
262
|
```
|
@@ -312,7 +312,7 @@ Attributes cannot be changed by search, filter, or state in any way. They're gua
|
|
312
312
|
```ruby
|
313
313
|
class PostsController < ApplicationController
|
314
314
|
def index
|
315
|
-
@datatable = PostsDatatable.new(
|
315
|
+
@datatable = PostsDatatable.new(user_id: current_user.id, admin: true)
|
316
316
|
end
|
317
317
|
end
|
318
318
|
```
|
@@ -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: false,
|
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: :dropleft }.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'
|
@@ -100,26 +102,6 @@ module Effective
|
|
100
102
|
end
|
101
103
|
end
|
102
104
|
|
103
|
-
def actions_col_locals(opts)
|
104
|
-
return {} unless opts[:as] == :actions
|
105
|
-
|
106
|
-
locals = {
|
107
|
-
show_action: (
|
108
|
-
active_record_collection? && opts[:show] && resource.routes[:show] &&
|
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
|
-
}
|
121
|
-
end
|
122
|
-
|
123
105
|
def resource_col_locals(opts)
|
124
106
|
return {} unless (resource = opts[:resource]).present?
|
125
107
|
|
@@ -1,10 +1 @@
|
|
1
|
-
=
|
2
|
-
- if edit_action && EffectiveDatatables.authorized?(self, :edit, resource)
|
3
|
-
= dropdown_link_to 'Edit', effective_resource.action_path(:edit, resource), title: "Edit #{resource}"
|
4
|
-
|
5
|
-
- if show_action && EffectiveDatatables.authorized?(self, :show, resource)
|
6
|
-
= dropdown_link_to 'View', effective_resource.action_path(:show, resource), title: resource.to_s
|
7
|
-
|
8
|
-
- if destroy_action && EffectiveDatatables.authorized?(self, :destroy, resource)
|
9
|
-
= dropdown_link_to "Delete #{resource}", effective_resource.action_path(:destroy, resource),
|
10
|
-
title: "Delete #{resource}", data: { method: :delete, confirm: "Delete #{resource}?" }
|
1
|
+
= render_resource_actions(resource, **actions_col_locals)
|
data/lib/effective_datatables.rb
CHANGED
@@ -30,7 +30,7 @@ module EffectiveDatatables
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.authorize!(controller, action, resource)
|
33
|
-
raise Effective::AccessDenied unless authorized?(controller, action, resource)
|
33
|
+
raise Effective::AccessDenied.new('Access Denied', action, resource) unless authorized?(controller, action, resource)
|
34
34
|
end
|
35
35
|
|
36
36
|
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: 4.0.
|
4
|
+
version: 4.0.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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|