effective_datatables 2.1.15 → 2.1.16
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66e34e1b67e2fc97fba5d01227d7878a55e3c102
|
4
|
+
data.tar.gz: 2a245701fa04c1baee5fd25458203a31836e847a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45e18b50fccd9e485b31e826141e9014cfd194288b78977cff12b4bdb875b9fba1543fc5a178a4d49532be0c86cda53ba2f44a2ad96b49c6d27eca496c86f82a
|
7
|
+
data.tar.gz: c99ffe12d35229644454a8ab5ee31a09ea86c2102fb2befb67b8d2edea5deca5524a35ba4bf6cd763ceb3029844dfe4060b9b7f8398cbbc33427819d2646af2e
|
@@ -2,7 +2,7 @@ module Effective
|
|
2
2
|
class ActiveRecordDatatableTool
|
3
3
|
attr_accessor :table_columns
|
4
4
|
|
5
|
-
delegate :order_name, :order_direction, :page, :per_page, :search_column, :collection_class, :to => :@datatable
|
5
|
+
delegate :order_name, :order_direction, :page, :per_page, :search_column, :collection_class, :quote_sql, :to => :@datatable
|
6
6
|
|
7
7
|
def initialize(datatable, table_columns)
|
8
8
|
@datatable = datatable
|
@@ -21,13 +21,20 @@ module Effective
|
|
21
21
|
return collection if order_column.blank?
|
22
22
|
|
23
23
|
column = order_column[:column]
|
24
|
+
before = ''; after = ''
|
24
25
|
|
25
|
-
if
|
26
|
-
|
27
|
-
elsif
|
28
|
-
|
26
|
+
if postgres?
|
27
|
+
after = ' NULLS LAST'
|
28
|
+
elsif mysql?
|
29
|
+
before = "ISNULL(#{column}), "
|
30
|
+
end
|
31
|
+
|
32
|
+
if order_column[:type] == :belongs_to_polymorphic
|
33
|
+
collection.order("#{before}#{column.sub('_id', '_type')} #{order_direction}, #{column} #{order_direction}#{after}")
|
34
|
+
elsif order_column[:sql_as_column] == true
|
35
|
+
collection.order("#{column} #{order_direction}")
|
29
36
|
else
|
30
|
-
collection.order("
|
37
|
+
collection.order("#{before}#{column} #{order_direction}#{after}")
|
31
38
|
end
|
32
39
|
end
|
33
40
|
|
@@ -49,14 +56,14 @@ module Effective
|
|
49
56
|
if (table_column[:filter][:type] == :select && table_column[:filter][:fuzzy] != true) || sql_op != :where
|
50
57
|
collection.public_send(sql_op, "#{column} = :term", term: term)
|
51
58
|
else
|
52
|
-
collection.public_send(sql_op, "#{column}
|
59
|
+
collection.public_send(sql_op, "#{column} #{ilike} :term", term: "%#{term}%")
|
53
60
|
end
|
54
61
|
when :belongs_to_polymorphic
|
55
62
|
# our key will be something like Post_15, or Event_1
|
56
63
|
(type, id) = term.split('_')
|
57
64
|
|
58
65
|
if type.present? && id.present?
|
59
|
-
collection.public_send(sql_op, "#{column} = :id AND #{column.sub('_id
|
66
|
+
collection.public_send(sql_op, "#{column} = :id AND #{column.sub('_id', '_type')} = :type", id: id, type: type)
|
60
67
|
else
|
61
68
|
collection
|
62
69
|
end
|
@@ -85,7 +92,7 @@ module Effective
|
|
85
92
|
when :effective_address
|
86
93
|
ids = Effective::Address
|
87
94
|
.where('addressable_type = ?', collection_class.name)
|
88
|
-
.where(
|
95
|
+
.where("address1 #{ilike} :term OR address2 #{ilike} :term OR city #{ilike} :term OR postal_code #{ilike} :term OR state_code = :code OR country_code = :code", term: "%#{term}%", code: term)
|
89
96
|
.pluck(:addressable_id)
|
90
97
|
|
91
98
|
collection.public_send(sql_op, id: ids)
|
@@ -137,5 +144,21 @@ module Effective
|
|
137
144
|
collection.page(page).per(per_page)
|
138
145
|
end
|
139
146
|
|
147
|
+
protected
|
148
|
+
|
149
|
+
def postgres?
|
150
|
+
return @postgres unless @postgres.nil?
|
151
|
+
@postgres ||= (collection_class.connection.kind_of?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) rescue false)
|
152
|
+
end
|
153
|
+
|
154
|
+
def mysql?
|
155
|
+
return @mysql unless @mysql.nil?
|
156
|
+
@mysql ||= (collection_class.connection.kind_of?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) rescue false)
|
157
|
+
end
|
158
|
+
|
159
|
+
def ilike
|
160
|
+
@ilike ||= (postgres? ? 'ILIKE' : 'LIKE') # Only Postgres supports ILIKE, Mysql and Sqlite3 use LIKE
|
161
|
+
end
|
162
|
+
|
140
163
|
end
|
141
164
|
end
|
@@ -8,6 +8,10 @@ module Effective
|
|
8
8
|
@table_columns = initialize_column_options(@table_columns)
|
9
9
|
end
|
10
10
|
|
11
|
+
def quote_sql(name)
|
12
|
+
collection_class.connection.quote_column_name(name) rescue name
|
13
|
+
end
|
14
|
+
|
11
15
|
protected
|
12
16
|
|
13
17
|
def initialize_column_options(cols)
|
@@ -47,7 +51,7 @@ module Effective
|
|
47
51
|
cols[name][:array_index] = index # The index of this column in the collection, regardless of hidden table_columns
|
48
52
|
cols[name][:name] ||= name
|
49
53
|
cols[name][:label] ||= name.titleize
|
50
|
-
cols[name][:column] ||= (sql_table && sql_column) ? "
|
54
|
+
cols[name][:column] ||= (sql_table && sql_column) ? "#{quote_sql(sql_table.name)}.#{quote_sql(sql_column.name)}" : name
|
51
55
|
cols[name][:width] ||= nil
|
52
56
|
cols[name][:sortable] = true if cols[name][:sortable].nil?
|
53
57
|
cols[name][:visible] = true if cols[name][:visible].nil?
|
@@ -89,7 +93,7 @@ module Effective
|
|
89
93
|
# EffectiveRoles, if you do table_column :roles, everything just works
|
90
94
|
if name == 'roles' && defined?(EffectiveRoles) && collection.respond_to?(:with_role)
|
91
95
|
cols[name][:sortable] = true
|
92
|
-
cols[name][:column] = sql_table.present? ? "
|
96
|
+
cols[name][:column] = sql_table.present? ? "#{quote_sql(sql_table.name)}.#{quote_sql('roles_mask')}" : name
|
93
97
|
cols[name][:type] = :effective_roles
|
94
98
|
end
|
95
99
|
|