diff options
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/My.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 35 |
3 files changed, 39 insertions, 6 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 1f45f8029..cd96c3b5d 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -292,9 +292,6 @@ sub ajax : Path('/ajax') { my $all_pins = $c->get_param('all_pins') ? 1 : undef; my $interval = $all_pins ? undef : $c->cobrand->on_map_default_max_pin_age; - # Need to be the class that can handle it - FixMyStreet::Map::set_map_class( 'OSM' ); - $c->forward( '/reports/stash_report_filter_status' ); # extract the data from the map diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm index 573c41446..b6f425ead 100644 --- a/perllib/FixMyStreet/App/Controller/My.pm +++ b/perllib/FixMyStreet/App/Controller/My.pm @@ -33,6 +33,9 @@ sub my : Path : Args(0) { $c->stash->{problems_rs} = $c->cobrand->problems->search( { user_id => $c->user->id }); $c->forward('get_problems'); + if ($c->get_param('ajax')) { + $c->detach('/reports/ajax', [ 'my/_problem-list.html' ]); + } $c->forward('get_updates'); $c->forward('setup_page_data'); } @@ -104,7 +107,9 @@ sub get_updates : Private { sub setup_page_data : Private { my ($self, $c) = @_; - my @categories = $c->stash->{problems_rs}->search({}, { + my @categories = $c->stash->{problems_rs}->search({ + state => [ FixMyStreet::DB::Result::Problem->visible_states() ], + }, { columns => [ 'category' ], distinct => 1, order_by => [ 'category' ], diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 60a7d1726..f05096525 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -116,6 +116,10 @@ sub ward : Path : Args(2) { $c->forward( 'stash_report_filter_status' ); $c->forward( 'load_and_group_problems' ); + if ($c->get_param('ajax')) { + $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} ) @@ -364,7 +368,7 @@ sub load_and_group_problems : Private { my $page = $c->get_param('p') || 1; # NB: If 't' is specified, it will override 'status'. my $type = $c->get_param('t') || 'all'; - my $category = $c->get_param('c') || $c->get_param('filter_category') || ''; + my $category = [ $c->get_param_list('filter_category', 1) ]; my $states = $c->stash->{filter_problem_states}; my $where = { @@ -391,7 +395,7 @@ sub load_and_group_problems : Private { $where->{state} = $not_open; } - if ($category) { + if (@$category) { $where->{category} = $category; } @@ -504,6 +508,33 @@ sub add_row { push @$pins, $problem->pin_data($c, 'reports'); } +sub ajax : Private { + my ($self, $c, $template) = @_; + + $c->res->content_type('application/json; charset=utf-8'); + $c->res->header( 'Cache_Control' => 'max-age=0' ); + + my @pins = map { + my $p = $_; + [ $p->{latitude}, $p->{longitude}, $p->{colour}, $p->{id}, $p->{title} ] + } @{$c->stash->{pins}}; + + my $list_html = $c->render_fragment($template); + + my $pagination = $c->render_fragment('pagination.html', { + pager => $c->stash->{problems_pager} || $c->stash->{pager}, + param => 'p', + }); + + my $json = { + pins => \@pins, + pagination => $pagination, + }; + $json->{reports_list} = $list_html if $list_html; + my $body = encode_json($json); + $c->res->body($body); +} + =head1 AUTHOR Matthew Somerville |