datagrid 0.1.2 → 0.2.0
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.
- data/{Readme.md → Readme.markdown} +2 -2
- data/VERSION +1 -1
- data/datagrid.gemspec +3 -2
- data/lib/datagrid/columns.rb +21 -11
- data/lib/datagrid/helper.rb +2 -1
- data/lib/datagrid/rspec.rb +2 -2
- data/lib/datagrid/utils.rb +12 -0
- data/spec/datagrid_spec.rb +1 -1
- metadata +5 -4
@@ -66,7 +66,7 @@ end
|
|
66
66
|
Basic grid api:
|
67
67
|
|
68
68
|
``` ruby
|
69
|
-
report = SimpleReport.new(:order => "group", :
|
69
|
+
report = SimpleReport.new(:order => "group", :descending => true, :group_id => [1,2], :from_logins_count => 1, :category => "first")
|
70
70
|
|
71
71
|
report.assets # => Array of User instances:
|
72
72
|
# SELECT * FROM users WHERE users.group_id in (1,2) AND users.logins_count >= 1 AND users.category = 'first' ORDER BY groups.name DESC
|
@@ -111,7 +111,7 @@ Read more about filters here:
|
|
111
111
|
### Columns
|
112
112
|
|
113
113
|
Each column is represented by name and code block to calculate the value.
|
114
|
-
Grids are sortable by it's columns. Ordering is controller by `#order` and `#
|
114
|
+
Grids are sortable by it's columns. Ordering is controller by `#order` and `#descending` attributes.
|
115
115
|
|
116
116
|
More information about columns here:
|
117
117
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/datagrid.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{datagrid}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
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"]
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
"Gemfile.lock",
|
23
23
|
"LICENSE.txt",
|
24
24
|
"Rakefile",
|
25
|
-
"Readme.
|
25
|
+
"Readme.markdown",
|
26
26
|
"VERSION",
|
27
27
|
"datagrid.gemspec",
|
28
28
|
"lib/datagrid.rb",
|
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
"lib/datagrid/form_builder.rb",
|
43
43
|
"lib/datagrid/helper.rb",
|
44
44
|
"lib/datagrid/rspec.rb",
|
45
|
+
"lib/datagrid/utils.rb",
|
45
46
|
"spec/datagrid/columns_spec.rb",
|
46
47
|
"spec/datagrid/filters_spec.rb",
|
47
48
|
"spec/datagrid/form_builder_spec.rb",
|
data/lib/datagrid/columns.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "datagrid/utils"
|
2
|
+
|
1
3
|
module Datagrid
|
2
4
|
|
3
5
|
class OrderUnsupported < StandardError
|
@@ -13,7 +15,9 @@ module Datagrid
|
|
13
15
|
include Datagrid::Core
|
14
16
|
|
15
17
|
datagrid_attribute :order
|
16
|
-
datagrid_attribute :
|
18
|
+
datagrid_attribute :descending do |value|
|
19
|
+
Datagrid::Utils.booleanize(value)
|
20
|
+
end
|
17
21
|
|
18
22
|
|
19
23
|
end
|
@@ -63,26 +67,32 @@ module Datagrid
|
|
63
67
|
# = Column value
|
64
68
|
#
|
65
69
|
# Column value can be defined by passing a block to <tt>#column</tt> method.
|
66
|
-
# If no block given column is generated automatically by sending column name method to model.
|
70
|
+
# If no block given column it is generated automatically by sending column name method to model.
|
67
71
|
# The block could have zero arguments(<tt>instance_eval</tt>) or one argument that is model object.
|
68
72
|
#
|
73
|
+
# = Column options
|
74
|
+
#
|
75
|
+
# The following options can be passed to column definition:
|
76
|
+
#
|
77
|
+
# * <tt>:order</tt> - an order SQL that should be used to sort by this column.
|
78
|
+
# Default: report column name if there is database column with this name.
|
79
|
+
# * <tt>:order_desc</tt> - descending order expression from this column. Default: "#{order} desc".
|
80
|
+
#
|
81
|
+
# TODO: frontend options description
|
82
|
+
#
|
69
83
|
# = Columns order
|
70
84
|
#
|
71
85
|
# Each column supports <tt>:order</tt> option that is used to specify SQL to sort data by the given column.
|
72
|
-
# In order to specify order
|
86
|
+
# In order to specify order the following attributes are used:
|
73
87
|
#
|
74
|
-
# * <tt>:order</tt> - column name to
|
75
|
-
# * <tt>:
|
88
|
+
# * <tt>:order</tt> - column name to sort with as <tt>Symbol</tt>. Default: nil.
|
89
|
+
# * <tt>:descending</tt> - if true descending suffix is added to specified order. Default: false.
|
76
90
|
#
|
77
|
-
#
|
78
91
|
# Example:
|
79
92
|
#
|
80
|
-
# grid = UserGrid.new(:order => :group, :
|
93
|
+
# grid = UserGrid.new(:order => :group, :descending => true)
|
81
94
|
# grid.assets # => Return assets ordered by :group column descending
|
82
95
|
#
|
83
|
-
# = Options
|
84
|
-
#
|
85
|
-
# TODO
|
86
96
|
def column(name, options = {}, &block)
|
87
97
|
check_scope_defined!("Scope should be defined before columns")
|
88
98
|
block ||= lambda do |model|
|
@@ -135,7 +145,7 @@ module Datagrid
|
|
135
145
|
if self.order
|
136
146
|
column = column_by_name(self.order)
|
137
147
|
raise Datagrid::OrderUnsupported, "Can not sort #{self.inspect} by #{name.inspect}" unless column
|
138
|
-
result = result.order(self.
|
148
|
+
result = result.order(self.descending ? column.desc_order : column.order)
|
139
149
|
end
|
140
150
|
result
|
141
151
|
end
|
data/lib/datagrid/helper.rb
CHANGED
@@ -32,6 +32,7 @@ module Datagrid
|
|
32
32
|
|
33
33
|
def datagrid_header(grid, options = {})
|
34
34
|
header = empty_string
|
35
|
+
options[:order] = true unless options.has_key?(:order)
|
35
36
|
grid.columns.each do |column|
|
36
37
|
data = _safe(column.header)
|
37
38
|
if options[:order] && column.order
|
@@ -60,7 +61,7 @@ module Datagrid
|
|
60
61
|
:class => "order asc"
|
61
62
|
) + " " + link_to(
|
62
63
|
I18n.t("datagrid.table.order.desc", :default => "DESC"),
|
63
|
-
url_for(grid.param_name => grid.attributes.merge(:order => column.name, :
|
64
|
+
url_for(grid.param_name => grid.attributes.merge(:order => column.name, :descending => true )),
|
64
65
|
:class => "order desc"
|
65
66
|
)
|
66
67
|
end
|
data/lib/datagrid/rspec.rb
CHANGED
@@ -21,8 +21,8 @@ shared_examples_for "Datagrid" do
|
|
21
21
|
subject.assets.first.should_not be_nil
|
22
22
|
end
|
23
23
|
|
24
|
-
it "should support
|
25
|
-
subject.
|
24
|
+
it "should support descending order" do
|
25
|
+
subject.descending = true
|
26
26
|
subject.assets.first.should_not be_nil
|
27
27
|
end
|
28
28
|
end
|
data/spec/datagrid_spec.rb
CHANGED
@@ -26,7 +26,7 @@ describe Datagrid do
|
|
26
26
|
|
27
27
|
describe ".attributes" do
|
28
28
|
it "should return report attributes" do
|
29
|
-
(subject.filters.map(&:name) + [:order, :
|
29
|
+
(subject.filters.map(&:name) + [:order, :descending]).each do |attribute|
|
30
30
|
subject.attributes.should have_key(attribute)
|
31
31
|
end
|
32
32
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datagrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 1
|
9
8
|
- 2
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bogdan Gusiev
|
@@ -211,7 +211,7 @@ files:
|
|
211
211
|
- Gemfile.lock
|
212
212
|
- LICENSE.txt
|
213
213
|
- Rakefile
|
214
|
-
- Readme.
|
214
|
+
- Readme.markdown
|
215
215
|
- VERSION
|
216
216
|
- datagrid.gemspec
|
217
217
|
- lib/datagrid.rb
|
@@ -231,6 +231,7 @@ files:
|
|
231
231
|
- lib/datagrid/form_builder.rb
|
232
232
|
- lib/datagrid/helper.rb
|
233
233
|
- lib/datagrid/rspec.rb
|
234
|
+
- lib/datagrid/utils.rb
|
234
235
|
- spec/datagrid/columns_spec.rb
|
235
236
|
- spec/datagrid/filters_spec.rb
|
236
237
|
- spec/datagrid/form_builder_spec.rb
|