]> git.decadent.org.uk Git - maypole.git/commitdiff
This gives us row ordering by column.
authorSimon Cozens <simon@simon-cozens.org>
Thu, 5 Feb 2004 17:44:27 +0000 (17:44 +0000)
committerSimon Cozens <simon@simon-cozens.org>
Thu, 5 Feb 2004 17:44:27 +0000 (17:44 +0000)
git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@47 48953598-375a-da11-a14b-00016c27c3ee

lib/Apache/MVC/Model/CDBI.pm
templates/factory/list
templates/factory/pager

index 854118e1559f2007fda5983a31a41b2708a604ae..2d2aa2b123a35c9d19ffe944eaa2acc949eff64b 100644 (file)
@@ -4,6 +4,7 @@ use Lingua::EN::Inflect::Number qw(to_PL);
 use Class::DBI::AsForm;
 use Class::DBI::FromCGI;
 use Class::DBI::AbstractSearch;
+use Class::DBI::Plugin::RetrieveAll;
 use Class::DBI::Pager;
 use CGI::Untaint;
 use strict;
@@ -83,11 +84,19 @@ sub search :Exported {
 
 sub list :Exported {
     my ($self, $r) = @_;
+    my %ok_columns = map {$_ => 1} $self->columns;
     if ( my $rows = $r->config->{rows_per_page}) {
         $self = $self->pager($rows, $r->query->{page});
         $r->{template_args}{pager} = $self;
     } 
-    $r->objects([ $self->retrieve_all ]);
+    my $order;
+    if ($order = $r->query->{order} and $ok_columns{$order}) {
+        $r->objects([ $self->retrieve_all_sorted_by( $order.
+            ($r->query->{o2} eq "desc" && " DESC")
+        )]);
+    } else {
+        $r->objects([ $self->retrieve_all ]);
+    }
 }
 1;
 
index 2a159648187e4d099715f8a39a57855febfd3e9a..f1290efb1b9dd57607cf07f085984b28252dc114 100644 (file)
 <TR>
 [% FOR col = classmetadata.columns.list;
     NEXT IF col == "id";
-    "<TH>"; classmetadata.colnames.$col; "</TH>";
+    "<TH>"; 
+        '<A HREF="'; base; classmetadata.moniker; "/list/?";
+        "page=" _ pager.current_page _ "&" IF pager;
+        "order="; col; 
+        "&o2=desc" IF col == request.query.order and request.query.o2 != "desc";
+        '">';
+        classmetadata.colnames.$col; 
+        '</A>';
+    "</TH>";
 END %]
 </TR>
 
index 9053098e37e2ec7eba8c49c47a91895e517dd46c..9defa40e0417d6efd028e0ed31579da4a3ffe487 100644 (file)
@@ -8,7 +8,7 @@ IF pager AND pager.first_page != pager.last_page;
           IF num == pager.current_page;
             "["; num; "] ";
           ELSE;
-          '<A HREF="'; base; table; "/list/?page="; num; '">';
+          '<A HREF="'; base; classmetadata.moniker; "/list/?page="; num; '">';
             "["; num; "]";
           '</A> ';
           END;