diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/Stats.pm | 27 | ||||
-rw-r--r-- | t/app/controller/admin/stats.t | 26 | ||||
-rw-r--r-- | templates/web/base/admin/stats/index.html | 3 | ||||
-rw-r--r-- | templates/web/fixmystreet.com/admin/stats/refused.html | 19 |
4 files changed, 75 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Stats.pm b/perllib/FixMyStreet/App/Controller/Admin/Stats.pm index 2860b3531..5f82094d6 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/Stats.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/Stats.pm @@ -72,4 +72,31 @@ sub questionnaire : Local : Args(0) { return 1; } +sub refused : Local : Args(0) { + my ($self, $c) = @_; + + my $contacts = $c->model('DB::Contact')->not_deleted->search([ + { email => 'REFUSED' }, + { 'body.can_be_devolved' => 1, 'me.send_method' => 'Refused' }, + ], { prefetch => 'body' }); + my %bodies; + while (my $contact = $contacts->next) { + my $body = $contact->body; + $bodies{$body->id}{body} = $body unless $bodies{$body->id}{body}; + push @{$bodies{$body->id}{contacts}}, $contact; + } + + my $bodies = $c->model('DB::Body')->search({ send_method => 'Refused' }); + while (my $body = $bodies->next) { + $bodies{$body->id}{body} = $body; + $bodies{$body->id}{all} = 1; + } + + my @bodies; + foreach (sort { $bodies{$a}{body}->name cmp $bodies{$b}{body}->name } keys %bodies) { + push @bodies, $bodies{$_}; + } + $c->stash->{bodies} = \@bodies; +} + 1; diff --git a/t/app/controller/admin/stats.t b/t/app/controller/admin/stats.t index dae51d31f..ce6f8466c 100644 --- a/t/app/controller/admin/stats.t +++ b/t/app/controller/admin/stats.t @@ -9,4 +9,30 @@ subtest "smoke view some stats pages" => sub { $mech->get_ok('/admin/stats/questionnaire'); }; +subtest "test refused stats page works" => sub { + my $body1 = $mech->create_body_ok(2651, 'Edinburgh Council'); + my $body2 = $mech->create_body_ok(2237, 'Oxfordshire Council', { send_method => 'Refused' }); + my $body3 = $mech->create_body_ok(2243, 'Warwickshire Council', { can_be_devolved => 1 }); + $mech->create_contact_ok(body_id => $body1->id, category => 'Street lighting', email => 'REFUSED'); + $mech->create_contact_ok(body_id => $body1->id, category => 'Potholes', email => 'potholes@example.org'); + $mech->create_contact_ok(body_id => $body2->id, category => 'Potholes', email => 'potholes@example.org'); + $mech->create_contact_ok(body_id => $body3->id, category => 'Street lighting', email => 'lights@example.org'); + $mech->create_contact_ok(body_id => $body3->id, category => 'Potholes', email => 'potholes@example.org', send_method => 'Refused'); + + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + }, sub { + $mech->get_ok('/admin/stats/refused'); + }; + $mech->content =~ /class="content"(.*)class="nav-wrapper/s; + my @lines = split /<li>/, $1; + is @lines, 7; + like $lines[1], qr/Edinburgh/; + like $lines[2], qr/Street lighting/; + like $lines[3], qr/Oxfordshire/; + like $lines[4], qr/ALL/; + like $lines[5], qr/Warwickshire/; + like $lines[6], qr/Potholes/; +}; + done_testing(); diff --git a/templates/web/base/admin/stats/index.html b/templates/web/base/admin/stats/index.html index 6ea1ae403..d47054427 100644 --- a/templates/web/base/admin/stats/index.html +++ b/templates/web/base/admin/stats/index.html @@ -5,6 +5,9 @@ <li><a href="[% c.uri_for_action('admin/stats/state') %]">[% loc('Problem breakdown by state') %]</a></li> <li><a href="[% c.uri_for_action('admin/stats/fix_rate') %]">[% loc('Category fix rate for problems > 4 weeks old') %]</a></li> <li><a href="[% c.uri_for_action('dashboard/index') %]">[% loc('Summary statistics') %]</a></li> +[% IF c.cobrand.moniker == 'fixmystreet' %] +<li><a href="[% c.uri_for_action('admin/stats/refused') %]">Refused</a></li> +[% END %] </ul> [% INCLUDE 'admin/footer.html' %] diff --git a/templates/web/fixmystreet.com/admin/stats/refused.html b/templates/web/fixmystreet.com/admin/stats/refused.html new file mode 100644 index 000000000..513416cf5 --- /dev/null +++ b/templates/web/fixmystreet.com/admin/stats/refused.html @@ -0,0 +1,19 @@ +[% INCLUDE 'admin/header.html' title=loc('Refused bodies') -%] + +<ul> +[%~ FOR data IN bodies; + SET body = data.body %] + <li>[% body.name %] + <ul> + [%~ IF data.all %] + <li>ALL</li> + [%~ END %] + [%~ IF data.contacts.size; FOR c IN data.contacts %] + <li>[% c.category %]</li> + [%~ END; END %] + </ul> + </li> +[%~ END %] +</ul> + +[% INCLUDE admin/footer.html %] |