effective_datatables 4.7.20 → 4.8.3

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: 64b15bd9c60e95f6097c087680780efc353785339a872b303214ba5bfe7f0b4d
4
- data.tar.gz: c60b68831df53a2b8e4d14684313f8c62b2a7dce346209358492d0276aa39804
3
+ metadata.gz: b1ebc0017738a2fc14868698d1ea0bc18e96c30b796abfc1c2b13e56a08e0af7
4
+ data.tar.gz: d3207a967e3ef7864da7865af6c9c349cc414a9a4d137437798c21971bc9dfe5
5
5
  SHA512:
6
- metadata.gz: b816c9a553c6c984f579728363208abbd686adc4ac649dba3c8b2315d1ae0af2a361ce272266bceed88bc732e17bc092f7f1c26359eed861fa97c4b5a806eac0
7
- data.tar.gz: 402548a22f0e10a00915eedf2c6f3e2d8847d6010b9a23b1cfa3633c2f297d25f8aa7e99c2ec229c910478da10f72f1b225c8ae93113cd669962a6139dcab4ed
6
+ metadata.gz: cedbeff6abe599502b345b034cb8c62aa27c404b72d27baa1d0648273b73731bcfba68437854458bc69e986eadf6936407513275234c594ffc3c6c0619c23860
7
+ data.tar.gz: '04650818c9871e4ba2e00ff07d919b9b81c25b867e6033626d6b41004cf7e51fc8943751ca0c8762d83040473127a92672906e6217a677fced997f024ff6510e'
@@ -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
 
@@ -169,7 +172,15 @@ initializeDataTables = (target) ->
169
172
  return if $input.is(':invalid')
170
173
 
171
174
  table = $input.closest('table.dataTable')
172
- table.DataTable().column("#{$input.data('column-name')}:name").search($input.val()).draw()
175
+
176
+ value = $input.val()
177
+
178
+ if value.startsWith('"') && value.endsWith('"')
179
+ value = value.substring(1, value.length-1)
180
+ else
181
+ value = $.trim(value)
182
+
183
+ table.DataTable().column("#{$input.data('column-name')}:name").search(value).draw()
173
184
 
174
185
  if reorder
175
186
  init_options['rowReorder'] = { selector: 'td.col-_reorder', snapX: true, dataSrc: datatable.data('reorder-index') }
@@ -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
 
@@ -18,7 +18,6 @@
18
18
  clearTimeout(timer);
19
19
  timer = setTimeout(function() {
20
20
  var newVal = element.val();
21
- newVal = $.trim(newVal);
22
21
  if (element.delayedChange.oldVal != newVal) {
23
22
  element.delayedChange.oldVal = newVal;
24
23
  o.onChange.call(this, element);
@@ -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,
@@ -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}",
@@ -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.20'.freeze
2
+ VERSION = '4.8.3'.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.20
4
+ version: 4.8.3
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-09 00:00:00.000000000 Z
11
+ date: 2020-07-02 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