effective_datatables 3.5.4 → 3.6.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
- SHA1:
3
- metadata.gz: bb6cc238f24434a34c62758d12f4fde3bbf4df04
4
- data.tar.gz: 9b256d994da5bc2cd2cea3ff806022df755e9a9b
2
+ SHA256:
3
+ metadata.gz: 831a378f29e67058bc5d8d313fd61f33f91589fc8a4968a1163963c63e1fa2ab
4
+ data.tar.gz: '0106983a5a9a22c509c3bb2f5302bcf1e9a0b15a6d9a00c296a62d1379f0f040'
5
5
  SHA512:
6
- metadata.gz: 691651d1bee6cada62b81b2157a096bd0c95d7bdf71251005854e05cf928a75fd0853820d2bcd468ba8a50e6702f8f1900feb2be8812f21b186c8f722a191185
7
- data.tar.gz: 892b8b0a4f070e714118ffad499e0a119c5ec9fc25cc57192e24f95d40a046ebc4045fa727358f59a1cef0f4013c922c5297d45413a42d2a10d98b5b02297fde
6
+ metadata.gz: 239f60681837ec733870367b539697a50249ba25380d727a147b084f170251457be6ab79665387a8edaf0642d5d81a214c9e84f83c21fff48c9e3bed6f288c59
7
+ data.tar.gz: 8daf8acdbcadc0c4de990bd1ddf0f3d1e49edb692dd1108ca415116717d459ce567f6d82016f25bd63e5cfaff1138ecebb60f516be81ad11d64d1954474a9282
@@ -16,7 +16,7 @@ module Effective
16
16
  next unless state[:visible][name]
17
17
 
18
18
  if opts[:partial]
19
- locals = { datatable: self, column: columns[name] }.merge(resource_col_locals(opts))
19
+ locals = { datatable: self, column: opts }.merge(resource_col_locals(opts))
20
20
 
