Commit | Line | Data |
e22de101 |
1 | package Reaction::UI::ViewPort::GridView::Role::Pager; |
2 | |
3 | use Reaction::Role; |
4 | |
5 | use aliased 'Reaction::InterfaceModel::Collection'; |
6 | |
7 | role Pager, which { |
8 | |
9 | has paged_collection => (isa => Collection, is => 'rw', lazy_build => 1); |
10 | |
11 | has pager => (isa => 'Data::Page', is => 'rw', lazy_build => 1); |
12 | has page => (isa => 'Int', is => 'rw', lazy_build => 1, trigger_adopt('page')); |
13 | has per_page => (isa => 'Int', is => 'rw', lazy_build => 1, trigger_adopt('page')); |
14 | |
15 | implements build_page => as { 1 }; |
16 | implements build_per_page => as { 10 }; |
17 | |
18 | implements build_pager => as { shift->paged_collection->pager }; |
19 | |
20 | implements adopt_page => as { |
21 | my ($self) = @_; |
22 | $self->clear_paged_collection; |
23 | $self->clear_pager; |
24 | }; |
25 | |
26 | around accept_events => sub { ('page', shift->(@_)); }; |
27 | |
28 | implements build_paged_collection => sub { |
29 | my ($self) = @_; |
30 | my $collection = $self->current_collection; |
31 | return $collection->where(undef, {rows => $self->per_page})->page($self->page); |
32 | }; |
33 | |
34 | }; |
35 | |
36 | 1; |