effective_datatables 3.4.4 → 3.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7a8fec13eb037474ef6f6ee0d105540c7e2dd9e
4
- data.tar.gz: f69f7de6525a423b215899666992c7b87892cffe
3
+ metadata.gz: 86d13c3823bb2ead08f5b0f149710589c150fd22
4
+ data.tar.gz: 8892b0cf84bd7f3e22e1381b6b32934e3f61b04d
5
5
  SHA512:
6
- metadata.gz: 40876b7464cfaa47b458e905f0e3fe97094052da5cb5ea345c9d0f446ccfcef53728cd0eb155c5e799534e6c1adc153f27606cd1131fc382f7afa0b4234e938a
7
- data.tar.gz: 5250d21495b069d3a1e8fe359e628b39251d1c862793fc0fcb9ca0bd8e13d206e00a302e587f4f1bcb1a410af39a914a464c9d02aa8b2b6933a6430af6c21e3e
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(self)
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(self, user_id: current_user.id)
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(self, user_id: current_user.id, admin: true)
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(self)`, and render it in your view `<%= render_datatable(@datatable) %>`
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(self)`, and render its filters anywhere with `<%= render_datatable_filters(@datatable) %>`.
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(self)
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
- datatable.send(method, *args)
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
- view.send(method, *args)
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
@@ -75,6 +75,8 @@ module Effective
75
75
  resource.send(name)
76
76
  end
77
77
 
78
+ elsif opts[:as] == :actions
79
+ obj
78
80
  elsif opts[:as] == :effective_obfuscation
79
81
  obj.to_param
80
82
  elsif array_collection?
@@ -1,7 +1,7 @@
1
1
  module Effective
2
2
  module EffectiveDatatable
3
3
  module Cookie
4
- MAX_COOKIE_SIZE = 2500 # String size. Real byte size is about 1.5 times bigger.
4
+ MAX_COOKIE_SIZE = 2000 # String size. Real byte size is about 1.5 times bigger.
5
5
 
6
6
  def cookie
7
7
  @cookie
@@ -97,7 +97,7 @@ module Effective
97
97
  )
98
98
  end
99
99
 
100
- def actions_col(show: true, edit: true, destroy: true, col_class: nil, partial: nil, partial_as: nil, responsive: 5000, visible: true, &format)
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 || '/effective/datatables/actions_column',
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(actions_col_locals(opts)).merge(resource_col_locals(opts))
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
- 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
- }
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
- - if show_action && EffectiveDatatables.authorized?(self, :show, resource)
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)
@@ -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) # Do the right thing with a view
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
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '3.4.4'.freeze
2
+ VERSION = '3.4.5'.freeze
3
3
  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
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-04-23 00:00:00.000000000 Z
11
+ date: 2018-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails