effective_datatables 4.26.1 → 4.27.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: f6fd6b02564f438e0aa52250f202db9db27c5388e677b3e8758eecaa0a46ea82
4
- data.tar.gz: b8fac9e5fbef111411e4b260e9d5ad4a2990cd7e5a8fbbda355b3baa1a2b4abc
3
+ metadata.gz: 87b7b506996cfe6ae06c7f798073c5d33fb77b338dccb923d562c154cd5eb649
4
+ data.tar.gz: a1c244dadeb7888540e1506dd6bd15603451759550115acbdaa05d4a9cb23bda
5
5
  SHA512:
6
- metadata.gz: c7b229e901f10e15b6a1991b68ef50d69575082657257095e811492a1efc830f05732e0747ea86087b57ee80cf0204bc5745e72d3eff7c4fedb654159a170d61
7
- data.tar.gz: fd3f4b8d1f6ad92d25b27bf220addec9754efa774bd941e23e6c1c6201533d6758f275403ff1b4f532eac5967c965fecf02e6d7f5313e9dbcfcbf0fd5d8e5292
6
+ metadata.gz: a69c9330ed0bcd594326a0b0634a0d502e0697299e8b673c38356e0d319090380728fd18f29470ab69d20f7aaf11e236636e1a3d616e226f48c3aa39bb12110f
7
+ data.tar.gz: 5411671b623970f7fc9d5162cc8e72a97757734e57fde615f2a53ac6aa27460010e91a1283692cc53031de59692057041b46b970b1093a24a9b277aab9e10b95
@@ -5,6 +5,13 @@ $(document).on 'click', '.dataTables_wrapper a.buttons-download', (event) ->
5
5
  url = $table.data('source').replace('.json', '/download.csv')
6
6
  attributes = 'attributes=' + encodeURIComponent($table.data('attributes'))
7
7
 
8
- $button.attr('href', url + '?' + attributes)
8
+ # Parse filters and flatten
9
+ filterParams = $table.DataTable().getFilterParams() || {}
10
+ params = filterParams['filter'] || {}
11
+ params['scope'] = filterParams['scope'] if filterParams['scope']
12
+
13
+ filters = '&' + $.param(params)
14
+
15
+ $button.attr('href', url + '?' + attributes + filters)
9
16
 
10
17
  setTimeout (=> $button.attr('href', 'download.csv')), 0
@@ -15,36 +15,38 @@ initializeDataTables = (target) ->
15
15
  ajax: { url: datatable.data('source'), type: 'POST' }
16
16
  autoWidth: false
17
17
  buttons: [
18
- {
19
- extend: 'colvis',
20
- postfixButtons: [
21
- { extend: 'colvisGroup', text: 'Show all', show: ':hidden', className: 'buttons-colvisGroup-first'},
22
- { extend: 'colvisGroup', text: 'Show none', hide: ':visible' },
23
- { extend: 'colvisGroup', text: 'Show default', hide: ':not(.colvis-default)', show: '.colvis-default' }
24
- ]
25
- },
26
- {
27
- extend: 'copy',
28
- exportOptions:
29
- format:
30
- header: (str) -> $("<div>#{str}</div>").children('span').first().text()
31
- columns: buttons_export_columns
32
- },
33
18
  {
34
19
  extend: 'csv',
20
+ text: 'Snapshot',
35
21
  exportOptions:
36
22
  format:
37
23
  header: (str) -> $("<div>#{str}</div>").children('span').first().text()
38
24
  columns: buttons_export_columns
39
25
  },
40
26
  {
41
- extend: 'print',
42
- footer: true,
43
- exportOptions:
44
- format:
45
- header: (str) -> $("<div>#{str}</div>").children('span').first().text()
46
- columns: ':visible:not(.col-actions)'
47
- },
27
+ extend: 'colvis',
28
+ postfixButtons: [
29
+ { extend: 'colvisGroup', text: 'Show all', show: ':hidden', className: 'buttons-colvisGroup-first'},
30
+ { extend: 'colvisGroup', text: 'Show none', hide: ':visible' },
31
+ { extend: 'colvisGroup', text: 'Show default', hide: ':not(.colvis-default)', show: '.colvis-default' }
32
+ ]
33
+ }
34
+ # {
35
+ # extend: 'copy',
36
+ # exportOptions:
37
+ # format:
38
+ # header: (str) -> $("<div>#{str}</div>").children('span').first().text()
39
+ # columns: buttons_export_columns
40
+ # },
41
+
42
+ # {
43
+ # extend: 'print',
44
+ # footer: true,
45
+ # exportOptions:
46
+ # format:
47
+ # header: (str) -> $("<div>#{str}</div>").children('span').first().text()
48
+ # columns: ':visible:not(.col-actions)'
49
+ # },
48
50
  ]
49
51
  columns: datatable.data('columns')
