effective_datatables 3.1.2 → 3.1.3

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: 8f5bf96a1360216798ef20643a5bcef4e8afd745
4
- data.tar.gz: beb7fff4b3ac339a6c1ef0957458a25daae091bd
3
+ metadata.gz: a4081fbe7767fc0dc7e6142ee15630d12f50b237
4
+ data.tar.gz: ba5f35b8180b134ce4b567f41acb689f119d3402
5
5
  SHA512:
6
- metadata.gz: 8165fee817a1bfbda1bdeb090a1821633b4808e376b5dc84ec899b64d2082a9dfd19026039dc8adfeef2444a1fa160c5510404f3ff9a96b5aab3bd196eb16244
7
- data.tar.gz: 9c3b609594be2ffd2002fb498a9731f357f170ef87ea18a7822be3675c060a872fcf8b3433c22c4600b5d7bbee170e5c37a15654a8fb88d17227086d89700c65
6
+ metadata.gz: d1c9af4a05da6623271d70a10cbcdc45580b889f345fc0896c51fdbaaba7506755b4043228d956cf3673e29b45a7f9aaa80ec4e3c0d4043f18441b9140df50b5
7
+ data.tar.gz: f9436b7939c2a844b792214f4aa95d447445253fcba4b3354ae92957a1149324a8a0fc36381dac68a0422760cb800fd199c47d839ce9fac9043fca91a91628a6
@@ -38,6 +38,7 @@ initializeDataTables = ->
38
38
  },
