diff options
author | Struan Donald <struan@exo.org.uk> | 2017-11-30 15:19:39 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-12-15 17:35:53 +0000 |
commit | fb75d4f912c504b42d11f2c8f32b5dcff2b348b6 (patch) | |
tree | 794942f1aa5fff74c3dd40439764c1ad86456692 /perllib | |
parent | f8f4d505ee63e3e8eb83576b3e3ce64c2b35c322 (diff) |
[fixmystreet.com] Marketing page, filterable stats
Uses the dashboard stats code to display a rough table of stats which
can be used as the basis for a chart later
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 93 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixMyStreet.pm | 5 |
3 files changed, 87 insertions, 19 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index 5fe473c54..cff4c8dab 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -175,15 +175,15 @@ sub generate_data { $state_map->{$_} = 'closed' foreach FixMyStreet::DB::Result::Problem->closed_states; $state_map->{$_} = 'fixed' foreach FixMyStreet::DB::Result::Problem->fixed_states; - $self->generate_grouped_data($c); + $c->forward('generate_grouped_data'); $self->generate_summary_figures($c); } -sub generate_grouped_data { +sub generate_grouped_data : Private { my ($self, $c) = @_; my $state_map = $c->stash->{state_map}; - my $group_by = $c->get_param('group_by') || ''; + my $group_by = $c->get_param('group_by') || $c->stash->{group_by_default} || ''; my (%grouped, @groups, %totals); if ($group_by eq 'category') { %grouped = map { $_->category => {} } @{$c->stash->{contacts}}; @@ -197,6 +197,8 @@ sub generate_grouped_data { ); } elsif ($group_by eq 'device+site') { @groups = qw/cobrand service/; + } elsif ($group_by eq 'device') { + @groups = qw/service/; } else { $group_by = 'category+state'; @groups = qw/category state/; diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index b6281f0ca..5ac3da197 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -69,19 +69,8 @@ sub index : Path : Args(0) { } } - my $dashboard = eval { - my $data = FixMyStreet->config('TEST_DASHBOARD_DATA'); - # uncoverable branch true - unless ($data) { - 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 $dashboard = $c->forward('load_dashboard_data'); + my $table = !$c->stash->{body} && eval { my $data = path(FixMyStreet->path_to('../data/all-reports.json'))->slurp_utf8; $c->stash(decode_json($data)); @@ -425,6 +414,65 @@ sub ward_check : Private { $c->detach( 'redirect_body' ); } +=head2 summary + +This is the summary page used on fixmystreet.com + +=cut + +sub summary : Private { + my ($self, $c) = @_; + my $dashboard = $c->forward('load_dashboard_data'); + + eval { + my $data = path(FixMyStreet->path_to('../data/all-reports-dashboard.json'))->slurp_utf8; + $data = decode_json($data); + $c->stash( + top_five_bodies => $data->{top_five_bodies}, + average => $data->{average}, + ); + }; + + my $dtf = $c->model('DB')->storage->datetime_parser; + my $period = $c->stash->{period} = $c->get_param('period') || ''; + my $start_date; + if ($period eq 'ever') { + $start_date = DateTime->new(year => 2007); + } elsif ($period eq 'year') { + $start_date = DateTime->now->subtract(years => 1); + } elsif ($period eq '3months') { + $start_date = DateTime->now->subtract(months => 3); + } elsif ($period eq 'week') { + $start_date = DateTime->now->subtract(weeks => 1); + } else { + $c->stash->{period} = 'month'; + $start_date = DateTime->now->subtract(months => 1); + } + + # required to stop errors in generate_grouped_data + $c->stash->{q_state} = ''; + $c->stash->{ward} = $c->get_param('ward'); + $c->stash->{start_date} = $dtf->format_date($start_date); + $c->stash->{end_date} = $c->get_param('end_date'); + + $c->stash->{group_by_default} = 'category'; + + my $area_id = $c->stash->{body}->body_areas->first->area_id; + my $children = mySociety::MaPit::call('area/children', $area_id, + type => $c->cobrand->area_types_children, + ); + $c->stash->{children} = $children; + + $c->forward('/admin/fetch_contacts'); + $c->stash->{contacts} = [ $c->stash->{contacts}->all ]; + + $c->forward('/dashboard/construct_rs_filter'); + + $c->forward('/dashboard/generate_grouped_data'); + + $c->stash->{template} = 'reports/summary.html'; +} + =head2 check_canonical_url Given an already found (case-insensitively) body, check what URL @@ -441,6 +489,25 @@ sub check_canonical_url : Private { $c->detach( 'redirect_body' ) unless $body_short eq $url_short; } +sub load_dashboard_data : Private { + my ($self, $c) = @_; + my $dashboard = eval { + my $data = FixMyStreet->config('TEST_DASHBOARD_DATA'); + # uncoverable branch true + unless ($data) { + 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; + }; + + return $dashboard; +} + sub load_and_group_problems : Private { my ( $self, $c ) = @_; diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm index 2153ca33b..591234877 100644 --- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm +++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm @@ -81,14 +81,13 @@ sub council_dashboard_hook { } $c->forward('/admin/fetch_contacts'); - $c->stash->{display_contacts} = 1; - return if $c->user->is_superuser; + $c->detach('/reports/summary') if $c->user->is_superuser; my $body = $c->user->from_body || _user_to_body($c); if ($body) { # Matching URL and user's email body - return if $body->id eq $c->stash->{body}->id; + $c->detach('/reports/summary') if $body->id eq $c->stash->{body}->id; # Matched /a/ body, redirect to its summary page $c->stash->{body} = $body; |