c14b0a8941dc3400c4da385e9fb037b5eca93fcb
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / GridView / Role / Pager.pm
1 package Reaction::UI::ViewPort::GridView::Role::Pager;
2
3 use Reaction::Role;
4
5 use aliased 'Reaction::InterfaceModel::Collection';
6
7 # XX This needs to be consumed after Ordered
8 role Pager, which {
9
10   #has paged_collection => (isa => Collection, is => 'rw', lazy_build => 1);
11
12   has pager    => (isa => 'Data::Page', is => 'rw', lazy_build => 1);
13   has page     => (isa => 'Int', is => 'rw', lazy_build => 1, trigger_adopt('page'));
14   has per_page => (isa => 'Int', is => 'rw', lazy_build => 1, trigger_adopt('page'));
15
16   implements build_page     => as { 1  };
17   implements build_per_page => as { 10 };
18
19   implements build_pager => as { shift->current_collection->pager };
20
21   implements adopt_page => as {
22     my ($self) = @_;
23     #$self->clear_paged_collection;
24     $self->clear_current_collection;
25     $self->clear_pager;
26   };
27
28   around accept_events => sub { ('page', shift->(@_)); };
29
30   #implements build_paged_collection => as {
31   #  my ($self) = @_;
32   #  my $collection = $self->current_collection;
33   #  return $collection->where(undef, {rows => $self->per_page})->page($self->page);
34   #};
35
36   around build_current_collection => sub {
37     my $orig = shift;
38     my ($self) = @_;
39     my $collection = $orig->(@_);
40     return $collection->where(undef, {rows => $self->per_page})->page($self->page);
41   };
42
43 };
44
45 1;