39
39
  {
40
40
  extend: 'print',
41
+ footer: true,
41
42
  exportOptions:
42
43
  format:
43
44
  header: (str) -> $("<div>#{str}</div>").children('.search-label').first().text()
@@ -79,6 +79,7 @@ module EffectiveDatatablesPrivateHelper
79
79
  multiple: opts[:search][:multiple],
80
80
  grouped: opts[:search][:grouped],
81
81
  polymorphic: opts[:search][:polymorphic],
82
+ template: opts[:search][:template],
82
83
  include_blank: include_blank,
83
84
  wrapper_html: wrapper_html,
84
85
  input_html: input_html,
@@ -41,11 +41,17 @@ module Effective
41
41
 
42
42
  if direction == :asc
43
43
  collection.sort! do |x, y|
44
- x[index] <=> y[index] || x[index].to_s <=> y[index].to_s || 0
44
+ x = obj_to_value(x[index], column)
45
+ y = obj_to_value(y[index], column)
46
+
47
+ x <=> y || x.to_s <=> y.to_s || 0
45
48
  end
46
49
  else
47
50
  collection.sort! do |x, y|
48
- y[index] <=> x[index] || y[index].to_s <=> x[index].to_s || 0
51
+ x = obj_to_value(x[index], column)
52
+ y = obj_to_value(y[index], column)
53
+
54
+ y <=> x || y.to_s <=> x.to_s || 0
49
55
  end
50
56
  end
51
57
 
@@ -71,44 +77,64 @@ module Effective
71
77
  def search_column(collection, value, column, index)
72
78
  Rails.logger.info "VALUE TOOL: search_column #{column.to_s} #{value} #{index}" if EffectiveDatatables.debug
73
79
 
80
+ macros = Effective::Resource.new('').macros
74
81
  fuzzy = column[:search][:fuzzy]
82
+
75
83
  term = Effective::Attribute.new(column[:as]).parse(value, name: column[:name])
76
84
  term_downcased = term.to_s.downcase
77
- macros = Effective::Resource.new('').macros
78
85
 
79
- if term == 'nil'
80
- return (collection.select! { |row| row[index].nil? } || collection)
86
+ # term == 'nil' rescue false is a Rails 4.1 fix, where you can't compare a TimeWithZone to 'nil'
87
+ if (term == 'nil' rescue false)
88
+ return collection.select! { |row| obj_to_value(row[index], column) == nil } || collection
81
89
  end
82
90
 
83
91
  # See effective_resources gem search() method # relation.rb
84
92
  collection.select! do |row|
93
+ obj = obj_to_value(row[index], column)
94
+
85
95
  case column[:as]
86
- when :duration
87
- if fuzzy && (term % 60 == 0) && value.to_s.include?('m') == false
96
+ when :boolean
97
+ if fuzzy
98
+ term ? (obj == true) : (obj != true)
99
+ else
100
+ obj == term
101
+ end
102
+ when :datetime, :date
103
+ end_at = (
104
+ case (value.to_s.scan(/(\d+)/).flatten).length
105
+ when 1 ; term.end_of_year # Year
106
+ when 2 ; term.end_of_month # Year-Month
107
+ when 3 ; term.end_of_day # Year-Month-Day
108
+ when 4 ; term.end_of_hour # Year-Month-Day Hour
109
+ when 5 ; term.end_of_minute # Year-Month-Day Hour-Minute
110
+ when 6 ; term + 1.second # Year-Month-Day Hour-Minute-Second
111
+ else term
112
+ end
113
+ )
114
+ obj >= term && obj <= end_at
115
+ when :decimal, :currency
116
+ if fuzzy && (term.round(0) == term) && value.to_s.include?('.') == false
88
117
  if term < 0
89
- row[index] <= term && row[index] > (term - 60)
118
+ obj <= term && obj > (term - 1.0)
90
119
  else
91
- row[index] >= term && row[index] < (term + 60)
120
+ obj >= term && obj < (term + 1.0)
92
121
  end
93
122
  else
94
- row[index] == term
123
+ obj == term
95
124
  end
96
- when :decimal, :currency
97
- if fuzzy && (term.round(0) == term) && value.to_s.include?('.') == false
125
+ when :duration
126
+ if fuzzy && (term % 60 == 0) && value.to_s.include?('m') == false
98
127
  if term < 0
99
- row[index] <= term && row[index] > (term - 1.0)
128
+ obj <= term && obj > (term - 60)
100
129
  else
101
- row[index] >= term && row[index] < (term + 1.0)
130
+ obj >= term && obj < (term + 60)
102
131
  end
103
132
  else
104
- row[index] == term
133
+ obj == term
105
134
  end
106
135
  when *macros, :resource
107
- resources = Array(column[:as] == :resource ? row[index] : row[index].send(column[:name]))
108
- terms = Array(term)
109
-
110
- resources.any? do |resource|
111
- terms.any? do |term|
136
+ Array(obj).any? do |resource|
137
+ Array(terms).any? do |term|
112
138
  matched = false
113
139
 
114
140
  if term.kind_of?(Integer) && resource.respond_to?(:to_param)
@@ -118,12 +144,11 @@ module Effective
118
144
  matched ||= (fuzzy ? resource.to_s.downcase.include?(term.to_s.downcase) : resource.to_s == term)
119
145
  end
120
146
  end
121
-
122
147
  else # :string, :text, :email
123
148
  if fuzzy
124
- row[index].to_s.downcase.include?(term_downcased)
149
+ obj.to_s.downcase.include?(term_downcased)
125
150
  else
126
- row[index] == term || (row[index].to_s == term.to_s)
151
+ obj == term || (obj.to_s == term.to_s)
127
152
  end
128
153
  end
129
154
  end || collection
@@ -140,6 +165,10 @@ module Effective
140
165
  collection.size
141
166
  end
142
167
 
168
+ def obj_to_value(obj, column)
169
+ ((column[:partial] || column[:format]) && !column[:compute]) ? obj.send(column[:name]) : obj
170
+ end
171
+
143
172
  end
144
173
  end
145
174
 
@@ -60,11 +60,9 @@ module Effective
60
60
  columns.map do |name, opts|
61
61
  if state[:visible][name] == false && (name != order_name) # Sort by invisible array column
62
62
  BLANK
63
- elsif opts[:partial]
64
- active_record_collection? ? obj : obj[opts[:index]]
65
63
  elsif opts[:compute]
66
64
  dsl_tool.instance_exec(obj, (active_record_collection? ? collection : obj[opts[:index]]), &opts[:compute])
67
- elsif opts[:format]
65
+ elsif (opts[:partial] || opts[:format])
68
66
  active_record_collection? ? obj : obj[opts[:index]]
69
67
  elsif opts[:resource]
70
68
  resource = active_record_collection? ? obj : obj[opts[:index]]
@@ -137,7 +137,7 @@ module Effective
137
137
 
138
138
  search[:as] ||= :select if (search.key?(:collection) && opts[:as] != :belongs_to_polymorphic)
139
139
 
140
- search[:fuzzy] = (opts[:sql_as_column] != true) unless search.key?(:fuzzy)
140
+ search[:fuzzy] = true unless search.key?(:fuzzy)
141
141
 
142
142
  if array_collection? && opts[:resource].present?
143
143
  search.reverse_merge!(resource.search_form_field(name, collection.first[opts[:index]]))
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '3.1.2'.freeze
2
+ VERSION = '3.1.3'.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.1.2
4
+ version: 3.1.3
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-18 00:00:00.000000000 Z
11
+ date: 2017-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails