effective_datatables 4.7.21 → 4.8.0

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
  SHA256:
3
- metadata.gz: 284930f6f95c88e0866c44be8ebf6f8377b45047bdc3e053ce69e02132ed2cff
4
- data.tar.gz: 07d299627c82e28f81cc35fccdf1529fbd9c63b099a4469e596d8941c87ab8a4
3
+ metadata.gz: c5a9a4233ee452020c92387b3bb140eac9df58bd52548c55a2eb41881c731f67
4
+ data.tar.gz: f738131e50148095ea9c1cee3b0f68911d4b2a4f1815b7d5aa6445ec4d849a49
5
5
  SHA512:
6
- metadata.gz: 76dea3b42df8d0c9b94405f6a4f882281c0bdc0684b5ed0472ecfb5c5e82b16d990b17dc62f210c48c93f3efa03630fe1caf8e2f1f36baf6953ebe8d31c453f0
7
- data.tar.gz: b9578ba204f634e184d77ba6dfec92bb770d353c6946dfc27391b4190c1936f242b7200b40d50cde5a7bce522559d5b1d07ca4da9d0be57e987ad816aeafb82b
6
+ metadata.gz: 2279b8c6b0f72dc5427a2d0cc876ee83021806a3152d325edcccbaf8532dd65de27c1a8275320a306568790a60965d6235ee585e4bba41c1337148568df62d51
7
+ data.tar.gz: a7e514c7caf226a633fbd5d6098df1241b38336343fc9d6927f3bab07419d56300c06c4cecab752ed4a43819f9f6946c820cff5af7e0b25c317922a06625155e
@@ -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
 
@@ -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],
@@ -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
@@ -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}",
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '4.7.21'.freeze
2
+ VERSION = '4.8.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: 4.7.21
4
+ version: 4.8.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: 2020-03-10 00:00:00.000000000 Z
11
+ date: 2020-03-31 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