tabulatr2 0.8.4 → 0.8.5

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: f040295cd2078f84e9b0379bb3de019cfbef72fd
4
- data.tar.gz: fffd809f5632e690cfd1506ea37e936e28c4ce27
3
+ metadata.gz: c86917764e777b62b55d5741f7d18d2caefcb2fd
4
+ data.tar.gz: aef2b2dadefb4ff48fae9734f33359a1a65e873a
5
5
  SHA512:
6
- metadata.gz: d235adcae54d4509002c521f03fd68e97f79f590a103b1a91b07fecf91d09b02d372aaf7f3601cf0cace1c3462df04f444aeeea0fbae9774197ea46fbf2af689
7
- data.tar.gz: 8e96e7988fd8bd40b496625fce9e063352109cce1ad3b7955ff4758b62e0c5442a9a138f1adcefd3415a136308cb29cfbe3629788fa9250060df988700995e7f
6
+ metadata.gz: a73c7babe347a36b98e7cf62ddbe8f3f44f5b7b443935a468f68fe91d4d96bd1f6cf990121487e997b6f6b841edaf10ebdb6d88a5e06cdef5ae4a7e56226a204
7
+ data.tar.gz: 132b552b8e86abe7bf07f35fc1f670c8d66806340c4662f608367b44a48a128501859898a00abd42fccda68f1d44ea87fd5f755dc4b81e5ef94653dc7b9ea845
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.8.5
2
+
3
+ * Added `order_by` option to `table_for` for default sorting.
4
+
1
5
  ## 0.8.3
2
6
 
3
7
  * New table_column_options `cell_style` and `header_style`
data/Gemfile CHANGED
@@ -15,8 +15,8 @@ end
15
15
 
16
16
  group :development, :test do
17
17
  gem 'sqlite3', :require => 'sqlite3'
18
- gem 'rspec'
19
- gem 'rspec-rails'
18
+ gem 'rspec', '~> 2.14.1'
19
+ gem 'rspec-rails', '~> 2.14.0'
20
20
  gem 'capybara'
21
21
  gem 'launchy'
22
22
  gem 'database_cleaner', '< 1.1.0'
@@ -21,7 +21,7 @@
21
21
 
22
22
 
23
23
  form.form.form-horizontal.tabulatr_filter_form data-table=table_id data-remote="true" role='form'
24
- input name="#{classname}_sort" type="hidden"
24
+ input name="#{classname}_sort" type="hidden" value=table_options[:order_by]
25
25
  - if table_options[:filter] && columns.filtered_columns.present?
26
26
  - columns.filtered_columns.each do |column|
27
27
  - name = column.full_name
@@ -39,7 +39,7 @@ module Tabulatr::Data::Sorting
39
39
  raise "asasa" unless ['asc', 'desc'].member?(orientation.downcase)
40
40
  @relation = @relation.order("#{nn} #{orientation}")
41
41
  else
42
- @relation = @relation.order(default_order || "#{@table_name}.#{@base.primary_key} asc")
42
+ @relation = @relation.order(default_order || "#{@table_name}.#{@base.primary_key} desc")
43
43
  end
44
44
  end
45
45
 
@@ -26,9 +26,9 @@
26
26
  if Object.const_defined? "ActiveRecord"
27
27
  class ActiveRecord::Base
28
28
  def self.tabulatr(relation, tabulatr_data_class = nil)
29
- return tabulatr_data_class.new(relation) if tabulatr_data_class
29
+ tabulatr_data_class = "#{self.name}TabulatrData".constantize unless tabulatr_data_class
30
30
  begin
31
- "#{self.name}TabulatrData".constantize.new(relation)
31
+ td = tabulatr_data_class.new(relation)
32
32
  rescue NameError => e
33
33
  puts e.message
34
34
  # TODO: Better message
@@ -31,7 +31,8 @@ class Tabulatr::Renderer
31
31
  sortable: true, # true to allow sorting (can be specified for every sortable column)
32
32
  batch_actions: false, # :name => value hash of batch action stuff
33
33
  footer_content: false, # if given, add a <%= content_for <footer_content> %> before the </table>
34
- path: '#') # where to send the AJAX-requests to
34
+ path: '#', # where to send the AJAX-requests to
35
+ order_by: nil) # default order
35
36
  @klass = klass
36
37
  @view = view
37
38
  @table_options = {
@@ -42,7 +43,8 @@ class Tabulatr::Renderer
42
43
  sortable: sortable,
43
44
  batch_actions: batch_actions,
44
45
  footer_content: footer_content,
45
- path: path
46
+ path: path,
47
+ order_by: order_by
46
48
  }
47
49
  @classname = @klass.name.underscore
48
50
  end
@@ -22,5 +22,5 @@
22
22
  #++
23
23
 
24
24
  module Tabulatr
25
- VERSION = "0.8.4"
25
+ VERSION = "0.8.5"
26
26
  end
@@ -1,14 +1,42 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Tabulatr::Data do
4
- it 'prefilters the result' do
4
+
5
+ before do
5
6
  Tabulatr::Data.any_instance.stub_chain(:table_columns, :klass=).and_return(Product)
6
7
  Tabulatr::Data.any_instance.stub_chain(:table_columns, :map).as_null_object
8
+ end
9
+
10
+ it 'prefilters the result' do
7
11
 
8
12
  td = Tabulatr::Data.new(Product.where(price: 10))
9
13
  td.data_for_table(example_params)
10
14
  expect(td.instance_variable_get('@relation').to_sql).to match(/.+WHERE \"products\".\"price\" = 10.+/)
11
15
  end
16
+
17
+ it 'uses default order' do
18
+ Product.create([{title: 'foo', price: 5}, {title: 'bar', price: 10}, {title: 'fuzz', price: 7}])
19
+
20
+ cols = {
21
+ title: {
22
+ name: 'title',
23
+ sort_sql: nil,
24
+ filter_sql: nil,
25
+ output: nil,
26
+ table_column: Tabulatr::Renderer::Column.from(name: 'title', klass: Product)
27
+ }
28
+ }
29
+ Tabulatr::Data.instance_variable_set('@columns', cols)
30
+ td = Tabulatr::Data.new(Product)
31
+ # mod_params = example_params.merge(product_sort: 'products.title DESC')
32
+ # raise mod_params.inspect
33
+ records = td.data_for_table(HashWithIndifferentAccess.new(example_params.merge(product_sort: 'products.title DESC')))
34
+ expect(records.count).to eql 3
35
+ titles = ['fuzz', 'foo', 'bar']
36
+ records.each_with_index do |r, ix|
37
+ expect(r[:title]).to eql titles[ix]
38
+ end
39
+ end
12
40
  end
13
41
 
14
42
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabulatr2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Horn
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-11-05 00:00:00.000000000 Z
13
+ date: 2013-11-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -268,4 +268,3 @@ test_files:
268
268
  - spec/features/tabulatrs_spec.rb
269
269
  - spec/lib/tabulatr/data/data_spec.rb
270
270
  - spec/spec_helper.rb
271
- has_rdoc: