aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/ViewPort/Collection/Role/Pager.pm
blob: 64752a6f9d8d1c77d5c6bb4d7c67ea578d072279 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package Reaction::UI::ViewPort::Collection::Role::Pager;

use Reaction::Role;

use aliased 'Reaction::InterfaceModel::Collection';

# XX This needs to be consumed after Ordered
use namespace::clean -except => [ qw(meta) ];


#has paged_collection => (isa => Collection, is => 'rw', lazy_build => 1);

has pager    => (isa => 'Data::Page', is => 'rw', lazy_build => 1);
has page     => (isa => 'Int', is => 'rw', lazy_build => 1, trigger_adopt('page'));
has per_page => (isa => 'Int', is => 'rw', lazy_build => 1, trigger_adopt('page'));
has per_page_max => (isa => 'Int', is => 'rw', lazy_build => 1);
sub _build_page { 1  };
sub _build_per_page { 10 };
sub _build_per_page_max { 100 };
sub _build_pager { shift->current_collection->pager };
sub adopt_page {
  my ($self) = @_;
  #$self->clear_paged_collection;

  $self->clear_pager;
  $self->clear_current_collection;
};

around accept_events => sub { ('page','per_page', shift->(@_)); };

#implements build_paged_collection => as {
#  my ($self) = @_;
#  my $collection = $self->current_collection;
#  return $collection->where(undef, {rows => $self->per_page})->page($self->page);
#};

around _build_current_collection => sub {
  my $orig = shift;
  my ($self) = @_;
  my $collection = $orig->(@_);
  return $collection->where(undef, {rows => $self->per_page})->page($self->page);
};



1;