effective_datatables 2.11.1 → 2.11.2

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: 0c6e56a24c68555820e8fd71b7db4717a01447c7
4
- data.tar.gz: 47a3d46c4ceeab5eac8612d37a077ee0aba09082
3
+ metadata.gz: 89fe9d65ab41811c5fe6f99d2a30178cdd17558e
4
+ data.tar.gz: 3778600b8979aeb4ec2553e00aef1dbd9d856e58
5
5
  SHA512:
6
- metadata.gz: b2b1e22237b8cdbff14edb359266f3079af6bfb52b072d590072ffa26382187b25d1f2306314d8e8e84826cb448190c31dde3d1837275f4b9f6a374795056987
7
- data.tar.gz: 8a4624ec83c4752f1a29141af17a61f6392c7425eed955753fd028c4afe50271ea00192fb1ea1a3bc296eedecad58d1a334583d74d0e04460972cbb4ebe1757b
6
+ metadata.gz: d25d50f56c92c86e72c812ff0d58ba59658cbe5856ff42965d5988406c7bca194e36114e6ad0958a135bd1447d7b3ed63bd6f2db7d2562eed02ae596662c0c1e
7
+ data.tar.gz: e5cf61f381816ab5946f7e5f689f644c522e9181d05940a73535018aae9ea5cc6b21394a8e7976921b53d4fde2a708d2b6458adcee37c59ac4ba775c0af09885
@@ -6,8 +6,9 @@ initializeCharts = ->
6
6
  type = $chart.data('type') || 'BarChart'
7
7
  options = $chart.data('options') || {}
8
8
 
9
- chart = new google.visualization[type](document.getElementById($chart.attr('id')))
10
- chart.draw(google.visualization.arrayToDataTable(data), options)
9
+ if google
10
+ chart = new google.visualization[type](document.getElementById($chart.attr('id')))
11
+ chart.draw(google.visualization.arrayToDataTable(data), options)
11
12
 
12
13
  $ -> initializeCharts()
13
14
  $(document).on 'page:change', -> initializeCharts()
@@ -175,6 +175,13 @@ destroyDataTables = ->
175
175
  if $.fn.DataTable.fnIsDataTable(this)
176
176
  $(this).DataTable().destroy()
177
177
 
178
+ anotherDestroy = ->
179
+ for settings in $.fn.dataTable.settings
180
+ $(settings.nTableWrapper).unbind('.DT').find(':not(tbody *)').unbind('.DT')
181
+ $(window).unbind('.DT-'+settings.sInstance)
182
+
183
+ $.fn.dataTable.settings.length = 0
184
+
178
185
  $ -> initializeDataTables()
179
186
  $(document).on 'page:change', -> initializeDataTables()
180
187
  $(document).on 'turbolinks:load', -> initializeDataTables()
@@ -43,7 +43,7 @@ module EffectiveDatatablesPrivateHelper
43
43
 
44
44
  include_blank = opts[:filter].key?(:include_blank) ? opts[:filter][:include_blank] : (opts[:label] || name.titleize)
45
45
  pattern = opts[:filter].key?(:pattern) ? opts[:filter][:pattern] : nil
46
- placeholder = opts[:filter].key?(:placeholder) ? opts[:filter][:placeholder] : (opts[:label] || name.titleize)
46
+ placeholder = (opts[:filter][:placeholder] || '')
47
47
  title = opts[:filter].key?(:title) ? opts[:filter][:title] : (opts[:label] || name.titleize)
48
48
  wrapper_html = { class: 'datatable_filter' }
49
49
 
@@ -60,7 +60,7 @@ module EffectiveDatatablesPrivateHelper
60
60
 
61
61
  form.input name, label: false, required: false, value: value,
62
62
  as: :string,
63
- placeholder: placeholder,
63
+ placeholder: placeholder.presence || '###-####-###',
64
64
  wrapper_html: wrapper_html,
