data_tables 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/data_tables.rb +26 -6
- metadata +19 -41
data/lib/data_tables.rb
CHANGED
@@ -38,6 +38,7 @@ module DataTablesController
|
|
38
38
|
conditions = options[:conditions] || []
|
39
39
|
scope = options[:scope] || :domain
|
40
40
|
named_scope = options[:named_scope]
|
41
|
+
named_scope_args = options[:named_scope_args]
|
41
42
|
except = options[:except]
|
42
43
|
|
43
44
|
if modelCls < Ohm::Model
|
@@ -59,7 +60,16 @@ module DataTablesController
|
|
59
60
|
current_page = (params[:iDisplayStart].to_i/params[:iDisplayLength].to_i rescue 0) + 1
|
60
61
|
objects = nil
|
61
62
|
if search_condition.nil?
|
62
|
-
|
63
|
+
if Gem.loaded_specs['ohm'].version == Gem::Version.create('0.1.5')
|
64
|
+
objects = records.sort_by(columns[sort_column][:name].to_sym,
|
65
|
+
:order => "ALPHA " + params[:sSortDir_0].capitalize,
|
66
|
+
:start => params[:iDisplayStart].to_i,
|
67
|
+
:limit => params[:iDisplayLength].to_i)
|
68
|
+
else
|
69
|
+
objects = records.sort_by(columns[sort_column][:name].to_sym,
|
70
|
+
:order => "ALPHA " + params[:sSortDir_0].capitalize,
|
71
|
+
:limit => [params[:iDisplayStart].to_i, params[:iDisplayLength].to_i])
|
72
|
+
end
|
63
73
|
total_display_records = total_records
|
64
74
|
else
|
65
75
|
options = {}
|
@@ -68,7 +78,16 @@ module DataTablesController
|
|
68
78
|
options[:fuzzy] = {columns[sort_column][:name].to_sym => search_condition}
|
69
79
|
objects = Lunar.search(modelCls, options)
|
70
80
|
total_display_records = objects.size
|
71
|
-
|
81
|
+
if Gem.loaded_specs['ohm'].version == Gem::Version.create('0.1.5')
|
82
|
+
objects = objects.sort(:by => columns[sort_column][:name].to_sym,
|
83
|
+
:order => "ALPHA " + params[:sSortDir_0].capitalize,
|
84
|
+
:start => params[:iDisplayStart].to_i,
|
85
|
+
:limit => params[:iDisplayLength].to_i)
|
86
|
+
else
|
87
|
+
objects = objects.sort(:by => columns[sort_column][:name].to_sym,
|
88
|
+
:order => "ALPHA " + params[:sSortDir_0].capitalize,
|
89
|
+
:limit => [params[:iDisplayStart].to_i, params[:iDisplayLength].to_i])
|
90
|
+
end
|
72
91
|
end
|
73
92
|
data = objects.collect do |instance|
|
74
93
|
columns.collect { |column| datatables_instance_get_value(instance, column) }
|
@@ -91,7 +110,7 @@ module DataTablesController
|
|
91
110
|
if sort_column && sort_column.has_key?(:attribute)
|
92
111
|
condstr = params[:sSearch].gsub(/_/, '\\\\_').gsub(/%/, '\\\\%')
|
93
112
|
condition_local = "(text(#{sort_column[:name]}) ILIKE '#{condstr}%')"
|
94
|
-
end
|
113
|
+
end
|
95
114
|
end
|
96
115
|
|
97
116
|
# We just need one conditions string for search at a time. Every time we input
|
@@ -117,8 +136,9 @@ module DataTablesController
|
|
117
136
|
end
|
118
137
|
|
119
138
|
if named_scope
|
120
|
-
|
121
|
-
|
139
|
+
args = named_scope_args ? Array(self.send(named_scope_args)) : []
|
140
|
+
total_records = modelCls.send(named_scope, *args).count :conditions => init_conditions.join(" AND ")
|
141
|
+
total_display_records = modelCls.send(named_scope, *args).count :conditions => conditions.join(" AND ")
|
122
142
|
else
|
123
143
|
total_records = modelCls.count :conditions => init_conditions.join(" AND ")
|
124
144
|
total_display_records = modelCls.count :conditions => conditions.join(" AND ")
|
@@ -127,7 +147,7 @@ module DataTablesController
|
|
127
147
|
sort_column = 1 if sort_column == 0
|
128
148
|
current_page = (params[:iDisplayStart].to_i/params[:iDisplayLength].to_i rescue 0)+1
|
129
149
|
if named_scope
|
130
|
-
objects = modelCls.send(named_scope).paginate(:page => current_page,
|
150
|
+
objects = modelCls.send(named_scope, *args).paginate(:page => current_page,
|
131
151
|
:order => "#{columns[sort_column][:name]} #{params[:sSortDir_0]}",
|
132
152
|
:conditions => conditions.join(" AND "),
|
133
153
|
:per_page => params[:iDisplayLength])
|
metadata
CHANGED
@@ -1,15 +1,10 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_tables
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 5
|
10
|
-
version: 0.1.5
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.6
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Duane Compton
|
14
9
|
- Calvin Bascom
|
15
10
|
- Yi Su
|
@@ -17,55 +12,38 @@ authors:
|
|
17
12
|
autorequire:
|
18
13
|
bindir: bin
|
19
14
|
cert_chain: []
|
20
|
-
|
21
|
-
date: 2012-10-10 00:00:00 -04:00
|
22
|
-
default_executable:
|
15
|
+
date: 2012-10-10 00:00:00.000000000 Z
|
23
16
|
dependencies: []
|
24
|
-
|
25
17
|
description: Originally a plugin
|
26
18
|
email: Duane.Compton@gmail.com
|
27
19
|
executables: []
|
28
|
-
|
29
20
|
extensions: []
|
30
|
-
|
31
21
|
extra_rdoc_files: []
|
32
|
-
|
33
|
-
files:
|
22
|
+
files:
|
34
23
|
- lib/data_tables.rb
|
35
24
|
- lib/data_tables/data_tables_helper.rb
|
36
|
-
has_rdoc: true
|
37
25
|
homepage: http://rubygems.org/gems/data_tables
|
38
26
|
licenses: []
|
39
|
-
|
40
27
|
post_install_message:
|
41
28
|
rdoc_options: []
|
42
|
-
|
43
|
-
require_paths:
|
29
|
+
require_paths:
|
44
30
|
- lib
|
45
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
46
36
|
none: false
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
- 0
|
53
|
-
version: "0"
|
54
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
55
42
|
none: false
|
56
|
-
requirements:
|
57
|
-
- - ">="
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
hash: 3
|
60
|
-
segments:
|
61
|
-
- 0
|
62
|
-
version: "0"
|
63
43
|
requirements: []
|
64
|
-
|
65
44
|
rubyforge_project:
|
66
|
-
rubygems_version: 1.
|
45
|
+
rubygems_version: 1.8.24
|
67
46
|
signing_key:
|
68
47
|
specification_version: 3
|
69
48
|
summary: Rails friendly interface into DataTables
|
70
49
|
test_files: []
|
71
|
-
|