Changeset 106 in bookmarks
- Timestamp:
- 10/19/15 21:16:31 (9 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cpanfile
r105 r106 8 8 requires 'Encode'; 9 9 requires 'Router::Resource'; 10 requires 'Data::Pageset'; 10 11 11 12 # web application -
trunk/lib/Bookmarks.pm
r92 r106 99 99 } 100 100 101 sub get_count { 102 my $self = shift; 103 my $search = shift; 104 105 my ($sql, @bind) = sql_interp( 106 'select count(*) from resources join bookmarks on resources.uri = bookmarks.uri', 107 $self->_sql_where_clause($search), 108 ); 109 my $sth = $self->dbh->prepare($sql); 110 $sth->execute(@bind); 111 my ($count) = $sth->fetchrow_array; 112 return $count; 113 } 114 101 115 sub search { 102 116 my $self = shift; 103 117 my $params = shift || {}; 104 118 my $search = Bookmarks::Search->new($params); 119 120 my ($limit, $offset); 121 if ($search->page) { 122 my $count = $self->get_count($search); 123 use Data::Pageset; 124 my $pages = Data::Pageset->new({ 125 total_entries => $count, 126 current_page => $search->page, 127 entries_per_page => 15, 128 mode => 'slide', 129 }); 130 $search->pages($pages); 131 $limit = $pages->entries_per_page; 132 $offset = $pages->skipped; 133 } else { 134 $limit = $search->limit; 135 $offset = $search->offset; 136 } 105 137 106 138 # build the query … … 110 142 push @sql, $self->_sql_where_clause($search); 111 143 push @sql, 'order by ctime desc'; 112 push @sql, ('limit', \$ search->limit) if $search->limit;144 push @sql, ('limit', \$limit) if $limit; 113 145 # an offset is only allowed if we have a limit clause 114 push @sql, ('offset', \$ search->offset) if $search->limit && $search->offset;146 push @sql, ('offset', \$offset) if $limit && $offset; 115 147 116 148 my ($sql, @bind) = sql_interp(@sql); -
trunk/lib/Bookmarks/Controller.pm
r100 r106 83 83 my $limit = $self->request->param('limit'); 84 84 my $offset = $self->request->param('offset'); 85 my $page = $self->request->param('page'); 85 86 86 87 my $list = Bookmarks::List->new({ … … 91 92 limit => $limit, 92 93 offset => $offset, 94 page => $page, 93 95 }), 94 96 }); -
trunk/lib/Bookmarks/List.pm
r95 r106 197 197 cotags => \@cotags, 198 198 resources => $self->results, 199 pages => $self->search->pages, 199 200 }, 200 201 \my $output, -
trunk/lib/Bookmarks/Search.pm
r88 r106 10 10 has limit => (is => 'ro'); 11 11 has offset => (is => 'ro'); 12 has page => (is => 'ro'); 12 13 13 14 has results => (is => 'rw', default => sub { [] }); 15 has pages => ( 16 is => 'rw', 17 isa => 'Data::Pageset', 18 ); 14 19 15 20 # module return -
trunk/lib/Bookmarks/list.tt
r95 r106 84 84 font-size: .875em; 85 85 } 86 .pagination { 87 margin: .5em; 88 } 86 89 </style> 87 90 </head> … … 96 99 <input type="submit" value="Go"/> 97 100 </form> 101 <div class="pagination"> 102 [% IF pages %] 103 <a href="?page=[% pages.first_page %]">«</a> 104 [% IF pages.previous_set %] 105 <a href="?page=[% pages.previous_set %]">‹</a> 106 [% END %] 107 [% FOREACH page IN pages.pages_in_set %] 108 [% IF page == pages.current_page %] 109 <strong>[% page %]</strong> 110 [% ELSE %] 111 <a href="?page=[% page %]">[% page %]</a> 112 [% END %] 113 [% END %] 114 [% IF pages.next_set %] 115 <a href="?page=[% pages.next_set %]">›</a> 116 [% END %] 117 <a href="?page=[% pages.last_page %]">»</a> 118 [% END %] 119 </div> 98 120 <ul class="main"> 99 121 [% FOREACH resource IN resources %]
Note: See TracChangeset
for help on using the changeset viewer.