datatablesnet 1.1 → 1.1.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.
- data/lib/datatablesnet/datatable.rb +66 -28
- data/lib/datatablesnet/hash_sql.rb +1 -1
- data/lib/datatablesnet/version.rb +1 -1
- metadata +3 -2
@@ -105,6 +105,8 @@ module Datatable
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
+
table_options["fnInfoCallback"] = NoEscape.new(options[:info_callback]) if options[:info_callback].present?
|
109
|
+
|
108
110
|
table_options["aoColumns"] = datatable_get_column_defs(options,columns)
|
109
111
|
|
110
112
|
config = {:options => options, :columns =>columns, :table_options => table_options}
|
@@ -216,11 +218,11 @@ module Datatable
|
|
216
218
|
if key =~ /.*_to/
|
217
219
|
field_name = key[6..-4]
|
218
220
|
search_by[field_name] = {} unless search_by[field_name].present?
|
219
|
-
search_by[field_name][:to] =
|
221
|
+
search_by[field_name][:to] = convert_string(value)
|
220
222
|
elsif key =~ /.*_from/
|
221
223
|
field_name = key[6..-6]
|
222
224
|
search_by[field_name] = {} unless search_by[field_name].present?
|
223
|
-
search_by[field_name][:from] =
|
225
|
+
search_by[field_name][:from] = convert_string(value)
|
224
226
|
else
|
225
227
|
search_by[key[6..-1]] = value
|
226
228
|
end
|
@@ -240,32 +242,29 @@ module Datatable
|
|
240
242
|
grid_options
|
241
243
|
end
|
242
244
|
|
245
|
+
def convert_string value
|
246
|
+
begin
|
247
|
+
value = Date.parse(value)
|
248
|
+
rescue ArgumentError
|
249
|
+
value = value.to_i
|
250
|
+
if value == 0
|
251
|
+
value = value
|
252
|
+
end
|
253
|
+
end
|
254
|
+
value
|
255
|
+
end
|
243
256
|
|
244
|
-
def find(klass, params={}, options = {})
|
245
|
-
puts params.to_json
|
246
|
-
field_filter_where = {}
|
247
|
-
all_filter_where = {}
|
248
|
-
search_filter_where = {}
|
249
257
|
|
258
|
+
def build_condition(klass, params={}, options = {})
|
250
259
|
grid_options = parse_params params
|
260
|
+
build_condition_internal(klass, grid_options, options[:conditions].present? ? options[:conditions] : nil)
|
261
|
+
end
|
251
262
|
|
263
|
+
def build_condition_internal(klass, grid_options, conditions)
|
264
|
+
field_filter_where = {}
|
265
|
+
all_filter_where = {}
|
266
|
+
search_filter_where = {}
|
252
267
|
|
253
|
-
options[:page] = grid_options[:page]
|
254
|
-
options[:per_page] = grid_options[:per_page]
|
255
|
-
|
256
|
-
# Build order by
|
257
|
-
grid_options[:order_by].each do |column, order|
|
258
|
-
if column
|
259
|
-
if options[:order].present?
|
260
|
-
options[:order] << ", "
|
261
|
-
else
|
262
|
-
options[:order] = ""
|
263
|
-
end
|
264
|
-
options[:order] << "#{column} #{order}"
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
# Build filter by
|
269
268
|
grid_options[:filter_by].each do |column, value|
|
270
269
|
field_filter_where[column] = value
|
271
270
|
end
|
@@ -279,9 +278,14 @@ module Datatable
|
|
279
278
|
end
|
280
279
|
end
|
281
280
|
|
281
|
+
#process search_by
|
282
282
|
grid_options[:search_by].each do |column, value|
|
283
283
|
if value.instance_of?(Hash)
|
284
|
-
|
284
|
+
if value[:to].present?
|
285
|
+
search_filter_where[column] = (value[:from]..value[:to])
|
286
|
+
else
|
287
|
+
search_filter_where[column] = value[:from]
|
288
|
+
end
|
285
289
|
else
|
286
290
|
search_filter_where[column] = value
|
287
291
|
end
|
@@ -289,13 +293,47 @@ module Datatable
|
|
289
293
|
|
290
294
|
if !field_filter_where.empty? or !all_filter_where.empty? or !search_filter_where.empty?
|
291
295
|
sql_where = [field_filter_where.sql_like, all_filter_where.sql_or.sql_like, search_filter_where.sql_and].sql_and.sql_where
|
292
|
-
if
|
293
|
-
|
296
|
+
if conditions
|
297
|
+
if conditions.instance_of?(Array)
|
298
|
+
condition_string = conditions[0]
|
299
|
+
condition_params = conditions[1..-1]
|
300
|
+
else
|
301
|
+
condition_string = conditions
|
302
|
+
condition_params = []
|
303
|
+
end
|
304
|
+
condition_string << " and (" << sql_where[0] << ")"
|
305
|
+
condition_params += sql_where[1..-1]
|
306
|
+
conditions = [condition_string] + condition_params
|
294
307
|
else
|
295
|
-
|
308
|
+
conditions = sql_where
|
309
|
+
end
|
310
|
+
end
|
311
|
+
conditions
|
312
|
+
end
|
313
|
+
|
314
|
+
def find(klass, params={}, options = {})
|
315
|
+
puts params.to_json
|
316
|
+
|
317
|
+
grid_options = parse_params params
|
318
|
+
|
319
|
+
options[:page] = grid_options[:page]
|
320
|
+
options[:per_page] = grid_options[:per_page]
|
321
|
+
|
322
|
+
# Build order by
|
323
|
+
grid_options[:order_by].each do |column, order|
|
324
|
+
if column
|
325
|
+
if options[:order].present?
|
326
|
+
options[:order] << ", "
|
327
|
+
else
|
328
|
+
options[:order] = ""
|
329
|
+
end
|
330
|
+
options[:order] << "#{column} #{order}"
|
296
331
|
end
|
297
332
|
end
|
298
333
|
|
334
|
+
# Build filter by
|
335
|
+
options[:conditions] = build_condition_internal(klass, grid_options, options[:conditions].present? ? options[:conditions] : nil)
|
336
|
+
|
299
337
|
puts options[:conditions]
|
300
338
|
|
301
339
|
rows = klass.paginate options
|
@@ -314,7 +352,7 @@ module Datatable
|
|
314
352
|
|
315
353
|
total_records = klass.count
|
316
354
|
if options[:conditions].present?
|
317
|
-
klass.count(:conditions => options[:conditions])
|
355
|
+
total_display_records = klass.count(:conditions => options[:conditions])
|
318
356
|
else
|
319
357
|
total_display_records = total_records
|
320
358
|
end
|
metadata
CHANGED
@@ -5,7 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 1
|
8
|
-
|
8
|
+
- 1
|
9
|
+
version: 1.1.1
|
9
10
|
platform: ruby
|
10
11
|
authors:
|
11
12
|
- Matt Fields
|
@@ -13,7 +14,7 @@ autorequire:
|
|
13
14
|
bindir: bin
|
14
15
|
cert_chain: []
|
15
16
|
|
16
|
-
date: 2011-08-
|
17
|
+
date: 2011-08-24 00:00:00 +03:00
|
17
18
|
default_executable:
|
18
19
|
dependencies: []
|
19
20
|
|