datagrid 1.3.2 → 1.3.3

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: bd9359f7f58b34ec6625249fc8d7d13cbb405316
4
- data.tar.gz: 6dbf5745b7f3135743ef3ed1b23fe630dc100b5b
3
+ metadata.gz: e7dd21661c0b7829a023451513b73670d0b0be11
4
+ data.tar.gz: 4b2b5bb748791497da883b6c24ad8f19c7ce3c81
5
5
  SHA512:
6
- metadata.gz: 77117b5608b994d9d67eace4a2b0e05ae9b1c02fa4786f7d21ca7ad748c1c0048a2ae98867570e7cabb2e2b32071b7b07cfb3d4948e7d13d5a5eb931e78c2f90
7
- data.tar.gz: a3cd49749291d88682cb943e738a30ff525f700d49a15cd8364c3dcadf8325043b2f94b44c61dc612bb3daddaaa344dd2f84c29119d45a76e62127162d50a042
6
+ metadata.gz: 7d33aa9a4a8eceaacad1ff76ee91ba9dc3b9e312d2158f70998e7eaef707877042ace5218df8de47a28373dce7d92f6886e4fdf7be70ea27bf90baa6246f763c
7
+ data.tar.gz: d19b2234cbaba7712206f4b9ed7159cdcf2fd44ec320ff0c3a937a4ea3f03caf237499b4d2a594a0f76a84526fe28cbf23132279e0072a3eaf0535334179692c
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.2
1
+ 1.3.3
@@ -0,0 +1,11 @@
1
+ <%#
2
+ Indent in this file may cause extra space to appear.
3
+ You can add indent if whitespace doesn't matter for you
4
+ %>
5
+ <%- elements.each do |value, text, checked| -%>
6
+ <%- id = [form.object_name, filter.name, value].join('_').underscore -%>
7
+ <%= form.label filter.name, options.merge(:for => id) do -%>
8
+ <%= form.check_box(filter.name, form.datagrid_extra_checkbox_options.merge(:multiple => true, :id => id, :checked => checked), value.to_s, nil) -%>
9
+ <%= text -%>
10
+ <%- end -%>
11
+ <%- end -%>
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: datagrid 1.3.2 ruby lib
5
+ # stub: datagrid 1.3.3 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "datagrid"
9
- s.version = "1.3.2"
9
+ s.version = "1.3.3"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Bogdan Gusiev"]
14
- s.date = "2014-10-27"
14
+ s.date = "2014-11-12"
15
15
  s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters"
16
16
  s.email = "agresso@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "Readme.markdown",
28
28
  "VERSION",
29
29
  "app/assets/stylesheets/datagrid.css.sass",
30
+ "app/views/datagrid/_enum_checkboxes.html.erb",
30
31
  "app/views/datagrid/_form.html.erb",
31
32
  "app/views/datagrid/_head.html.erb",
32
33
  "app/views/datagrid/_order_for.html.erb",
@@ -27,7 +27,7 @@ module Datagrid
27
27
  end
28
28
 
29
29
  define_method :"#{name}=" do |value|
30
- instance_variable_set("@#{name}", block.call(value))
30
+ instance_variable_set("@#{name}", instance_exec(value, &block))
31
31
  end
32
32
  end
33
33
  end
@@ -108,6 +108,15 @@ class Datagrid::Filters::BaseFilter #:nodoc:
108
108
  options[:dummy]
109
109
  end
110
110
 
111
+ def type
112
+ Datagrid::Filters::FILTER_TYPES.each do |type, klass|
113
+ if is_a?(klass)
114
+ return type
115
+ end
116
+ end
117
+ raise "wtf is #{inspect}"
118
+ end
119
+
111
120
  protected
112
121
 
113
122
  def default_filter_where(driver, scope, value)
@@ -10,4 +10,8 @@ class Datagrid::Filters::BooleanEnumFilter < Datagrid::Filters::EnumFilter #:nod
10
10
  super(report, attribute, options, &block)
11
11
  end
12
12
 
13
+
14
+ def checkbox_id(value)
15
+ [object_name, name, value].join('_').underscore
16
+ end
13
17
  end
@@ -17,6 +17,10 @@ module Datagrid
17
17
  label(filter.name, text, options, &block)
18
18
  end
19
19
 
20
+ def datagrid_extra_checkbox_options
21
+ ::ActionPack::VERSION::MAJOR >= 4 ? {:include_hidden => false} : {}
22
+ end
23
+
20
24
  protected
21
25
  def datagrid_boolean_enum_filter(attribute_or_filter, options = {})
22
26
  datagrid_enum_filter(attribute_or_filter, options)
@@ -44,18 +48,25 @@ module Datagrid
44
48
  end
45
49
 