21
21
  rendered[name] = (view.render(
22
22
  partial: opts[:partial],
@@ -29,11 +29,24 @@ module Effective
29
29
  elsif opts[:as] == :actions # This is actions_col and actions_col do .. end, but not actions_col partial: 'something'
30
30
  resources = collection.map { |row| row[opts[:index]] }
31
31
  locals = { datatable: self, column: opts, spacer_template: SPACER_TEMPLATE }
32
- atts = { actions: actions_col_actions(opts), effective_resource: resource, locals: locals, partial: opts[:actions_partial] }.merge(opts[:actions])
33
32
 
34
- rendered[name] = (view.render_resource_actions(resources, atts, &opts[:format]) || '').split(SPACER)
35
- end
33
+ atts = {
34
+ actions: actions_col_actions(opts),
35
+ btn_class: opts[:btn_class],
36
+ effective_resource: effective_resource,
37
+ locals: locals,
38
+ partial: opts[:actions_partial],
39
+ }.compact.merge(opts[:actions])
36
40
 
41
+ rendered[name] = if effective_resource.blank?
42
+ resources.map do |resource|
43
+ polymorphic_resource = Effective::Resource.new(resource, namespace: controller_namespace)
44
+ (view.render_resource_actions(resource, atts.merge(effective_resource: polymorphic_resource), &opts[:format]) || '')
45
+ end
46
+ else
47
+ (view.render_resource_actions(resources, atts, &opts[:format]) || '').split(SPACER)
48
+ end
49
+ end
37
50
  end
38
51
 
39
52
  collection.each_with_index do |row, row_index|
@@ -69,8 +82,7 @@ module Effective
69
82
 
70
83
  case column[:as]
71
84
  when :actions
72
- atts = { actions: actions_col_actions(column), effective_resource: resource, partial: column[:actions_partial] }.merge(column[:actions])
73
- (view.render_resource_actions(value, atts) || '')
85
+ raise("please use actions_col instead of col(#{name}, as: :actions)")
74
86
  when :boolean
75
87
  case value
76
88
  when true ; 'Yes'
@@ -96,10 +108,10 @@ module Effective
96
108
  view.mail_to(value)
97
109
  when :integer
98
110
  value
99
- when :percentage
111
+ when :percent
100
112
  case value
101
- when Integer ; "#{value}%"
102
- when Numeric ; view.number_to_percentage(value * 100, precision: 2)
113
+ when Integer ; view.number_to_percentage(value / 1000.0, precision: 3).gsub('.000%', '%')
114
+ when Numeric ; view.number_to_percentage(value, precision: 3).gsub('.000%', '%')
103
115
  end
104
116
  when :price
105
117
  case value
@@ -115,29 +127,66 @@ module Effective
115
127
 
116
128
  # Takes all default resource actions
117
129
  # Applies data-remote to anything that's data-method post or delete
130
+ # Merges in any extra attributes when passed as a Hash
118
131
  def actions_col_actions(column)
119
- resource.resource_actions
132
+ resource_actions = (effective_resource&.resource_actions || fallback_effective_resource.fallback_resource_actions)
133
+
134
+ actions = if column[:inline]
135
+ resource_actions.transform_values { |opts| opts['data-remote'] = true; opts }
136
+ else
137
+ resource_actions.transform_values { |opts| opts['data-remote'] = true if opts['data-method']; opts }
138
+ end
139
+
140
+ # Merge local options. Special behaviour for remote: false
141
+ if column[:actions].kind_of?(Hash)
142
+ column[:actions].each do |action, opts|
143
+ next unless opts.kind_of?(Hash)
144
+
145
+ existing = actions.find { |_, v| v[:action] == action }&.first
146
+ next unless existing.present?
147
+
148
+ actions[existing]['data-remote'] = opts[:remote] if opts.key?(:remote)
149
+ actions[existing]['data-remote'] = opts['remote'] if opts.key?('remote')
150
+
151
+ actions[existing].merge!(opts.except(:remote, 'remote'))
152
+ end
153
+
154
+ actions = actions.sort do |(_, a), (_, b)|
155
+ (column[:actions].keys.index(a[:action]) || 99) <=> (column[:actions].keys.index(b[:action]) || 99)
156
+ end.to_h
157
+
158
+ end
159
+
160
+ actions
120
161
  end
121
162
 
122
163
  def resource_col_locals(opts)
123
- return {} unless (resource = opts[:resource]).present?
164
+ return {} unless (associated_resource = opts[:resource]).present?
165
+
166
+ associated = associated_resource.macros.include?(opts[:as])
167
+ polymorphic = (opts[:as] == :belongs_to_polymorphic)
124
168
 
125
- locals = { name: opts[:name], effective_resource: resource, show_action: false, edit_action: false }
169
+ resource_name = opts[:name] if associated
170
+ resource_to_s = opts[:name] unless associated || array_collection?
171
+
172
+ locals = {
173
+ resource_name: resource_name,
174
+ resource_to_s: resource_to_s,
175
+ effective_resource: associated_resource,
176
+ show_action: false,
177
+ edit_action: false
178
+ }
126
179
 
127
180
  case opts[:action]
128
181
  when :edit
129
- locals[:edit_action] = (resource.routes[:edit] && EffectiveDatatables.authorized?(view.controller, :edit, resource.klass))
182
+ locals[:edit_action] = (polymorphic || associated_resource.routes[:edit].present?)
130
183
  when :show
131
- locals[:show_action] = (resource.routes[:show] && EffectiveDatatables.authorized?(view.controller, :show, resource.klass))
184
+ locals[:show_action] = (polymorphic || associated_resource.routes[:show].present?)
132
185
  when false
133
- # Nothing
186
+ # Nothing. Already false.
134
187
  else
135
- # Fallback to defaults - check edit then show
136
- if resource.routes[:edit] && EffectiveDatatables.authorized?(view.controller, :edit, resource.klass)
137
- locals[:edit_action] = true
138
- elsif resource.routes[:show] && EffectiveDatatables.authorized?(view.controller, :show, resource.klass)
139
- locals[:show_action] = true
140
- end
188
+ locals[:edit_action] = (polymorphic || associated_resource.routes[:edit].present?)
189
+ locals[:show_action] = (polymorphic || associated_resource.routes[:show].present?)
141
190
  end
142
191
 
143
192
  locals
@@ -1,8 +1,11 @@
1
- - Array(datatable.array_collection? ? resource : resource.send(name)).each do |resource|
2
- .col-resource_item
3
- - if show_action
4
- = link_to resource.to_s, effective_resource.action_path(:show, resource), title: resource.to_s
5
- - elsif edit_action
6
- = link_to resource.to_s, effective_resource.action_path(:edit, resource), title: resource.to_s
7
- - else
8
- = resource.to_s.html_safe
1
+ - Array(local_assigns[:resource_name] ? resource.public_send(resource_name) : resource).each do |resource|
2
+ - resource_to_s = ((local_assigns[:resource_to_s] && resource) ? resource.public_send(resource_to_s) : resource.to_s)
3
+
4
+ - if resource_to_s.present?
5
+ .col-resource_item
6
+ - if edit_action && EffectiveDatatables.authorized?(controller, :edit, resource) && (path = effective_resource.action_path(:edit, resource)).present?
7
+ = link_to resource_to_s, path, title: resource_to_s
8
+ - elsif show_action && EffectiveDatatables.authorized?(controller, :show, resource) && (path = effective_resource.action_path(:show, resource)).present?
9
+ = link_to resource_to_s, path, title: resource_to_s
10
+ - else
11
+ = resource_to_s.to_s.html_safe
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '3.5.4'.freeze
2
+ VERSION = '3.6.0'.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.5.4
4
+ version: 3.6.0
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: 2019-04-12 00:00:00.000000000 Z
11
+ date: 2019-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -113,9 +113,9 @@ files:
113
113
  - app/assets/javascripts/effective_datatables/responsive.js.coffee
114
114
  - app/assets/javascripts/vendor/jquery.delayedChange.js
115
115
  - app/assets/javascripts/vendor/jquery.fileDownload.js
116
- - app/assets/stylesheets/dataTables/buttons/buttons.bootstrap.css
117
- - app/assets/stylesheets/dataTables/dataTables.bootstrap.css
118
- - app/assets/stylesheets/dataTables/responsive/responsive.bootstrap.css
116
+ - app/assets/stylesheets/dataTables/buttons/buttons.bootstrap.scss
117
+ - app/assets/stylesheets/dataTables/dataTables.bootstrap.scss
118
+ - app/assets/stylesheets/dataTables/responsive/responsive.bootstrap.scss
119
119
  - app/assets/stylesheets/effective_datatables.scss
120
120
  - app/assets/stylesheets/effective_datatables/_filters.scss
121
121
  - app/assets/stylesheets/effective_datatables/_overrides.scss
@@ -179,8 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  requirements: []
182
- rubyforge_project:
183
- rubygems_version: 2.4.5.1
182
+ rubygems_version: 3.0.3
184
183
  signing_key:
185
184
  specification_version: 4
186
185
  summary: Uniquely powerful server-side searching, sorting and filtering of any ActiveRecord