effective_datatables 4.7.21 → 4.8.4

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
  SHA256:
3
- metadata.gz: 284930f6f95c88e0866c44be8ebf6f8377b45047bdc3e053ce69e02132ed2cff
4
- data.tar.gz: 07d299627c82e28f81cc35fccdf1529fbd9c63b099a4469e596d8941c87ab8a4
3
+ metadata.gz: 53f857de2d8388bada0837e3eca598ab75e45cba907bde7b43c01a13c2037cb1
4
+ data.tar.gz: '0488a5bf9fafd8a54833615f6d7610d22567d97c5e1b0d13cd2476e24706d08b'
5
5
  SHA512:
6
- metadata.gz: 76dea3b42df8d0c9b94405f6a4f882281c0bdc0684b5ed0472ecfb5c5e82b16d990b17dc62f210c48c93f3efa03630fe1caf8e2f1f36baf6953ebe8d31c453f0
7
- data.tar.gz: b9578ba204f634e184d77ba6dfec92bb770d353c6946dfc27391b4190c1936f242b7200b40d50cde5a7bce522559d5b1d07ca4da9d0be57e987ad816aeafb82b
6
+ metadata.gz: 740d034417e5aa04860b12a308f4e495b3856c4b86a67443f6ec2e18900a55be58c6edb7235d8ef66981bb827f05ecab29d3f691765b5dee43f5312804644adf
7
+ data.tar.gz: 91712a50aff213013867fd46bbdedc717e0c95fef1748d2d9076bfdd5930ce14a3fff1d158f0feed409c8431fb16b317fae1c34b21accd855546dc089c9dbb0d
@@ -5,6 +5,9 @@ initializeDataTables = (target) ->
5
5
  buttons_export_columns = options['buttons_export_columns'] || ':not(.col-actions)'
6
6
  reorder = datatable.data('reorder')
7
7
 
8
+ if datatable.data('inline') && datatable.closest('form').length > 0
9
+ console.error('inline datatable cannot work inside a form')
10
+
8
11
  if options['buttons'] == false
9
12
  options['buttons'] = []
10
13
 
@@ -1,11 +1,32 @@
1
1
  $(document).on 'click', '.dataTables_wrapper a.buttons-reset-search', (event) ->
2
2
  event.preventDefault() # prevent the click
3
3
 
4
+ # Reset the HTML
4
5
  $table = $(event.currentTarget).closest('.dataTables_wrapper').find('table.dataTable').first()
5
6
  $thead = $table.children('thead').first()
6
7
 
7
- $thead.find('input').val('').removeAttr('checked').removeAttr('selected')
8
+ # Reset all inputs
8
9
  $thead.find('select').val('').trigger('change.select2')
9
10
 
10
- $table.DataTable().search('').columns().search('').draw()
11
+ $inputs = $thead.find('input')
12
+ $inputs.val('').removeAttr('checked').removeAttr('selected')
13
+
14
+ # Reset delayedChange
15
+ $.each $inputs, (input) =>
16
+ $input = $(input)
17
+ if ($input.delayedChange.oldVal)
18
+ $input.delayedChange.oldVal = undefined
19
+
20
+ # Reset the datatable
21
+ datatable = $table.DataTable()
22
+
23
+ # Reset search
24
+ datatable.search('').columns().search('')
25
+
26
+ # Reset to default visibility
27
+ $.each $table.data('default-visibility'), (index, visible) =>
28
+ datatable.column(index).visible(visible, false)
29
+
30
+ # Don't pass up the click
31
+ false
11
32
 
@@ -162,9 +162,7 @@ div.dataTables_scrollFoot > .dataTables_scrollFootInner > table {
162
162
  text-align: center;
163
163
  }
164
164
  }
165
- table.dataTable.table-sm > thead > tr > th {
166
- padding-right: 20px;
167
- }
165
+
168
166
  table.dataTable.table-sm .sorting:before,
169
167
  table.dataTable.table-sm .sorting_asc:before,
