effective_datatables 4.26.1 → 4.28.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
2
  SHA256:
3
- metadata.gz: f6fd6b02564f438e0aa52250f202db9db27c5388e677b3e8758eecaa0a46ea82
4
- data.tar.gz: b8fac9e5fbef111411e4b260e9d5ad4a2990cd7e5a8fbbda355b3baa1a2b4abc
3
+ metadata.gz: dd87ac5079fa518fdc3c9950d5f998a49a391be1acb4c1bda843b63396457c49
4
+ data.tar.gz: 7be54cba3747f6f5959169ab2948f7d4661d8be2aeee27f67ab9c3555d1679ef
5
5
  SHA512:
6
- metadata.gz: c7b229e901f10e15b6a1991b68ef50d69575082657257095e811492a1efc830f05732e0747ea86087b57ee80cf0204bc5745e72d3eff7c4fedb654159a170d61
7
- data.tar.gz: fd3f4b8d1f6ad92d25b27bf220addec9754efa774bd941e23e6c1c6201533d6758f275403ff1b4f532eac5967c965fecf02e6d7f5313e9dbcfcbf0fd5d8e5292
6
+ metadata.gz: 229acdb52df7be9a8fc670eaabbb5886da426f2b152002d8b775bcbb269c38ad289d208e9efe6f366cb36d2f9191fd8d8c4e97a69f580d6b2eece63d55f1461b
7
+ data.tar.gz: 373054322bf303ce7f6b4ef15aa5de4a034db4a19c219734e645bb430f69f8b5e810b7b6219080e946dc9b13a2e4534a4b42a15f3f2797254764f9b16793d008
@@ -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,14 +15,6 @@ 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
18
  {
27
19
  extend: 'copy',
28
20
  exportOptions:
@@ -32,19 +24,28 @@ initializeDataTables = (target) ->
32
24
  },
33
25
  {
34
26
  extend: 'csv',
27
+ text: 'Snapshot',
35
28
  exportOptions:
36
29
  format:
37
30
  header: (str) -> $("<div>#{str}</div>").children('span').first().text()
38
31
  columns: buttons_export_columns
39
32
  },
40
33
  {
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
- },
34
+ extend: 'colvis',
35
+ postfixButtons: [
36
+ { extend: 'colvisGroup', text: 'Show all', show: ':hidden', className: 'buttons-colvisGroup-first'},
37
+ { extend: 'colvisGroup', text: 'Show none', hide: ':visible' },
38
+ { extend: 'colvisGroup', text: 'Show default', hide: ':not(.colvis-default)', show: '.colvis-default' }
39
+ ]
40
+ }
41
+ # {
42
+ # extend: 'print',
43
+ # footer: true,
44
+ # exportOptions:
45
+ # format:
46
+ # header: (str) -> $("<div>#{str}</div>").children('span').first().text()
47
+ # columns: ':visible:not(.col-actions)'
48
+ # },
48
49
  ]
49
50
  columns: datatable.data('columns')
50
51
  deferLoading: [datatable.data('display-records'), datatable.data('total-records')]
@@ -61,29 +62,13 @@ initializeDataTables = (target) ->
61
62
  api.columns().flatten().each (index) => params['columns'][index]['visible'] = api.column(index).visible()
62
63
 
63
64
  $table = $(api.table().node())
64
- $form = $(".effective-datatables-filters[aria-controls='#{$table.attr('id')}']").first()
65
-
66
65
  params['attributes'] = $table.data('attributes')
67
66
  params['authenticity_token'] = $table.data('authenticity-token')
68
67
 
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()
68
+ filterParams = api.getFilterParams()
69
+ params['scope'] = filterParams['scope'] if filterParams['scope']
70
+ params['filter'] = filterParams['filter'] if filterParams['filter']
71
+ params
87
72
 
88
73
  serverSide: true
89
74
  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.28.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.28.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-14 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