]> Frank Brehm's Git Trees - books.git/commitdiff
Seitennavigation bei den Autoren dazu
authorFrank Brehm <frank@brehm-online.com>
Wed, 10 Jun 2009 20:10:22 +0000 (20:10 +0000)
committerFrank Brehm <frank@brehm-online.com>
Wed, 10 Jun 2009 20:10:22 +0000 (20:10 +0000)
lib/FrBr/Books/Controller/Autor.pm
lib/FrBr/Books/Controller/Books.pm
lib/FrBr/Books/Util/Author.pm
root/src/autor/list.tt2

index ce7226fc2e99168b9773a3671e5c85d6add59fe6..6aa360d4d74b5eb5fc9cc934f0614385e6d37fd4 100644 (file)
@@ -83,6 +83,20 @@ sub default : Private {
 
 #-------------------------------------------------------
 
+sub add_autorlist_menu : Private {
+
+    my ( $self, $c ) = @_;
+    my $K = ( caller(0) )[3] . "(): ";
+
+    push @{ $c->stash->{'menu_path'} }, {
+        'path' => $c->web_path("/autor/list"),
+        'name' => "Liste"
+    };
+
+}
+
+#-------------------------------------------------------
+
 =head2 list
     
 Fetch all author objects and pass to autor/list.tt2 in stash to be displayed
@@ -95,13 +109,44 @@ sub list : Local {
     my $K = ( caller(0) )[3] . "(): ";
     $c->log->debug( $K . "aufgerufen." ) if $c->stash->{'debug_level'} > 2;
 
-    push @{ $c->stash->{'menu_path'} }, {
-        'path' => $c->web_path("/autor/list"),
-        'name' => "Liste"
-    };
+       $self->add_autorlist_menu($c);
+
+    my $page = $c->session->{'autor_list_page'} || 1;
+    my $list_length = $c->stash->{'list_length'} || 10;
 
-    my $liste = get_author_list( $c, 'get_books' => 1 );
+    if ( $c->request->params->{'page'} and to_int( $c->request->params->{'page'} ) ) {
+        $page = to_int( $c->request->params->{'page'} );
+        $c->session->{'autor_list_page'} = $page;
+    }
+
+    my ( $liste, $anzahl )  = get_author_list( $c, 'get_books' => 1, 'page' => $page );
     $c->log->debug( get_output_string( $K, "Erhaltene Liste der Autoren: ", $liste ) ) if $c->stash->{'debug_level'} >= 2;
+    my $max_page = 1;
+    if ( $anzahl ) {
+        $max_page = int( $anzahl / $list_length ) + 1;
+        if ( ( $page - 1 ) * $list_length > $anzahl ) {
+            $page = $max_page;
+            $c->session->{'autor_list_page'} = $page;
+        }
+    }
+    else {
+        $page = 1;
+        $c->session->{'autor_list_page'} = 1;
+    }
+
+       my $nav = {
+               'cur'        => $page,
+               'first'      => 1,
+               'last'       => $max_page,
+               'prev'       => ( ( $page > 1 ) ? ( $page - 1 ) : 1 ),
+               'next'       => ( ( ( $page + 1 ) > $max_page ) ? $max_page : ( $page + 1 ) ),
+               'autoren'    => $anzahl,
+               'autor_from' => ( $anzahl ? ( ( $page - 1 ) * $list_length ) + 1 : 0 ),
+               'autor_to'   => ( ( $page * $list_length ) > $anzahl ? $anzahl : ( $page * $list_length ) ),
+       };
+       $c->stash->{'autor_liste_page'} = $nav;
+    $c->log->debug( get_output_string( $K, "Seitennavigation: ", $nav ) ) if $c->stash->{'debug_level'} >= 2;
+
     $c->stash->{'authors'} = $liste;
     $c->session->{'return_target_view'} = $c->web_path("/autor/list");
 
@@ -365,4 +410,4 @@ it under the same terms as Perl itself.
 
 __END__
 
-# vim: noai : ts=4 fenc=utf-8 filetype=perl expandtab :
+# vim: noai : ts=4 fenc=utf-8 filetype=perl
index f01525ffbe33b8b3a99709f629652329b3dea30a..a1fc0325d5312879baf9aacafdc781418472d65e 100644 (file)
@@ -1202,4 +1202,4 @@ it under the same terms as Perl itself.
 
 __END__
 
-# vim: noai : ts=4 fenc=utf-8 filetype=perl expandtab :
+# vim: noai : ts=4 fenc=utf-8 filetype=perl
index 9243c456c7083b1c6ed1aaa2b86d67dcc6da5d83..c661dfb4b0dd0f6d22f9998840ba3bb62438a921 100644 (file)
@@ -70,7 +70,9 @@ Wenn nicht angegeben, werden alle Verlage zurückgegeben.
 
 =back
 
-Rueckgabe: Eine Array-Ref von Hash-Refs mit allen Autoren, die den uebergebenen Suchkriterien entsprechen:
+Rueckgabe: Eine Array-Ref von Hash-Refs mit allen Autoren, die den uebergebenen Suchkriterien entsprechen, sowie im Listenkontext die Anzahl der Autoren, die den uebergebenen Suchkriterien entsprechen.
+
+Die zurueckgegebene Array-Ref hat folgenden Aufbau:
 
        $res = [
                {
@@ -126,6 +128,7 @@ sub get_author_list {
     $c->log->debug(  get_output_string( $K, "Uebergebene Parameter: ", $params ) ) if $c->stash->{'debug_level'} >= 2;
 
     my $list = [];
+       my $anzahl_autoren = 0;
 
        my $page = to_int( $params->{'page'} ) ? to_int( $params->{'page'} ) : undef;
        my $rows = undef;
@@ -138,6 +141,9 @@ sub get_author_list {
                };
        }
 
+       $anzahl_autoren = $c->model('Schema::Autoren')->count( $search_params );
+    $c->log->debug(  get_output_string( $K, "Anzahl gefundene Autoren: ", $anzahl_autoren ) ) if $c->stash->{'debug_level'} >= 2;
+
     my $other_params = {};
     $other_params->{'order_by'} = [ 'nachname', 'vorname', 'mittelname', 'name_suffix' ];
     $other_params->{'select'} = [
@@ -230,7 +236,7 @@ sub get_author_list {
         }
     }
 
-    return $list;
+    return ( wantarray ? ( $list, $anzahl_autoren ) : $list );
 }
 
 #-----------------------------------------------------------------------------------
index 6fcd902d5091f1e8fdb1891d947f3da4e7d63bc6..5b94622897ed18bd2974e3bf7a1d8c14baca2c95 100644 (file)
 
 -->
 
+[% tab_colspan = 4 %][% IF Catalyst.user_exists %][% tab_colspan = 6 %][% END -%]
+
 [% META title = 'Autorenliste' -%]
 
+[% BLOCK navrow %]
+  <tr>
+    <td class="nav" colspan="[% tab_colspan %]"><table cellspacing="0" class="nav" width="100%">
+          <tr>
+              <td width="33%" style="text-align: left;"><b>[% IF autor_liste_page.cur != 1 %]<a href="[% self_url %]?page=1" title="Erste Seite">&lt;&lt;</a>[% ELSE %]&lt;&lt;[% END %]&nbsp;&nbsp;[% IF autor_liste_page.cur != autor_liste_page.prev %]<a href="[% self_url %]?page=[% autor_liste_page.prev %]" title="Vorherige Seite">&lt;</a>[% ELSE %]&lt;[% END %]</b></td>
+              <td width="33%" style="text-align: center;">Autor [% autor_liste_page.autor_from %] bis [% autor_liste_page.autor_to %] von [% autor_liste_page.autoren %]</td>
+              <td width="33%" style="text-align: right;"><b>[% IF autor_liste_page.cur != autor_liste_page.next %]<a href="[% self_url %]?page=[% autor_liste_page.next %]" title="Nächste Seite">&gt;</a>[% ELSE %]&gt;[% END %]&nbsp;&nbsp;[% IF autor_liste_page.cur != autor_liste_page.last %]<a href="[% self_url %]?page=[% autor_liste_page.last %]" title="Letzte Seite">&gt;&gt;</a>[% ELSE %]&gt;&gt;[% END %]</b></td>
+          </tr>
+        </table></td>
+  </tr>
+[% END -%]
+
 <div class="center">
 
 <table class="wrapper" cellspacing="0">
-<tr><th>Liste der Bücher</th> </tr>
+<tr><th>Liste der Autoren</th> </tr>
 [% IF Catalyst.user_exists %]<tr><td class="action"><a href="[% path('/autor/new') %]">Neuer Autor ...</a></td></tr>[% END %]
 <tr><td><table class="autorliste">
   <tr>
@@ -29,7 +43,7 @@
     <th></th>
     [% IF Catalyst.user_exists %]<th></th>
     <th></th>[% END %]
-  </tr>
+  </tr>[% PROCESS navrow %]
 [% rowstyle = 'even' %][%- FOREACH author IN authors -%][% author_id = author.id %]
   <tr>
     <td class="[% rowstyle %]">[% author.name %]</td>
@@ -43,6 +57,6 @@
     <td class="button [% rowstyle %]">[% IF author.books and author.books.size > 0 %]Löschen[% ELSE %]<a href="[% path('/autor/delete') %]?delete_autor_id=[% author.id %]">Löschen</a>[% END %]</td>[% END %]
   </tr>
 [% IF rowstyle == 'even' %][% rowstyle = 'odd'%][% ELSE %][% rowstyle = 'even' %][% END %][% END -%]
-</table></td></tr></table>
+[% PROCESS navrow %]</table></td></tr></table>
 </div>
 <br />