/[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 1141 by dpavlin, Wed Apr 22 14:27:25 2009 UTC
# Line 13  use Data::Dump qw/dump/; Line 13  use Data::Dump qw/dump/;
13    
14  my $range_around = 5;  my $range_around = 5;
15  my $entries_per_page = 30;  my $entries_per_page = 30;
16    my $debug = param('debug');
17    
18  print header;  print header;
19    
20  sub dump_yaml {  sub dump_yaml {
21          my $name = shift;          my $name = shift;
22          print qq|<pre># $name\n|, YAML::Dump( @_ ), qq|</pre>|;          print qq|<pre># $name\n|, YAML::Dump( @_ ), qq|</pre>| if $debug;
23  }  }
24    
25  sub show_pages {  sub show_pager {
26          my ($pager,$coderef) = @_;          my ($pager) = @_;
27    
28          my @show_pages;          my @show_pages;
29          my $after_current = 0;          my $after_current = 0;
# Line 34  sub show_pages { Line 35  sub show_pages {
35                  @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 );
36          }          }
37    
38          if ( $pager->current_page + $range_around + 1 >= $pager->last_page ) {          if ( $pager->current_page + $after_current + $range_around + 1 >= $pager->last_page ) {
39                  push @show_pages, ( $pager->current_page + 1 .. $pager->last_page );                  push @show_pages, ( $pager->current_page + 1 .. $pager->last_page );
40          } else {          } else {
41                  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 );
42          }          }
43    
44          warn "## show_pages = ",dump( @show_pages );  #       dump_yaml( 'show_pages', \@show_pages );
45    
46          return join( ' ', map {          return '' unless $#show_pages;
47                  if ( $_ == $pager->current_page ) {  
48                          qq|<b>$_</b>|;          my ( $prev, $next ) = ( '&lt;&lt;', '&gt;&gt;' );
49                  } elsif ( $_ eq '' ) {  
50                          qq|...|;          sub li_a_href {
51                  } else {                  my ( $page, $label, $attr ) = @_;
52                          $coderef->( $_ );                  param( 'current_page', $page );
53                  }                  my $url = self_url( -query => 1 );
54          } @show_pages );                  $attr ||= '';
55                    $label ||= $page;
56                    qq|<li$attr><a href="$url" title="$page">$label</a></li>|;
57            }
58    
59            return
60                      $pager->previous_page ? li_a_href( $pager->previous_page, $prev ) : qq|<li class=skip>$prev</li>|
61                    , ( map {
62                            if ( $_ == $pager->current_page ) {
63                                    qq|<li class=current_page>$_</li>|;
64                            } elsif ( $_ eq '' ) {
65                                    qq|<li class=skip>...</li>|;
66                            } else {
67                                    li_a_href( $_ );
68                            }
69                    } @show_pages )
70                    , $pager->next_page ? li_a_href( $pager->next_page, $next ) : qq|<li class=skip>$next</li>|
71                    ;
72                    
73  }  }
74    
75  my $path = $ENV{PATH_INFO} || 'ecas';  my $path = $ENV{PATH_INFO} || 'ecas';
# Line 84  print Line 103  print
103          ),          ),
104          h1( $db->{name} ),          h1( $db->{name} ),
105          qq|<div id=description>|, $db->{description}, qq|</div>|,          qq|<div id=description>|, $db->{description}, qq|</div>|,
106          start_form,          start_form( -action => self_url( query => 0 ) ),
107                  radio_group(                  radio_group(
108                          -name => 'attr',                          -name => 'attr',
109                          -values => [ @attr ],                          -values => [ @attr ],
# Line 108  if ( my $search = param('search') ) { Line 127  if ( my $search = param('search') ) {
127          );          );
128    
129          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?
130            my $pager = Data::Page->new;
131            $pager->total_entries( param('current_page') * param('entries_per_page') );
132            $pager->$_( param($_) ) foreach ( qw/entries_per_page current_page/ );
133    
134            dump_yaml( 'pager', $pager );
135    
136          my $cond = Search::Estraier::Condition->new;          my $cond = Search::Estraier::Condition->new;
137          $cond->set_phrase( $search );          $cond->set_phrase( $search );
138          $cond->set_skip( param('current_page') );          $cond->set_skip( $pager->skipped );
139          $cond->set_max( param('entries_per_page') );          $cond->set_max(  $pager->entries_per_page );
140          my $nres = $node->search( $cond, 0 );          my $nres = $node->search( $cond, 0 );
141            $pager->total_entries( $nres->hits );
142    
143    
144          my $pager = Data::Page->new( $nres->hits, param('entries_per_page'), param('current_page') );          dump_yaml( 'cond', $cond );
145    
146          if ( ! $nres ) {          if ( ! $nres ) {
147                  my $no_results = "No results for search '%s'";                  my $no_results = "No results for search '%s'";
148                  printf qq|<div class="error">$no_results</div>|, $search;                  printf qq|<div class="error">$no_results</div>\n\n|, $search;
149          } else {          } else {
150    
151                  my $results = "Got %d results for search '%s'";                  my $results = "%d results for search '%s' showing results %d - %d on page %d";
152                  printf qq|<div class="message">$results</div>|, $nres->hits, $search;                  printf qq|<div class="message">$results</div>\n\n|, $nres->hits, $search, $pager->first, $pager->last, $pager->current_page;
153    
154                  print                  dump_yaml( 'pager html', show_pager( $pager ));
155                          qq|<div class=pager>|,  
156                          show_pages( $pager,                  my $pager_html = join("\n", show_pager( $pager ));
157                                  sub {  
158                                          my ($page) = @_;                  print qq|<ul class="pager">$pager_html</ul>\n\n| if $pager_html;
                                         param( 'current_page', $page );  
                                         my $url = self_url( -query => 1 );  
                                         qq|<a href="$url">$_</a>|;  
                                 }  
                         ),  
                         qq|</div>|  
                 ;  
159    
160                  my $start = $pager->first;                  my $start = $pager->first;
161                  print qq|<ol start=$start>|;                  print qq|<ol start=$start>\n|;
162    
163                  foreach my $i ( 1 .. $nres->doc_num ) {                  foreach my $i ( 1 .. $nres->doc_num ) {
164                          my $rdoc = $nres->get_doc( $i - 1 );                          my $rdoc = $nres->get_doc( $i - 1 );
# Line 158  if ( my $search = param('search') ) { Line 177  if ( my $search = param('search') ) {
177                          }                          }
178                          print qq|</li>\n|;                          print qq|</li>\n|;
179                  }                  }
180                  print qq|</ol>|;                  print qq|</ol>\n\n|;
181    
182                    print qq|<ul class="pager bottom">$pager_html</ul>\n\n| if $pager_html;
183          }          }
184          print qq|</div>|;          print qq|</div>|;
185    

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

  ViewVC Help
Powered by ViewVC 1.1.26