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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1c0242dbad62480da69762b2a04510d3cb981c3
4
- data.tar.gz: a2df8c30649013e402b8f4732865d762d1efafc8
3
+ metadata.gz: d69d595177621883ab3c5780638b85faa04d8f32
4
+ data.tar.gz: 7c9f57a71d65beabe49c5d8f4adc5f5362128eea
5
5
  SHA512:
6
- metadata.gz: 905f3715cb5952943b5037138a1ee879d6e50e298dc11b6b29f4087d37f9a559797b787869fca2201109ccebe1d001a9bc0071729d0f4981a2c70ee468d5f335
7
- data.tar.gz: 8dc776904f5ace7f5ec0b0fbc74b8576336803f36cb95c5f76cd7ece4d649902d1fd10bdcd468f0a28376c608246d0e138695bbd5c53410d6d3300f28d1f93ec
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 in icons to show/edit/destroy actions, if authorized to those actions.
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
- actions_col show: false do |post|
241
- if !post.approved? && can?(:approve, Post)
242
- link_to 'Approve', approve_post_path(post) data: { method: :post, confirm: 'Really approve?'}
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|:authorize
527
- edit: true|false|:authorize
528
- destroy: true|false|:authorize
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 show: false do |post|
540
- (post.approved? ? link_to('Approve', approve_post_path(post)) : '') +
541
- glyphicon_to('print', print_ticket_path(ticket), title: 'Print')
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: '/effective/datatables/spacer_template',
27
- ) || '').split('EFFECTIVEDATATABLESSPACER')
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: :authorize)`
37
+ # by calling `actions_column(show: false, edit: true, destroy: false)`
39
38
  config.actions_column = {
40
39
  show: true,
41
40
  edit: true,
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '4.0.6'.freeze
2
+ VERSION = '4.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_datatables
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.6
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect