grid_table 1.4 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/grid_table/control.rb +15 -11
- data/lib/grid_table/table.rb +1 -1
- data/lib/grid_table/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6037e9f180243d42182c4eb6a5739fc457d256d
|
4
|
+
data.tar.gz: 34ddfabfae33383f69c46f4f4d1920d78d1ab495
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b74ed307fb917880bad85c2f519f962c6370cc9fdf1f9515a1b0ba4ed828a1f37f28ed65fd8f525d3d7ff21753796bf91c13e41c8250f0482c1d6560b469e5f
|
7
|
+
data.tar.gz: 83537aac94772bf820c8650a246eccc7171c51eecac5215b91b1b4053e36db27b455faf288f32b2d0b09913853194fa3ef82b21c64321186dae180aaeb54b1f5
|
data/lib/grid_table/control.rb
CHANGED
@@ -34,27 +34,27 @@ class GridTable::Control
|
|
34
34
|
false
|
35
35
|
end
|
36
36
|
|
37
|
-
attr_writer :model, :attribute, :source, :source_class, :source_column, :
|
37
|
+
attr_writer :model, :attribute, :source, :source_class, :source_column, :source_sql, :filter, :polymorphic
|
38
38
|
|
39
39
|
def filter(param_filter_value, records)
|
40
|
-
return if @filter
|
40
|
+
return records if @filter == false
|
41
41
|
|
42
42
|
arel_query = nil
|
43
43
|
strategy_map = {
|
44
|
-
exact_match: ->(col) { col
|
45
|
-
prefix: ->(col) {
|
46
|
-
suffix: ->(col) { col
|
47
|
-
fuzzy: ->(col) { col
|
48
|
-
array: ->(
|
49
|
-
date_range: ->(_col) { "#{
|
44
|
+
exact_match: ->(col) { "(#{col}) = #{param_filter_value}" },
|
45
|
+
prefix: ->(col) { "(#{col}) ILIKE '#{param_filter_value}%'" },
|
46
|
+
suffix: ->(col) { "(#{col}) ILIKE '%#{param_filter_value}'" },
|
47
|
+
fuzzy: ->(col) { "(#{col}) ILIKE '%#{param_filter_value}%'" },
|
48
|
+
array: ->(col) { "(#{col}) @> ARRAY[#{[param_filter_value].flatten.join(',')}]" },
|
49
|
+
date_range: ->(_col) { "(#{col}) BETWEEN #{param_filter_value}" }
|
50
50
|
}
|
51
51
|
|
52
52
|
polymorphic_models.each_with_index do |klass, i|
|
53
53
|
# TODO: implement array filtering
|
54
|
-
arel_query = i.zero? ? strategy_map[strategy].call(klass
|
54
|
+
arel_query = i.zero? ? strategy_map[strategy].call(polymorphic_table_with_column(klass)) : arel_query.or(strategy_map[strategy].call(polymorphic_table_with_column(klass)))
|
55
55
|
end
|
56
56
|
|
57
|
-
arel_query ||= strategy_map[strategy].call(
|
57
|
+
arel_query ||= strategy_map[strategy].call(table_with_column)
|
58
58
|
prepared_records(records).where(arel_query)
|
59
59
|
end
|
60
60
|
|
@@ -113,7 +113,11 @@ class GridTable::Control
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def table_with_column
|
116
|
-
@
|
116
|
+
@source_sql || "#{source_table.name}.#{column}"
|
117
|
+
end
|
118
|
+
|
119
|
+
def polymorphic_table_with_column(klass)
|
120
|
+
@source_sql || "#{klass.arel_table.name}.#{klass.arel_table[column].name}"
|
117
121
|
end
|
118
122
|
|
119
123
|
def model_fk
|
data/lib/grid_table/table.rb
CHANGED
@@ -12,7 +12,7 @@ class GridTable::Table
|
|
12
12
|
source: options[:source],
|
13
13
|
source_class: options[:source_class],
|
14
14
|
source_column: options[:source_column],
|
15
|
-
|
15
|
+
source_sql: options[:source_sql],
|
16
16
|
filter: options[:filter],
|
17
17
|
polymorphic: options[:polymorphic]
|
18
18
|
)
|
data/lib/grid_table/version.rb
CHANGED