diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 126 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 30 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bromley.pm | 33 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 2 |
5 files changed, 193 insertions, 8 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 42e218f61..d11f1645e 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -547,8 +547,7 @@ sub report_edit : Path('report_edit') : Args(1) { } )->first; - $c->detach( '/page_error_404_not_found', - [ _('The requested URL was not found on this server.') ] ) + $c->detach( '/page_error_404_not_found' ) unless $problem; $c->stash->{problem} = $problem; @@ -710,8 +709,7 @@ sub update_edit : Path('update_edit') : Args(1) { } )->first; - $c->detach( '/page_error_404_not_found', - [ _('The requested URL was not found on this server.') ] ) + $c->detach( '/page_error_404_not_found' ) unless $update; $c->forward('get_token'); @@ -1044,7 +1042,7 @@ sub check_token : Private { my ( $self, $c ) = @_; if ( !$c->req->param('token') || $c->req->param('token' ) ne $c->stash->{token} ) { - $c->detach( '/page_error_404_not_found', [ _('The requested URL was not found on this server.') ] ); + $c->detach( '/page_error_404_not_found' ); } return 1; @@ -1214,7 +1212,7 @@ sub check_page_allowed : Private { $page ||= 'summary'; if ( !grep { $_ eq $page } keys %{ $c->stash->{allowed_pages} } ) { - $c->detach( '/page_error_404_not_found', [ _('The requested URL was not found on this server.') ] ); + $c->detach( '/page_error_404_not_found' ); } return 1; diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm new file mode 100644 index 000000000..6c327d479 --- /dev/null +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -0,0 +1,126 @@ +package FixMyStreet::App::Controller::Dashboard; +use Moose; +use namespace::autoclean; + +use DateTime; + +BEGIN { extends 'Catalyst::Controller'; } + +=head1 NAME + +FixMyStreet::App::Controller::Dashboard - Catalyst Controller + +=head1 DESCRIPTION + +Catalyst Controller. + +=head1 METHODS + +=cut + +=head2 check_page_allowed + +Checks if we can view this page, and if not redirect to 404. + +=cut + +sub check_page_allowed : Private { + my ( $self, $c ) = @_; + + $c->detach( '/auth/redirect' ) unless $c->user_exists; + + $c->detach( '/page_error_404_not_found' ) + unless $c->user_exists && $c->user->from_council; + + return $c->user->from_council; +} + +=head2 index + +Show the dashboard table. + +=cut + +sub index : Path : Args(0) { + my ( $self, $c ) = @_; + + my $council = $c->forward('check_page_allowed'); + + my $children = mySociety::MaPit::call('area/children', $council, + type => $mySociety::VotingArea::council_child_types, + ); + $c->stash->{children} = $children; + + my %counts; + my $t = DateTime->today; + + $counts{wtd} = $c->forward( 'updates_search', [ { + council => $council, + 'me.confirmed' => { '>=', $t->subtract( days => $t->dow - 1 ) + } } ] ); + + $counts{week} = $c->forward( 'updates_search', [ { + council => $council, + 'me.confirmed' => { '>=', DateTime->now->subtract( weeks => 1 ) + } } ] ); + + $counts{weeks} = $c->forward( 'updates_search', [ { + council => $council, + 'me.confirmed' => { '>=', DateTime->now->subtract( weeks => 4 ) + } } ] ); + + $counts{ytd} = $c->forward( 'updates_search', [ { + council => $council, + 'me.confirmed' => { '>=', DateTime->today->set( day => 1, month => 1 ) + } } ] ); + + $c->stash->{problems} = \%counts; +} + +sub updates_search : Private { + my ( $self, $c, $params ) = @_; + + my $comments = $c->model('DB::Comment')->search( + $params, + { + group_by => [ 'problem_state' ], + select => [ 'problem_state', { count => 'me.id' } ], + as => [ qw/state state_count/ ], + join => 'problem' + } + ); + + my %counts = + map { ($_->state||'-') => $_->get_column('state_count') } $comments->all; + %counts = + map { $_ => $counts{$_} || 0 } + ('confirmed', 'investigating', 'in progress', 'closed', 'fixed - council', + 'fixed - user', 'fixed', 'unconfirmed', 'hidden', + 'partial', 'planned'); + + $counts{fixed_user} = $c->model('DB::Comment')->search( + { %$params, mark_fixed => 1 }, { join => 'problem' } + )->count; + + $counts{total} = $c->cobrand->problems->search( + { %$params, state => [ FixMyStreet::DB::Result::Problem::visible_states() ] } + )->count; + + return \%counts; +} + +=head1 AUTHOR + +Matthew Somerville + +=head1 LICENSE + +Copyright (c) 2012 UK Citizens Online Democracy. All rights reserved. +Licensed under the Affero GPL. + +=cut + +__PACKAGE__->meta->make_immutable; + +1; + diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index afe180c29..cca625bd5 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -153,6 +153,36 @@ sub generate_map_tags : Private { return 1; } +sub delete :Local :Args(1) { + my ( $self, $c, $id ) = @_; + + $c->forward( 'load_problem_or_display_error', [ $id ] ); + my $p = $c->stash->{problem}; + + my $uri = $c->uri_for( '/report', $id ); + + return $c->res->redirect($uri) unless $c->user_exists; + + my $council = $c->user->obj->from_council; + return $c->res->redirect($uri) unless $council; + + my %councils = map { $_ => 1 } @{$p->councils}; + return $c->res->redirect($uri) unless $councils{$council}; + + $p->state('hidden'); + $p->lastupdate( \'ms_current_timestamp()' ); + $p->update; + + $c->model('DB::AdminLog')->create( { + admin_user => $c->user->email, + object_type => 'problem', + action => 'state_change', + object_id => $id, + } ); + + return $c->res->redirect($uri); +} + __PACKAGE__->meta->make_immutable; 1; diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm index acdefb41e..5bc292306 100644 --- a/perllib/FixMyStreet/Cobrand/Bromley.pm +++ b/perllib/FixMyStreet/Cobrand/Bromley.pm @@ -36,6 +36,10 @@ sub example_places { return ( 'BR1 3UH', 'Glebe Rd, Bromley' ); } +sub on_map_default_max_pin_age { + return '1 month'; +} + sub recent_photos { my ( $self, $area, $num, $lat, $lon, $dist ) = @_; $num = 3 if $num > 3 && $area eq 'alert'; @@ -44,10 +48,37 @@ sub recent_photos { sub pin_colour { my ( $self, $p ) = @_; - return 'green' if time() - $p->confirmed_local->epoch < 7 * 24 * 60 * 60; + #return 'green' if time() - $p->confirmed_local->epoch < 7 * 24 * 60 * 60; return 'yellow'; } +# Copy of function from FixMyStreet.pm cobrand as it's not inherited currently +sub generate_problem_banner { + my ( $self, $problem ) = @_; + + my $banner = {}; + if ( $problem->is_open && time() - $problem->lastupdate_local->epoch > 8 * 7 * 24 * 60 * 60 ) + { + $banner->{id} = 'unknown'; + $banner->{text} = _('Unknown'); + } + if ($problem->is_fixed) { + $banner->{id} = 'fixed'; + $banner->{text} = _('Fixed'); + } + if ($problem->is_closed) { + $banner->{id} = 'closed'; + $banner->{text} = _('Closed'); + } + + if ( grep { $problem->state eq $_ } ( 'investigating', 'in progress', 'planned' ) ) { + $banner->{id} = 'progress'; + $banner->{text} = _('In progress'); + } + + return $banner; +} + sub process_extras { my $self = shift; my $ctx = shift; diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 6788447d7..7f43d1a52 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -195,7 +195,7 @@ sub split_name { my ($first, $last) = $self->name =~ /^(\S*)(?: (.*))?$/; - return { first => $first, last => $last }; + return { first => $first || '', last => $last || '' }; } 1; |