diff options
author | Matthew Somerville <matthew@mysociety.org> | 2012-05-04 20:32:59 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2012-05-09 10:19:52 +0100 |
commit | f8ba2f1ea1bb596aa8f9d40bd9c4915a3a44ae4e (patch) | |
tree | 1242268f266dc4cd52d8f1947812275856372c9b | |
parent | 4975c9ed6ed5542e5a3a679cf606cbc1a5a09d44 (diff) |
Dashboard initial start.
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 124 | ||||
-rw-r--r-- | templates/web/default/dashboard/index.html | 131 |
3 files changed, 259 insertions, 6 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 198acade6..21b820423 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -571,8 +571,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; @@ -734,8 +733,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'); @@ -1068,7 +1066,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; @@ -1238,7 +1236,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..74588df36 --- /dev/null +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -0,0 +1,124 @@ +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( '/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/templates/web/default/dashboard/index.html b/templates/web/default/dashboard/index.html new file mode 100644 index 000000000..c54635b2a --- /dev/null +++ b/templates/web/default/dashboard/index.html @@ -0,0 +1,131 @@ +[% + INCLUDE 'header.html' + title = loc('Dashboard') + robots = 'noindex, nofollow' + bodyclass = 'fullwidthpage' +%] + +<style> + th[scope=row] { text-align: left; } + tr.subtotal { background-color: #eee; } + #overview tr:nth-child(2) { background-color: #fee; } +</style> + +<p>Ward: <select name="ward"><option>All</option> + [% FOR ward IN children.values.sort('name') %] + <option value="[% ward.id %]">[% ward.name %]</option> + [% END %] +</select> + +<h2>Performance Overview</h2> + +<p>Report category: <select name="category"><option>All</option> + [% FOR category IN categories %] + <option></option> + [% END %] +</select> + +<table width="100%" id="overview"> + <tr> + <td> </td> + <th scope="col">WTD</th> + <th scope="col">Last 7 days</th> + <th scope="col">Last 4 weeks</th> + <th scope="col">YTD</th> + </tr> + + [% + rows = { + '0' => [ "total", "Total reports received" ] + '1' => [ "fixed - council", "Council has marked as fixed" ] + '2' => [ "fixed_user", "User has marked as fixed" ] + }; + FOR row IN rows %] + <tr> + <th scope="row">[% row.value.1 %]</th> + <td>[% problems.wtd.${row.value.0} %]</td> + <td>[% problems.week.${row.value.0} %]</td> + <td>[% problems.weeks.${row.value.0} %]</td> + <td>[% problems.ytd.${row.value.0} %]</td> + </tr> + [% END %] + + <tr class='subtotal'> + <th scope="row">Total marked as fixed</th> + <td>[% problems.wtd.${"fixed - council"} + problems.wtd.fixed_user %]</td> + <td>[% problems.week.${"fixed - council"} + problems.week.fixed_user %]</td> + <td>[% problems.weeks.${"fixed - council"} + problems.weeks.fixed_user %]</td> + <td>[% problems.ytd.${"fixed - council"} + problems.ytd.fixed_user %]</td> + </tr> + + [% + rows = { + '0' => [ "in progress", "Council has marked as in progress" ] + '1' => [ "planned", "Council has marked as planned" ] + '2' => [ "investigating", "Council has marked as investigating" ] + }; + wtd = 0, week = 0, weeks = 0, ytd = 0; + FOR row IN rows %] + <tr> + <th scope="row">[% row.value.1 %]</th> + <td>[% problems.wtd.${row.value.0} %]</td> + <td>[% problems.week.${row.value.0} %]</td> + <td>[% problems.weeks.${row.value.0} %]</td> + <td>[% problems.ytd.${row.value.0} %]</td> + </tr> + [% END %] + + <tr class='subtotal'> + <th scope="row">Total marked</th> + <td>[% problems.wtd.${"in progress"} + problems.wtd.planned + problems.wtd.investigating %]</td> + <td>[% problems.week.${"in progress"} + problems.week.planned + problems.week.investigating %]</td> + <td>[% problems.weeks.${"in progress"} + problems.weeks.planned + problems.weeks.investigating %]</td> + <td>[% problems.ytd.${"in progress"} + problems.ytd.planned + problems.ytd.investigating %]</td> + </tr> + + <tr> + <th scope="row">Average time to fix</th> + <td>-</td> + <td>-</td> + <td>-</td> + <td>-</td> + </tr> + + <tr> + <th scope="row">Average time to mark</th> + <td>-</td> + <td>-</td> + <td>-</td> + <td>-</td> + </tr> + + <tr class='subtotal'> + <th scope="row">Total not marked</th> + <td>-</td> + <td>-</td> + <td>-</td> + <td>-</td> + </tr> + +</table> + +<h2>Reports</h2> + +<p>Report state: <select name="state"><option>All</option></select> + +<table width="100%"> + <tr> + <th scope="col">Less than 7 days old</th> + <th scope="col">7-14 days old</th> + <th scope="col">14-30 days old</th> + <th scope="col">30+ days old</th> + </tr> + <tr> + <td><ul><li></li></ul></td> + <td><ul><li></li></ul></td> + <td><ul><li></li></ul></td> + <td><ul><li></li></ul></td> + </tr> +</table> + +[% INCLUDE 'footer.html' %] |