aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-10-14 19:17:48 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-10-14 19:22:19 +0100
commitfc507074651b9f70dab1eeed4772f678a21fe272 (patch)
tree4fdf00e3503c7612ea82953d41050c218b495861 /perllib/FixMyStreet/App/Controller
parent4760a1306737536070c2efb97918530af750f4e9 (diff)
Add ajax pin fetching to reports/my pages.
This matches the behaviour on /around, and prevents a refresh when changing the state or category filters.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm3
-rw-r--r--perllib/FixMyStreet/App/Controller/My.pm7
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm27
3 files changed, 31 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..79e11af9c 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,25 @@ 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 $json = { pins => \@pins };
+ $json->{reports_list} = $list_html if $list_html;
+ my $body = encode_json($json);
+ $c->res->body($body);
+}
+
=head1 AUTHOR
Matthew Somerville