diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Develop.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 48 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Zurich.pm | 25 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 4 | ||||
-rwxr-xr-x | perllib/FixMyStreet/Script/UpdateAllReports.pm | 36 | ||||
-rw-r--r-- | web/js/dashboard.js | 30 |
7 files changed, 92 insertions, 58 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index f6d5363f5..53807228b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * Unreleased - Bugfixes: - Fix display of area/pins on body page when using Bing or TonerLite map. + - Do not scan through all problems to show /_dev pages. * v2.4 (6th September 2018) - Security diff --git a/perllib/FixMyStreet/App/Controller/Develop.pm b/perllib/FixMyStreet/App/Controller/Develop.pm index 1cc8f8906..ae7122fa1 100755 --- a/perllib/FixMyStreet/App/Controller/Develop.pm +++ b/perllib/FixMyStreet/App/Controller/Develop.pm @@ -38,7 +38,7 @@ Shows a list of links to preview HTML emails. sub index : Path('/_dev') : Args(0) { my ( $self, $c ) = @_; - $c->stash->{problem} = $c->model('DB::Problem')->first; + $c->stash->{problem} = $c->model('DB::Problem')->search(undef, { rows => 1 } )->first; } =item email_list @@ -63,8 +63,8 @@ sub email_list : Path('/_dev/email') : Args(0) { 'confirm_report_sent' => 1, 'problem-moderated' => 1, 'questionnaire' => 1, 'submit' => 1); - my $update = $c->model('DB::Comment')->first; - my $problem = $c->model('DB::Problem')->first; + my $update = $c->model('DB::Comment')->search(undef, { rows => 1 } )->first; + my $problem = $c->model('DB::Problem')->search(undef, { rows => 1 } )->first; $c->stash->{templates} = []; foreach (sort keys %templates) { diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 3414f9a2f..ade04fc7c 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -31,26 +31,7 @@ Show the summary page of all reports. sub index : Path : Args(0) { my ( $self, $c ) = @_; - # Zurich goes straight to map page, with all reports - if ( $c->cobrand->moniker eq 'zurich' ) { - $c->stash->{page} = 'reports'; - $c->forward( 'stash_report_filter_status' ); - $c->forward( 'load_and_group_problems' ); - $c->stash->{body} = { id => 0 }; # So template can fetch the list - - if ($c->get_param('ajax')) { - $c->detach('ajax', [ 'reports/_problem-list.html' ]); - } - - my $pins = $c->stash->{pins}; - FixMyStreet::Map::display_map( - $c, - latitude => @$pins ? $pins->[0]{latitude} : 0, - longitude => @$pins ? $pins->[0]{longitude} : 0, - area => 274456, - pins => $pins, - any_zoom => 1, - ); + if ( $c->cobrand->call_hook('report_page_data') ) { return 1; } @@ -59,14 +40,7 @@ sub index : Path : Args(0) { $c->detach( 'redirect_body' ); } - if (my $body = $c->get_param('body')) { - $body = $c->model('DB::Body')->find( { id => $body } ); - if ($body) { - $body = $c->cobrand->short_name($body); - $c->res->redirect("/reports/$body"); - $c->detach; - } - } + $c->forward('display_body_stats'); my $dashboard = $c->forward('load_dashboard_data'); @@ -101,6 +75,24 @@ sub index : Path : Args(0) { $c->response->header('Cache-Control' => 'max-age=3600'); } +=head2 display_body_stats + +Show the stats for a body if body param is set. + +=cut + +sub display_body_stats : Private { + my ( $self, $c ) = @_; + if (my $body = $c->get_param('body')) { + $body = $c->model('DB::Body')->find( { id => $body } ); + if ($body) { + $body = $c->cobrand->short_name($body); + $c->res->redirect("/reports/$body"); + $c->detach; + } + } +} + =head2 body Show the summary page for a particular body. diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm index 817fc48a1..fd0201f02 100644 --- a/perllib/FixMyStreet/Cobrand/Zurich.pm +++ b/perllib/FixMyStreet/Cobrand/Zurich.pm @@ -316,6 +316,31 @@ sub get_or_check_overdue { return $self->overdue($problem); } +sub report_page_data { + my $self = shift; + my $c = $self->{c}; + + $c->stash->{page} = 'reports'; + $c->forward( 'stash_report_filter_status' ); + $c->forward( 'load_and_group_problems' ); + $c->stash->{body} = { id => 0 }; # So template can fetch the list + + if ($c->get_param('ajax')) { + $c->detach('ajax', [ 'reports/_problem-list.html' ]); + } + + my $pins = $c->stash->{pins}; + FixMyStreet::Map::display_map( + $c, + latitude => @$pins ? $pins->[0]{latitude} : 0, + longitude => @$pins ? $pins->[0]{longitude} : 0, + area => 274456, + pins => $pins, + any_zoom => 1, + ); + return 1; +} + =head1 C<set_problem_state> If the state has changed, sets the state and calls C::Admin's C<log_edit> action. diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 05e0b620a..246159009 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -176,8 +176,8 @@ sub phone_display { sub latest_anonymity { my $self = shift; - my $p = $self->problems->search(undef, { order_by => { -desc => 'id' } } )->first; - my $c = $self->comments->search(undef, { order_by => { -desc => 'id' } } )->first; + my $p = $self->problems->search(undef, { rows => 1, order_by => { -desc => 'id' } } )->first; + my $c = $self->comments->search(undef, { rows => 1, order_by => { -desc => 'id' } } )->first; my $p_created = $p ? $p->created->epoch : 0; my $c_created = $c ? $c->created->epoch : 0; my $obj = $p_created >= $c_created ? $p : $c; diff --git a/perllib/FixMyStreet/Script/UpdateAllReports.pm b/perllib/FixMyStreet/Script/UpdateAllReports.pm index 21d8d28a0..e3ea63e6e 100755 --- a/perllib/FixMyStreet/Script/UpdateAllReports.pm +++ b/perllib/FixMyStreet/Script/UpdateAllReports.pm @@ -99,13 +99,14 @@ sub generate { } sub end_period { - my $period = shift; - FixMyStreet->set_time_zone(DateTime->now)->truncate(to => $period)->add($period . 's' => 1)->subtract(seconds => 1); + my ($period, $end) = @_; + $end ||= DateTime->now; + FixMyStreet->set_time_zone($end)->truncate(to => $period)->add($period . 's' => 1)->subtract(seconds => 1); } sub loop_period { - my ($date, $period, $extra) = @_; - my $end = end_period($period); + my ($date, $extra, $period, $end) = @_; + $end = end_period($period, $end); my @out; while ($date <= $end) { push @out, { n => $date->$period, $extra ? (d => $date->$extra) : () }; @@ -114,6 +115,21 @@ sub loop_period { return @out; } +sub get_period_group { + my ($start, $end) = @_; + my ($group_by, $extra); + if (DateTime::Duration->compare($end - $start, DateTime::Duration->new(months => 1)) < 0) { + $group_by = 'day'; + } elsif (DateTime::Duration->compare($end - $start, DateTime::Duration->new(years => 1)) < 0) { + $group_by = 'month'; + $extra = 'month_abbr'; + } else { + $group_by = 'year'; + } + + return ($group_by, $extra); +} + sub generate_dashboard { my $body = shift; @@ -138,16 +154,8 @@ sub generate_dashboard { $min_confirmed = FixMyStreet->set_time_zone(DateTime->now)->truncate(to => 'day'); } - my ($group_by, $extra); - if (DateTime::Duration->compare($end_today - $min_confirmed, DateTime::Duration->new(months => 1)) < 0) { - $group_by = 'day'; - } elsif (DateTime::Duration->compare($end_today - $min_confirmed, DateTime::Duration->new(years => 1)) < 0) { - $group_by = 'month'; - $extra = 'month_abbr'; - } else { - $group_by = 'year'; - } - my @problem_periods = loop_period($min_confirmed, $group_by, $extra); + my ($group_by, $extra) = get_period_group($min_confirmed, $end_today); + my @problem_periods = loop_period($min_confirmed, $extra, $group_by); my %problems_reported_by_period = stuff_by_day_or_year( $group_by, $rs, diff --git a/web/js/dashboard.js b/web/js/dashboard.js index 82b5e6188..848fb0c2e 100644 --- a/web/js/dashboard.js +++ b/web/js/dashboard.js @@ -30,6 +30,9 @@ $(function(){ var lasty = 0; $.each(chart.config.data.datasets, function(datasetIndex, dataset){ + if (dataset.data.length == 0) { + return; + } var $label = $('.label[data-datasetIndex="' + datasetIndex + '"]', $parent); var latestPoint = chart.getDatasetMeta(datasetIndex).data[ dataset.data.length - 1 ]; var y = latestPoint._model.y; @@ -136,21 +139,26 @@ $(function(){ data0 = $allReports.data('values-reports'), data1 = $allReports.data('values-fixed'); - window.chartAllReports = new Chart($allReports, { - type: 'line', - data: { - labels: labels, - datasets: [{ - data: data0, - pointRadius: pointRadiusFinalDot(data0.length, 4), - pointBackgroundColor: colours[1], - borderColor: colours[1] - }, { + var data = [{ + data: data0, + pointRadius: pointRadiusFinalDot(data0.length, 4), + pointBackgroundColor: colours[1], + borderColor: colours[1] + }]; + if ( data1 ) { + data.push({ data: data1, pointRadius: pointRadiusFinalDot(data1.length, 4), pointBackgroundColor: colours[3], borderColor: colours[3] - }] + }); + } + + window.chartAllReports = new Chart($allReports, { + type: 'line', + data: { + labels: labels, + datasets: data }, options: { animation: { |