170
168
  table.dataTable.table-sm .sorting_desc:before {
@@ -44,6 +44,7 @@ module EffectiveDatatablesHelper
44
44
  'authenticity-token' => form_authenticity_token,
45
45
  'bulk-actions' => datatable_bulk_actions(datatable),
46
46
  'columns' => datatable_columns(datatable),
47
+ 'default-visibility' => datatable.default_visibility.to_json,
47
48
  'display-length' => datatable.display_length,
48
49
  'display-order' => datatable_display_order(datatable),
49
50
  'display-records' => datatable.to_json[:recordsFiltered],
@@ -149,6 +149,8 @@ module EffectiveDatatablesPrivateHelper
149
149
  elsif as == :boolean
150
150
  collection ||= [true, false].map { |value| [t("effective_datatables.boolean_#{value}"), value] }
151
151
  form.public_send(:select, name, collection, options) # boolean
152
+ elsif as == :string
153
+ form.public_send(:text_field, name, options)
152
154
  elsif form.respond_to?(as)
153
155
  form.public_send(as, name, options) # check_box, text_area
154
156
  else
@@ -33,7 +33,7 @@ module Effective
33
33
  include Effective::EffectiveDatatable::Resource
34
34
  include Effective::EffectiveDatatable::State
35
35
 
36
- def initialize(view = nil, attributes = nil)
36
+ def initialize(view = nil, attributes = nil)
37
37
  (attributes = view; view = nil) if view.kind_of?(Hash)
38
38
 
39
39
  @attributes = (attributes || {})
@@ -49,6 +49,7 @@ module Effective
49
49
 
50
50
  raise 'expected a hash of arguments' unless @attributes.kind_of?(Hash)
51
51
  raise 'collection is defined as a method. Please use the collection do ... end syntax.' unless collection.nil?
52
+
52
53
  self.view = view if view
53
54
  end
54
55
 
@@ -170,6 +171,10 @@ module Effective
170
171
  @fallback_effective_resource ||= Effective::Resource.new('', namespace: controller_namespace)
171
172
  end
172
173
 
174
+ def default_visibility
175
+ columns.values.inject({}) { |h, col| h[col[:index]] = col[:visible]; h }
176
+ end
177
+
173
178
  private
174
179
 
175
180
  def column_tool
@@ -20,7 +20,7 @@ module Effective
20
20
  elsif value != nil
21
21
  Effective::Attribute.new(value).type
22
22
  end
23
- ) || :text
23
+ ) || :string
24
24
 
