rails-tables 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/app/tables/column.rb +2 -2
- data/app/tables/datatable.rb +4 -10
- data/lib/rails-tables/version.rb +1 -1
- metadata +1 -1
data/app/tables/column.rb
CHANGED
@@ -7,7 +7,7 @@ class Column
|
|
7
7
|
|
8
8
|
attributes = args.pop || {}
|
9
9
|
self.method = attributes.fetch(:method, name)
|
10
|
-
self.column_source = attributes.fetch(:column_source, '')
|
10
|
+
self.column_source = attributes.fetch(:column_source, '').to_s
|
11
11
|
self.render_with = attributes.fetch(:render_with, :default_render)
|
12
12
|
self.sortable = attributes.fetch(:sortable, true)
|
13
13
|
self.searchable = attributes.fetch(:searchable, true)
|
@@ -39,7 +39,7 @@ class Column
|
|
39
39
|
view.link_to property, property if not property.nil?
|
40
40
|
end
|
41
41
|
def related_link_list(view, objects)
|
42
|
-
objects.map{ |object| related_link(view, object) }.reject(&:
|
42
|
+
objects.map{ |object| related_link(view, object).strip }.reject(&:blank?).join(', ') if not objects.nil?
|
43
43
|
end
|
44
44
|
def time(view, object)
|
45
45
|
property = object.try(:send, self.method)
|
data/app/tables/datatable.rb
CHANGED
@@ -62,15 +62,9 @@ class_attribute :columns, :column_factory
|
|
62
62
|
@columns ||= self.column_factory.map{ |new_column| Column.new(self.model, new_column[:name], new_column[:args]) }
|
63
63
|
end
|
64
64
|
|
65
|
-
class_attribute :match_any
|
66
|
-
self.match_any = true
|
67
|
-
def self.match_all_columns
|
68
|
-
self.match_any = false
|
69
|
-
end
|
70
|
-
|
71
65
|
attr_accessor :joins
|
72
66
|
def joins
|
73
|
-
@joins ||= self.columns.map(&:column_source).
|
67
|
+
@joins ||= self.columns.map(&:column_source).reject(&:blank?).uniq
|
74
68
|
end
|
75
69
|
attr_accessor :searches
|
76
70
|
def searches
|
@@ -80,13 +74,13 @@ attr_accessor :searches
|
|
80
74
|
private
|
81
75
|
|
82
76
|
def objects
|
83
|
-
query = self.model
|
77
|
+
query = self.model.uniq
|
84
78
|
self.joins.each do |join|
|
85
|
-
query = query.
|
79
|
+
query = query.joins{ join.split('.').inject(self, :__send__).outer }.includes{ join.split('.').inject(self, :__send__).outer }
|
86
80
|
end
|
87
81
|
if sortable
|
88
82
|
sort_expression = sort
|
89
|
-
query = query.reorder{ my{sort_expression} }
|
83
|
+
query = query.reorder{ my{sort_expression} }
|
90
84
|
end
|
91
85
|
self.scopes.each do |scope|
|
92
86
|
query = scope.call(query)
|
data/lib/rails-tables/version.rb
CHANGED