effective_datatables 4.0.4 → 4.0.5

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: a8dde14a2c549834fa79c68dc0631d892cd13e16
4
- data.tar.gz: 0a6c3c8a8b7b2b3ace863ff3529eb42e50c1fd5c
3
+ metadata.gz: 04e0a6631353c2886a27998e81421932eab67e61
4
+ data.tar.gz: e8ebacdf2f46047dc0b1c83577c6fda40e8c28c0
5
5
  SHA512:
6
- metadata.gz: df0878341b50d73ab2cae46045d436e21f0c755790786fdab0c4763d5085a25f1fcaa94ce9cd06ff4bf4cef3d731279cc499c875b28f58931f4443164be5fba6
7
- data.tar.gz: 6ff3ca409d916d1e32809e2b65676128f0171b275a84286b00d2cdfb9b30a3257b5d21ba1a4ebe01d3842cdc2e7f30764c3007f863777cd29846d42313506e29
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(self)
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 effective_form_inputs gem)
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(self, user_id: current_user.id)
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(self, user_id: current_user.id, admin: true)
315
+ @datatable = PostsDatatable.new(user_id: current_user.id, admin: true)
316
316
  end
317
317
  end
318
318
  ```
@@ -1,3 +1,4 @@
1
+ # In practice this is just a regular hash with the aggregate, format, search, sort do syntax that saves a block
1
2
  module Effective
2
3
  class DatatableColumn
3
4
  attr_accessor :attributes
@@ -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: false,
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: :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(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'
@@ -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
- = dropdown(variation: :dropleft) do
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)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '4.0.4'.freeze
2
+ VERSION = '4.0.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: 4.0.4
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-04-23 00:00:00.000000000 Z
11
+ date: 2018-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails