effective_datatables 2.7.0 → 2.8.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ce0fed54f90ff8b2008a4bc483f76b04c0a0b40
4
- data.tar.gz: c7b9e3d1ccd3246c0caff7b1a52843c99cfebc66
3
+ metadata.gz: 254850f988b403fcd7bab23babac6af5905a7ee4
4
+ data.tar.gz: c5722ac344bc0798bbe8ddab55582bd5b4c0fead
5
5
  SHA512:
6
- metadata.gz: 4f17f6ea328d0cb5f6d7b8c17fbc55de4a02dd3ff9936754772ae73d66bf0003504fb8aa335389a4d73fb380b9560469061f7333baaadfeaf0ddd47f7d82fb32
7
- data.tar.gz: d95868d508ca03ed0af7f347bcae93da40f34efa267e1bd9db650ab8458042a925f4c50d02e54e9de42c5185e6c2fd5a4648cb5366490cd1c3d3462c80461815
6
+ metadata.gz: 47d8354626af6be0d1a8176e5609d4f9e7ee58e2a851845ff4d37260e86f4eb3ad344382ac64fd3e9a0755d8d663b178fb7f6c4355bb968229cb942853733aaa
7
+ data.tar.gz: ed8ab8398e717bea338457560fdbf2fb25f1e008069a73b34d9d20389587e1f5538c14b11028b02fa71780b5a7b3f073ec4a4c492e3f19b9199228e9cfc022cd
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2014 Code and Effect Inc.
1
+ Copyright 2017 Code and Effect Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -565,6 +565,12 @@ As well, you need to change the controller where you define the datatable to be
565
565
  @datatable = Effective::Datatables::Posts.new(params[:scopes])
