effective_datatables 4.0.6 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -17
- data/app/models/effective/effective_datatable/format.rb +16 -7
- data/config/effective_datatables.rb +1 -2
- data/lib/effective_datatables/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d69d595177621883ab3c5780638b85faa04d8f32
|
4
|
+
data.tar.gz: 7c9f57a71d65beabe49c5d8f4adc5f5362128eea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d69c22547212f4fb751ddc18e4047555fe9c4a26837f713a000574f7f9f19511131b3f5308a4e29cac6d144759310b49cdb91f1e1f0b5bef2d79db6cbf634dd
|
7
|
+
data.tar.gz: f68c1fcfdd7182f2ec3ea825204f0e811aafde21a86a7bab3c3110ee84ff3ba86df8fcaf45d632af4e61a77f93c3924c1a40b26ff4cfb9d94eee92ce90ddc09c
|
data/README.md
CHANGED
@@ -235,11 +235,12 @@ class PostsDatatable < Effective::Datatable
|
|
235
235
|
aggregate :total
|
236
236
|
|
237
237
|
# Uses effective_resources gem to discover the resource path and authorization actions
|
238
|
-
# Puts
|
238
|
+
# Puts links to show/edit/destroy actions, if authorized to those actions.
|
239
239
|
# Use the actions_col block to add additional actions
|
240
|
-
|
241
|
-
|
242
|
-
|
240
|
+
|
241
|
+
actions_col do |post|
|
242
|
+
render_resource_actions(resource, post, edit: false, partial: :dropleft) do
|
243
|
+
dropdown_link_to('Approve', approve_post_path(post) data: { method: :post, confirm: "Approve #{post}?"})
|
243
244
|
end
|
244
245
|
end
|
245
246
|
end
|
@@ -515,35 +516,31 @@ You can only have one `bulk_actions_col` per datatable.
|
|
515
516
|
|
516
517
|
### actions_col
|
517
518
|
|
518
|
-
When working with an ActiveRecord based collection, this column will consider the `current_user`'s authorization, and generate
|
519
|
-
glyphicon links to edit, show and destroy actions for any collection class.
|
519
|
+
When working with an ActiveRecord based collection, this column will consider the `current_user`'s authorization, and generate links to edit, show and destroy actions for any collection class.
|
520
520
|
|
521
521
|
The authorization method is configured via the `config/initializers/effective_datatables.rb` initializer file.
|
522
522
|
|
523
523
|
There are just a few options:
|
524
524
|
|
525
525
|
```ruby
|
526
|
-
show: true|false
|
527
|
-
edit: true|false
|
528
|
-
destroy: true|false
|
529
|
-
|
526
|
+
show: true|false
|
527
|
+
edit: true|false
|
528
|
+
destroy: true|false
|
530
529
|
visible: true|false
|
531
530
|
```
|
532
531
|
|
533
532
|
When the show, edit and destroy actions are `true` (default), the permission check will be made just once, authorizing the class.
|
534
|
-
When set to `:authorize`, permission to each individual object will be checked.
|
535
533
|
|
536
|
-
Use the block syntax to add additional actions
|
534
|
+
Use the block syntax to add additional actions. This helper comes from `effective_resources` gem.
|
537
535
|
|
538
536
|
```ruby
|
539
|
-
actions_col
|
540
|
-
(post
|
541
|
-
|
537
|
+
actions_col do |post|
|
538
|
+
render_resource_actions(resource, post, edit: false, partial: :dropleft) do
|
539
|
+
dropdown_link_to('Approve', approve_post_path(post) data: { method: :post, confirm: "Approve #{post}?"})
|
540
|
+
end
|
542
541
|
end
|
543
542
|
```
|
544
543
|
|
545
|
-
The `glyphicon_to` helper is part of the [effective_resources](https://github.com/code-and-effect/effective_resources) gem, which is a dependency of this gem.
|
546
|
-
|
547
544
|
### length
|
548
545
|
|
549
546
|
Sets the default number of rows per page. Valid lengths are `5`, `10`, `25`, `50`, `100`, `250`, `500`, `:all`
|
@@ -2,6 +2,8 @@ module Effective
|
|
2
2
|
module EffectiveDatatable
|
3
3
|
module Format
|
4
4
|
BLANK = ''.freeze
|
5
|
+
SPACER = 'EFFECTIVEDATATABLESSPACER'.freeze
|
6
|
+
SPACER_TEMPLATE = '/effective/datatables/spacer_template'.freeze
|
5
7
|
|
6
8
|
private
|
7
9
|
|
@@ -11,11 +13,7 @@ module Effective
|
|
11
13
|
|
12
14
|
columns.each do |name, opts|
|
13
15
|
if opts[:partial] && state[:visible][name]
|
14
|
-
locals = {
|
15
|
-
datatable: self,
|
16
|
-
column: columns[name],
|
17
|
-
controller_namespace: controller_namespace
|
18
|
-
}.merge(resource_col_locals(opts))
|
16
|
+
locals = { datatable: self, column: columns[name] }.merge(resource_col_locals(opts))
|
19
17
|
|
20
18
|
rendered[name] = (view.render(
|
21
19
|
partial: opts[:partial],
|
@@ -23,9 +21,18 @@ module Effective
|
|
23
21
|
collection: collection.map { |row| row[opts[:index]] },
|
24
22
|
formats: :html,
|
25
23
|
locals: locals,
|
26
|
-
spacer_template:
|
27
|
-
) || '').split(
|
24
|
+
spacer_template: SPACER_TEMPLATE
|
25
|
+
) || '').split(SPACER)
|
26
|
+
elsif opts[:as] == :actions # This is default actions_col
|
27
|
+
locals = { datatable: self, column: columns[name], spacer_template: SPACER_TEMPLATE }
|
28
|
+
|
29
|
+
rendered[name] = (view.render_resource_actions(
|
30
|
+
resource,
|
31
|
+
collection.map { |row| row[opts[:index]] },
|
32
|
+
opts[:actions].merge(locals: locals)
|
33
|
+
) || '').split(SPACER)
|
28
34
|
end
|
35
|
+
|
29
36
|
end
|
30
37
|
|
31
38
|
collection.each_with_index do |row, row_index|
|
@@ -42,6 +49,8 @@ module Effective
|
|
42
49
|
dsl_tool.instance_exec(value, row, &opts[:format])
|
43
50
|
elsif opts[:partial]
|
44
51
|
rendered[name][row_index]
|
52
|
+
elsif opts[:as] == :actions
|
53
|
+
rendered[name][row_index]
|
45
54
|
else
|
46
55
|
format_column(value, opts)
|
47
56
|
end
|
@@ -32,10 +32,9 @@ EffectiveDatatables.setup do |config|
|
|
32
32
|
# Valid values for each action are:
|
33
33
|
# true - display this action if authorized?(:show, Post)
|
34
34
|
# false - do not display this action
|
35
|
-
# :authorize - display this action if authorized?(:show, Post<3>) (every instance is checked)
|
36
35
|
#
|
37
36
|
# You can override these defaults on a per-table basis
|
38
|
-
# by calling `actions_column(show: false, edit: true, destroy:
|
37
|
+
# by calling `actions_column(show: false, edit: true, destroy: false)`
|
39
38
|
config.actions_column = {
|
40
39
|
show: true,
|
41
40
|
edit: true,
|