datatablesnet 1.0 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/datatablesnet/datatable.rb +49 -9
- data/lib/datatablesnet/hash_sql.rb +5 -1
- data/lib/datatablesnet/version.rb +1 -1
- metadata +7 -10
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'datatablesnet/types'
|
2
|
+
require 'datatablesnet/hash_sql'
|
3
|
+
require 'uri'
|
2
4
|
|
3
5
|
module Datatable
|
4
6
|
|
@@ -70,16 +72,19 @@ module Datatable
|
|
70
72
|
|
71
73
|
options =
|
72
74
|
{
|
73
|
-
:show_actions =>
|
75
|
+
:show_actions => false,
|
74
76
|
:per_page => 25,
|
75
77
|
:toolbar_external => false
|
76
78
|
}.merge(options)
|
77
79
|
|
80
|
+
url = URI::split(options[:data_url]);
|
81
|
+
|
78
82
|
index = 0
|
79
83
|
columns.each do |column|
|
80
84
|
column[:label] = field_to_label(column[:field]) unless column[:label].present?
|
81
85
|
if options[:data_url].present?
|
82
|
-
options[:data_url] << "?" if column == columns.first
|
86
|
+
options[:data_url] << "?" if column == columns.first and url[7] == nil
|
87
|
+
options[:data_url] << "&" if column == columns.first and url[7] != nil
|
83
88
|
options[:data_url] << "column_field_#{index.to_s}=#{column[:field]}"
|
84
89
|
if column[:view_link].present?
|
85
90
|
options[:data_url] << "&column_view_link_#{index.to_s}=#{column[:view_link]}"
|
@@ -205,6 +210,24 @@ module Datatable
|
|
205
210
|
end
|
206
211
|
end
|
207
212
|
|
213
|
+
search_by = {}
|
214
|
+
params.each do |key, value|
|
215
|
+
if key =~ /query_.*/ and !value.empty?
|
216
|
+
if key =~ /.*_to/
|
217
|
+
field_name = key[6..-4]
|
218
|
+
search_by[field_name] = {} unless search_by[field_name].present?
|
219
|
+
search_by[field_name][:to] = Date.parse(value)
|
220
|
+
elsif key =~ /.*_from/
|
221
|
+
field_name = key[6..-6]
|
222
|
+
search_by[field_name] = {} unless search_by[field_name].present?
|
223
|
+
search_by[field_name][:from] = Date.parse(value)
|
224
|
+
else
|
225
|
+
search_by[key[6..-1]] = value
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
grid_options[:search_by] = search_by
|
208
231
|
grid_options[:columns] = columns
|
209
232
|
grid_options[:order_by] = order_by
|
210
233
|
grid_options[:filter_by] = filter_by
|
@@ -219,8 +242,10 @@ module Datatable
|
|
219
242
|
|
220
243
|
|
221
244
|
def find(klass, params={}, options = {})
|
245
|
+
puts params.to_json
|
222
246
|
field_filter_where = {}
|
223
247
|
all_filter_where = {}
|
248
|
+
search_filter_where = {}
|
224
249
|
|
225
250
|
grid_options = parse_params params
|
226
251
|
|
@@ -230,12 +255,14 @@ module Datatable
|
|
230
255
|
|
231
256
|
# Build order by
|
232
257
|
grid_options[:order_by].each do |column, order|
|
233
|
-
if
|
234
|
-
options[:order]
|
235
|
-
|
236
|
-
|
258
|
+
if column
|
259
|
+
if options[:order].present?
|
260
|
+
options[:order] << ", "
|
261
|
+
else
|
262
|
+
options[:order] = ""
|
263
|
+
end
|
264
|
+
options[:order] << "#{column} #{order}"
|
237
265
|
end
|
238
|
-
options[:order] << "#{column} #{order}"
|
239
266
|
end
|
240
267
|
|
241
268
|
# Build filter by
|
@@ -252,8 +279,21 @@ module Datatable
|
|
252
279
|
end
|
253
280
|
end
|
254
281
|
|
255
|
-
|
256
|
-
|
282
|
+
grid_options[:search_by].each do |column, value|
|
283
|
+
if value.instance_of?(Hash)
|
284
|
+
search_filter_where[column] = (value[:from]..value[:to])
|
285
|
+
else
|
286
|
+
search_filter_where[column] = value
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
if !field_filter_where.empty? or !all_filter_where.empty? or !search_filter_where.empty?
|
291
|
+
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 options[:conditions].present?
|
293
|
+
options[:conditions] << " and (" << sql_where << ")"
|
294
|
+
else
|
295
|
+
options[:conditions] = sql_where
|
296
|
+
end
|
257
297
|
end
|
258
298
|
|
259
299
|
puts options[:conditions]
|
@@ -45,7 +45,11 @@ module HashSql
|
|
45
45
|
where_string << " #{sql_operator ? sql_operator : 'and'} "
|
46
46
|
end
|
47
47
|
|
48
|
-
if
|
48
|
+
if value.instance_of?(Range)
|
49
|
+
where_string << "(#{name} BETWEEN ? AND ?)"
|
50
|
+
values << value.min
|
51
|
+
values << value.max
|
52
|
+
elsif self.sql_comparator = "like"
|
49
53
|
where_string << "#{name} LIKE ?"
|
50
54
|
values << '%' + value + '%'
|
51
55
|
else
|
metadata
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datatablesnet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
4
|
+
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 1
|
8
|
-
-
|
9
|
-
version: "1.
|
7
|
+
- 1
|
8
|
+
version: "1.1"
|
10
9
|
platform: ruby
|
11
10
|
authors:
|
12
11
|
- Matt Fields
|
@@ -14,7 +13,8 @@ autorequire:
|
|
14
13
|
bindir: bin
|
15
14
|
cert_chain: []
|
16
15
|
|
17
|
-
date: 2011-
|
16
|
+
date: 2011-08-09 00:00:00 +03:00
|
17
|
+
default_executable:
|
18
18
|
dependencies: []
|
19
19
|
|
20
20
|
description: Component abstraction for datatables.net
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- lib/datatablesnet/railtie.rb
|
37
37
|
- lib/datatablesnet/types.rb
|
38
38
|
- lib/datatablesnet/version.rb
|
39
|
+
has_rdoc: true
|
39
40
|
homepage: https://github.com/IslandPort/datatablesnet
|
40
41
|
licenses: []
|
41
42
|
|
@@ -45,27 +46,23 @@ rdoc_options: []
|
|
45
46
|
require_paths:
|
46
47
|
- lib
|
47
48
|
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
49
|
requirements:
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
hash: 3
|
53
52
|
segments:
|
54
53
|
- 0
|
55
54
|
version: "0"
|
56
55
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
56
|
requirements:
|
59
57
|
- - ">="
|
60
58
|
- !ruby/object:Gem::Version
|
61
|
-
hash: 3
|
62
59
|
segments:
|
63
60
|
- 0
|
64
61
|
version: "0"
|
65
62
|
requirements: []
|
66
63
|
|
67
64
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.
|
65
|
+
rubygems_version: 1.3.6
|
69
66
|
signing_key:
|
70
67
|
specification_version: 3
|
71
68
|
summary: Datatables.net component for rails
|