diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 59 | ||||
-rw-r--r-- | templates/web/default/admin/header.html | 1 | ||||
-rw-r--r-- | templates/web/default/admin/stats.html | 35 |
3 files changed, 95 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index a7b0bda0f..af87e39fd 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -755,6 +755,64 @@ sub list_flagged : Path('list_flagged') : Args(0) { return 1; } +sub stats : Path('stats') : Args(0) { + my ( $self, $c ) = @_; + + $c->forward('check_page_allowed'); + + if ( $c->req->param('getcounts') ) { + + my ( $start_date, $end_date, @errors ); + + eval { + $start_date = DateTime->new( + year => $c->req->param('start_date_year'), + month => $c->req->param('start_date_month'), + day => $c->req->param('start_date_day'), + ); + }; + + push @errors, _('Invalid start date') if $@; + + eval { + $end_date = DateTime->new( + year => $c->req->param('end_date_year'), + month => $c->req->param('end_date_month'), + day => $c->req->param('end_date_day'), + ); + }; + + push @errors, _('Invalid end date') if $@; + + $c->stash->{errors} = \@errors; + $c->stash->{start_date} = $start_date; + $c->stash->{end_date} = $end_date; + + $c->stash->{unconfirmed} = $c->req->param('unconfirmed') eq 'on' ? 1 : 0; + + return 1 if @errors; + + my $field = 'confirmed'; + + $field = 'created' if $c->req->param('unconfirmed'); + + my $p = $c->model('DB::Problem')->search( + { + -AND => [ + $field => { '>=', $start_date->ymd }, + $field => { '<=', $end_date->ymd }, + ], + } + ); + + # in case the total_report count is 0 + $c->stash->{show_count} = 1; + $c->stash->{total_reports} = $p->count; + } + + return 1; +} + =head2 set_allowed_pages Sets up the allowed_pages stash entry for checking if the current page is @@ -776,6 +834,7 @@ sub set_allowed_pages : Private { 'questionnaire' => [_('Survey Results'), 4], 'search_abuse' => [_('Search Abuse'), 5], 'list_flagged' => [_('List Flagged'), 6], + 'stats' => [_('Stats'), 6], 'council_contacts' => [undef, undef], 'council_edit' => [undef, undef], 'report_edit' => [undef, undef], diff --git a/templates/web/default/admin/header.html b/templates/web/default/admin/header.html index 261f0efb2..e0317cca0 100644 --- a/templates/web/default/admin/header.html +++ b/templates/web/default/admin/header.html @@ -5,6 +5,7 @@ dt { clear: left; float: left; font-weight: bold; } dd { margin-left: 8em; } .hidden { color: #666666; } +.error { color: red; } </style> </head> <body> diff --git a/templates/web/default/admin/stats.html b/templates/web/default/admin/stats.html new file mode 100644 index 000000000..17776c41c --- /dev/null +++ b/templates/web/default/admin/stats.html @@ -0,0 +1,35 @@ +[% INCLUDE 'admin/header.html' title=loc('Stats') %] + +[% IF show_count %] +<strong>[% tprintf( loc( 'Total %sreports between %s and %s: %d' ), ( unconfirmed ? '' : loc( 'confirmed' ) _ ' ' ), start_date.ymd, end_date.ymd, total_reports ) | html %]</strong> +[% END %] + +[% IF errors %] + [% FOREACH error IN errors %] + <p class="error">[% error %]</p> + [% END %] +[% END %] + +<form method="post" action="[% c.uri_for('stats') %]" enctype="application/x-www-form-urlencoded" accept-charset="utf-8"> + <p> + <label for="start_date_year">[% loc('Start Year:') %]</label><input type="text" name="start_date_year" id="start_date_year" size="5" value="[% start_date ? start_date.year : '' | html %]" /> + <label for="start_date_month">[% loc('Start month:') %]</label><input type="text" name="start_date_month" id="start_date_month" size="3" value="[% start_date ? start_date.month : '' | html %]" /> + <label for="start_date_day">[% loc('Start day:') %]</label><input type="text" name="start_date_day" id="start_date_day" size="3" value="[% start_date ? start_date.day : '' | html %]" /> + </p> + + <p> + <label for="end_date_year">[% loc('End Year:') %]</label><input type="text" name="end_date_year" id="end_date_year" size="5" value="[% end_date ? end_date.year : '' | html %]" /> + <label for="end_date_month">[% loc('End month:') %]</label><input type="text" name="end_date_month" id="end_date_month" size="3" value="[% end_date ? end_date.month : '' | html %]" /> + <label for="end_date_day">[% loc('End day:') %]</label><input type="text" name="end_date_day" id="end_date_day" size="3" value="[% end_date ? end_date.day : '' | html %]" /> + </p> + + <p> + <input type="checkbox" name="unconfirmed" id="unconfirmed"[% unconfirmed ? ' checked' : '' %] /><label for="unconfirmed">[% loc('Include unconfirmed reports') %]</label> + </p> + + <p> + <input type="submit" name="getcounts" size="30" id="getcounts" value="Get Count" /> + </p> +</form> + +[% INCLUDE 'admin/footer.html' %] |