65
65
  input_html: { name: nil, value: value, title: title, pattern: pattern, autocomplete: 'off', data: {'column-name' => opts[:name], 'column-index' => opts[:index]} }
66
66
  when :date
@@ -22,13 +22,10 @@ module Effective
22
22
  include Effective::EffectiveDatatable::Rendering
23
23
 
24
24
  def initialize(*args)
25
- if respond_to?(:initialize_scopes) # There was at least one scope defined in the scopes do .. end block
26
- initialize_scopes
27
- end
28
-
29
25
  initialize_attributes(args)
30
26
 
31
- if respond_to?(:initialize_scopes) # There was at least one scope defined in the scopes do .. end block
27
+ if respond_to?(:initialize_scopes) # There was at least one scope defined in the scopes do .. end block
28
+ initialize_scopes
32
29
  initialize_scope_options
33
30
  end
34
31
 
@@ -27,7 +27,7 @@ module Effective
27
27
  (params[:columns][order_by_column_index] || {})[:name]
28
28
  elsif @default_order.present?
29
29
  @default_order.keys.first
30
- end || table_columns.find { |col, opts| opts[:type] != :bulk_actions_column }.first
30
+ end || table_columns.find { |col, opts| opts[:type] != :bulk_actions_column }.try(:first)
31
31
  end
32
32
  end
33
33
 
@@ -29,11 +29,14 @@ module Effective
29
29
 
30
30
  def _initialize_attributes(args)
31
31
  args.compact.each do |arg|
32
- arg = arg.to_unsafe_h if arg.respond_to?(:permit) # ActionController::Parameters / Rails 5 hack. TODO.
32
+ # ActionController::Parameters / Rails 5 hack. TODO.
33
+ if arg.respond_to?(:permit)
34
+ arg = (arg.respond_to?(:to_unsafe_h) ? arg.to_unsafe_h : arg.to_h)
35
+ end
33
36
 
34
37
  raise "#{self.class.name}.new() can only be initialized with a Hash like arguments" unless arg.kind_of?(Hash)
35
38
 
36
- arg.each { |k, v| self.attributes[k] = v.presence }
39
+ arg.each { |k, v| self.attributes[k] = v }
37
40
  end
38
41
  end
39
42
 
@@ -86,7 +89,7 @@ module Effective
86
89
  # We set some memoized helper values
87
90
  @collection_class = (collection.respond_to?(:klass) ? collection.klass : self.class)
88
91
  @active_record_collection = (collection.ancestors.include?(ActiveRecord::Base) rescue false)
89
- @array_collection = (collection.kind_of?(Array) && collection.first.kind_of?(Array))
92
+ @array_collection = (collection.kind_of?(Array) && (collection.length == 0 || collection.first.kind_of?(Array)))
90
93
 
91
94
  # And then parse all the colums
92
95
  sql_table = (collection.table rescue nil)
@@ -118,7 +121,7 @@ module Effective
118
121
  end
119
122
  end
120
123
 
121
- table_columns = cols.each_with_index do |(name, _), index|
124
+ table_columns = (cols || {}).each_with_index do |(name, _), index|
122
125
  sql_column = (collection.columns rescue []).find do |column|
123
126
  column.name == name.to_s || (belong_tos.key?(name) && column.name == belong_tos[name][:foreign_key])
124
127
  end
