diff options
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Reports.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 55 |
1 files changed, 15 insertions, 40 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 68dbd6359..9fb72121e 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -102,7 +102,6 @@ sub ward : Path : Args(2) { $c->forward( 'load_parent' ); $c->forward( 'check_canonical_url', [ $council ] ); $c->forward( 'load_and_group_problems' ); - $c->forward( 'sort_problems' ); my $council_short = $c->cobrand->short_name( $c->stash->{council}, $c->stash->{areas_info} ); $c->stash->{rss_url} = '/rss/reports/' . $council_short; @@ -342,8 +341,12 @@ sub load_and_group_problems : Private { { columns => [ 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', - { duration => { extract => "epoch from current_timestamp-lastupdate" } }, - { age => { extract => "epoch from current_timestamp-confirmed" } }, + #{ duration => { extract => "epoch from current_timestamp-lastupdate" } }, + #{ age => { extract => "epoch from current_timestamp-confirmed" } }, + { confirmed => { extract => 'epoch from confirmed' } }, + { whensent => { extract => 'epoch from whensent' } }, + { lastupdate => { extract => 'epoch from lastupdate' } }, + { photo => 'photo is not null' }, ], order_by => { -desc => 'lastupdate' }, rows => 100, @@ -352,17 +355,18 @@ sub load_and_group_problems : Private { $c->stash->{pager} = $problems->pager; $problems = $problems->cursor; # Raw DB cursor for speed - my ( %fixed, %open, @pins ); + my ( %problems, @pins ); my $re_councils = join('|', keys %{$c->stash->{areas_info}}); - my @cols = ( 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'duration', 'age' ); + my @cols = ( 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'confirmed', 'whensent', 'lastupdate', 'photo' ); while ( my @problem = $problems->next ) { my %problem = zip @cols, @problem; + $problem{is_fixed} = FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}}; $c->log->debug( $problem{'cobrand'} . ', cobrand is ' . $c->cobrand->moniker ); if ( !$problem{council} ) { # Problem was not sent to any council, add to possible councils $problem{councils} = 0; while ($problem{areas} =~ /,($re_councils)(?=,)/g) { - add_row( \%problem, $1, \%fixed, \%open, \@pins ); + add_row( \%problem, $1, \%problems, \@pins ); } } else { # Add to councils it was sent to @@ -371,37 +375,19 @@ sub load_and_group_problems : Private { $problem{councils} = scalar @council; foreach ( @council ) { next if $c->stash->{council} && $_ != $c->stash->{council}->{id}; - add_row( \%problem, $_, \%fixed, \%open, \@pins ); + add_row( \%problem, $_, \%problems, \@pins ); } } } $c->stash( - fixed => \%fixed, - open => \%open, + problems => \%problems, pins => \@pins, ); return 1; } -sub sort_problems : Private { - my ( $self, $c ) = @_; - - my $id = $c->stash->{council}->{id}; - my $fixed = $c->stash->{fixed}; - my $open = $c->stash->{open}; - - foreach (qw/new old/) { - $c->stash->{fixed}{$id}{$_} = [ sort { $a->{duration} <=> $b->{duration} } @{$fixed->{$id}{$_}} ] - if $fixed->{$id}{$_}; - } - foreach (qw/new older unknown/) { - $c->stash->{open}{$id}{$_} = [ sort { $a->{age} <=> $b->{age} } @{$open->{$id}{$_}} ] - if $open->{$id}{$_}; - } -} - sub redirect_index : Private { my ( $self, $c ) = @_; my $url = '/reports'; @@ -419,24 +405,13 @@ sub redirect_area : Private { $c->res->redirect( $c->uri_for($url) ); } -my $fourweeks = 4*7*24*60*60; sub add_row { - my ( $problem, $council, $fixed, $open, $pins ) = @_; - my $duration_str = ( $problem->{duration} > 2 * $fourweeks ) ? 'old' : 'new'; - my $type = ( $problem->{duration} > 2 * $fourweeks ) - ? 'unknown' - : ($problem->{age} > $fourweeks ? 'older' : 'new'); - # Fixed problems are either old or new - push @{$fixed->{$council}{$duration_str}}, $problem if - exists FixMyStreet::DB::Result::Problem->fixed_states()->{$problem->{state}}; - # Open problems are either unknown, older, or new - push @{$open->{$council}{$type}}, $problem if - exists FixMyStreet::DB::Result::Problem->open_states->{$problem->{state}}; - + my ( $problem, $council, $problems, $pins ) = @_; + push @{$problems->{$council}}, $problem; push @$pins, { latitude => $problem->{latitude}, longitude => $problem->{longitude}, - colour => FixMyStreet::DB::Result::Problem->fixed_states()->{$problem->{state}} ? 'green' : 'red', + colour => 'yellow', # FixMyStreet::DB::Result::Problem->fixed_states()->{$problem->{state}} ? 'green' : 'red', id => $problem->{id}, title => $problem->{title}, }; |