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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2fd403395ba41023758912f2316bd3550ce87b0
4
- data.tar.gz: da929e087db2cdf263b1c5f85c1e9304b834acfa
3
+ metadata.gz: 756f3e374ce0dcbc877f0c29406af8392e461334
4
+ data.tar.gz: 780bc128c0eefd39b17bbb8b163fb4ce92578b4c
5
5
  SHA512:
6
- metadata.gz: 398b32bf5d7d09c1fe70f60b2cc7a808ba9d0e3d3203027503b3c88d292e1ef35c3941393055f87b74e1f25cedf3be2aa9b733af90a782209a0227daf33efd3b
7
- data.tar.gz: 2ceb4c659055f4de79ce573078f7a0bc054fdb67533d560bc44ea75c59cec4ebff4fefb2902b4000dc50f810a59243d2a944ac05f17128d487da0f0782f1fa70
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[:visible] = (
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') { dsl_tool.instance_exec(&block) }
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: datatable.columns.length,
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: datatable.columns.length,
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: datatable.columns.length,
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: datatable.columns.length,
109
+ index: nil,
110
110
  label: '',
111
111
  name: :actions,
112
112
  partial: partial || '/effective/datatables/actions_column',
@@ -161,7 +161,7 @@ module Effective
161
161
  columns.delete(associated)
162
162
  end
163
163
 
164
- columns.each_with_index { |(_, column), index| column[:index] = index } if changed
164
+ load_columns! if changed
165
165
  end
166
166
 
167
167
  end
@@ -52,7 +52,7 @@ module Effective
52
52
 
53
53
  private
54
54
 
55
- # This is called first. Our initial state is set.
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
- visible: {}
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 state[:visible].kind_of?(Integer)
165
- visible_mask = state[:visible] # bitmask
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] = (visible_mask & (2 ** opts[:index])) != 0 }
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) }
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '3.2'.freeze
2
+ VERSION = '3.2.1'.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: '3.2'
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-06 00:00:00.000000000 Z
11
+ date: 2017-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails