aboutsummaryrefslogtreecommitdiffstats
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
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.
-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
-rw-r--r--templates/web/base/my/my.html4
-rwxr-xr-xtemplates/web/base/reports/body.html4
-rw-r--r--web/cobrands/fixmystreet/fixmystreet.js6
-rw-r--r--web/js/map-OpenLayers.js25
7 files changed, 62 insertions, 14 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
diff --git a/templates/web/base/my/my.html b/templates/web/base/my/my.html
index cddb37b6e..8924736eb 100644
--- a/templates/web/base/my/my.html
+++ b/templates/web/base/my/my.html
@@ -39,7 +39,9 @@
<section class="full-width">
[% INCLUDE "reports/_list-filters.html", use_form_wrapper = 1 %]
[% INCLUDE 'pagination.html', pager = problems_pager, param = 'p' %]
-[% INCLUDE 'my/_problem-list.html' %]
+<div id="js-reports-list">
+ [% INCLUDE 'my/_problem-list.html' %]
+</div>
</section>
[% FOREACH u IN updates %]
diff --git a/templates/web/base/reports/body.html b/templates/web/base/reports/body.html
index bf5a1ee9a..6cad2cd1a 100755
--- a/templates/web/base/reports/body.html
+++ b/templates/web/base/reports/body.html
@@ -63,7 +63,9 @@
<section class="full-width">
[% INCLUDE "reports/_list-filters.html", use_form_wrapper = 1 %]
[% INCLUDE 'pagination.html', param = 'p' %]
-[% INCLUDE 'reports/_problem-list.html' %]
+<div id="js-reports-list">
+ [% INCLUDE 'reports/_problem-list.html' %]
+</div>
[% INCLUDE 'pagination.html', param = 'p' %]
</section>
diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js
index 13635b9aa..9f103a615 100644
--- a/web/cobrands/fixmystreet/fixmystreet.js
+++ b/web/cobrands/fixmystreet/fixmystreet.js
@@ -578,12 +578,6 @@ $.extend(fixmystreet.set_up, {
// to refresh the map when the filter inputs are changed.
$(".report-list-filters [type=submit]").hide();
- if (fixmystreet.page == "my" || fixmystreet.page == "reports") {
- $(".report-list-filters select").change(function() {
- $(this).closest("form").submit();
- });
- }
-
function make_multi(id) {
var $id = $('#' + id),
all = $id.data('all');
diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js
index 353d75707..1ccb7febc 100644
--- a/web/js/map-OpenLayers.js
+++ b/web/js/map-OpenLayers.js
@@ -431,6 +431,13 @@ var fixmystreet = fixmystreet || {};
format: new OpenLayers.Format.FixMyStreet()
});
}
+ if (fixmystreet.page == 'reports' || fixmystreet.page == 'my') {
+ pin_layer_options.strategies = [ new OpenLayers.Strategy.FixMyStreetFixed() ];
+ pin_layer_options.protocol = new OpenLayers.Protocol.FixMyStreet({
+ url: '?ajax=1',
+ format: new OpenLayers.Format.FixMyStreet()
+ });
+ }
fixmystreet.markers = new OpenLayers.Layer.Vector("Pins", pin_layer_options);
fixmystreet.markers.events.register( 'loadend', fixmystreet.markers, function(evt) {
if (fixmystreet.map.popups.length) {
@@ -724,6 +731,20 @@ OpenLayers.Strategy.FixMyStreet = OpenLayers.Class(OpenLayers.Strategy.BBOX, {
}
});
+/* Copy of Strategy.Fixed, but with no initial load */
+OpenLayers.Strategy.FixMyStreetFixed = OpenLayers.Class(OpenLayers.Strategy.Fixed, {
+ activate: function() {
+ var activated = OpenLayers.Strategy.prototype.activate.apply(this, arguments);
+ if (activated) {
+ this.layer.events.on({
+ "refresh": this.load,
+ scope: this
+ });
+ }
+ return activated;
+ }
+});
+
/* Pan data request handler */
// This class is used to get a JSON object from /ajax that contains
// pins for the map and HTML for the sidebar. It does a fetch whenever the map
@@ -771,6 +792,10 @@ OpenLayers.Format.FixMyStreet = OpenLayers.Class(OpenLayers.Format.JSON, {
if (typeof(obj.current) != 'undefined' && (current = document.getElementById('current'))) {
current.innerHTML = obj.current;
}
+ var reports_list;
+ if (typeof(obj.reports_list) != 'undefined' && (reports_list = document.getElementById('js-reports-list'))) {
+ reports_list.innerHTML = obj.reports_list;
+ }
return fixmystreet.maps.markers_list( obj.pins, false );
},
CLASS_NAME: "OpenLayers.Format.FixMyStreet"