effective_datatables 3.0.16 → 3.1.0

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: a36c56e15a3e3c9d57862183dc41ed61dfa7be69
4
- data.tar.gz: 38ada5d0f882aabd61510b21d2153bd0708ee437
3
+ metadata.gz: ed64f666d0e25311df8bd6d261f91561ff5a4b06
4
+ data.tar.gz: 80cbfdb2f683497fdbfff4f373068ee254fefb69
5
5
  SHA512:
6
- metadata.gz: 6d0cfc1d01e242b7b5afe8b74b6c27d1cafc24fcf8bec8f1de0e13295ca9ae3f005e5dd9a5cb5c2d04f8d96ba9b8fc01b34592662dc74a46317a489f1cd59d61
7
- data.tar.gz: 3379dbd9030d211d3f21d72a7c8db65ffb5746e506a6d9497b5d6b30eda3b78408ba00c546c17a4e3679929c9a7d7efc385a69c6cffb2fcee955263795472185
6
+ metadata.gz: c5f12a41603c30fdbaea17b0eabcdf801baada748aca0b020e0d570911389b599fb1c10a1b09b4b5a4cfa77346c85c70940435ddf7cac64d567c786c2336f2be
7
+ data.tar.gz: 149fcbcf5c3e48bf996db130b649b84acbfceac7f77b47a34a2db90e76c4228bedf96e9e9db6f96ace6826a17695c64c3ad0246942b5b2edd3a7d614b0211a9c
@@ -83,6 +83,10 @@ initializeDataTables = ->
83
83
  $table = $(this.api().table().node())
84
84
 
85
85
  if settings['json']
86
+ if settings['json']['effective_datatables_error']
87
+ alert("DataTable error: #{settings['json']['effective_datatables_error']}\n\nPlease refresh the page and try again")
88
+ return
89
+
86
90
  if settings['json']['aggregates']
87
91
  drawAggregates($table, settings['json']['aggregates'])
88
92
 
@@ -4,22 +4,18 @@ module Effective
4
4
 
5
5
  # This will respond to both a GET and a POST
6
6
  def show
7
- @datatable = find_datatable(params[:id]).try(:new)
8
- @datatable.view = view_context if !@datatable.nil?
9
-
10
- EffectiveDatatables.authorized?(self, :index, @datatable.try(:collection_class))
11
-
12
- respond_to do |format|
13
- format.html
14
- format.json {
15
- if Rails.env.production?
16
- render json: (@datatable.to_json rescue error_json)
17
- else
18
- render json: @datatable.to_json
19
- end
20
- }
21
- end
7
+ begin
8
+ @datatable = find_datatable(params[:id]).try(:new) || raise('unable to find datatable')
9
+ @datatable.view = view_context
10
+
11
+ EffectiveDatatables.authorized?(self, :index, @datatable.collection_class)
12
+
13
+ render json: @datatable.to_json
14
+ rescue => e
15
+ (EffectiveDatatables.authorized?(self, :index, @datatable.try(:collection_class)) rescue false)
22
16
 
17
+ render json: error_json(message: e.message)
18
+ end
23
19
  end
24
20
 
25
21
  private
@@ -29,15 +25,16 @@ module Effective
29
25
  id.classify.safe_constantize || id.classify.pluralize.safe_constantize
30
26
  end
31
27
 
32
- def error_json
28
+ def error_json(message:)
33
29
  {
34
- draw: params[:draw].to_i,
35
30
  data: [],
31
+ draw: params[:draw].to_i,
32
+ effective_datatables_error: message.presence || 'unknown error',
36
33
  recordsTotal: 0,
37
34
  recordsFiltered: 0,
38
35
  aggregates: [],
39
36
  charts: {}
40
- }.to_json
37
+ }
41
38
  end
42
39
 
43
40
  end
@@ -11,7 +11,9 @@ 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 && cookie[:attributes]
14
+ raise 'expected cookie to be present' unless cookie
15
+ raise 'expected attributes cookie to be present' unless cookie[:attributes]
16
+
15
17
  @attributes = cookie.delete(:attributes)
16
18
  end
17
19
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '3.0.16'.freeze
2
+ VERSION = '3.1.0'.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.0.16
4
+ version: 3.1.0
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-07-10 00:00:00.000000000 Z
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails