effective_datatables 4.26.0 → 4.27.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: e6af5d5e2542f1b4b587ad472f4be837fe81cf57cad38edf272986ba358710ae
4
- data.tar.gz: ada5f3e65dd9c40eedf6acda70db0e5955dc0b693fb1604392a1fbd5e7e98bba
3
+ metadata.gz: 87b7b506996cfe6ae06c7f798073c5d33fb77b338dccb923d562c154cd5eb649
4
+ data.tar.gz: a1c244dadeb7888540e1506dd6bd15603451759550115acbdaa05d4a9cb23bda
5
5
  SHA512:
6
- metadata.gz: 6833350b97bb37061602f756c291b7fb30af237b0895952f6ac41ac4e4b565e03d7ce1ab5503e1ef4adc2fca3574edb325b81d5d3a9818515be2b039f3d580f0
7
- data.tar.gz: '0859ffbe2c11c23c58d2743d76bd99f23af3c67d28f3b888ab3ecd9f68e0a9b9c181b37ad7e93b406e7bde949c04566dd4b7d0bf7b1a183cb6fb0df7e13dbb22'
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)
@@ -170,6 +170,11 @@ table.dataTable > thead {
170
170
  }
171
171
  }
172
172
 
173
+ // Filters
174
+ .effective-datatables-filter {
175
+ p { margin-bottom: 0; }
176
+ }
177
+
173
178
  // Processing div
174
179
  div.dataTables_wrapper div.dataTables_processing {
175
180
  margin: -26px 25% 0px 25%;
@@ -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)
@@ -33,15 +33,15 @@
33
33
 
34
34
  = f.show_if :date_range, :year do
35
35
  = f.static_field :year, wrapper: { class: 'effective-datatables-filter' } do
36
- - date = f.object.start_date.beginning_of_year
36
+ - date = start_date.beginning_of_year
37
37
 
38
38
  = link_to '#', 'data-effective-datatables-filter-prev-year': date.advance(years: -1).strftime('%F') do
39
39
  = icon('arrow-left-circle')
40
40
  %span.prev-year= date.advance(years: -1).strftime('%Y')
41
41
 
42
- %span.start-date= f.object.start_date.strftime('%F')
42
+ %span.start-date= start_date.strftime('%F')
43
43
  to
44
- %span.end-date= f.object.end_date.strftime('%F')
44
+ %span.end-date= end_date.strftime('%F')
45
45
 
46
46
  = link_to '#', 'data-effective-datatables-filter-next-year': date.advance(years: 1).strftime('%F') do
47
47
  = icon('arrow-right-circle')
@@ -53,15 +53,15 @@
53
53
 
54
54
  = f.show_if :date_range, :month do
55
55
  = f.static_field :month, wrapper: { class: 'effective-datatables-filter' } do
56
- - date = f.object.start_date.beginning_of_month
56
+ - date = start_date.beginning_of_month
57
57
 
58
58
  = link_to '#', 'data-effective-datatables-filter-prev-month': date.advance(months: -1).strftime('%F') do
59
59
  = icon('arrow-left-circle')
60
60
  %span.prev-month= date.advance(months: -1).strftime('%b')
61
61
 
62
- %span.start-date= f.object.start_date.strftime('%F')
62
+ %span.start-date= start_date.strftime('%F')
63
63
  to
64
- %span.end-date= f.object.end_date.strftime('%F')
64
+ %span.end-date= end_date.strftime('%F')
65
65
 
66
66
  = link_to '#', 'data-effective-datatables-filter-next-month': date.advance(months: 1).strftime('%F') do
67
67
  = icon('arrow-right-circle')
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '4.26.0'.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.0
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-04-12 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