diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 63 | ||||
-rwxr-xr-x | templates/web/base/reports/index.html | 39 |
3 files changed, 77 insertions, 26 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d56976aec..b3c9b96be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Allow multiple wards to be shown on reports page - Don't cover whole map with pin loading indicator. - Add Expand map toggle to more mobile maps. + - Add functionality to have per-body /reports page. - Bugfixes - Shortlist menu item always remains a link #1855 - Fix encoded entities in RSS output. #1859 diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index c30c113ec..e19c7628f 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -69,33 +69,26 @@ sub index : Path : Args(0) { } } - # Fetch all bodies - my @bodies = $c->model('DB::Body')->search({ - deleted => 0, - }, { - '+select' => [ { count => 'area_id' } ], - '+as' => [ 'area_count' ], - join => 'body_areas', - distinct => 1, - })->all; - @bodies = sort { strcoll($a->name, $b->name) } @bodies; - $c->stash->{bodies} = \@bodies; - $c->stash->{any_empty_bodies} = any { $_->get_column('area_count') == 0 } @bodies; - my $dashboard = eval { my $data = FixMyStreet->config('TEST_DASHBOARD_DATA'); unless ($data) { - $data = decode_json(path(FixMyStreet->path_to('../data/all-reports-dashboard.json'))->slurp_utf8); + my $fn = '../data/all-reports-dashboard'; + if ($c->stash->{body}) { + $fn .= '-' . $c->stash->{body}->id; + } + $data = decode_json(path(FixMyStreet->path_to($fn . '.json'))->slurp_utf8); } $c->stash($data); return 1; }; - my $table = eval { + my $table = !$c->stash->{body} && eval { my $data = path(FixMyStreet->path_to('../data/all-reports.json'))->slurp_utf8; $c->stash(decode_json($data)); return 1; }; if (!$dashboard && !$table) { + $c->detach('/page_error_404_not_found') if $c->stash->{body}; + my $message = _("There was a problem showing the All Reports page. Please try again later."); if ($c->config->{STAGING_SITE}) { $message .= '</p><p>Perhaps the bin/update-all-reports script needs running. Use: bin/update-all-reports</p><p>' @@ -104,6 +97,26 @@ sub index : Path : Args(0) { $c->detach('/page_error_500_internal_error', [ $message ]); } + if ($c->stash->{body}) { + my $children = $c->stash->{body}->first_area_children; + unless ($children->{error}) { + $c->stash->{children} = $children; + } + } else { + # Fetch all bodies + my @bodies = $c->model('DB::Body')->search({ + deleted => 0, + }, { + '+select' => [ { count => 'area_id' } ], + '+as' => [ 'area_count' ], + join => 'body_areas', + distinct => 1, + })->all; + @bodies = sort { strcoll($a->name, $b->name) } @bodies; + $c->stash->{bodies} = \@bodies; + $c->stash->{any_empty_bodies} = any { $_->get_column('area_count') == 0 } @bodies; + } + # Down here so that error pages aren't cached. $c->response->header('Cache-Control' => 'max-age=3600'); } @@ -132,6 +145,19 @@ sub ward : Path : Args(2) { my @wards = split /\|/, $ward || ""; $c->forward( 'body_check', [ $body ] ); + + my $body_short = $c->cobrand->short_name( $c->stash->{body} ); + $c->stash->{body_url} = '/reports/' . $body_short; + + if ($ward && $ward eq 'summary') { + if (my $actual_ward = $c->get_param('ward')) { + $ward = $c->cobrand->short_name({ name => $actual_ward }); + $c->res->redirect($ward); + $c->detach; + } + $c->go('index'); + } + $c->forward( 'ward_check', [ @wards ] ) if @wards; $c->forward( 'check_canonical_url', [ $body ] ); @@ -142,13 +168,10 @@ sub ward : Path : Args(2) { $c->detach('ajax', [ 'reports/_problem-list.html' ]); } - my $body_short = $c->cobrand->short_name( $c->stash->{body} ); $c->stash->{rss_url} = '/rss/reports/' . $body_short; $c->stash->{rss_url} .= '/' . $c->cobrand->short_name( $c->stash->{ward} ) if $c->stash->{ward}; - $c->stash->{body_url} = '/reports/' . $body_short; - $c->stash->{stats} = $c->cobrand->get_report_stats(); my @categories = $c->stash->{body}->contacts->not_deleted->search( undef, { @@ -177,9 +200,7 @@ sub ward : Path : Args(2) { # List of wards if ( !$c->stash->{wards} && $c->stash->{body}->id && $c->stash->{body}->body_areas->first ) { - my $children = mySociety::MaPit::call('area/children', [ $c->stash->{body}->body_areas->first->area_id ], - type => $c->cobrand->area_types_children, - ); + my $children = $c->stash->{body}->first_area_children; unless ($children->{error}) { foreach (values %$children) { $_->{url} = $c->uri_for( $c->stash->{body_url} diff --git a/templates/web/base/reports/index.html b/templates/web/base/reports/index.html index a653a2686..70f4b3929 100755 --- a/templates/web/base/reports/index.html +++ b/templates/web/base/reports/index.html @@ -15,7 +15,9 @@ [% INCLUDE 'header.html', title = loc('Dashboard'), bodyclass => 'dashboard fullwidthpage' %] <div class="dashboard-header"> - <h1>[% loc('Dashboard') %]</h1> + <h1>[% loc('Dashboard') %] + [% IF body %] – [% body.name %] [% END %] + </h1> </div> <div class="dashboard-row"> @@ -58,19 +60,31 @@ </div> </div> <div class="dashboard-item dashboard-item--6"> - <form class="dashboard-search" action="/reports"> + <form class="dashboard-search"> <h2>[% loc('Show reports in your area') %]</h2> + [% IF body %] + <label for="ward">[% loc('Pick your ward') %]</label> + <div class="dashboard-search__input"> + <select id="ward" name="ward" class="js-autocomplete"> + <option value="">[% loc('Pick your ward') %]</option> + [% FOR child IN children.values.sort('name') %] + <option>[% child.name | html ~%]</option> + [% END %] + </select> + </div> + [% ELSE %] <label for="body">[% loc('Pick your council') %]</label> <div class="dashboard-search__input"> <select id="body" name="body" class="js-autocomplete"> <option value="">[% loc('Pick your council') %]</option> - [% FOR body IN bodies %] - <option value="[% body.id %]">[% body.name | html ~%] - [% IF NOT body.get_column("area_count") %] [% loc('(no longer exists)') %][% END ~%] + [% FOR b IN bodies # Not body as 'body' may be on stash %] + <option value="[% b.id %]">[% b.name | html ~%] + [% IF NOT b.get_column("area_count") %] [% loc('(no longer exists)') %][% END ~%] </option> [% END %] </select> </div> + [% END %] <div class="dashboard-search__submit"> <input type="submit" value="[% loc('Go') %]"> </div> @@ -80,6 +94,20 @@ <div class="dashboard-row"> <div class="dashboard-item dashboard-item--6"> + [% IF body %] + <h2 class="dashboard-subheading">[% loc('Top 5 wards') %]</h2> + <p>[% loc('Number of problems reported in each ward, in the last 7 days.') %]</p> + <table class="dashboard-ranking-table"> + <tbody> + [% FOR line IN wards %] + <tr><td>[% line.name %]</td><td>[% tprintf(nget("%s report", "%s reports", line.reports), line.reports) %]</td></tr> + [% END %] + </tbody> + <tfoot> + <tr><td>[% loc('Other wards') %]</td><td>[% tprintf(nget("%s report", "%s reports", other_wards), other_wards) %]</td></tr> + </tfoot> + </table> + [% ELSE %] <h2 class="dashboard-subheading">[% loc('Top 5 responsive councils') %]</h2> <p>[% loc('Average time between a problem being reported and being fixed, last 100 reports.') %]</p> <table class="dashboard-ranking-table"> @@ -92,6 +120,7 @@ <tr><td>[% loc('Overall average') %]</td><td>[% tprintf(nget("%s day", "%s days", average), average) %]</td></tr> </tfoot> </table> + [% END %] </div> <div class="dashboard-item dashboard-item--6"> <h2 class="dashboard-subheading">[% loc('Top 5 most used categories') %]</h2> |