@@ -239,6 +242,8 @@ module Effective
239
242
  collection: (
240
243
  if belongs_to[:klass].respond_to?(:datatables_filter)
241
244
  Proc.new { belongs_to[:klass].datatables_filter }
245
+ elsif belongs_to[:klass].respond_to?(:sorted)
246
+ Proc.new { belongs_to[:klass].sorted }
242
247
  else
243
248
  Proc.new { belongs_to[:klass].all.map { |obj| [obj.to_s, obj.id] }.sort { |x, y| x[0] <=> y[0] } }
244
249
  end
@@ -253,6 +258,8 @@ module Effective
253
258
  collection: (
254
259
  if has_many[:klass].respond_to?(:datatables_filter)
255
260
  Proc.new { has_many[:klass].datatables_filter }
261
+ elsif has_many[:klass].respond_to?(:sorted)
262
+ Proc.new { has_many[:klass].sorted }
256
263
  else
257
264
  Proc.new { has_many[:klass].all.map { |obj| [obj.to_s, obj.id] }.sort { |x, y| x[0] <=> y[0] } }
258
265
  end
@@ -265,6 +272,8 @@ module Effective
265
272
  collection: (
266
273
  if has_and_belongs_to_manys[:klass].respond_to?(:datatables_filter)
267
274
  Proc.new { has_and_belongs_to_manys[:klass].datatables_filter }
275
+ elsif has_and_belongs_to_manys[:klass].respond_to?(:sorted)
276
+ Proc.new { has_and_belongs_to_manys[:klass].sorted }
268
277
  else
269
278
  Proc.new { has_and_belongs_to_manys[:klass].all.map { |obj| [obj.to_s, obj.id] }.sort { |x, y| x[0] <=> y[0] } }
270
279
  end
@@ -23,19 +23,19 @@
23
23
  unarchive_action = instance_exec(resource, &unarchive_action)
24
24
  end
25
25
 
26
- - if show_action && show_path
26
+ - if show_action && defined?(show_path)
27
27
  = show_icon_to show_path.gsub(':to_param', resource.to_param)
28
28
 
29
- - if edit_action && edit_path
29
+ - if edit_action && defined?(edit_path)
30
30
  = edit_icon_to edit_path.gsub(':to_param', resource.to_param)
31
31
 
32
- - if destroy_action && destroy_path
32
+ - if destroy_action && defined?(destroy_path)
33
33
  - if resource.respond_to?(:archived?) && !resource.archived?
34
34
  = archive_icon_to destroy_path.gsub(':to_param', resource.to_param)
35
35
  - elsif resource.respond_to?(:archived?) == false
36
36
  = destroy_icon_to destroy_path.gsub(':to_param', resource.to_param)
37
37
 
38
- - if unarchive_action && unarchive_path
38
+ - if unarchive_action && defined?(unarchive_path)
39
39
  - if resource.respond_to?(:archived?) && resource.archived?
40
40
  = unarchive_icon_to unarchive_path.gsub(':to_param', resource.to_param)
41
41
 
@@ -18,9 +18,21 @@
18
18
 
19
19
  %table.effective-datatable{effective_datatable_params}
20
20
  %thead
21
- %tr
22
- - datatable.table_columns.each do |name, opts|
23
- %th= opts[:label] || name
21
+ - if datatable.table_columns.any? { |_, opts| opts[:th].present? } == false
22
+ %tr
23
+ - datatable.table_columns.each do |name, opts|
24
+ %th= opts[:label] || name
25
+ - else
26
+ - max_depth = datatable.table_columns.map { |_, opts| opts[:th].try(:[], :depth) || 0 }.max
27
+ - [*0..max_depth].each do |depth|
28
+ %tr
29
+ - table_columns = datatable.table_columns.select { |_, opts| (opts[:th].try(:[], :depth) || 0) == depth }
30
+ - table_columns.each do |name, opts|
31
+ %th{(opts[:th] || {}).merge(title: (opts[:label] || name))}
32
+ = opts[:label] || name
33
+ - (opts[:append_th] || []).each do |faux_col|
34
+ %th{(faux_col[:th] || {}).merge(title: faux_col[:label])}
35
+ = faux_col[:label]
24
36
 
25
37
  %tbody
26
38
  - datatable.to_json[:data].each do |row|
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '2.11.1'.freeze
2
+ VERSION = '2.11.2'.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: 2.11.1
4
+ version: 2.11.2
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-01-25 00:00:00.000000000 Z
11
+ date: 2017-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails