admino 0.0.8 → 0.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8452d6a30488e570a6db66b94321de492c261337
4
- data.tar.gz: d45d064082c74e72675f15c85b0a1c2fbf1c2771
3
+ metadata.gz: e06d7c035647ac161360ae08222d2b06b1abca0b
4
+ data.tar.gz: f223ee1b778e59436a7a61ae13b34e59710ea612
5
5
  SHA512:
6
- metadata.gz: 264b1621f826d1b0dd33020edb46e16b1228d5c788b2029315b524fd9f33e1e972e330968410e6518f0e6e89a1c0221e8faa55acef880b0b857338941e9c2f2f
7
- data.tar.gz: 22ed8914aa029593876190c46ac5991155026e5bdbd4ef393ed2ec828db2e6e37d10365981347042e1704780959194aef68c291aa719d344bcae2399ae38394a
6
+ metadata.gz: 50f41c99c286533749958ead22766d0a06458eb20d0a17e1b74101c6376ea3e631515bb5cd91a00b99e287e64c2f5f7ce9d70b523c79e250ac2e1db1bd500c65
7
+ data.tar.gz: 007a6a7a9e3dc548e6bdcbab58ff960f5eb9c74013443e4d57b5c92d09eced051bd8b4684850715031e5539f1f40b3be2be62e274ff025d43d23ecd9d03f8951
@@ -1,3 +1,11 @@
1
+ # v0.0.9
2
+
3
+ * Allow `include_empty_scope` option in filter groups
4
+
5
+ ```
6
+ filter_by :status, [:foo, :bar], include_empty_scope: true
7
+ ```
8
+
1
9
  # v0.0.8
2
10
 
3
11
  * Support a symbol column label. It will use human attribute name:
@@ -20,10 +20,19 @@ module Admino
20
20
  class FilterGroup
21
21
  attr_reader :name
22
22
  attr_reader :scopes
23
+ attr_reader :options
24
+
25
+ def initialize(name, scopes, options = {})
26
+ options.symbolize_keys!
27
+ options.assert_valid_keys(:include_empty_scope)
23
28
 
24
- def initialize(name, scopes)
25
29
  @name = name.to_sym
26
30
  @scopes = scopes.map(&:to_sym)
31
+ @options = options
32
+ end
33
+
34
+ def include_empty_scope?
35
+ @options.fetch(:include_empty_scope) { false }
27
36
  end
28
37
  end
29
38
 
@@ -64,8 +73,8 @@ module Admino
64
73
  end
65
74
  end
66
75
 
67
- def add_filter_group(name, scopes)
68
- FilterGroup.new(name, scopes).tap do |filter_group|
76
+ def add_filter_group(name, scopes, options = {})
77
+ FilterGroup.new(name, scopes, options).tap do |filter_group|
69
78
  self.filter_groups << filter_group
70
79
  end
71
80
  end
@@ -13,8 +13,8 @@ module Admino
13
13
  end
14
14
  end
15
15
 
16
- def filter_by(name, scopes)
17
- config.add_filter_group(name, scopes)
16
+ def filter_by(name, scopes, options = {})
17
+ config.add_filter_group(name, scopes, options)
18
18
  end
19
19
 
20
20
  def sorting(*args)
@@ -15,7 +15,7 @@ module Admino
15
15
  end
16
16
 
17
17
  def augment_scope(scope)
18
- if active_scope
18
+ if active_scope && active_scope != :empty
19
19
  scope.send(active_scope)
20
20
  else
21
21
  scope
@@ -35,7 +35,8 @@ module Admino
35
35
  end
36
36
 
37
37
  def value
38
- params.fetch(:query, {}).fetch(param_name, nil)
38
+ default_value = config.include_empty_scope? ? :empty : nil
39
+ params.fetch(:query, {}).fetch(param_name, default_value)
39
40
  end
40
41
 
41
42
  def param_name
@@ -43,7 +44,11 @@ module Admino
43
44
  end
44
45
 
45
46
  def scopes
46
- config.scopes
47
+ @scopes ||= config.scopes.dup.tap do |scopes|
48
+ if config.include_empty_scope?
49
+ scopes.unshift :empty
50
+ end
51
+ end
47
52
  end
48
53
 
49
54
  def i18n_key
@@ -1,4 +1,4 @@
1
1
  module Admino
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
4
4
 
@@ -16,6 +16,7 @@ module Admino
16
16
  filter_group = config.filter_groups.first
17
17
  expect(filter_group.name).to eq :bar
18
18
  expect(filter_group.scopes).to eq [:one, :two]
19
+ expect(filter_group.include_empty_scope?).to be_true
19
20
  end
20
21
 
21
22
  it 'allows #sortings declaration' do
@@ -14,6 +14,14 @@ module Admino
14
14
  it 'returns nil' do
15
15
  expect(filter_group.active_scope).to be_nil
16
16
  end
17
+
18
+ context 'if include_empty_scope is true' do
19
+ let(:config) { Configuration::FilterGroup.new(:foo, [:bar], include_empty_scope: true) }
20
+
21
+ it 'returns the :empty scope' do
22
+ expect(filter_group.active_scope).to eq :empty
23
+ end
24
+ end
17
25
  end
18
26
 
19
27
  context 'with an invalid value' do
@@ -22,6 +30,14 @@ module Admino
22
30
  it 'returns nil' do
23
31
  expect(filter_group.active_scope).to be_nil
24
32
  end
33
+
34
+ context 'if include_empty_scope is true' do
35
+ let(:config) { Configuration::FilterGroup.new(:foo, [:bar], include_empty_scope: true) }
36
+
37
+ it 'returns nil' do
38
+ expect(filter_group.active_scope).to be_nil
39
+ end
40
+ end
25
41
  end
26
42
 
27
43
  context 'with a valid value' do
@@ -49,6 +65,14 @@ module Admino
49
65
  it 'returns the original scope' do
50
66
  expect(result).to eq scope
51
67
  end
68
+
69
+ context 'if include_empty_scope is true' do
70
+ let(:config) { Configuration::FilterGroup.new(:foo, [:bar], include_empty_scope: true) }
71
+
72
+ it 'returns the original scope' do
73
+ expect(result).to eq scope
74
+ end
75
+ end
52
76
  end
53
77
  end
54
78
 
@@ -59,6 +83,19 @@ module Admino
59
83
  expect(filter_group.is_scope_active?('bar')).to be_true
60
84
  end
61
85
  end
86
+
87
+ describe '#scopes' do
88
+ subject { filter_group.scopes }
89
+
90
+ context 'if include_empty_scope is true' do
91
+ let(:config) { Configuration::FilterGroup.new(:foo, [:bar], include_empty_scope: true) }
92
+ it { should eq [:empty, :bar] }
93
+ end
94
+
95
+ context 'else' do
96
+ it { should eq [:bar] }
97
+ end
98
+ end
62
99
  end
63
100
  end
64
101
  end
@@ -35,7 +35,7 @@ class TestQuery < Admino::Query::Base
35
35
  search_field :foo
36
36
  search_field :starting_from, coerce: :to_date
37
37
 
38
- filter_by :bar, [:one, :two]
38
+ filter_by :bar, [:one, :two], include_empty_scope: true
39
39
 
40
40
  sorting :by_title, :by_date,
41
41
  default_scope: :by_title,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: admino
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-27 00:00:00.000000000 Z
11
+ date: 2014-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: showcase
@@ -249,4 +249,3 @@ test_files:
249
249
  - spec/admino/table/resource_row_spec.rb
250
250
  - spec/admino/table/row_spec.rb
251
251
  - spec/spec_helper.rb
252
- has_rdoc: