admino 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -4
- data/README.md +43 -3
- data/lib/admino/query/filter_group.rb +1 -1
- data/lib/admino/query/filter_group_presenter.rb +2 -1
- data/lib/admino/query/sorting.rb +1 -1
- data/lib/admino/query/sorting_presenter.rb +4 -1
- data/lib/admino/version.rb +1 -1
- data/spec/admino/query/filter_group_presenter_spec.rb +13 -4
- data/spec/admino/query/filter_group_spec.rb +1 -1
- data/spec/admino/query/sorting_presenter_spec.rb +9 -1
- data/spec/admino/table/presenter_spec.rb +14 -7
- data/spec/spec_helper.rb +0 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb9eedd24736483e6944b06a6b6b0952aeb20408
|
4
|
+
data.tar.gz: a0f73747f2038acbc6faffbafc02ea4845339826
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0214c1c5f397f0d75874b0e83a93f75bdb3e0afb6d292ca398b4d98457af4dc6c25c09f41edb99a33e42d2d4ba9ab3ff546fe3733f1fa001515aa4ba77bdda19
|
7
|
+
data.tar.gz: bb590aa9fa115d5dbd0f91f027b4430df595a31d3675f4649232d16ec0b8e32484c4683a45ce966a818913d80d3e84d5495a059431133d46cbd7d480d4174d09
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# v0.0.7
|
2
|
+
|
3
|
+
* `#scope_params` does not change request params
|
4
|
+
|
1
5
|
# v0.0.6
|
2
6
|
|
3
7
|
* Moved the filter group params inside of the `:query` hash
|
@@ -10,14 +14,14 @@
|
|
10
14
|
# v0.0.4
|
11
15
|
|
12
16
|
* Rename Group into FilterGroup
|
13
|
-
* Rename FilterGroup#available_scopes into
|
14
|
-
* Rename Sorting#available_scopes into
|
15
|
-
* Removed nil scope in FilterGroup
|
17
|
+
* Rename `FilterGroup#available_scopes` into `#scopes`
|
18
|
+
* Rename `Sorting#available_scopes` into `#scopes`
|
19
|
+
* Removed nil scope in `FilterGroup`
|
16
20
|
* Clicking on an active filter scope link will deactivate it
|
17
21
|
|
18
22
|
# v0.0.3
|
19
23
|
|
20
|
-
* Fixed bug in SortingPresenter with default scope
|
24
|
+
* Fixed bug in `SortingPresenter` with default scope
|
21
25
|
|
22
26
|
# v0.0.2
|
23
27
|
|
data/README.md
CHANGED
@@ -371,12 +371,12 @@ Admino offers a [Showcase collection presenter](https://github.com/stefanoverna/
|
|
371
371
|
</tr>
|
372
372
|
<thead>
|
373
373
|
<tbody>
|
374
|
-
<tr
|
374
|
+
<tr class='is-even'>
|
375
375
|
<td role='title'>Call mum ASAP</td>
|
376
376
|
<td role='completed'>✓</td>
|
377
377
|
<td role='due-date'>2013-02-04</td>
|
378
378
|
</tr>
|
379
|
-
<tr
|
379
|
+
<tr class='is-odd'>
|
380
380
|
<!-- ... -->
|
381
381
|
</tr>
|
382
382
|
<tbody>
|
@@ -407,7 +407,7 @@ Often tables need to offer some kind of action associated with the records. The
|
|
407
407
|
</tr>
|
408
408
|
<thead>
|
409
409
|
<tbody>
|
410
|
-
<tr
|
410
|
+
<tr class='is-even'>
|
411
411
|
<!-- ... -->
|
412
412
|
<td role='actions'>
|
413
413
|
<a href='/admin/tasks/1' role='show'>Show</a>
|
@@ -570,6 +570,46 @@ This will enable you to generate row actions even faster, simply declaring them
|
|
570
570
|
<% end %>
|
571
571
|
```
|
572
572
|
|
573
|
+
### Showcase::Traits::Record
|
574
|
+
|
575
|
+
As funny it may sound, it is strongly suggested to pass to the table presenter an array of records which in turn have been already presented. This enables you to use as columns not only the raw attributes of the model, but all the methods defined in the presenter.
|
576
|
+
|
577
|
+
Furthermore, if the record presenter includes the `Showcase::Traits::Record` trait, each row of the table will automatically have an unique id attribute thanks to the [`#dom_id` method](https://github.com/stefanoverna/showcase#dom_id).
|
578
|
+
|
579
|
+
```ruby
|
580
|
+
class TaskPresenter < Showcase::Presenter
|
581
|
+
include Showcase::Traits::Record
|
582
|
+
|
583
|
+
def truncated_title
|
584
|
+
h.truncate(title, length: 50)
|
585
|
+
end
|
586
|
+
end
|
587
|
+
```
|
588
|
+
|
589
|
+
```erb
|
590
|
+
<% tasks = present_collection(@tasks)
|
591
|
+
|
592
|
+
<%= Admino::Table::Presenter.new(tasks, Task, self).to_html do |row, record| %>
|
593
|
+
<%= row.column :truncated_title, 'Title' %>
|
594
|
+
<% end %>
|
595
|
+
```
|
596
|
+
|
597
|
+
```html
|
598
|
+
<table>
|
599
|
+
<thead>
|
600
|
+
<th role='truncated-title'>Title</th>
|
601
|
+
<thead>
|
602
|
+
<tbody>
|
603
|
+
<tr id='task_1' class='is-even'>
|
604
|
+
<td role='truncated-title'>Call mum ASAP</td>
|
605
|
+
</tr>
|
606
|
+
<tr id='task_2' class='is-odd'>
|
607
|
+
<td role='truncated-title'>Buy some milk</td>
|
608
|
+
</tr>
|
609
|
+
<tbody>
|
610
|
+
</table>
|
611
|
+
```
|
612
|
+
|
573
613
|
### I18n
|
574
614
|
|
575
615
|
Column titles are generated using the model [`#human_attribute_name`](http://apidock.com/rails/ActiveRecord/Base/human_attribute_name/class) method, so if you already translated the model attribute names, you're good to go. To translate actions, please refer to the following YAML file:
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'i18n'
|
2
2
|
require 'showcase'
|
3
3
|
require 'showcase/helpers/html_options'
|
4
|
+
require 'active_support/core_ext/object/deep_dup'
|
4
5
|
require 'active_support/core_ext/array/extract_options'
|
5
6
|
require 'active_support/hash_with_indifferent_access'
|
6
7
|
require 'active_support/core_ext/hash'
|
@@ -29,7 +30,7 @@ module Admino
|
|
29
30
|
|
30
31
|
def scope_params(scope)
|
31
32
|
params = ActiveSupport::HashWithIndifferentAccess.new(
|
32
|
-
h.request.query_parameters
|
33
|
+
h.request.query_parameters.deep_dup
|
33
34
|
)
|
34
35
|
|
35
36
|
params[:query] ||= {}
|
data/lib/admino/query/sorting.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'showcase'
|
2
|
+
require 'active_support/core_ext/object/deep_dup'
|
2
3
|
|
3
4
|
module Admino
|
4
5
|
module Query
|
@@ -25,7 +26,9 @@ module Admino
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def scope_params(scope)
|
28
|
-
params = ActiveSupport::HashWithIndifferentAccess.new(
|
29
|
+
params = ActiveSupport::HashWithIndifferentAccess.new(
|
30
|
+
h.request.query_parameters.deep_dup
|
31
|
+
)
|
29
32
|
|
30
33
|
if is_scope_active?(scope)
|
31
34
|
params.merge!(sorting: scope.to_s, sort_order: ascending? ? 'desc' : 'asc')
|
data/lib/admino/version.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'active_support/hash_with_indifferent_access'
|
2
3
|
|
3
4
|
module Admino
|
4
5
|
module Query
|
@@ -16,7 +17,9 @@ module Admino
|
|
16
17
|
let(:request_object) do
|
17
18
|
double(
|
18
19
|
'ActionDispatch::Request',
|
19
|
-
query_parameters:
|
20
|
+
query_parameters: ActiveSupport::HashWithIndifferentAccess.new(
|
21
|
+
'query' => { 'field' => 'value', 'filter_group' => 'bar' }
|
22
|
+
),
|
20
23
|
path: '/'
|
21
24
|
)
|
22
25
|
end
|
@@ -87,6 +90,7 @@ module Admino
|
|
87
90
|
|
88
91
|
describe '#scope_params' do
|
89
92
|
let(:scope_active) { false }
|
93
|
+
subject { presenter.scope_params(:foo) }
|
90
94
|
|
91
95
|
before do
|
92
96
|
filter_group.stub(:is_scope_active?).with(:foo).and_return(scope_active)
|
@@ -96,7 +100,12 @@ module Admino
|
|
96
100
|
let(:scope_active) { true }
|
97
101
|
|
98
102
|
it 'deletes the filter_group param' do
|
99
|
-
expect(
|
103
|
+
expect(subject[:query]).not_to have_key 'filter_group'
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'keeps the request parameters intact' do
|
107
|
+
presenter.scope_params(:foo)
|
108
|
+
expect(request_object.query_parameters[:query][:filter_group]).to be_present
|
100
109
|
end
|
101
110
|
end
|
102
111
|
|
@@ -104,12 +113,12 @@ module Admino
|
|
104
113
|
let(:scope_active) { false }
|
105
114
|
|
106
115
|
it 'is set as filter group value' do
|
107
|
-
expect(
|
116
|
+
expect(subject[:query][:filter_group]).to eq 'foo'
|
108
117
|
end
|
109
118
|
end
|
110
119
|
|
111
120
|
it 'preserves the other params' do
|
112
|
-
expect(
|
121
|
+
expect(subject[:query][:field]).to eq 'value'
|
113
122
|
end
|
114
123
|
end
|
115
124
|
|
@@ -56,7 +56,7 @@ module Admino
|
|
56
56
|
let(:params) { { 'query' => { 'foo' => 'bar' } } }
|
57
57
|
|
58
58
|
it 'returns true if the provided scope is the one currently active' do
|
59
|
-
expect(filter_group.is_scope_active?(
|
59
|
+
expect(filter_group.is_scope_active?('bar')).to be_true
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'active_support/hash_with_indifferent_access'
|
2
3
|
|
3
4
|
module Admino
|
4
5
|
module Query
|
@@ -15,7 +16,9 @@ module Admino
|
|
15
16
|
let(:request_object) do
|
16
17
|
double(
|
17
18
|
'ActionDispatch::Request',
|
18
|
-
query_parameters:
|
19
|
+
query_parameters: ActiveSupport::HashWithIndifferentAccess.new(
|
20
|
+
'sorting' => 'by_date', 'other' => 'value'
|
21
|
+
),
|
19
22
|
path: '/'
|
20
23
|
)
|
21
24
|
end
|
@@ -107,6 +110,11 @@ module Admino
|
|
107
110
|
expect(subject[:other]).to eq 'value'
|
108
111
|
end
|
109
112
|
|
113
|
+
it 'keeps the request parameters intact' do
|
114
|
+
subject
|
115
|
+
expect(request_object.query_parameters[:sorting]).to eq 'by_date'
|
116
|
+
end
|
117
|
+
|
110
118
|
it 'sets the sorting param as the scope' do
|
111
119
|
expect(subject[:sorting]).to eq 'by_title'
|
112
120
|
end
|
@@ -37,14 +37,21 @@ module Admino
|
|
37
37
|
expect(result).to have_tag('table tbody tr', count: 2)
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
context 'if the record responds to #dom_id' do
|
41
|
+
before do
|
42
|
+
first_post.stub(:dom_id).and_return('post_1')
|
43
|
+
second_post.stub(:dom_id).and_return('post_2')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'adds a record identifier to each collection row' do
|
47
|
+
expect(result).to have_tag('tbody tr#post_1:first-child')
|
48
|
+
expect(result).to have_tag('tbody tr#post_2:last-child')
|
49
|
+
end
|
43
50
|
end
|
44
51
|
|
45
52
|
it 'adds zebra classes to each collection row' do
|
46
|
-
expect(result).to have_tag('tbody
|
47
|
-
expect(result).to have_tag('tbody
|
53
|
+
expect(result).to have_tag('tbody tr.is-even:first-child')
|
54
|
+
expect(result).to have_tag('tbody tr.is-odd:last-child')
|
48
55
|
end
|
49
56
|
|
50
57
|
it 'delegates thead columns creation to .to_html HeadRow' do
|
@@ -126,11 +133,11 @@ module Admino
|
|
126
133
|
end
|
127
134
|
|
128
135
|
it "allows customizing the tbody_tr html attributes" do
|
129
|
-
expect(presenter.to_html).to have_tag(
|
136
|
+
expect(presenter.to_html).to have_tag("tbody tr.index-0:first-child")
|
130
137
|
end
|
131
138
|
|
132
139
|
it 'allows customizing zebra classes' do
|
133
|
-
expect(presenter.to_html).to have_tag(
|
140
|
+
expect(presenter.to_html).to have_tag("tbody tr.one:first-child")
|
134
141
|
end
|
135
142
|
end
|
136
143
|
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.0.7
|
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-
|
11
|
+
date: 2014-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: showcase
|