/[Frey]/trunk/lib/Frey/View/NoPager.pm
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/lib/Frey/View/NoPager.pm

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

revision 965 by dpavlin, Wed Jan 7 20:31:51 2009 UTC revision 966 by dpavlin, Wed Jan 7 23:00:40 2009 UTC
# Line 26  has 'page' => ( Line 26  has 'page' => (
26  );  );
27    
28  has 'on_page' => (  has 'on_page' => (
29          documentation => 'numer of items on page',          documentation => 'number of items on page',
30          is => 'rw',          is => 'rw',
31          isa => 'Int',          isa => 'Int',
32          default => 30,          default => 20,
33  );  );
34    
35  has 'sort' => (  has 'sort' => (
# Line 46  sub results_as_markup { Line 46  sub results_as_markup {
46          my $v = {          my $v = {
47                  search => $search,                  search => $search,
48                  page => $page,                  page => $page,
49                  max_page => $page,                  max_page => 0,
50                  id => time() . rand(99),                  id => time() . rand(99),
51          };          };
52    
53          sub next_page {          sub next_page {
54                  my $self = shift;                  my $self = shift;
55                    my $v = shift;
56                  my $json = $self->html_escape( JSON::Syck::Dump( $v ) );                  my $json = $self->html_escape( JSON::Syck::Dump( $v ) );
57    
58                  my $message = join("\n", @_);                  my $message = join("\n", @_);
59    
60                  # <textarea id="json" style="display:none">                  my $next_page = $v->{page} + 1;
61    
62                  return qq|                  return qq|
63                          <div id="next_page">                          <div id="next_page_$next_page">
64                                  $message                                  $message
65                                  <textarea id="json">                                  <textarea id="json" style="display:none">$json</textarea>
                                 $json  
                                 </textarea>  
66                          </div>                          </div>
67                  |                  |
68                  ;                  ;
# Line 70  sub results_as_markup { Line 70  sub results_as_markup {
70    
71          if (! $search || $search =~ m/^\s*$/) {          if (! $search || $search =~ m/^\s*$/) {
72                  $v->{status} = 'Enter search query';                  $v->{status} = 'Enter search query';
73                  return $self->next_page;                  return $self->next_page( $v );
74          }          }
75    
76          $search = join(" AND ", split(/\s+/, $search)) unless ($search =~ m/(?:AND|OR|\[|\])/);          $search = join(" AND ", split(/\s+/, $search)) unless ($search =~ m/(?:AND|OR|\[|\])/);
77            $v->{search} = $search;
78    
79          my $node = new Search::Estraier::Node(%{ $self->config->{estraier} });          my $node = new Search::Estraier::Node(%{ $self->config->{estraier} });
80    
# Line 82  sub results_as_markup { Line 83  sub results_as_markup {
83    
84          my $cond = new Search::Estraier::Condition;          my $cond = new Search::Estraier::Condition;
85          $cond->set_phrase( $search );          $cond->set_phrase( $search );
86          $cond->set_max( $on_page * $page );     ## FIXME * $page is needed by hest 1.3.8          $cond->set_max( $on_page );
87          $cond->set_skip( $skip );          $cond->set_skip( $skip );
88          $cond->set_order( $self->sort ) if $self->sort;          $cond->set_order( $self->sort ) if $self->sort;
89    
# Line 90  sub results_as_markup { Line 91  sub results_as_markup {
91    
92          my $nres = $node->search($cond, ( $self->config->{estraier}->{depth} || 0 ) );          my $nres = $node->search($cond, ( $self->config->{estraier}->{depth} || 0 ) );
93    
94          my $out;          my $out = qq|<!-- page $page -->|;
95    
96          if (defined($nres)) {          if (defined($nres)) {
97    
# Line 99  sub results_as_markup { Line 100  sub results_as_markup {
100    
101                  if ($v->{hits} == 0) {                  if ($v->{hits} == 0) {
102                          $v->{status} = qq{<strong>No results for your search.</strong>};                          $v->{status} = qq{<strong>No results for your search.</strong>};
103                          return $self->next_page;                          return $self->next_page( $v, qq|<strong>No results found.</strong>| );
104                  } elsif ($nres->doc_num == 0) {                  } elsif ($nres->doc_num == 0) {
105                          $v->{status} = qq{<strong>Error getting results for page $page.</strong>};                          $v->{status} = qq{<strong>Error getting results for page $page.</strong>};
106                          return $self->next_page('<strong>No results found.</strong>');                          return $self->next_page( $v );
107                  }                  }
108    
109                  $v->{max_page} = int( ($nres->hits + $on_page - 1) / $on_page );                  $v->{max_page} = int( ($nres->hits + $on_page - 1) / $on_page );
# Line 147  sub results_as_markup { Line 148  sub results_as_markup {
148    
149                  my $result = q|                  my $result = q|
150                          <div class="result">                          <div class="result">
151                          <h1><% attr_regex( $rdoc, '@title' ) %></h1>                          <span class="nr"><% $nr %></span>
152                            <h1 title="<% $nr %>"><% attr_regex( $rdoc, '@title' ) %></h1>
153                          <p>                          <p>
154                          <% html_snippet( $rdoc->snippet ) %>                          <% html_snippet( $rdoc->snippet ) %>
155                          </p>                          </p>
                         <span style="color: #888"><% $nr %></span>  
156                          <strong><% attr_regex( $rdoc, 'source' ) %></strong>                          <strong><% attr_regex( $rdoc, 'source' ) %></strong>
157                          <em>                          <em>
158                          <% attr_regex( $rdoc, '@size' ) %> bytes                          <% attr_regex( $rdoc, '@size' ) %> bytes
# Line 184  sub results_as_markup { Line 185  sub results_as_markup {
185          }          }
186    
187          if ($v->{page} == $v->{max_page}) {          if ($v->{page} == $v->{max_page}) {
188                  $out .= $self->next_page('<br/><strong>All results shown</strong>');                  $out .= $self->next_page( $v, qq|<br/><strong>All results shown</strong>|);
189          } else {          } else {
190                  $out .= $self->next_page(                  $out .= $self->next_page( $v, qq|
191                          '<br/><strong>Loading results...</strong><br/>',                          <br/><strong>Loading results...</strong>
192                          'If you are using the scroll bar, release the mouse to see more results.'                          <br/>If you are using the scroll bar, release the mouse to see more results.
193                  );                  |);
194          }          }
195    
196          warn "# v = ", dump( $v );          warn "# v = ", dump( $v );
# Line 219  sub as_markup { Line 220  sub as_markup {
220    
221          my ( $results, $status ) = $self->results_as_markup;          my ( $results, $status ) = $self->results_as_markup;
222    
223            $self->add_css(q|
224                    #results {
225                            margin-top: 3em;
226                            margin-bottom: 3em;
227                    }
228            |);
229    
230          my $html = join("\n",          my $html = join("\n",
231          qq|          qq|
232                  <div id="search_form_div">                  <div id="search_form_div">
# Line 235  sub as_markup { Line 243  sub as_markup {
243                          </form>                          </form>
244                  </div>                  </div>
245    
246                  <div style="margin-top: 3em;">                  <div id="results">
247                  <!-- Dynamic Content -->                  <!-- Dynamic Content -->
248                          $results                          $results
   
                         <!-- Back Button Content -->  
                         <div style="position:absolute;top:0px;left:0px;visibility:hidden;" id="spacer">space</div>  
                         <!-- footer at end of results -->  
                         <div style="display:none;" id="footer">  
                                 Thanks for trying out no pager. Hope you like it.  
                         </div>  
   
249                  </div>                  </div>
250    
251          |          |

Legend:
Removed from v.965  
changed lines
  Added in v.966

  ViewVC Help
Powered by ViewVC 1.1.26