effective_datatables 3.0.1 → 3.0.2
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 +4 -4
- data/app/assets/javascripts/effective_datatables/initialize.js.coffee +2 -0
- data/app/assets/javascripts/effective_datatables/reset.js.coffee +1 -1
- data/app/helpers/effective_datatables_helper.rb +1 -0
- data/app/models/effective/datatable.rb +1 -2
- data/app/models/effective/effective_datatable/attributes.rb +5 -3
- data/app/models/effective/effective_datatable/cookie.rb +48 -12
- data/app/models/effective/effective_datatable/resource.rb +1 -1
- data/app/models/effective/effective_datatable/state.rb +12 -5
- data/app/views/effective/datatables/_reset.html.haml +1 -1
- data/lib/effective_datatables/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76b12d9c51e6dd4d3e040161ea88d8cc04d9f451
|
4
|
+
data.tar.gz: 45787258cc49d4b0b87f459b16d99fc9e2b420eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 843709309dc8d2bf2047d4fb0dff94ee369f48c3de8852b53d498fc07a9dd783b074dcdd9f22051db35b82413aa955764c46bc15d2215dcb1f4be6358f302916
|
7
|
+
data.tar.gz: 93d36172ba1e8b0b4e435bb90dc88fb1ef7dc1b4fb3544419532c2a17dee1bc786c85488481286c1ea3bf34d77e981ec34c4c6bcddaf0472ac8a3f31e75c00b6
|
@@ -62,6 +62,8 @@ initializeDataTables = ->
|
|
62
62
|
$table = $(api.table().node())
|
63
63
|
$form = $(".effective-datatable-filters[aria-controls='#{$table.attr('id')}']").first()
|
64
64
|
|
65
|
+
params['cookie'] = $table.data('cookie')
|
66
|
+
|
65
67
|
if $form.length > 0
|
66
68
|
params['scope'] = $form.find("input[id^='filters_scope']:checked").val() || ''
|
67
69
|
params['filter'] = {}
|
@@ -3,5 +3,5 @@ $(document).on 'click', 'a.buttons-reset-cookie', (event) ->
|
|
3
3
|
|
4
4
|
$obj = $(event.currentTarget)
|
5
5
|
$obj.find('span').text('Resetting...')
|
6
|
-
document.cookie = "
|
6
|
+
document.cookie = "_effective_dt=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/"
|
7
7
|
location.reload()
|
@@ -22,6 +22,7 @@ module EffectiveDatatablesHelper
|
|
22
22
|
'effective-form-inputs' => defined?(EffectiveFormInputs),
|
23
23
|
'bulk-actions' => datatable_bulk_actions(datatable),
|
24
24
|
'columns' => datatable_columns(datatable),
|
25
|
+
'cookie' => datatable.cookie_name,
|
25
26
|
'display-length' => datatable.display_length,
|
26
27
|
'display-order' => [datatable.order_index, datatable.order_direction].to_json(),
|
27
28
|
'display-records' => datatable.to_json[:recordsFiltered],
|
@@ -11,12 +11,14 @@ module Effective
|
|
11
11
|
|
12
12
|
def load_attributes!
|
13
13
|
if datatables_ajax_request?
|
14
|
-
raise 'Expected attributes cookie to be present' unless cookie
|
15
|
-
|
14
|
+
raise 'Expected attributes cookie to be present' unless cookie && cookie[:attributes]
|
15
|
+
# Cookie will still be just values here. Attributes is the first value.
|
16
|
+
|
17
|
+
@attributes = cookie.delete(:attributes)
|
16
18
|
end
|
17
19
|
|
18
20
|
unless datatables_ajax_request?
|
19
|
-
@attributes[:
|
21
|
+
@attributes[:_n] ||= view.controller_path.split('/')[0...-1].join('/').presence
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
@@ -1,30 +1,66 @@
|
|
1
1
|
module Effective
|
2
2
|
module EffectiveDatatable
|
3
3
|
module Cookie
|
4
|
+
MAX_COOKIE_SIZE = 2500 # String size. Real byte size is about 1.5 times bigger.
|
5
|
+
|
6
|
+
def cookie
|
7
|
+
@cookie
|
8
|
+
end
|
4
9
|
|
5
10
|
def cookie_name
|
6
|
-
@cookie_name ||=
|
11
|
+
@cookie_name ||= (
|
12
|
+
if datatables_ajax_request?
|
13
|
+
view.params[:cookie]
|
14
|
+
else
|
15
|
+
[self.class, attributes].hash.to_s.last(12)
|
16
|
+
end
|
17
|
+
)
|
7
18
|
end
|
8
19
|
|
9
20
|
private
|
10
21
|
|
11
22
|
def load_cookie!
|
12
|
-
@
|
13
|
-
cookie = view.cookies.signed[cookie_name]
|
23
|
+
@dt_cookie = view.cookies.signed['_effective_dt']
|
14
24
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
25
|
+
# Load global datatables cookie
|
26
|
+
if @dt_cookie.present?
|
27
|
+
@dt_cookie = Marshal.load(Base64.decode64(@dt_cookie))
|
28
|
+
raise 'invalid datatables cookie' unless @dt_cookie.kind_of?(Array)
|
29
|
+
|
30
|
+
# Assign individual cookie
|
31
|
+
index = @dt_cookie.rindex { |name, _| name == cookie_name }
|
32
|
+
@cookie = @dt_cookie.delete_at(index)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Load my individual cookie
|
36
|
+
if @cookie.kind_of?(Array)
|
37
|
+
@cookie = initial_state.keys.zip(@cookie.second).to_h
|
38
|
+
end
|
21
39
|
end
|
22
40
|
|
23
41
|
def save_cookie!
|
24
|
-
|
25
|
-
|
42
|
+
@dt_cookie ||= []
|
43
|
+
@dt_cookie << [cookie_name, cookie_payload]
|
44
|
+
|
45
|
+
while @dt_cookie.to_s.size > MAX_COOKIE_SIZE
|
46
|
+
@dt_cookie.shift((@dt_cookie.length / 3) + 1)
|
47
|
+
end
|
48
|
+
|
49
|
+
view.cookies.signed['_effective_dt'] = Base64.encode64(Marshal.dump(@dt_cookie))
|
50
|
+
end
|
51
|
+
|
52
|
+
def cookie_payload
|
53
|
+
payload = state.except(:attributes)
|
54
|
+
|
55
|
+
# Turn visible into a bitmask. This is undone in load_columns!
|
56
|
+
payload[:visible] = (
|
57
|
+
if columns.keys.length < 63 # 64-bit integer
|
58
|
+
columns.keys.map { |name| (2 ** columns[name][:index]) if state[:visible][name] }.compact.sum
|
59
|
+
end
|
60
|
+
)
|
26
61
|
|
27
|
-
|
62
|
+
# Just store the values
|
63
|
+
[attributes.delete_if { |k, v| v.nil? }] + payload.values
|
28
64
|
end
|
29
65
|
|
30
66
|
end
|
@@ -50,6 +50,7 @@ module Effective
|
|
50
50
|
# This is called first. Our initial state is set.
|
51
51
|
def initial_state
|
52
52
|
{
|
53
|
+
attributes: {},
|
53
54
|
filter: {},
|
54
55
|
length: nil,
|
55
56
|
order_name: nil,
|
@@ -84,7 +85,7 @@ module Effective
|
|
84
85
|
if datatables_ajax_request?
|
85
86
|
load_filter_params!
|
86
87
|
load_ajax_state!
|
87
|
-
elsif cookie.present? && cookie[:
|
88
|
+
elsif cookie.present? && cookie[:params] == params.length
|
88
89
|
load_cookie_state!
|
89
90
|
else
|
90
91
|
# Nothing to do for default state
|
@@ -123,11 +124,11 @@ module Effective
|
|
123
124
|
state[:filter][name] = parse_filter_value(_filters[name], value)
|
124
125
|
end
|
125
126
|
|
126
|
-
state[:params] = cookie[:
|
127
|
+
state[:params] = cookie[:params]
|
127
128
|
end
|
128
129
|
|
129
130
|
def load_cookie_state!
|
130
|
-
@state = cookie
|
131
|
+
@state = cookie
|
131
132
|
end
|
132
133
|
|
133
134
|
def load_columns!
|
@@ -153,8 +154,14 @@ module Effective
|
|
153
154
|
end
|
154
155
|
end
|
155
156
|
|
156
|
-
|
157
|
-
|
157
|
+
# Load cookie bitmask
|
158
|
+
if state[:visible].kind_of?(Integer)
|
159
|
+
visible_mask = state[:visible] # bitmask
|
160
|
+
state[:visible] = {}
|
161
|
+
columns.each { |name, opts| state[:visible][name] = (visible_mask & (2 ** opts[:index])) != 0 }
|
162
|
+
else
|
163
|
+
state[:visible] = {} unless state[:visible].kind_of?(Hash)
|
164
|
+
columns.each { |name, opts| state[:visible][name] = opts[:visible] unless state[:visible].key?(name) }
|
158
165
|
end
|
159
166
|
|
160
167
|
unless datatables_ajax_request?
|
@@ -1,2 +1,2 @@
|
|
1
|
-
%a.btn.btn-default.buttons-reset-cookie{
|
1
|
+
%a.btn.btn-default.buttons-reset-cookie{href: '#'}
|
2
2
|
%span Reset
|
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: 3.0.
|
4
|
+
version: 3.0.2
|
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: 2017-05-
|
11
|
+
date: 2017-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|