/[webpac2]/trunk/vhost/webpac2.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/vhost/webpac2.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1138 by dpavlin, Wed Apr 22 10:14:56 2009 UTC revision 1139 by dpavlin, Wed Apr 22 12:51:23 2009 UTC
# Line 21  sub dump_yaml { Line 21  sub dump_yaml {
21          print qq|<pre># $name\n|, YAML::Dump( @_ ), qq|</pre>|;          print qq|<pre># $name\n|, YAML::Dump( @_ ), qq|</pre>|;
22  }  }
23    
24  sub show_pages {  sub show_pager {
25          my ($pager,$coderef) = @_;          my ($pager,$coderef) = @_;
26    
27          my @show_pages;          my @show_pages;
# Line 34  sub show_pages { Line 34  sub show_pages {
34                  @show_pages = ( $pager->first_page, '', $pager->current_page - $range_around .. $pager->current_page );                  @show_pages = ( $pager->first_page, '', $pager->current_page - $range_around .. $pager->current_page );
35          }          }
36    
37          if ( $pager->current_page + $range_around + 1 >= $pager->last_page ) {          if ( $pager->current_page + $after_current + $range_around + 1 >= $pager->last_page ) {
38                  push @show_pages, ( $pager->current_page + 1 .. $pager->last_page );                  push @show_pages, ( $pager->current_page + 1 .. $pager->last_page );
39          } else {          } else {
40                  push @show_pages, ( $pager->current_page + 1 .. $pager->current_page + $after_current + $range_around, '', $pager->last_page );                  push @show_pages, ( $pager->current_page + 1 .. $pager->current_page + $after_current + $range_around, '', $pager->last_page );
41          }          }
42    
43          warn "## show_pages = ",dump( @show_pages );          dump_yaml( 'show_pages', \@show_pages );
44    
45          return join( ' ', map {          return '' unless $#show_pages;
46                  if ( $_ == $pager->current_page ) {  
47                          qq|<b>$_</b>|;          my ( $prev, $next ) = ( '&lt;&lt;', '&gt;&gt;' );
48                  } elsif ( $_ eq '' ) {  
49                          qq|...|;          return
50                  } else {                    $pager->previous_page ? $coderef->( $pager->previous_page, $prev ) : $prev
51                          $coderef->( $_ );                  , join( ' ', map {
52                  }                          if ( $_ == $pager->current_page ) {
53          } @show_pages );                                  qq|<span class=current_page>$_</span>|;
54                            } elsif ( $_ eq '' ) {
55                                    qq|<span class=skip>...</span>|;
56                            } else {
57                                    $coderef->( $_ );
58                            }
59                    } @show_pages )
60                    , $pager->next_page ? $coderef->( $pager->next_page, $next ) : $next
61                    ;
62                    
63  }  }
64    
65  my $path = $ENV{PATH_INFO} || 'ecas';  my $path = $ENV{PATH_INFO} || 'ecas';
# Line 84  print Line 93  print
93          ),          ),
94          h1( $db->{name} ),          h1( $db->{name} ),
95          qq|<div id=description>|, $db->{description}, qq|</div>|,          qq|<div id=description>|, $db->{description}, qq|</div>|,
96          start_form,          start_form( -action => self_url( query => 0 ) ),
97                  radio_group(                  radio_group(
98                          -name => 'attr',                          -name => 'attr',
99                          -values => [ @attr ],                          -values => [ @attr ],
# Line 108  if ( my $search = param('search') ) { Line 117  if ( my $search = param('search') ) {
117          );          );
118    
119          param( 'entries_per_page', $entries_per_page ) unless param('entries_per_page'); # FIXME not needed?          param( 'entries_per_page', $entries_per_page ) unless param('entries_per_page'); # FIXME not needed?
120            my $pager = Data::Page->new;
121            $pager->total_entries( param('current_page') * param('entries_per_page') );
122            $pager->$_( param($_) ) foreach ( qw/entries_per_page current_page/ );
123    
124            dump_yaml( 'pager', $pager );
125    
126          my $cond = Search::Estraier::Condition->new;          my $cond = Search::Estraier::Condition->new;
127          $cond->set_phrase( $search );          $cond->set_phrase( $search );
128          $cond->set_skip( param('current_page') );          $cond->set_skip( $pager->skipped );
129          $cond->set_max( param('entries_per_page') );          $cond->set_max(  $pager->entries_per_page );
130          my $nres = $node->search( $cond, 0 );          my $nres = $node->search( $cond, 0 );
131            $pager->total_entries( $nres->hits );
132    
133          my $pager = Data::Page->new( $nres->hits, param('entries_per_page'), param('current_page') );          dump_yaml( 'cond', $cond );
134    
135          if ( ! $nres ) {          if ( ! $nres ) {
136                  my $no_results = "No results for search '%s'";                  my $no_results = "No results for search '%s'";
# Line 127  if ( my $search = param('search') ) { Line 142  if ( my $search = param('search') ) {
142    
143                  print                  print
144                          qq|<div class=pager>|,                          qq|<div class=pager>|,
145                          show_pages( $pager,                          join(' ', show_pager( $pager,
146                                  sub {                                  sub {
147                                          my ($page) = @_;                                          my ($page,$label) = @_;
148                                          param( 'current_page', $page );                                          param( 'current_page', $page );
149                                          my $url = self_url( -query => 1 );                                          my $url = self_url( -query => 1 );
150                                          qq|<a href="$url">$_</a>|;                                          $label = $page unless defined $label;
151                                            qq|<a href="$url">$label</a>|;
152                                  }                                  }
153                          ),                          )),
154                          qq|</div>|                          qq|</div>|
155                  ;                  ;
156    

Legend:
Removed from v.1138  
changed lines
  Added in v.1139

  ViewVC Help
Powered by ViewVC 1.1.26