25
25
  datatable._filters[name.to_sym] = {
26
26
  value: value,
@@ -4,7 +4,7 @@ module Effective
4
4
  AGGREGATE_SQL_FUNCTIONS = ['ARRAY_AGG(', 'AVG(', 'COUNT(', 'MAX(', 'MIN(', 'STRING_AGG(', 'SUM(']
5
5
 
6
6
  def admin_namespace?
7
- controller_namespace == 'admin'
7
+ [:admin, 'admin'].include?(controller_namespace)
8
8
  end
9
9
 
10
10
  def controller_namespace
@@ -91,6 +91,8 @@ module Effective
91
91
  opts[:sql_column] = :effective_addresses
92
92
  when :effective_roles
93
93
  opts[:sql_column] = :effective_roles
94
+ when :active_storage
95
+ opts[:sql_column] = :active_storage
94
96
  when :string # This is the fallback
95
97
  # Anything that doesn't belong to the model or the sql table, we assume is a SELECT SUM|AVG|RANK() as fancy
96
98
  opts[:sql_as_column] = true if (effective_resource.table && effective_resource.column(name).blank?)
@@ -137,6 +139,10 @@ module Effective
137
139
  opts[:partial] ||= '/effective/datatables/resource_column'
138
140
  end
139
141
 
142
+ if opts[:as] == :active_storage
143
+ opts[:partial] ||= '/effective/datatables/active_storage_column'
144
+ end
145
+
140
146
  opts[:col_class] = [
141
147
  "col-#{opts[:as]}",
142
148
  "col-#{name.to_s.parameterize}",
@@ -194,6 +200,7 @@ module Effective
194
200
 
195
201
  def load_resource_belongs_tos!
196
202
  return unless active_record_collection?
203
+ return unless @_collection_apply_belongs_to
197
204
 
198
205
  changed = attributes.select do |attribute, value|
199
206
  attribute = attribute.to_s
@@ -204,7 +211,7 @@ module Effective
204
211
  next unless columns[associated]
205
212
 
206
213
  if columns[associated][:as] == :belongs_to
207
- if @_collection_apply_belongs_to && !@_collection.where_values_hash.include?(attribute)
214
+ unless @_collection.where_values_hash.include?(attribute)
208
215
  @_collection = @_collection.where(attribute => value)
209
216
  end
210
217
 
@@ -212,10 +219,8 @@ module Effective
212
219
  elsif columns[associated][:as] == :belongs_to_polymorphic
213
220
  associated_type = attributes["#{associated}_type".to_sym] || raise("Expected #{associated}_type attribute to be present when #{associated}_id is present on a polymorphic belongs to")
214
221
 
215
- if @_collection_apply_belongs_to
216
- if !@_collection.where_values_hash.include?(attribute) && !@_collection.where_values_hash.include?("#{associated}_type")
217
- @_collection = @_collection.where(attribute => value).where("#{associated}_type" => associated_type)
218
- end
222
+ unless @_collection.where_values_hash.include?(attribute) || @_collection.where_values_hash.include?("#{associated}_type")
223
+ @_collection = @_collection.where(attribute => value).where("#{associated}_type" => associated_type)
219
224
  end
220
225
 
221
226
  columns.delete(associated)
@@ -198,7 +198,7 @@ module Effective
198
198
  def parse_filter_value(filter, value)
199
199
  return filter[:parse].call(value) if filter[:parse]
200
200
  return nil if value.blank? && !filter[:required]
201
- Effective::Attribute.new(filter[:value]).parse(value, name: filter[:name])
201
+ Effective::Attribute.new(filter[:as] || filter[:value] || :string).parse(value, name: filter[:name])
202
202
  end
203
203
 
204
204
  def cookie_state_params
@@ -0,0 +1,4 @@
1
+ - Array(resource.public_send(column[:name])).each do |file|
2
+ .col-resource_item
3
+ - title = [file.content_type, number_to_human_size(file.byte_size)].map(&:presence).compact
4
+ = link_to(file.filename, url_for(file), title: title, target: '_blank')
@@ -35,7 +35,7 @@ EffectiveDatatables.setup do |config|
35
35
  config.save_state = true
36
36
 
37
37
  # Configure the _effective_dt cookie.
38
- config.cookie_max_size = 2000 # String size. Final byte size is about 1.5 times bigger, after rails signs it
38
+ config.cookie_max_size = 1500 # String size. Final byte size is about 1.5 times bigger, after rails signs it
39
39
  config.cookie_domain = :all # Should usually be :all
40
40
  config.cookie_tld_length = nil # Leave nil to autodetect, or set to probably 2
41
41
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '4.7.21'.freeze
2
+ VERSION = '4.8.4'.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.7.21
4
+ version: 4.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-10 00:00:00.000000000 Z
11
+ date: 2020-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -153,6 +153,7 @@ files:
153
153
  - app/models/effective/effective_datatable/params.rb
154
154
  - app/models/effective/effective_datatable/resource.rb
155
155
  - app/models/effective/effective_datatable/state.rb
156
+ - app/views/effective/datatables/_active_storage_column.html.haml
156
157
  - app/views/effective/datatables/_bulk_actions_column.html.haml
157
158
  - app/views/effective/datatables/_bulk_actions_dropdown.html.haml
158
159
  - app/views/effective/datatables/_chart.html.haml
@@ -177,7 +178,7 @@ homepage: https://github.com/code-and-effect/effective_datatables
177
178
  licenses:
178
179
  - MIT
179
180
  metadata: {}
180
- post_install_message:
181
+ post_install_message:
181
182
  rdoc_options: []
182
183
  require_paths:
183
184
  - lib
@@ -192,8 +193,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
193
  - !ruby/object:Gem::Version
193
194
  version: '0'
194
195
  requirements: []
195
- rubygems_version: 3.0.3
196
- signing_key:
196
+ rubygems_version: 3.1.2
197
+ signing_key:
197
198
  specification_version: 4
198
199
  summary: Uniquely powerful server-side searching, sorting and filtering of any ActiveRecord
199
200
  or Array collection as well as post-rendered content displayed as a frontend jQuery