From e039a7e191d1f352b5d24bf5f965f2efeb5dc3de Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 20 May 2016 14:33:37 +0100 Subject: Add search boxes to admin index page, move stats. Move most index page statistics to their own pages. --- perllib/FixMyStreet/App/Controller/Admin.pm | 67 +++++++++++++++++----------- perllib/FixMyStreet/App/Controller/Status.pm | 2 +- templates/web/base/admin/index.html | 57 +++++++++++------------ templates/web/base/admin/stats.html | 7 +++ templates/web/base/admin/stats_by_state.html | 24 ++++++++++ templates/web/base/admin/stats_fix_rate.html | 10 +++++ templates/web/base/status/stats.html | 2 +- 7 files changed, 108 insertions(+), 61 deletions(-) create mode 100644 templates/web/base/admin/stats_by_state.html create mode 100644 templates/web/base/admin/stats_fix_rate.html diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index db9545830..4e288556f 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -71,25 +71,7 @@ sub index : Path : Args(0) { return $c->cobrand->admin(); } - my $problems = $c->cobrand->problems->summary_count; - - my %prob_counts = - map { $_->state => $_->get_column('state_count') } $problems->all; - - %prob_counts = - map { $_ => $prob_counts{$_} || 0 } - ( FixMyStreet::DB::Result::Problem->all_states() ); - $c->stash->{problems} = \%prob_counts; - $c->stash->{total_problems_live} += $prob_counts{$_} ? $prob_counts{$_} : 0 - for ( FixMyStreet::DB::Result::Problem->visible_states() ); - $c->stash->{total_problems_users} = $c->cobrand->problems->unique_users; - - my $comments = $c->cobrand->updates->summary_count; - - my %comment_counts = - map { $_->state => $_->get_column('state_count') } $comments->all; - - $c->stash->{comments} = \%comment_counts; + $c->forward('stats_by_state'); my $alerts = $c->model('DB::Alert')->summary_report_alerts( $c->cobrand->restriction ); @@ -129,11 +111,7 @@ sub index : Path : Args(0) { : _('n/a'); $c->stash->{questionnaires} = \%questionnaire_counts; - if ($c->get_param('show_categories')) { - $c->stash->{categories} = $c->cobrand->problems->categories_summary(); - } - - $c->stash->{total_bodies} = $c->model('DB::Body')->count(); + $c->forward('fetch_all_bodies'); return 1; } @@ -196,7 +174,7 @@ sub timeline : Path( 'timeline' ) : Args(0) { return 1; } -sub questionnaire : Path('questionnaire') : Args(0) { +sub questionnaire : Path('stats/questionnaire') : Args(0) { my ( $self, $c ) = @_; my $questionnaires = $c->model('DB::Questionnaire')->search( @@ -232,6 +210,11 @@ sub questionnaire : Path('questionnaire') : Args(0) { sub bodies : Path('bodies') : Args(0) { my ( $self, $c ) = @_; + if (my $body_id = $c->get_param('body')) { + $c->res->redirect( $c->uri_for( 'body', $body_id ) ); + return; + } + $c->forward( 'get_token' ); my $edit_activity = $c->model('DB::ContactsHistory')->search( @@ -1187,6 +1170,36 @@ sub flagged : Path('flagged') : Args(0) { return 1; } +sub stats_by_state : Path('stats/state') : Args(0) { + my ( $self, $c ) = @_; + + my $problems = $c->cobrand->problems->summary_count; + + my %prob_counts = + map { $_->state => $_->get_column('state_count') } $problems->all; + + %prob_counts = + map { $_ => $prob_counts{$_} || 0 } + ( FixMyStreet::DB::Result::Problem->all_states() ); + $c->stash->{problems} = \%prob_counts; + $c->stash->{total_problems_live} += $prob_counts{$_} ? $prob_counts{$_} : 0 + for ( FixMyStreet::DB::Result::Problem->visible_states() ); + $c->stash->{total_problems_users} = $c->cobrand->problems->unique_users; + + my $comments = $c->cobrand->updates->summary_count; + + my %comment_counts = + map { $_->state => $_->get_column('state_count') } $comments->all; + + $c->stash->{comments} = \%comment_counts; +} + +sub stats_fix_rate : Path('stats/fix-rate') : Args(0) { + my ( $self, $c ) = @_; + + $c->stash->{categories} = $c->cobrand->problems->categories_summary(); +} + sub stats : Path('stats') : Args(0) { my ( $self, $c ) = @_; @@ -1285,7 +1298,6 @@ sub set_allowed_pages : Private { 'bodies' => [_('Bodies'), 1], 'reports' => [_('Reports'), 2], 'timeline' => [_('Timeline'), 3], - 'questionnaire' => [_('Survey'), 4], 'users' => [_('Users'), 5], 'flagged' => [_('Flagged'), 6], 'stats' => [_('Stats'), 7], @@ -1552,7 +1564,8 @@ sub check_page_allowed : Private { $c->forward('set_allowed_pages'); - (my $page = $c->req->action) =~ s#admin/?##; + (my $page = $c->req->path) =~ s#admin/?##; + $page =~ s#/.*##; $page ||= 'summary'; diff --git a/perllib/FixMyStreet/App/Controller/Status.pm b/perllib/FixMyStreet/App/Controller/Status.pm index 931c7bd47..57c8f362e 100755 --- a/perllib/FixMyStreet/App/Controller/Status.pm +++ b/perllib/FixMyStreet/App/Controller/Status.pm @@ -58,7 +58,7 @@ sub index : Path : Args(0) { alerts_unconfirmed => $c->stash->{alerts}{0}, questionnaires_sent => $c->stash->{questionnaires}{total}, questionnaires_answered => $c->stash->{questionnaires}{1}, - bodies => $c->stash->{total_bodies}, + bodies => scalar @{$c->stash->{bodies}}, contacts => $c->stash->{contacts}{total}, }; my $body = JSON->new->utf8(1)->pretty->encode($data); diff --git a/templates/web/base/admin/index.html b/templates/web/base/admin/index.html index 4c4a7b388..66d986aaf 100644 --- a/templates/web/base/admin/index.html +++ b/templates/web/base/admin/index.html @@ -12,7 +12,7 @@ or get in touch to let us know about your use of the FixMyStreet Platform, and to receive notices of updates. -[% IF total_bodies == 0 %] +[% IF bodies.size == 0 %]

[% loc('Currently no bodies have been created.') %]
@@ -20,14 +20,31 @@ and to receive notices of updates.

[% END %] -[%- BLOCK states -%] -[%- FOREACH state IN list %] -[%- '" IF loop.last %] -[%- END %] -[% END -%] +
+

+ +

+ +
+

+ +

+ +
+ + + +
+

[% loc('Stats') %]

[% INCLUDE 'status/stats.html' admin_include_users=1 %] [% IF c.cobrand.admin_show_creation_graph -%] @@ -36,28 +53,4 @@ and to receive notices of updates.

[% END -%] -

[% loc('Problem breakdown by state') %]

-[% FOREACH group IN state_groups %] -[%- '" IF loop.last %] -[%- END %] - -

[% loc('Update breakdown by state') %]

-[% PROCESS states object=comments list=comments.keys.sort %] - -[% IF categories.size %] -

[% loc('Category fix rate for problems > 4 weeks old') %]

- - -[% FOREACH category IN categories %] - -[% END %] -
[% loc('Category') %][% loc('Total') %][% loc('Fixed') %]
[% category.key %][% category.value.total %][% category.value.fixed / category.value.total * 100 | format('%.1f') %]%
-[% ELSE %] -

[% loc('Category fix rate for problems > 4 weeks old') %]

-[% END %] - [% INCLUDE 'admin/footer.html' %] diff --git a/templates/web/base/admin/stats.html b/templates/web/base/admin/stats.html index d143d9f28..5aaf59068 100644 --- a/templates/web/base/admin/stats.html +++ b/templates/web/base/admin/stats.html @@ -51,6 +51,13 @@ [% loc( 'Note that when including unconfirmed reports we use the date the report was created which may not be in the same month the report was confirmed so the numbers may jump about a little' ) %]

[% END %] +[% ELSE %] + + [% END %] [% IF errors %] diff --git a/templates/web/base/admin/stats_by_state.html b/templates/web/base/admin/stats_by_state.html new file mode 100644 index 000000000..b003d934e --- /dev/null +++ b/templates/web/base/admin/stats_by_state.html @@ -0,0 +1,24 @@ +[% INCLUDE 'admin/header.html' title=loc('Stats') -%] +[% PROCESS 'admin/report_blocks.html' %] + +[%- BLOCK states -%] +[%- FOREACH state IN list %] +[%- '" IF loop.last %] +[%- END %] +[% END -%] + +

[% loc('Problem breakdown by state') %]

+[% FOREACH group IN state_groups %] +[%- '" IF loop.last %] +[%- END %] + +

[% loc('Update breakdown by state') %]

+[% PROCESS states object=comments list=comments.keys.sort %] + +[% INCLUDE 'admin/footer.html' %] diff --git a/templates/web/base/admin/stats_fix_rate.html b/templates/web/base/admin/stats_fix_rate.html new file mode 100644 index 000000000..fb88a1c06 --- /dev/null +++ b/templates/web/base/admin/stats_fix_rate.html @@ -0,0 +1,10 @@ +[% INCLUDE 'admin/header.html' title=loc('Category fix rate for problems > 4 weeks old') -%] + + + +[% FOREACH category IN categories %] + +[% END %] +
[% loc('Category') %][% loc('Total') %][% loc('Fixed') %]
[% category.key %][% category.value.total %][% category.value.fixed / category.value.total * 100 | format('%.1f') %]%
+ +[% INCLUDE 'admin/footer.html' %] diff --git a/templates/web/base/status/stats.html b/templates/web/base/status/stats.html index f847db2ef..0f201920d 100644 --- a/templates/web/base/status/stats.html +++ b/templates/web/base/status/stats.html @@ -8,7 +8,7 @@ alerts_0 = alerts.0 | format_number; questionnaires_total = questionnaires.total | format_number; questionnaires_1 = questionnaires.1 | format_number; - total_bodies = total_bodies | format_number; + total_bodies = bodies.size | format_number; contacts_total = contacts.total | format_number; contacts_1 = contacts.1 | format_number; contacts_0 = contacts.0 | format_number; -- cgit v1.2.3