50
52
  deferLoading: [datatable.data('display-records'), datatable.data('total-records')]
@@ -61,29 +63,13 @@ initializeDataTables = (target) ->
61
63
  api.columns().flatten().each (index) => params['columns'][index]['visible'] = api.column(index).visible()
62
64
 
63
65
  $table = $(api.table().node())
64
- $form = $(".effective-datatables-filters[aria-controls='#{$table.attr('id')}']").first()
65
-
66
66
  params['attributes'] = $table.data('attributes')
67
67
  params['authenticity_token'] = $table.data('authenticity-token')
68
68
 
69
- if $form.length > 0
70
- params['scope'] = $form.find("input[name='filters[scope]']:checked").val() || ''
71
- params['filter'] = {}
72
-
73
- $form.find("select,textarea,input:enabled:not([type=submit])").each ->
74
- $input = $(this)
75
-
76
- if ['utf8', 'authenticity_token', 'filters[scope]'].includes($input.attr('name'))
77
- # Skipped
78
- else if $input.attr('type') == 'radio'
79
- name = $input.attr('name')
80
- filter_name = name.replace('filters[', '').substring(0, name.length-9)
81
-
82
- params['filter'][filter_name] = $form.find("input[name='#{name}']:checked").val()
83
-
84
- else if $input.attr('id')
85
- filter_name = $input.attr('id').replace('filters_', '')
86
- params['filter'][filter_name] = $input.val()
69
+ filterParams = api.getFilterParams()
70
+ params['scope'] = filterParams['scope'] if filterParams['scope']
71
+ params['filter'] = filterParams['filter'] if filterParams['filter']
72
+ params
87
73
 
88
74
  serverSide: true
89
75
  scrollCollapse: true
@@ -0,0 +1,29 @@
1
+ getFilterParams = ->
2
+ table_id = @table().node().id
3
+ $form = $(".effective-datatables-filters[aria-controls='#{table_id}']").first()
4
+
5
+ # Parse Filter & Scope Params
6
+ params = {}
7
+
8
+ if $form.length > 0
9
+ params['scope'] = $form.find("input[name='filters[scope]']:checked").val() || ''
10
+ params['filter'] = {}
11
+
12
+ $form.find("select,textarea,input:enabled:not([type=submit])").each ->
13
+ $input = $(this)
14
+
15
+ if ['utf8', 'authenticity_token', 'filters[scope]'].includes($input.attr('name'))
16
+ # Skipped
17
+ else if $input.attr('type') == 'radio'
18
+ name = $input.attr('name')
19
+ filter_name = name.replace('filters[', '').substring(0, name.length-9)
20
+
21
+ params['filter'][filter_name] = $form.find("input[name='#{name}']:checked").val()
22
+
23
+ else if $input.attr('id')
24
+ filter_name = $input.attr('id').replace('filters_', '')
25
+ params['filter'][filter_name] = $input.val()
26
+
27
+ params
28
+
29
+ $.fn.DataTable.Api.register('getFilterParams()', getFilterParams)
@@ -51,12 +51,20 @@ module Effective
51
51
  end
52
52
  end
53
53
 
54
+ def csv_collection
55
+ value = if active_record_collection? && @_collection_apply_scope
56
+ column_tool.scope(collection)
57
+ else
58
+ collection
59
+ end
60
+ end
61
+
54
62
  def csv_stream
55
63
  EffectiveResources.with_resource_enumerator do |lines|
56
64
  lines << CSV.generate_line(csv_header)
57
65
 
58
66
  if active_record_collection?
59
- collection.find_in_batches do |resources|
67
+ csv_collection().find_in_batches do |resources|
60
68
  resources = arrayize(resources, csv: true)
61
69
  format(resources, csv: true)
62
70
  finalize(resources)
@@ -64,7 +72,7 @@ module Effective
64
72
  resources.each { |resource| lines << CSV.generate_line(resource) }
65
73
  end
66
74
  else
67
- resources = collection
75
+ resources = csv_collection()
68
76
 
69
77
  format(resources, csv: true)
70
78
  finalize(resources)
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '4.26.1'.freeze
2
+ VERSION = '4.27.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.26.1
4
+ version: 4.27.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: 2024-05-09 00:00:00.000000000 Z
11
+ date: 2024-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -119,6 +119,7 @@ files:
119
119
  - app/assets/javascripts/effective_datatables/initialize.js.coffee
120
120
  - app/assets/javascripts/effective_datatables/inline_crud.js.coffee
121
121
  - app/assets/javascripts/effective_datatables/overrides.js.coffee
122
+ - app/assets/javascripts/effective_datatables/params.js.coffee
122
123
  - app/assets/javascripts/effective_datatables/reorder.js.coffee
123
124
  - app/assets/javascripts/effective_datatables/reset.js.coffee
124
125
  - app/assets/javascripts/effective_datatables/responsive.js.coffee