effective_datatables 3.2 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/effective/datatable_dsl_tool.rb +7 -0
- data/app/models/effective/effective_datatable/cookie.rb +2 -2
- data/app/models/effective/effective_datatable/dsl.rb +5 -1
- data/app/models/effective/effective_datatable/dsl/datatable.rb +4 -4
- data/app/models/effective/effective_datatable/resource.rb +1 -1
- data/app/models/effective/effective_datatable/state.rb +9 -5
- 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: 756f3e374ce0dcbc877f0c29406af8392e461334
|
4
|
+
data.tar.gz: 780bc128c0eefd39b17bbb8b163fb4ce92578b4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05b80f00a90149f1acfe007bce5a75c52030c1121e09fda0467aa148f7d389791f302be20cd6930fde4f6ed403e198ab9471d7b897d2261e2aa2660a21ce0af2
|
7
|
+
data.tar.gz: 69421f676f951392bd0002a4287aea8fb73127b436abb4d55efdad301d0fb9f2759c0c570e45eb148a75946b6a07a99b9cfced0649e81fcd77044082ac00d360
|
@@ -4,6 +4,8 @@ module Effective
|
|
4
4
|
attr_reader :datatable
|
5
5
|
attr_reader :view
|
6
6
|
|
7
|
+
attr_accessor :in_datatables_do_block
|
8
|
+
|
7
9
|
include Effective::EffectiveDatatable::Dsl::BulkActions
|
8
10
|
include Effective::EffectiveDatatable::Dsl::Charts
|
9
11
|
include Effective::EffectiveDatatable::Dsl::Datatable
|
@@ -15,6 +17,11 @@ module Effective
|
|
15
17
|
end
|
16
18
|
|
17
19
|
def method_missing(method, *args)
|
20
|
+
# Catch a common error
|
21
|
+
if [:bulk_actions, :charts, :collection, :filters].include?(method) && in_datatables_do_block
|
22
|
+
raise "#{method} block must be declared outside the datatable do ... end block"
|
23
|
+
end
|
24
|
+
|
18
25
|
if datatable.respond_to?(method)
|
19
26
|
datatable.send(method, *args)
|
20
27
|
elsif view.respond_to?(method)
|
@@ -50,10 +50,10 @@ module Effective
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def cookie_payload
|
53
|
-
payload = state.except(:attributes)
|
53
|
+
payload = state.except(:attributes, :visible)
|
54
54
|
|
55
55
|
# Turn visible into a bitmask. This is undone in load_columns!
|
56
|
-
payload[:
|
56
|
+
payload[:vismask] = (
|
57
57
|
if columns.keys.length < 63 # 64-bit integer
|
58
58
|
columns.keys.map { |name| (2 ** columns[name][:index]) if state[:visible][name] }.compact.sum
|
59
59
|
end
|
@@ -15,7 +15,11 @@ module Effective
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def datatable(&block)
|
18
|
-
define_method('initialize_datatable')
|
18
|
+
define_method('initialize_datatable') do
|
19
|
+
dsl_tool.in_datatables_do_block = true
|
20
|
+
dsl_tool.instance_exec(&block)
|
21
|
+
dsl_tool.in_datatables_do_block = false
|
22
|
+
end
|
19
23
|
end
|
20
24
|
|
21
25
|
def filters(&block)
|
@@ -30,7 +30,7 @@ module Effective
|
|
30
30
|
compute: nil,
|
31
31
|
col_class: col_class,
|
32
32
|
format: (format if block_given?),
|
33
|
-
index:
|
33
|
+
index: nil,
|
34
34
|
label: label || name.to_s.split('.').last.titleize,
|
35
35
|
name: name,
|
36
36
|
partial: partial,
|
@@ -58,7 +58,7 @@ module Effective
|
|
58
58
|
compute: (compute if block_given?),
|
59
59
|
col_class: col_class,
|
60
60
|
format: nil,
|
61
|
-
index:
|
61
|
+
index: nil,
|
62
62
|
label: label || name.to_s.split('.').last.titleize,
|
63
63
|
name: name,
|
64
64
|
partial: partial,
|
@@ -82,7 +82,7 @@ module Effective
|
|
82
82
|
compute: nil,
|
83
83
|
col_class: col_class,
|
84
84
|
format: nil,
|
85
|
-
index:
|
85
|
+
index: nil,
|
86
86
|
label: '',
|
87
87
|
name: :bulk_actions,
|
88
88
|
partial: partial || '/effective/datatables/bulk_actions_column',
|
@@ -106,7 +106,7 @@ module Effective
|
|
106
106
|
compute: nil,
|
107
107
|
col_class: col_class,
|
108
108
|
format: (format if block_given?),
|
109
|
-
index:
|
109
|
+
index: nil,
|
110
110
|
label: '',
|
111
111
|
name: :actions,
|
112
112
|
partial: partial || '/effective/datatables/actions_column',
|
@@ -52,7 +52,7 @@ module Effective
|
|
52
52
|
|
53
53
|
private
|
54
54
|
|
55
|
-
# This is called first.
|
55
|
+
# This is called first. Our initial state is set.
|
56
56
|
def initial_state
|
57
57
|
{
|
58
58
|
attributes: {},
|
@@ -65,7 +65,8 @@ module Effective
|
|
65
65
|
scope: nil,
|
66
66
|
start: 0,
|
67
67
|
search: {},
|
68
|
-
|
68
|
+
vismask: nil,
|
69
|
+
visible: {},
|
69
70
|
}
|
70
71
|
end
|
71
72
|
|
@@ -140,6 +141,8 @@ module Effective
|
|
140
141
|
state[:length] ||= EffectiveDatatables.default_length
|
141
142
|
|
142
143
|
if columns.present?
|
144
|
+
columns.each_with_index { |(_, column), index| column[:index] = index }
|
145
|
+
|
143
146
|
if order_index.present?
|
144
147
|
state[:order_name] = columns.keys[order_index]
|
145
148
|
end
|
@@ -161,10 +164,11 @@ module Effective
|
|
161
164
|
end
|
162
165
|
|
163
166
|
# Load cookie bitmask
|
164
|
-
if
|
165
|
-
|
167
|
+
if datatables_ajax_request?
|
168
|
+
# Nothing to do
|
169
|
+
elsif state[:vismask].kind_of?(Integer) # bitmask
|
166
170
|
state[:visible] = {}
|
167
|
-
columns.each { |name, opts| state[:visible][name] = (
|
171
|
+
columns.each { |name, opts| state[:visible][name] = (state[:vismask] & (2 ** opts[:index])) != 0 }
|
168
172
|
else
|
169
173
|
state[:visible] = {} unless state[:visible].kind_of?(Hash)
|
170
174
|
columns.each { |name, opts| state[:visible][name] = opts[:visible] unless state[:visible].key?(name) }
|
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
|
+
version: 3.2.1
|
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-09-
|
11
|
+
date: 2017-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|