effective_datatables 4.3.0 → 4.3.1
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 +1 -1
- data/app/assets/javascripts/effective_datatables/inline_crud.js.coffee +5 -1
- data/app/controllers/effective/datatables_controller.rb +1 -6
- data/app/helpers/effective_datatables_helper.rb +18 -30
- data/app/helpers/effective_datatables_private_helper.rb +36 -1
- data/app/models/effective/datatable.rb +5 -0
- data/app/models/effective/effective_datatable/attributes.rb +2 -2
- data/app/models/effective/effective_datatable/cookie.rb +9 -1
- data/app/models/effective/effective_datatable/dsl/datatable.rb +2 -2
- data/app/models/effective/effective_datatable/params.rb +7 -0
- data/lib/effective_datatables.rb +7 -0
- 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: f26102e385bdb4b061e3ba0b6a92ce1c975a62f3
|
4
|
+
data.tar.gz: 906ce6f0160143978795ef3a5e5dfb662312e0e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 100b6dc5e3d8cad0b06462bc40cc73088e9ed265a3aad8f228141ce63183cdf6ccf7162eed530dad67b4390e6286a429e20410ad3fa977b677c6bdc2e0ddcdc1
|
7
|
+
data.tar.gz: 199448f57486dede9c8dabd426c0182564a454461f77b60d6b104b2b82e1c89ec740c7cae02e285949d02164262c1103d493d521fa3ba1dd079d9a5752c501eb
|
@@ -168,7 +168,7 @@ initializeDataTables = ->
|
|
168
168
|
|
169
169
|
destroyDataTables = ->
|
170
170
|
$('.effective-datatables-inline-expanded').removeClass('effective-datatables-inline-expanded')
|
171
|
-
$('table.effective-datatable').each -> $(this).DataTable().
|
171
|
+
$('table.effective-datatable').each -> try $(this).removeClass('initialized').DataTable().destroy()
|
172
172
|
|
173
173
|
$ -> initializeDataTables()
|
174
174
|
$(document).on 'page:change', -> initializeDataTables()
|
@@ -2,8 +2,12 @@
|
|
2
2
|
# This works with EffectiveForm.remote_form which is part of the effective_bootstrap gem.
|
3
3
|
|
4
4
|
# About to do a resource action, or fetch a partial. Show loading.
|
5
|
-
$(document).on 'ajax:beforeSend', '.dataTables_wrapper', (e) ->
|
5
|
+
$(document).on 'ajax:beforeSend', '.dataTables_wrapper', (e, xhr, settings) ->
|
6
6
|
$action = $(e.target)
|
7
|
+
$table = $(e.target).closest('table')
|
8
|
+
|
9
|
+
$params = $.param({_datatable_id: $table.attr('id'), _datatable_cookie: $table.data('cookie') })
|
10
|
+
settings.url += (if settings.url.indexOf('?') == -1 then '?' else '&') + $params
|
7
11
|
|
8
12
|
if $action.closest('.effective-datatables-inline-row').length > 0
|
9
13
|
# Nothing. This is a save action from within the inline form.
|
@@ -5,7 +5,7 @@ module Effective
|
|
5
5
|
# This will respond to both a GET and a POST
|
6
6
|
def show
|
7
7
|
begin
|
8
|
-
@datatable =
|
8
|
+
@datatable = EffectiveDatatables.find(params[:id])
|
9
9
|
@datatable.view = view_context
|
10
10
|
|
11
11
|
EffectiveDatatables.authorize!(self, :index, @datatable.collection_class)
|
@@ -23,11 +23,6 @@ module Effective
|
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
-
def find_datatable(id)
|
27
|
-
id = id.to_s.gsub(/-\d+\z/, '').gsub('-', '/')
|
28
|
-
id.classify.safe_constantize || id.classify.pluralize.safe_constantize
|
29
|
-
end
|
30
|
-
|
31
26
|
def error_json(e)
|
32
27
|
{
|
33
28
|
data: [],
|
@@ -1,9 +1,12 @@
|
|
1
1
|
# These are expected to be called by a developer. They are part of the datatables DSL.
|
2
2
|
module EffectiveDatatablesHelper
|
3
3
|
|
4
|
-
def render_datatable(datatable, input_js: {}, buttons: true, charts: true, filters: true, simple: false)
|
4
|
+
def render_datatable(datatable, input_js: {}, buttons: true, charts: true, filters: true, simple: false, inline: false)
|
5
5
|
raise 'expected datatable to be present' unless datatable
|
6
6
|
|
7
|
+
datatable.attributes[:simple] = true if simple
|
8
|
+
datatable.attributes[:inline] = true if inline
|
9
|
+
|
7
10
|
datatable.view ||= self
|
8
11
|
|
9
12
|
unless EffectiveDatatables.authorized?(controller, :index, datatable.collection_class)
|
@@ -13,7 +16,6 @@ module EffectiveDatatablesHelper
|
|
13
16
|
charts = charts && datatable._charts.present?
|
14
17
|
filters = filters && (datatable._scopes.present? || datatable._filters.present?)
|
15
18
|
|
16
|
-
datatable.attributes[:simple] = true if simple
|
17
19
|
input_js[:buttons] = false if simple || !buttons
|
18
20
|
|
19
21
|
effective_datatable_params = {
|
@@ -27,6 +29,7 @@ module EffectiveDatatablesHelper
|
|
27
29
|
'display-order' => [datatable.order_index, datatable.order_direction].to_json().html_safe,
|
28
30
|
'display-records' => datatable.to_json[:recordsFiltered],
|
29
31
|
'display-start' => datatable.display_start,
|
32
|
+
'inline' => datatable.inline?.to_s,
|
30
33
|
'options' => (input_js || {}).to_json.html_safe,
|
31
34
|
'reset' => datatable_reset(datatable),
|
32
35
|
'simple' => datatable.simple?.to_s,
|
@@ -59,6 +62,10 @@ module EffectiveDatatablesHelper
|
|
59
62
|
end
|
60
63
|
end
|
61
64
|
|
65
|
+
def render_inline_datatable(datatable)
|
66
|
+
render_datatable(datatable, inline: true)
|
67
|
+
end
|
68
|
+
|
62
69
|
def render_simple_datatable(datatable)
|
63
70
|
raise 'expected datatable to be present' unless datatable
|
64
71
|
|
@@ -79,39 +86,20 @@ module EffectiveDatatablesHelper
|
|
79
86
|
)
|
80
87
|
end
|
81
88
|
|
82
|
-
def
|
83
|
-
|
84
|
-
|
85
|
-
datatable.view ||= self
|
86
|
-
return unless datatable._scopes.present? || datatable._filters.present?
|
87
|
-
|
88
|
-
if datatable._filters_form_required?
|
89
|
-
render partial: 'effective/datatables/filters', locals: { datatable: datatable }
|
90
|
-
else
|
91
|
-
render(partial: 'effective/datatables/filters', locals: { datatable: datatable }).gsub('<form', '<div').gsub('/form>', '/div>').html_safe
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
def render_datatable_charts(datatable)
|
97
|
-
raise 'expected datatable to be present' unless datatable
|
98
|
-
|
99
|
-
datatable.view ||= self
|
100
|
-
return unless datatable._charts.present?
|
101
|
-
|
102
|
-
datatable._charts.map { |name, _| render_datatable_chart(datatable, name) }.join.html_safe
|
89
|
+
def inline_datatable?
|
90
|
+
params[:_datatable_id].present?
|
103
91
|
end
|
104
92
|
|
105
|
-
def
|
106
|
-
|
93
|
+
def inline_datatable
|
94
|
+
return nil unless inline_datatable?
|
95
|
+
return @_inline_datatable if @_inline_datatable
|
107
96
|
|
108
|
-
datatable
|
109
|
-
|
97
|
+
datatable = EffectiveDatatables.find(params[:_datatable_id])
|
98
|
+
datatable.view = self
|
110
99
|
|
111
|
-
|
112
|
-
chart_data = datatable.to_json[:charts][name][:data]
|
100
|
+
EffectiveDatatables.authorize!(self, :index, datatable.collection_class)
|
113
101
|
|
114
|
-
|
102
|
+
@_inline_datatable ||= datatable
|
115
103
|
end
|
116
104
|
|
117
105
|
end
|
@@ -30,7 +30,7 @@ module EffectiveDatatablesPrivateHelper
|
|
30
30
|
def datatable_new_resource_button(datatable, name, column)
|
31
31
|
if column[:inline] && column[:actions][:new] != false
|
32
32
|
actions = {'New' => { action: :new, class: 'btn btn-outline-primary', 'data-remote': true } }
|
33
|
-
render_resource_actions(datatable.resource.klass, actions: actions) # Will only work if permitted
|
33
|
+
render_resource_actions(datatable.resource.klass, actions: actions, effective_resource: datatable.resource) # Will only work if permitted
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -74,6 +74,20 @@ module EffectiveDatatablesPrivateHelper
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
def render_datatable_filters(datatable)
|
78
|
+
raise 'expected datatable to be present' unless datatable
|
79
|
+
|
80
|
+
datatable.view ||= self
|
81
|
+
return unless datatable._scopes.present? || datatable._filters.present?
|
82
|
+
|
83
|
+
if datatable._filters_form_required?
|
84
|
+
render partial: 'effective/datatables/filters', locals: { datatable: datatable }
|
85
|
+
else
|
86
|
+
render(partial: 'effective/datatables/filters', locals: { datatable: datatable }).gsub('<form', '<div').gsub('/form>', '/div>').html_safe
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
77
91
|
def datatable_filter_tag(form, datatable, name, opts)
|
78
92
|
placeholder = opts.delete(:label)
|
79
93
|
|
@@ -106,4 +120,25 @@ module EffectiveDatatablesPrivateHelper
|
|
106
120
|
end
|
107
121
|
end
|
108
122
|
|
123
|
+
def render_datatable_charts(datatable)
|
124
|
+
raise 'expected datatable to be present' unless datatable
|
125
|
+
|
126
|
+
datatable.view ||= self
|
127
|
+
return unless datatable._charts.present?
|
128
|
+
|
129
|
+
datatable._charts.map { |name, _| render_datatable_chart(datatable, name) }.join.html_safe
|
130
|
+
end
|
131
|
+
|
132
|
+
def render_datatable_chart(datatable, name)
|
133
|
+
raise 'expected datatable to be present' unless datatable
|
134
|
+
|
135
|
+
datatable.view ||= self
|
136
|
+
return unless datatable._charts[name].present?
|
137
|
+
|
138
|
+
chart = datatable._charts[name]
|
139
|
+
chart_data = datatable.to_json[:charts][name][:data]
|
140
|
+
|
141
|
+
render partial: chart[:partial], locals: { datatable: datatable, chart: chart, chart_data: chart_data }
|
142
|
+
end
|
143
|
+
|
109
144
|
end
|
@@ -124,6 +124,11 @@ module Effective
|
|
124
124
|
attributes[:simple] == true
|
125
125
|
end
|
126
126
|
|
127
|
+
# Inline crud
|
128
|
+
def inline?
|
129
|
+
attributes[:inline] == true
|
130
|
+
end
|
131
|
+
|
127
132
|
# Whether the filters must be rendered as a <form> or we can keep the normal <div> behaviour
|
128
133
|
def _filters_form_required?
|
129
134
|
_form[:verb].present?
|
@@ -10,14 +10,14 @@ module Effective
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def load_attributes!
|
13
|
-
if datatables_ajax_request?
|
13
|
+
if datatables_ajax_request? || datatables_inline_request?
|
14
14
|
raise 'expected cookie to be present' unless cookie
|
15
15
|
raise 'expected attributes cookie to be present' unless cookie[:attributes]
|
16
16
|
|
17
17
|
@attributes = cookie.delete(:attributes)
|
18
18
|
end
|
19
19
|
|
20
|
-
unless datatables_ajax_request?
|
20
|
+
unless datatables_ajax_request? || datatables_inline_request?
|
21
21
|
@attributes[:_n] ||= view.controller_path.split('/')[0...-1].join('/').presence
|
22
22
|
end
|
23
23
|
end
|
@@ -8,7 +8,15 @@ module Effective
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def cookie_key
|
11
|
-
@cookie_key ||= (
|
11
|
+
@cookie_key ||= (
|
12
|
+
if datatables_ajax_request?
|
13
|
+
view.params[:cookie]
|
14
|
+
elsif datatables_inline_request?
|
15
|
+
view.params[:_datatable_cookie]
|
16
|
+
else
|
17
|
+
cookie_param
|
18
|
+
end
|
19
|
+
)
|
12
20
|
end
|
13
21
|
|
14
22
|
# All possible dt cookie keys. Used to make sure the datatable has a cookie set for this session.
|
@@ -97,7 +97,7 @@ module Effective
|
|
97
97
|
)
|
98
98
|
end
|
99
99
|
|
100
|
-
def actions_col(col_class: nil, inline:
|
100
|
+
def actions_col(col_class: nil, inline: nil, partial: nil, partial_as: nil, actions_partial: nil, responsive: 5000, visible: true, **actions, &format)
|
101
101
|
raise 'You can only have one actions column' if datatable.columns[:_actions].present?
|
102
102
|
|
103
103
|
datatable._columns[:_actions] = Effective::DatatableColumn.new(
|
@@ -107,7 +107,7 @@ module Effective
|
|
107
107
|
col_class: col_class,
|
108
108
|
format: (format if block_given?),
|
109
109
|
index: nil,
|
110
|
-
inline: inline,
|
110
|
+
inline: (inline.nil? ? datatable.inline? : inline),
|
111
111
|
label: false,
|
112
112
|
name: :actions,
|
113
113
|
partial: partial,
|
@@ -11,6 +11,13 @@ module Effective
|
|
11
11
|
(view && view.params[:draw] && view.params[:columns] && cookie_keys.include?(view.params[:cookie])) == true
|
12
12
|
end
|
13
13
|
|
14
|
+
def datatables_inline_request?
|
15
|
+
return @_datatables_inline_request unless @_datatables_inline_request.nil?
|
16
|
+
|
17
|
+
@_datatables_inline_request =
|
18
|
+
(view && view.params[:_datatable_cookie] && cookie_keys.include?(view.params[:_datatable_cookie])) == true
|
19
|
+
end
|
20
|
+
|
14
21
|
def params
|
15
22
|
return {} unless view.present?
|
16
23
|
@params ||= {}.tap do |params|
|
data/lib/effective_datatables.rb
CHANGED
@@ -32,4 +32,11 @@ module EffectiveDatatables
|
|
32
32
|
raise Effective::AccessDenied.new('Access Denied', action, resource) unless authorized?(controller, action, resource)
|
33
33
|
end
|
34
34
|
|
35
|
+
def self.find(id)
|
36
|
+
id = id.to_s.gsub(/-\d+\z/, '').gsub('-', '/')
|
37
|
+
klass = (id.classify.safe_constantize || id.classify.pluralize.safe_constantize)
|
38
|
+
|
39
|
+
klass.try(:new) || raise('unable to find datatable')
|
40
|
+
end
|
41
|
+
|
35
42
|
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.3.
|
4
|
+
version: 4.3.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: 2018-09-
|
11
|
+
date: 2018-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|