tabulatr2 0.8.4 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +2 -2
- data/app/views/tabulatr/_tabulatr_filter_dialog.html.slim +1 -1
- data/lib/tabulatr/data/sorting.rb +1 -1
- data/lib/tabulatr/rails/active_record.rb +2 -2
- data/lib/tabulatr/renderer/renderer.rb +4 -2
- data/lib/tabulatr/version.rb +1 -1
- data/spec/lib/tabulatr/data/data_spec.rb +29 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c86917764e777b62b55d5741f7d18d2caefcb2fd
|
4
|
+
data.tar.gz: aef2b2dadefb4ff48fae9734f33359a1a65e873a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a73c7babe347a36b98e7cf62ddbe8f3f44f5b7b443935a468f68fe91d4d96bd1f6cf990121487e997b6f6b841edaf10ebdb6d88a5e06cdef5ae4a7e56226a204
|
7
|
+
data.tar.gz: 132b552b8e86abe7bf07f35fc1f670c8d66806340c4662f608367b44a48a128501859898a00abd42fccda68f1d44ea87fd5f755dc4b81e5ef94653dc7b9ea845
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -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}
|
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
|
-
|
29
|
+
tabulatr_data_class = "#{self.name}TabulatrData".constantize unless tabulatr_data_class
|
30
30
|
begin
|
31
|
-
|
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: '#'
|
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
|
data/lib/tabulatr/version.rb
CHANGED
@@ -1,14 +1,42 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Tabulatr::Data do
|
4
|
-
|
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
|
+
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-
|
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:
|