566
566
  ```
567
567
 
568
+ And to display the scopes anywhere in your view:
569
+
570
+ ```ruby
571
+ = render_datatable_scopes(@datatable)
572
+ ```
573
+
568
574
  So initially, the `:start_date` will have the value of `Time.zone.now-3.months` and when submitted by the form, the value will be set there.
569
575
 
570
576
  The form value will come back as a string, so you may need to `Time.zone.parse` that value.
@@ -200,8 +200,7 @@ destroyDataTables = ->
200
200
  if $.fn.DataTable.fnIsDataTable(this)
201
201
  $(this).DataTable().destroy()
202
202
 
203
- $ -> initializeDataTables()
204
203
  $(document).on 'page:change', -> initializeDataTables()
205
204
  $(document).on 'turbolinks:load', -> initializeDataTables()
206
- $(document).on 'turbolinks:before-cache', -> destroyDataTables()
205
+
207
206
 
@@ -30,7 +30,7 @@ module Effective
30
30
  if direction == :asc
31
31
  collection.sort! do |x, y|
32
32
  if (x[index] && y[index])
33
- convert_to_column_type(table_column, x[index]) <=> convert_to_column_type(table_column, y[index])
33
+ x[index] <=> y[index]
34
34
  elsif x[index]
35
35
  -1
36
36
  elsif y[index]
@@ -42,7 +42,7 @@ module Effective
42
42
  else
43
43
  collection.sort! do |x, y|
44
44
  if (x[index] && y[index])
45
- convert_to_column_type(table_column, y[index]) <=> convert_to_column_type(table_column, x[index])
45
+ y[index] <=> x[index]
46
46
  elsif x[index]
47
47
  1
48
48
  elsif y[index]
@@ -70,7 +70,7 @@ module Effective
70
70
 
71
71
  collection.select! do |row|
72
72
  if table_column[:filter][:fuzzy]
73
- convert_to_column_type(table_column, row[index]).to_s.downcase.include?(search_term)
73
+ row[index].to_s.downcase.include?(search_term)
74
74
  else
75
75
  row[index] == search_term
76
76
  end
@@ -186,11 +186,19 @@ module Effective
186
186
  # Check if collection has an order() clause and warn about it
187
187
  # Usually that will make the table results look weird.
188
188
  def active_record_collection?
189
- @active_record_collection ||= (collection.ancestors.include?(ActiveRecord::Base) rescue false)
189
+ if @active_record_collection == nil
190
+ @active_record_collection = (collection.ancestors.include?(ActiveRecord::Base) rescue false)
191
+ end
192
+
193
+ @active_record_collection
190
194
  end
191
195
 
192
196
  def array_collection?
193
- collection.kind_of?(Array) && collection.first.kind_of?(Array)
197
+ if @array_collection == nil
198
+ @array_collection = (collection.kind_of?(Array) && collection.first.kind_of?(Array))
199
+ end
200
+
201
+ @array_collection
194
202
  end
195
203
 
196
204
  # Not every ActiveRecord query will work when calling the simple .count
@@ -134,7 +134,7 @@ module Effective
134
134
  end
135
135
  )
136
136
 
137
- cols[name][:class] = "col-#{cols[name][:type]} col-#{name} #{cols[name][:class]}".strip
137
+ cols[name][:class] = "col-#{cols[name][:type]} col-#{name.parameterize} #{cols[name][:class]}".strip
138
138
 
139
139
  # Formats
140
140
  if name == 'id' || name.include?('year') || name.end_with?('_id')
@@ -19,28 +19,34 @@ module Effective
19
19
  if table_tool.search_terms.present? && array_tool.search_terms.blank?
20
20
  self.display_records = active_record_collection_size(col)
21
21
  end
22
- end
23
22
 
24
- if array_tool.search_terms.present?
25
- col = self.arrayize(col)
26
- col = array_tool.search(col)
27
- self.display_records = col.size
23
+ if array_tool.search_terms.present?
24
+ col = self.arrayize(col)
25
+ col = array_tool.search(col)
26
+ self.display_records = col.size
27
+ end
28
+
29
+ if array_tool.order_by_column.present?
30
+ col = self.arrayize(col)
31
+ col = array_tool.order(col)
32
+ end
28
33
  end
29
34
 
30
- if array_tool.order_by_column.present?
31
- col = self.arrayize(col)
35
+ if array_collection?
32
36
  col = array_tool.order(col)
37
+ col = array_tool.search(col)
33
38
  end
34
39
 
35
40
  self.display_records ||= total_records
36
41
 
37
- if col.kind_of?(Array)
42
+ if array_collection?
38
43
  col = array_tool.paginate(col)
39
44
  else
40
45
  col = table_tool.paginate(col)
41
- col = self.arrayize(col)
42
46
  end
43
47
 
48
+ col = self.arrayize(col)
49
+
44
50
  self.format(col)
45
51
  col = self.finalize(col)
46
52
  end
@@ -85,7 +91,11 @@ module Effective
85
91
  BLANK
86
92
  elsif opts[:block]
87
93
  begin
88
- view.instance_exec(obj, collection, self, &opts[:block])
94
+ if active_record_collection?
95
+ view.instance_exec(obj, collection, self, &opts[:block])
96
+ else
97
+ view.instance_exec(obj, obj[opts[:array_index]], collection, self, &opts[:block])
98
+ end
89
99
  rescue NoMethodError => e
90
100
  if opts[:type] == :actions && e.message == 'super called outside of method'
91
101
  rendered[name][index]
@@ -94,7 +104,11 @@ module Effective
94
104
  end
95
105
  end
96
106
  elsif opts[:proc]
97
- view.instance_exec(obj, collection, self, &opts[:proc])
107
+ if active_record_collection?
108
+ view.instance_exec(obj, collection, self, &opts[:proc])
109
+ else
110
+ view.instance_exec(obj, obj[opts[:array_index]], collection, self, &opts[:proc])
111
+ end
98
112
  elsif opts[:partial]
99
113
  rendered[name][index]
100
114
  elsif opts[:type] == :belongs_to
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '2.7.0'.freeze
2
+ VERSION = '2.8.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: 2.7.0
4
+ version: 2.8.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: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2017-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -105,7 +105,6 @@ extra_rdoc_files: []
105
105
  files:
106
106
  - MIT-LICENSE
107
107
  - README.md
108
- - Rakefile
109
108
  - app/assets/images/dataTables/sort_asc.png
110
109
  - app/assets/images/dataTables/sort_both.png
111
110
  - app/assets/images/dataTables/sort_desc.png
data/Rakefile DELETED
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env rake
2
- begin
3
- require 'bundler/setup'
4
- rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
- end
7
-
8
- # Our tasks
9
- load 'lib/tasks/effective_datatables_tasks.rake'
10
-
11
- # Testing tasks
12
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
13
- load 'rails/tasks/engine.rake'
14
-
15
- Bundler::GemHelper.install_tasks
16
-
17
- require 'rspec/core'
18
- require 'rspec/core/rake_task'
19
-
20
- desc "Run all specs in spec directory (excluding plugin specs)"
21
- RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
22
-
23
- task :default => :spec