diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-11-01 16:56:08 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-11-04 17:24:46 +0000 |
commit | 051093f803444d99c48d130d59dcfe2ba9759c90 (patch) | |
tree | 7407d9616442dc5bc9c81f29532b9a5b7704b6f5 /perllib/FixMyStreet/App/Controller/Reports.pm | |
parent | b3bb51dab4f620463c551e7bbe6814d415ebf227 (diff) |
Add sort order options to list pages.
Includes newest, oldest, least/most recently updated, and most comments.
The default remains the same, which is last updated on /reports, and
newest on /my and /around (the latter plus not-in-view
sorted-by-distance ones).
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Reports.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index f05096525..813c2052d 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -365,6 +365,8 @@ sub check_canonical_url : Private { sub load_and_group_problems : Private { my ( $self, $c ) = @_; + $c->forward('stash_report_sort', [ $c->cobrand->reports_ordering ]); + my $page = $c->get_param('p') || 1; # NB: If 't' is specified, it will override 'status'. my $type = $c->get_param('t') || 'all'; @@ -411,10 +413,10 @@ sub load_and_group_problems : Private { $problems = $problems->search( $where, { - order_by => $c->cobrand->reports_ordering, + order_by => $c->stash->{sort_order}, rows => $c->cobrand->reports_per_page, } - )->page( $page ); + )->include_comment_counts->page( $page ); $c->stash->{pager} = $problems->pager; my ( %problems, @pins ); @@ -502,6 +504,27 @@ sub stash_report_filter_status : Private { return 1; } +sub stash_report_sort : Private { + my ( $self, $c, $default ) = @_; + + my %types = ( + updated => 'lastupdate', + created => 'confirmed', + comments => 'comment_count', + ); + + my $sort = $c->get_param('sort') || $default; + $sort = $default unless $sort =~ /^((updated|created)-(desc|asc)|comments-desc)$/; + $sort =~ /^(updated|created|comments)-(desc|asc)$/; + my $order_by = $types{$1} || $1; + my $dir = $2; + $order_by = { -desc => $order_by } if $dir eq 'desc'; + + $c->stash->{sort_key} = $sort; + $c->stash->{sort_order} = $order_by; + return 1; +} + sub add_row { my ( $c, $problem, $body, $problems, $pins ) = @_; push @{$problems->{$body}}, $problem; |