effective_datatables 4.3.4 → 4.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -1
- data/app/assets/javascripts/dataTables/buttons/buttons.bootstrap4.js +1 -0
- data/app/assets/javascripts/dataTables/buttons/buttons.colVis.js +12 -2
- data/app/assets/javascripts/dataTables/buttons/buttons.html5.js +58 -6
- data/app/assets/javascripts/dataTables/buttons/buttons.print.js +16 -5
- data/app/assets/javascripts/dataTables/buttons/dataTables.buttons.js +26 -10
- data/app/assets/javascripts/dataTables/rowReorder/dataTables.rowReorder.js +818 -0
- data/app/assets/javascripts/dataTables/rowReorder/rowReorder.bootstrap4.js +38 -0
- data/app/assets/javascripts/effective_datatables.js +3 -10
- data/app/assets/javascripts/effective_datatables/flash.js.coffee +20 -0
- data/app/assets/javascripts/effective_datatables/initialize.js.coffee +12 -1
- data/app/assets/javascripts/effective_datatables/overrides.js.coffee +0 -24
- data/app/assets/javascripts/effective_datatables/reorder.js.coffee +37 -0
- data/app/assets/stylesheets/dataTables/buttons/buttons.bootstrap4.css +6 -0
- data/app/assets/stylesheets/dataTables/rowReorder/rowReorder.bootstrap4.css +22 -0
- data/app/assets/stylesheets/effective_datatables.scss +1 -0
- data/app/assets/stylesheets/effective_datatables/_overrides.scss +15 -2
- data/app/controllers/effective/datatables_controller.rb +25 -0
- data/app/helpers/effective_datatables_helper.rb +3 -1
- data/app/helpers/effective_datatables_private_helper.rb +28 -4
- data/app/models/effective/datatable.rb +23 -3
- data/app/models/effective/effective_datatable/dsl.rb +1 -1
- data/app/models/effective/effective_datatable/dsl/datatable.rb +65 -26
- data/app/models/effective/effective_datatable/format.rb +7 -4
- data/app/models/effective/effective_datatable/resource.rb +0 -2
- data/app/models/effective/effective_datatable/state.rb +15 -8
- data/app/views/effective/datatables/_reorder_column.html.haml +5 -0
- data/config/routes.rb +1 -0
- data/lib/effective_datatables/version.rb +1 -1
- metadata +8 -2
@@ -3,7 +3,7 @@ module Effective
|
|
3
3
|
module Dsl
|
4
4
|
|
5
5
|
def bulk_actions(&block)
|
6
|
-
define_method('initialize_bulk_actions') { dsl_tool.instance_exec(&block) }
|
6
|
+
define_method('initialize_bulk_actions') { dsl_tool.instance_exec(&block); dsl_tool.bulk_actions_col }
|
7
7
|
end
|
8
8
|
|
9
9
|
def charts(&block)
|
@@ -3,6 +3,11 @@ module Effective
|
|
3
3
|
module Dsl
|
4
4
|
module Datatable
|
5
5
|
# Instance Methods inside the datatable do .. end block
|
6
|
+
def length(length)
|
7
|
+
raise 'length must be 5, 10, 25, 50, 100, 250, 500, :all' unless [5, 10, 25, 50, 100, 250, 500, :all].include?(length)
|
8
|
+
datatable.state[:length] ||= (length == :all ? 9999999 : length)
|
9
|
+
end
|
10
|
+
|
6
11
|
def order(name, dir = nil)
|
7
12
|
raise 'order direction must be :asc or :desc' unless [nil, :asc, :desc].include?(dir)
|
8
13
|
|
@@ -10,9 +15,13 @@ module Effective
|
|
10
15
|
datatable.state[:order_dir] ||= dir
|
11
16
|
end
|
12
17
|
|
13
|
-
def
|
14
|
-
raise '
|
15
|
-
|
18
|
+
def reorder(name, dir = nil)
|
19
|
+
raise 'order direction must be :asc or :desc' unless [nil, :asc, :desc].include?(dir)
|
20
|
+
|
21
|
+
datatable.state[:order_name] = :_reorder
|
22
|
+
datatable.state[:order_dir] = dir
|
23
|
+
|
24
|
+
reorder_col(name)
|
16
25
|
end
|
17
26
|
|
18
27
|
# A col has its internal values sorted/searched before the block is run
|
@@ -73,8 +82,47 @@ module Effective
|
|
73
82
|
)
|
74
83
|
end
|
75
84
|
|
85
|
+
def actions_col(col_class: nil, inline: nil, partial: nil, partial_as: nil, actions_partial: nil, responsive: 5000, visible: true, **actions, &format)
|
86
|
+
raise 'You can only have one actions column' if datatable.columns[:_actions].present?
|
87
|
+
|
88
|
+
datatable._columns[:_actions] = Effective::DatatableColumn.new(
|
89
|
+
action: false,
|
90
|
+
as: :actions,
|
91
|
+
compute: nil,
|
92
|
+
col_class: col_class,
|
93
|
+
format: (format if block_given?),
|
94
|
+
index: nil,
|
95
|
+
inline: (inline.nil? ? datatable.inline? : inline),
|
96
|
+
label: false,
|
97
|
+
name: :actions,
|
98
|
+
partial: partial,
|
99
|
+
partial_as: partial_as,
|
100
|
+
actions_partial: (actions_partial || :dropleft),
|
101
|
+
responsive: responsive,
|
102
|
+
search: false,
|
103
|
+
sort: false,
|
104
|
+
sql_column: nil,
|
105
|
+
th: nil,
|
106
|
+
th_append: nil,
|
107
|
+
visible: visible,
|
108
|
+
|
109
|
+
# { approve: false }. These args are passed to effective_resources render_resource_actions
|
110
|
+
actions: actions
|
111
|
+
)
|
112
|
+
end
|
113
|
+
|
114
|
+
def aggregate(name, label: nil, &compute)
|
115
|
+
datatable._aggregates[name.to_sym] = {
|
116
|
+
compute: (compute if block_given?),
|
117
|
+
label: label || name.to_s.titleize,
|
118
|
+
name: name.to_sym,
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
# Called automatically after bulk_actions do ... end
|
123
|
+
# Call again if you want to change the position of the bulk_actions_col
|
76
124
|
def bulk_actions_col(col_class: nil, partial: nil, partial_as: nil, responsive: 5000)
|
77
|
-
|
125
|
+
datatable._columns.delete(:_bulk_actions) if datatable.columns[:_bulk_actions]
|
78
126
|
|
79
127
|
datatable._columns[:_bulk_actions] = Effective::DatatableColumn.new(
|
80
128
|
action: false,
|
@@ -97,42 +145,33 @@ module Effective
|
|
97
145
|
)
|
98
146
|
end
|
99
147
|
|
100
|
-
|
101
|
-
|
148
|
+
# Called automatically after reorder
|
149
|
+
# Call again if you want to change the position of the reorder_col
|
150
|
+
def reorder_col(name, col_class: nil, partial: nil, partial_as: nil, sql_column: nil, responsive: 5000)
|
151
|
+
datatable._columns.delete(:_reorder) if datatable.columns[:_reorder]
|
102
152
|
|
103
|
-
datatable._columns[:
|
153
|
+
datatable._columns[:_reorder] = Effective::DatatableColumn.new(
|
104
154
|
action: false,
|
105
|
-
as: :
|
155
|
+
as: :reorder,
|
106
156
|
compute: nil,
|
107
157
|
col_class: col_class,
|
108
|
-
format:
|
158
|
+
format: nil,
|
109
159
|
index: nil,
|
110
|
-
inline: (inline.nil? ? datatable.inline? : inline),
|
111
160
|
label: false,
|
112
|
-
name: :
|
113
|
-
partial: partial,
|
161
|
+
name: :reorder,
|
162
|
+
partial: partial || '/effective/datatables/reorder_column',
|
114
163
|
partial_as: partial_as,
|
115
|
-
|
164
|
+
reorder: name,
|
116
165
|
responsive: responsive,
|
117
166
|
search: false,
|
118
|
-
sort:
|
119
|
-
sql_column:
|
167
|
+
sort: true,
|
168
|
+
sql_column: (sql_column || name),
|
120
169
|
th: nil,
|
121
170
|
th_append: nil,
|
122
|
-
visible:
|
123
|
-
|
124
|
-
# { approve: false }. These args are passed to effective_resources render_resource_actions
|
125
|
-
actions: actions
|
171
|
+
visible: false
|
126
172
|
)
|
127
173
|
end
|
128
174
|
|
129
|
-
def aggregate(name, label: nil, &compute)
|
130
|
-
datatable._aggregates[name.to_sym] = {
|
131
|
-
compute: (compute if block_given?),
|
132
|
-
label: label || name.to_s.titleize,
|
133
|
-
name: name.to_sym,
|
134
|
-
}
|
135
|
-
end
|
136
175
|
end
|
137
176
|
end
|
138
177
|
end
|
@@ -2,6 +2,7 @@ module Effective
|
|
2
2
|
module EffectiveDatatable
|
3
3
|
module Format
|
4
4
|
BLANK = ''.freeze
|
5
|
+
NONVISIBLE = '...'.freeze
|
5
6
|
SPACER = 'EFFECTIVEDATATABLESSPACER'.freeze
|
6
7
|
SPACER_TEMPLATE = '/effective/datatables/spacer_template'.freeze
|
7
8
|
|
@@ -12,7 +13,9 @@ module Effective
|
|
12
13
|
rendered = {}
|
13
14
|
|
14
15
|
columns.each do |name, opts|
|
15
|
-
|
16
|
+
next unless state[:visible][name]
|
17
|
+
|
18
|
+
if opts[:partial]
|
16
19
|
locals = { datatable: self, column: columns[name] }.merge(resource_col_locals(opts))
|
17
20
|
|
18
21
|
rendered[name] = (view.render(
|
@@ -35,13 +38,13 @@ module Effective
|
|
35
38
|
|
36
39
|
collection.each_with_index do |row, row_index|
|
37
40
|
columns.each do |name, opts|
|
38
|
-
next unless state[:visible][name]
|
39
|
-
|
40
41
|
index = opts[:index]
|
41
42
|
value = row[index]
|
42
43
|
|
43
44
|
row[index] = (
|
44
|
-
if
|
45
|
+
if state[:visible][name] == false
|
46
|
+
NONVISIBLE
|
47
|
+
elsif opts[:as] == :actions
|
45
48
|
rendered[name][row_index]
|
46
49
|
elsif opts[:format] && rendered.key?(name)
|
47
50
|
dsl_tool.instance_exec(value, row, rendered[name][row_index], &opts[:format])
|
@@ -104,8 +104,10 @@ module Effective
|
|
104
104
|
def load_ajax_state!
|
105
105
|
state[:length] = params[:length].to_i
|
106
106
|
|
107
|
-
|
108
|
-
|
107
|
+
if params[:order]
|
108
|
+
state[:order_dir] = (params[:order]['0'][:dir] == 'desc' ? :desc : :asc)
|
109
|
+
state[:order_index] = params[:order]['0'][:column].to_i
|
110
|
+
end
|
109
111
|
|
110
112
|
state[:scope] = _scopes.keys.find { |name| params[:scope] == name.to_s }
|
111
113
|
state[:start] = params[:start].to_i
|
@@ -140,14 +142,19 @@ module Effective
|
|
140
142
|
def load_columns!
|
141
143
|
state[:length] ||= EffectiveDatatables.default_length
|
142
144
|
|
143
|
-
|
144
|
-
columns.each_with_index { |(_, column), index| column[:index] = index }
|
145
|
+
(columns || {}).each_with_index { |(_, column), index| column[:index] = index }
|
145
146
|
|
146
|
-
|
147
|
-
|
148
|
-
|
147
|
+
if columns.present?
|
148
|
+
state[:order_name] = (
|
149
|
+
if columns.key?(:_reorder)
|
150
|
+
:_reorder
|
151
|
+
elsif order_index.present?
|
152
|
+
columns.keys[order_index]
|
153
|
+
else
|
154
|
+
columns.find { |name, opts| opts[:sort] }.first
|
155
|
+
end
|
156
|
+
)
|
149
157
|
|
150
|
-
state[:order_name] ||= columns.find { |name, opts| opts[:sort] }.first
|
151
158
|
raise "order column :#{order_name} must exist as a col or val" unless columns[order_name]
|
152
159
|
|
153
160
|
state[:order_index] = columns[order_name][:index]
|
data/config/routes.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
EffectiveDatatables::Engine.routes.draw do
|
2
2
|
scope :module => 'effective' do
|
3
3
|
match 'datatables/:id(.:format)', to: 'datatables#show', via: [:get, :post], as: :datatable
|
4
|
+
match 'datatables/:id/reorder(.:format)', to: 'datatables#reorder', via: [:post], as: :reorder_datatable
|
4
5
|
end
|
5
6
|
end
|
6
7
|
|
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.3.
|
4
|
+
version: 4.3.5
|
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: 2018-10-
|
11
|
+
date: 2018-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -103,14 +103,18 @@ files:
|
|
103
103
|
- app/assets/javascripts/dataTables/jquery.dataTables.js
|
104
104
|
- app/assets/javascripts/dataTables/responsive/dataTables.responsive.js
|
105
105
|
- app/assets/javascripts/dataTables/responsive/responsive.bootstrap4.js
|
106
|
+
- app/assets/javascripts/dataTables/rowReorder/dataTables.rowReorder.js
|
107
|
+
- app/assets/javascripts/dataTables/rowReorder/rowReorder.bootstrap4.js
|
106
108
|
- app/assets/javascripts/effective_datatables.js
|
107
109
|
- app/assets/javascripts/effective_datatables/bulk_actions.js.coffee
|
108
110
|
- app/assets/javascripts/effective_datatables/charts.js.coffee
|
109
111
|
- app/assets/javascripts/effective_datatables/events.js.coffee
|
110
112
|
- app/assets/javascripts/effective_datatables/filters.js.coffee
|
113
|
+
- app/assets/javascripts/effective_datatables/flash.js.coffee
|
111
114
|
- app/assets/javascripts/effective_datatables/initialize.js.coffee
|
112
115
|
- app/assets/javascripts/effective_datatables/inline_crud.js.coffee
|
113
116
|
- app/assets/javascripts/effective_datatables/overrides.js.coffee
|
117
|
+
- app/assets/javascripts/effective_datatables/reorder.js.coffee
|
114
118
|
- app/assets/javascripts/effective_datatables/reset.js.coffee
|
115
119
|
- app/assets/javascripts/effective_datatables/responsive.js.coffee
|
116
120
|
- app/assets/javascripts/vendor/jquery.delayedChange.js
|
@@ -118,6 +122,7 @@ files:
|
|
118
122
|
- app/assets/stylesheets/dataTables/buttons/buttons.bootstrap4.css
|
119
123
|
- app/assets/stylesheets/dataTables/dataTables.bootstrap4.css
|
120
124
|
- app/assets/stylesheets/dataTables/responsive/responsive.bootstrap4.css
|
125
|
+
- app/assets/stylesheets/dataTables/rowReorder/rowReorder.bootstrap4.css
|
121
126
|
- app/assets/stylesheets/effective_datatables.scss
|
122
127
|
- app/assets/stylesheets/effective_datatables/_overrides.scss
|
123
128
|
- app/controllers/effective/datatables_controller.rb
|
@@ -150,6 +155,7 @@ files:
|
|
150
155
|
- app/views/effective/datatables/_chart.html.haml
|
151
156
|
- app/views/effective/datatables/_datatable.html.haml
|
152
157
|
- app/views/effective/datatables/_filters.html.haml
|
158
|
+
- app/views/effective/datatables/_reorder_column.html.haml
|
153
159
|
- app/views/effective/datatables/_resource_column.html.haml
|
154
160
|
- app/views/effective/datatables/_spacer_template.html
|
155
161
|
- app/views/effective/datatables/index.html.haml
|