33 |
}, |
}, |
34 |
); |
); |
35 |
|
|
36 |
|
has 'range_around' => ( |
37 |
|
is => 'rw', |
38 |
|
isa => 'Int', |
39 |
|
default => 10, |
40 |
|
); |
41 |
|
|
42 |
|
sub first_item { |
43 |
|
my $self = shift; |
44 |
|
$self->items->[0]; |
45 |
|
} |
46 |
|
|
47 |
sub last_item { |
sub last_item { |
48 |
my $self = shift; |
my $self = shift; |
|
warn "## last_item = ", |
|
49 |
my $last = $#{ $self->items }; |
my $last = $#{ $self->items }; |
50 |
$self->update_collection if $last < 0; |
$self->update_collection if $last < 0; |
51 |
$self->items->[ $#{ $self->items } ]; |
$self->items->[ $#{ $self->items } ]; |
64 |
|
|
65 |
warn "## update_collection from iterator"; |
warn "## update_collection from iterator"; |
66 |
|
|
67 |
|
if ( ! $self->fey_class->can('collection') ) { |
68 |
|
warn "ERROR: ", $self->fey_class, " can't do collection"; |
69 |
|
return; |
70 |
|
} |
71 |
|
|
72 |
my $i = $self->fey_class->collection( $self->pager ); |
my $i = $self->fey_class->collection( $self->pager ); |
73 |
while ( my $u = $i->next ) { |
while ( my $u = $i->next ) { |
74 |
$self->add_item( |
$self->add_item( |
116 |
|
|
117 |
my $pager = $self->pager; |
my $pager = $self->pager; |
118 |
|
|
119 |
|
my @show_pages; |
120 |
|
my $after_current = 0; |
121 |
|
|
122 |
|
if ( $pager->current_page <= $self->range_around + 2 ) { |
123 |
|
@show_pages = ( $pager->first_page .. $pager->current_page ); |
124 |
|
$after_current = $self->range_around - $pager->current_page; |
125 |
|
} else { |
126 |
|
@show_pages = ( $pager->first_page, '', $pager->current_page - $self->range_around .. $pager->current_page ); |
127 |
|
} |
128 |
|
|
129 |
|
if ( $pager->current_page + $self->range_around + 1 >= $pager->last_page ) { |
130 |
|
push @show_pages, ( $pager->current_page + 1 .. $pager->last_page ); |
131 |
|
} else { |
132 |
|
push @show_pages, ( $pager->current_page + 1 .. $pager->current_page + $after_current + $self->range_around, '', $pager->last_page ); |
133 |
|
} |
134 |
|
|
135 |
|
warn "## show_pages = ",dump( @show_pages ); |
136 |
|
|
137 |
return join( ' ', |
return join( ' ', |
138 |
qq|<div class="notice">|, |
qq|<div class="notice">|, |
139 |
'Showing', |
'Showing', |
145 |
Frey::Web::Links->new( |
Frey::Web::Links->new( |
146 |
name => 'page', |
name => 'page', |
147 |
current => $pager->current_page, |
current => $pager->current_page, |
148 |
values => [ $pager->first_page .. $pager->last_page ], |
values => \@show_pages, |
149 |
|
empty => '...', |
150 |
|
current_tag => 'b', |
151 |
)->links, |
)->links, |
152 |
qq|</div>| |
qq|</div>| |
153 |
); |
); |