datagrid 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.markdown +34 -0
- data/VERSION +1 -1
- data/datagrid.gemspec +2 -2
- data/lib/datagrid/columns.rb +9 -1
- data/spec/datagrid/columns_spec.rb +49 -29
- metadata +3 -3
data/Readme.markdown
CHANGED
@@ -130,5 +130,39 @@ Each column is sortable.
|
|
130
130
|
|
131
131
|
[More about columns](https://github.com/bogdan/datagrid/wiki/Columns)
|
132
132
|
|
133
|
+
### Front end
|
133
134
|
|
135
|
+
In order to create form for your report you can use all set of rails built-in tools.
|
136
|
+
|
137
|
+
More over Datagrid provides you two additional form helpers:
|
138
|
+
|
139
|
+
* datagrid\_label
|
140
|
+
* datagrid\_filter
|
141
|
+
|
142
|
+
The easiest way to create a report form:
|
143
|
+
|
144
|
+
(haml for readablity)
|
145
|
+
|
146
|
+
``` haml
|
147
|
+
- form_for @report do |f|
|
148
|
+
- @report.filters.each do |filter|
|
149
|
+
%div
|
150
|
+
= f.datagrid_label filter
|
151
|
+
= f.datagrid_filter filter
|
152
|
+
= f.submit
|
153
|
+
```
|
154
|
+
|
155
|
+
There is a simple helper set of helpers that allows you display report:
|
156
|
+
|
157
|
+
(require will_paginate)
|
158
|
+
|
159
|
+
``` haml
|
160
|
+
- assets = @report.assets.paginate(:page => params[:page])
|
161
|
+
|
162
|
+
%div== Total #{assets.total}
|
163
|
+
= datagrid_table(@report, assets)
|
164
|
+
= will_paginate assets
|
165
|
+
```
|
166
|
+
|
167
|
+
[More about frontend](https://github.com/bogdan/datagrid/wiki/Frontend)
|
134
168
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/datagrid.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{datagrid}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Bogdan Gusiev"]
|
12
|
-
s.date = %q{2011-07-
|
12
|
+
s.date = %q{2011-07-07}
|
13
13
|
s.description = %q{This allows you to easily build datagrid aka data tables with sortable columns and filters}
|
14
14
|
s.email = %q{agresso@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/datagrid/columns.rb
CHANGED
@@ -109,7 +109,7 @@ module Datagrid
|
|
109
109
|
result = super
|
110
110
|
if self.order
|
111
111
|
column = column_by_name(self.order)
|
112
|
-
result = result
|
112
|
+
result = apply_order(result, self.descending ? column.desc_order : column.order)
|
113
113
|
end
|
114
114
|
result
|
115
115
|
end
|
@@ -139,6 +139,14 @@ module Datagrid
|
|
139
139
|
self.class.column_by_name(name)
|
140
140
|
end
|
141
141
|
|
142
|
+
private
|
143
|
+
|
144
|
+
def apply_order(assets, order)
|
145
|
+
# Rails 3.0.x don't able to override already applied order
|
146
|
+
# Using #reorder instead
|
147
|
+
assets.respond_to?(:reorder) ? assets.reorder(order) : assets.order(order)
|
148
|
+
end
|
149
|
+
|
142
150
|
end # InstanceMethods
|
143
151
|
|
144
152
|
end
|
@@ -1,32 +1,36 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Datagrid::Columns do
|
4
|
-
|
4
|
+
|
5
5
|
let(:group) { Group.create!(:name => "Pop") }
|
6
|
-
|
7
|
-
:group => group, :name => "Star", :disabled => false, :confirmed => false, :category => "first"
|
8
|
-
) }
|
9
|
-
|
6
|
+
|
10
7
|
subject do
|
11
8
|
SimpleReport.new
|
12
9
|
end
|
13
|
-
it "should build rows of data" do
|
14
|
-
subject.rows.should == [["Pop", "Star"]]
|
15
|
-
end
|
16
|
-
it "should generate header" do
|
17
|
-
subject.header.should == ["Group", "Name"]
|
18
|
-
end
|
19
10
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
11
|
+
describe "basic methods" do
|
12
|
+
|
13
|
+
let!(:entry) { Entry.create!(
|
14
|
+
:group => group, :name => "Star", :disabled => false, :confirmed => false, :category => "first"
|
15
|
+
) }
|
16
|
+
it "should build rows of data" do
|
17
|
+
subject.rows.should == [["Pop", "Star"]]
|
18
|
+
end
|
19
|
+
it "should generate header" do
|
20
|
+
subject.header.should == ["Group", "Name"]
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should generate data" do
|
24
|
+
subject.data.should == [
|
25
|
+
subject.header,
|
26
|
+
subject.row_for(entry)
|
27
|
+
]
|
28
|
+
end
|
26
29
|
|
27
30
|
it "should support csv export" do
|
28
31
|
subject.to_csv.should == "Group,Name\nPop,Star\n"
|
29
32
|
end
|
33
|
+
end
|
30
34
|
|
31
35
|
it "should support columns with model and report arguments" do
|
32
36
|
report = test_report(:category => "foo") do
|
@@ -45,21 +49,37 @@ describe Datagrid::Columns do
|
|
45
49
|
report.rows.last.first.should be_false
|
46
50
|
end
|
47
51
|
|
52
|
+
describe "ordering" do
|
48
53
|
|
49
|
-
it "should raise error if ordered by not existing column" do
|
50
|
-
lambda {
|
51
|
-
test_report(:order => :hello)
|
52
|
-
}.should raise_error(Datagrid::OrderUnsupported)
|
53
|
-
end
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
it "should raise error if ordered by not existing column" do
|
56
|
+
lambda {
|
57
|
+
test_report(:order => :hello)
|
58
|
+
}.should raise_error(Datagrid::OrderUnsupported)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should raise error if ordered by column without order" do
|
62
|
+
lambda do
|
63
|
+
test_report(:order => :category) do
|
64
|
+
filter(:category, :default, :order => false) do |value|
|
65
|
+
self
|
66
|
+
end
|
60
67
|
end
|
61
|
-
end
|
62
|
-
|
68
|
+
end.should raise_error(Datagrid::OrderUnsupported)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should override default order" do
|
72
|
+
Entry.all.should be_empty
|
73
|
+
e1 = Entry.create!
|
74
|
+
e2 = Entry.create!
|
75
|
+
test_report(:order => :id) do
|
76
|
+
scope { Entry.order("id desc")}
|
77
|
+
column(:id) do
|
78
|
+
self.order("id asc")
|
79
|
+
end
|
80
|
+
end.assets.all.should == [e1, e2]
|
81
|
+
end
|
82
|
+
|
63
83
|
end
|
64
84
|
|
65
85
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: datagrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Bogdan Gusiev
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-07 00:00:00 +03:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -205,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
205
205
|
requirements:
|
206
206
|
- - ">="
|
207
207
|
- !ruby/object:Gem::Version
|
208
|
-
hash:
|
208
|
+
hash: 4430126750120291741
|
209
209
|
segments:
|
210
210
|
- 0
|
211
211
|
version: "0"
|