diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 48 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bromley.pm | 131 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Oxfordshire.pm | 4 |
3 files changed, 158 insertions, 25 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 4c28563de..b77e89d0e 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -118,7 +118,7 @@ sub ward : Path : Args(2) { $c->forward('/auth/get_csrf_token'); - my @wards = split /\|/, $ward || ""; + my @wards = $c->get_param('wards') ? $c->get_param_list('wards', 1) : split /\|/, $ward || ""; $c->forward( 'body_check', [ $body ] ); # If viewing multiple wards, rewrite the url from @@ -154,7 +154,8 @@ sub ward : Path : Args(2) { $c->forward( 'load_and_group_problems' ); if ($c->get_param('ajax')) { - $c->detach('ajax', [ 'reports/_problem-list.html' ]); + my $ajax_template = $c->stash->{ajax_template} || 'reports/_problem-list.html'; + $c->detach('ajax', [ $ajax_template ]); } $c->stash->{rss_url} = '/rss/reports/' . $body_short; @@ -164,14 +165,14 @@ sub ward : Path : Args(2) { $c->stash->{stats} = $c->cobrand->get_report_stats(); my @categories = $c->stash->{body}->contacts->not_deleted->search( undef, { - columns => [ 'category', 'extra' ], + columns => [ 'id', 'category', 'extra' ], distinct => 1, order_by => [ 'category' ], } )->all; $c->stash->{filter_categories} = \@categories; $c->stash->{filter_category} = { map { $_ => 1 } $c->get_param_list('filter_category', 1) }; - my $pins = $c->stash->{pins}; + my $pins = $c->stash->{pins} || []; my %map_params = ( latitude => @$pins ? $pins->[0]{latitude} : 0, @@ -554,7 +555,7 @@ sub load_and_group_problems : Private { my $states = $c->stash->{filter_problem_states}; my $where = { - state => [ keys %$states ] + 'me.state' => [ keys %$states ] }; $c->forward('check_non_public_reports_permission', [ $where ] ); @@ -613,12 +614,21 @@ sub load_and_group_problems : Private { $where->{longitude} = { '>=', $min_lon, '<', $max_lon }; } - $problems = $problems->search( - $where, - $filter - )->include_comment_counts->page( $page ); + my $cobrand_problems = $c->cobrand->call_hook('munge_load_and_group_problems', $where, $filter); - $c->stash->{pager} = $problems->pager; + # JS will request the same (or more) data client side + return if $c->get_param('js'); + + if ($cobrand_problems) { + $problems = $cobrand_problems; + } else { + $problems = $problems->search( + $where, + $filter + )->include_comment_counts->page( $page ); + + $c->stash->{pager} = $problems->pager; + } my ( %problems, @pins ); while ( my $problem = $problems->next ) { @@ -626,19 +636,11 @@ sub load_and_group_problems : Private { add_row( $c, $problem, 0, \%problems, \@pins ); next; } - if ( !$problem->bodies_str ) { - # Problem was not sent to any body, add to all possible areas XXX - my $a = $problem->areas; # Store, as otherwise is looked up every iteration. - while ($a =~ /,(\d+)(?=,)/g) { - add_row( $c, $problem, $1, \%problems, \@pins ); - } - } else { - # Add to bodies it was sent to - my $bodies = $problem->bodies_str_ids; - foreach ( @$bodies ) { - next if $_ != $body->id; - add_row( $c, $problem, $_, \%problems, \@pins ); - } + # Add to bodies it was sent to + my $bodies = $problem->bodies_str_ids; + foreach ( @$bodies ) { + next if $_ != $body->id; + add_row( $c, $problem, $_, \%problems, \@pins ); } } diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm index 3ae8ef140..55a366b60 100644 --- a/perllib/FixMyStreet/Cobrand/Bromley.pm +++ b/perllib/FixMyStreet/Cobrand/Bromley.pm @@ -3,6 +3,7 @@ use parent 'FixMyStreet::Cobrand::UKCouncils'; use strict; use warnings; +use utf8; use DateTime::Format::W3CDTF; sub council_area_id { return 2482; } @@ -139,6 +140,39 @@ sub tweak_all_reports_map { $c->stash->{map}->{any_zoom} = 0; $c->stash->{map}->{zoom} = 11; } + + # A place where this can happen + return unless $c->stash->{template} && $c->stash->{template} eq 'about/heatmap.html'; + + my $children = $c->stash->{body}->first_area_children; + foreach (values %$children) { + $_->{url} = $c->uri_for( $c->stash->{body_url} + . '/' . $c->cobrand->short_name( $_ ) + ); + } + $c->stash->{children} = $children; + + my %subcats = $self->subcategories; + my $filter = $c->stash->{filter_categories}; + my @new_contacts; + foreach (@$filter) { + push @new_contacts, $_; + foreach (@{$subcats{$_->id}}) { + push @new_contacts, { + category => $_->{key}, + category_display => (" " x 4) . $_->{name}, + }; + } + } + $c->stash->{filter_categories} = \@new_contacts; + + if (!%{$c->stash->{filter_category}}) { + my $cats = $c->user->categories; + my $subcats = $c->user->get_extra_metadata('subcategories') || []; + $c->stash->{filter_category} = { map { $_ => 1 } @$cats, @$subcats } if @$cats || @$subcats; + } + + $c->stash->{ward_hash} = { map { $_->{id} => 1 } @{$c->stash->{wards}} } if $c->stash->{wards}; } sub title_list { @@ -300,5 +334,102 @@ sub add_admin_subcategories { return \@new_contacts; } +sub about_hook { + my $self = shift; + my $c = $self->{c}; + + # Display a special custom dashboard page, with heatmap + if ($c->stash->{template} eq 'about/heatmap.html') { + $c->forward('/dashboard/check_page_allowed'); + # We want a special sidebar + $c->stash->{ajax_template} = "about/heatmap-list.html"; + $c->set_param('js', 1) unless $c->get_param('ajax'); # Want to load pins client-side + $c->forward('/reports/body', [ 'Bromley' ]); + } +} + +# On heatmap page, include querying on subcategories, wards, dates, provided +sub munge_load_and_group_problems { + my ($self, $where, $filter) = @_; + my $c = $self->{c}; + + return unless $c->stash->{template} && $c->stash->{template} eq 'about/heatmap.html'; + + if (!$where->{category}) { + my $cats = $c->user->categories; + my $subcats = $c->user->get_extra_metadata('subcategories') || []; + $where->{category} = [ @$cats, @$subcats ] if @$cats || @$subcats; + } + + my %subcats = $self->subcategories; + my $subcat; + my %chosen = map { $_ => 1 } @{$where->{category} || []}; + my @subcat = grep { $chosen{$_} } map { $_->{key} } map { @$_ } values %subcats; + if (@subcat) { + my %chosen = map { $_ => 1 } @subcat; + $where->{'-or'} = { + category => [ grep { !$chosen{$_} } @{$where->{category}} ], + subcategory => \@subcat, + }; + delete $where->{category}; + } + + # Wards + my @areas = @{$c->user->area_ids || []}; + # Want to get everything if nothing given in an ajax call + if (!$c->stash->{wards} && @areas) { + $c->stash->{wards} = [ map { { id => $_ } } @areas ]; + $where->{areas} = [ + map { { 'like', '%,' . $_ . ',%' } } @areas + ]; + } + + # Date range + my $dtf = $c->model('DB')->storage->datetime_parser; + my $start_default = DateTime->today(time_zone => FixMyStreet->time_zone || FixMyStreet->local_time_zone)->subtract(months => 3); + $c->stash->{start_date} = $c->get_param('start_date') || $start_default->strftime('%Y-%m-%d'); + $c->stash->{end_date} = $c->get_param('end_date'); + + my $start_date = $dtf->parse_datetime($c->stash->{start_date}); + $where->{'me.confirmed'} = { '>=', $dtf->format_datetime($start_date) }; + if (my $end_date = $c->stash->{end_date}) { + my $one_day = DateTime::Duration->new( days => 1 ); + $end_date = $dtf->parse_datetime($end_date) + $one_day; + $where->{'me.confirmed'} = [ -and => $where->{'me.confirmed'}, { '<', $dtf->format_datetime($end_date) } ]; + } + + delete $filter->{rows}; + + # Load the relevant stuff for the sidebar as well + my $problems = $self->problems->search($where, $filter); + + $c->stash->{five_newest} = [ $problems->search(undef, { + rows => 5, + order_by => { -desc => 'confirmed' }, + })->all ]; + + $c->stash->{ten_oldest} = [ $problems->search({ + 'me.state' => [ FixMyStreet::DB::Result::Problem->open_states() ], + }, { + rows => 10, + order_by => 'lastupdate', + })->all ]; + + my $params = { map { my $n = $_; s/me\./problem\./; $_ => $where->{$n} } keys %$where }; + my @c = $c->model('DB::Comment')->to_body($self->body)->search({ + %$params, + 'me.user_id' => { -not_in => [ $c->user->id, $self->body->comment_user_id ] }, + 'me.state' => 'confirmed', + }, { + columns => 'problem_id', + group_by => 'problem_id', + order_by => { -desc => \'max(me.confirmed)' }, + rows => 5, + })->all; + $c->stash->{five_commented} = [ map { $_->problem } @c ]; + + return $problems; +} + 1; diff --git a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm index 63e52dc20..b8dc49f72 100644 --- a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm +++ b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm @@ -21,8 +21,8 @@ sub report_validation { $errors->{name} = sprintf( 'Names are limited to %d characters in length.', 50 ); } - if ( length( $report->user->phone ) > 30 ) { - $errors->{phone} = sprintf( 'Phone numbers are limited to %s characters in length.', 30 ); + if ( length( $report->user->phone ) > 20 ) { + $errors->{phone} = sprintf( 'Phone numbers are limited to %s characters in length.', 20 ); } if ( length( $report->user->email ) > 50 ) { |