46
50
  def datagrid_enum_filter(attribute_or_filter, options = {}, &block)
51
+ options = options.clone
47
52
  filter = datagrid_get_filter(attribute_or_filter)
48
53
  if filter.checkboxes?
49
54
  options = add_html_classes(options, 'checkboxes')
50
- filter.select(object).map do |element|
55
+ partials_path = options.delete(:partials) || 'datagrid'
56
+ elements = filter.select(object).map do |element|
51
57
  text, value = @template.send(:option_text_and_value, element)
52
- id = [object_name, filter.name, value].join('_').underscore
53
- html_options = datagrid_extra_checkbox_options.reverse_merge(
54
- :id => id, :multiple => true, :checked => enum_checkbox_checked?(filter, value)
55
- )
56
- input = check_box(filter.name, html_options, value.to_s, nil)
57
- label(filter.name, input + text, options.reverse_merge(:for => id))
58
- end.join("\n").html_safe
58
+ checked = enum_checkbox_checked?(filter, value)
59
+ [value, text, checked]
60
+ end
61
+ @template.render(
62
+ :partial => File.join(partials_path, 'enum_checkboxes'),
63
+ :locals => {
64
+ :elements => elements,
65
+ :form => self,
66
+ :filter => filter,
67
+ :options => options,
68
+ }
69
+ )
59
70
  else
60
71
  if !options.has_key?(:multiple) && filter.multiple?
61
72
  options[:multiple] = true
@@ -186,10 +197,6 @@ module Datagrid
186
197
  Datagrid::Utils.add_html_classes(options, *classes)
187
198
  end
188
199
 
189
- def datagrid_extra_checkbox_options
190
- ::ActionPack::VERSION::MAJOR >= 4 ? {:include_hidden => false} : {}
191
- end
192
-
193
200
  class Error < StandardError
194
201
  end
195
202
 
@@ -15,10 +15,10 @@ module Datagrid
15
15
  value = value.to_sym
16
16
  column = column_by_name(value)
17
17
  unless column
18
- order_unsupported(value, "no column #{value} in #{self.class}")
18
+ self.class.order_unsupported(value, "no column #{value} in #{self.class}")
19
19
  end
20
20
  unless column.supports_order?
21
- order_unsupported(column.name, "column don't support order" )
21
+ self.class.order_unsupported(column.name, "column don't support order" )
22
22
  end
23
23
  value
24
24
  else
@@ -191,4 +191,17 @@ describe Datagrid::Filters do
191
191
  expect(grid.class.filters.map(&:name)).to eq([:id, :name])
192
192
 
193
193
  end
194
+
195
+
196
+ describe "#filter_by_name" do
197
+ it "should return filter object" do
198
+ r = test_report do
199
+ scope {Entry}
200
+ filter(:id, :integer)
201
+ end
202
+
203
+ object = r.filter_by_name(:id)
204
+ expect(object.type).to eq(:integer)
205
+ end
206
+ end
194
207
  end
@@ -12,7 +12,12 @@ end
12
12
 
13
13
  describe Datagrid::FormBuilder do
14
14
 
15
- let(:template) { ActionView::Base.new}
15
+ let(:template) do
16
+ ActionView::Base.new.tap do |v|
17
+ v.view_paths << File.expand_path("../../../app/views", __FILE__)
18
+ v.view_paths << File.expand_path("../../support/test_partials", __FILE__)
19
+ end
20
+ end
16
21
  let(:view) { ActionView::Helpers::FormBuilder.new(:report, _grid, template, {}, Proc.new {|f| })}
17
22
 
18
23
 
@@ -106,4 +106,19 @@ describe Datagrid::Ordering do
106
106
  expect(report.assets).to eq([second, first, third])
107
107
  end
108
108
 
109
+ it "should work correctly with inherited classes" do
110
+ class OrderInheritenceBase
111
+ include Datagrid
112
+ scope { Entry }
113
+ end
114
+
115
+ class OrderInheritenceChild < OrderInheritenceBase
116
+ column(:name)
117
+ end
118
+
119
+ grid = OrderInheritenceChild.new(order: 'name')
120
+ expect(grid.assets).to eq([first, second, third])
121
+ grid.descending = true
122
+ expect(grid.assets).to eq([third, second, first])
123
+ end
109
124
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datagrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-27 00:00:00.000000000 Z
11
+ date: 2014-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -223,6 +223,7 @@ files:
223
223
  - Readme.markdown
224
224
  - VERSION
225
225
  - app/assets/stylesheets/datagrid.css.sass
226
+ - app/views/datagrid/_enum_checkboxes.html.erb
226
227
  - app/views/datagrid/_form.html.erb
227
228
  - app/views/datagrid/_head.html.erb
228
229
  - app/views/datagrid/_order_for.html.erb