rails-tables 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,7 +12,7 @@ A clean jQuery datatables DSL
12
12
  [jqd-railscast]: http://railscasts.com/episodes/340-datatables (Episode #340: Datatables)
13
13
  [squeel]: https://github.com/ernie/squeel (Squeel: ActiveRecord 3, improved)
14
14
 
15
- Version: 0.5.0
15
+ Version: 0.5.1
16
16
 
17
17
  Please refer to the [RailsTables Wiki][wiki] for:
18
18
 
@@ -19,7 +19,7 @@ class Datatable
19
19
  end
20
20
  unless self.initial_orderings.nil?
21
21
  self.class.initial_orderings.each do |column, order|
22
- options["#{column}_ordering"] = order.to_s
22
+ options["#{column}_ordering".to_sym] = order.to_s
23
23
  end
24
24
  end
25
25
  options[:unsorted] = 'true'
@@ -85,17 +85,11 @@ private
85
85
  query = query.joins{ join.split('.').inject((join.present? ? self : nil), :__send__).outer }
86
86
  query = query.includes{ join.split('.').inject((join.present? ? self : nil), :__send__).outer }
87
87
  end
88
- if sortable
89
- sort_expression = sort
90
- query = query.reorder{ my{sort_expression} }
91
- end
92
88
  self.scopes.each do |scope|
93
89
  query = scope.call(query)
94
90
  end
95
- if params[:sSearch].present?
96
- search_expression = search(params[:sSearch])
97
- query = query.where{ my{search_expression} }
98
- end
91
+ query = query.reorder{ my{sort} } if sortable
92
+ query = query.where{ my{search(params[:sSearch])} } if searchable
99
93
  query = query.paginate(page: page, per_page: per_page)
100
94
  end
101
95
 
@@ -5,7 +5,6 @@ module Datatable::Searching
5
5
  class_attribute :searches
6
6
  self.searches = []
7
7
  extend ClassMethods
8
- include InstanceMethods
9
8
  end
10
9
 
11
10
  module ClassMethods
@@ -18,21 +17,27 @@ module Datatable::Searching
18
17
  end
19
18
  end
20
19
 
21
- module InstanceMethods
22
- private
23
- # Introspect available searches as well as user defined ones
24
- def searches
25
- @searches ||= (self.columns.select(&:searchable).select{|c| c.column_source.present?}.map{|c| {column_source: c.column_source, method: c.method} } + self.class.searches).uniq
26
- end
27
- # Build Squeel Stubs for search
28
- def search(terms)
29
- terms = terms.split if terms.is_a? String
30
- self.searches.map do |search|
31
- terms.map do |word|
32
- Squeel::Nodes::KeyPath.new(search[:column_source].split('.') << Squeel::Nodes::Stub.new(search[:method])) =~ "%#{word}%"
33
- end.compact.inject(&:|)
20
+ attr_accessor :searches
21
+ private
22
+ def searchable
23
+ params[:sSearch].present?
24
+ end
25
+ # Introspect available searches as well as user defined ones
26
+ def searchables
27
+ searches = self.columns.
28
+ select(&:searchable).
29
+ map{ |c| {column_source: c.column_source, method: c.method} }
30
+ searches += self.class.searches
31
+ @searches ||= searches.uniq
32
+ end
33
+ # Build Squeel Stubs for search
34
+ def search(terms)
35
+ terms = terms.split if terms.is_a? String
36
+ searchables.map do |search|
37
+ terms.map do |word|
38
+ Squeel::Nodes::KeyPath.new(search[:column_source].split('.') << Squeel::Nodes::Stub.new(search[:method])) =~ "%#{word}%"
34
39
  end.compact.inject(&:|)
35
- end
40
+ end.compact.inject(&:|)
36
41
  end
37
42
 
38
43
  end
@@ -4,7 +4,6 @@ module Datatable::Sorting
4
4
  included do
5
5
  class_attribute :initial_orderings
6
6
  extend ClassMethods
7
- include InstanceMethods
8
7
  end
9
8
 
10
9
  module ClassMethods
@@ -19,19 +18,17 @@ module Datatable::Sorting
19
18
 
20
19
  end
21
20
 
22
- module InstanceMethods
23
- private
24
- # Check if table is sortable
25
- def sortable
26
- self.columns.map{ |column| column.sortable }[params[:iSortCol_0].to_i] unless params[:bUseDefaultSort] == 'true'
27
- end
28
- # Find column to search by and create a Squeel Order
29
- def sort
30
- column = self.columns[params[:iSortCol_0].to_i]
31
- if column.sortable
32
- direction = params[:sSortDir_0] == "asc" ? 1 : -1
33
- Squeel::Nodes::KeyPath.new(column.column_source.split('.') << Squeel::Nodes::Order.new(column.method, direction))
34
- end
21
+ private
22
+ # Check if table is sortable
23
+ def sortable
24
+ self.columns.map{ |column| column.sortable }[params[:iSortCol_0].to_i] unless params[:bUseDefaultSort] == 'true'
25
+ end
26
+ # Find column to search by and create a Squeel Order
27
+ def sort
28
+ column = self.columns[params[:iSortCol_0].to_i]
29
+ if column.sortable
30
+ direction = params[:sSortDir_0] == "asc" ? 1 : -1
31
+ Squeel::Nodes::KeyPath.new(column.column_source.split('.') << Squeel::Nodes::Order.new(Squeel::Nodes::Stub.new(column.method), direction))
35
32
  end
36
33
  end
37
34
 
@@ -1,3 +1,3 @@
1
1
  module RailsTables
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-tables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-29 00:00:00.000000000 Z
12
+ date: 2012-11-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails