aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-10-21 11:01:20 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-10-21 11:01:20 +0100
commit32690f423f65ab281cb9ec8122b3977140b40984 (patch)
treed09586bc004d051be660c1709c497a8f025efd53
parentc51d8e6b5ed134521dbdd376271481029b605aaf (diff)
parent3a2b49ebcb8c65d73108930f421142f2536cb893 (diff)
Merge branch '1543-reports-page-fixes'
-rw-r--r--perllib/FixMyStreet/App.pm12
-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.pm35
-rw-r--r--templates/web/base/my/my.html7
-rw-r--r--templates/web/base/my/planned.html3
-rw-r--r--templates/web/base/pagination.html4
-rwxr-xr-xtemplates/web/base/reports/body.html9
-rw-r--r--web/cobrands/fixmystreet/fixmystreet.js6
-rw-r--r--web/js/map-OpenLayers.js41
10 files changed, 108 insertions, 19 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm
index ab5e62233..7809b5f12 100644
--- a/perllib/FixMyStreet/App.pm
+++ b/perllib/FixMyStreet/App.pm
@@ -346,13 +346,21 @@ sub send_email {
$uri = $c->uri_with( ... );
-Simply forwards on to $c->req->uri_with - this is a common typo I make!
+Forwards on to $c->req->uri_with, but also deletes keys that have a "" value
+(as undefined is passed as that from a template).
=cut
sub uri_with {
my $c = shift;
- return $c->req->uri_with(@_);
+ my $uri = $c->req->uri_with(@_);
+ my $args = $_[0];
+ my %params = %{$uri->query_form_hash};
+ foreach my $key (keys %$args) {
+ delete $params{$key} if $args->{$key} eq "";
+ }
+ $uri->query_form(\%params);
+ return $uri;
}
=head2 uri_for
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
diff --git a/templates/web/base/my/my.html b/templates/web/base/my/my.html
index 69f686f68..a61a8ea44 100644
--- a/templates/web/base/my/my.html
+++ b/templates/web/base/my/my.html
@@ -1,5 +1,6 @@
[%
SET bodyclass = 'mappage';
+ PROCESS "report/photo-js.html";
PROCESS "maps/${map.type}.html" IF problems.size;
INCLUDE 'header.html', title = loc('Your Reports')
%]
@@ -37,8 +38,12 @@
<section class="full-width">
[% INCLUDE "reports/_list-filters.html", use_form_wrapper = 1 %]
+<div class="js-pagination">
[% INCLUDE 'pagination.html', pager = problems_pager, param = 'p' %]
-[% INCLUDE 'my/_problem-list.html' %]
+</div>
+<div id="js-reports-list">
+ [% INCLUDE 'my/_problem-list.html' %]
+</div>
</section>
[% FOREACH u IN updates %]
diff --git a/templates/web/base/my/planned.html b/templates/web/base/my/planned.html
index 19d29f970..eb67247c4 100644
--- a/templates/web/base/my/planned.html
+++ b/templates/web/base/my/planned.html
@@ -1,5 +1,6 @@
[%
SET bodyclass = 'mappage';
+ PROCESS "report/photo-js.html";
PROCESS "maps/${map.type}.html" IF problems.size;
INCLUDE 'header.html', title = loc('Your shortlist')
%]
@@ -22,7 +23,9 @@
<section class="full-width">
[% INCLUDE "reports/_list-filters.html", use_form_wrapper = 1 %]
+<div class="js-pagination">
[% INCLUDE 'pagination.html', pager = problems_pager, param = 'p' %]
+</div>
[% INCLUDE 'my/_problem-list.html' %]
</section>
diff --git a/templates/web/base/pagination.html b/templates/web/base/pagination.html
index f0c51bb10..448186838 100644
--- a/templates/web/base/pagination.html
+++ b/templates/web/base/pagination.html
@@ -1,13 +1,13 @@
[% IF pager.last_page > 1 %]
<p class="pagination">
[% IF pager.previous_page %]
- <a class="prev" href="[% c.req.uri_with({ $param => pager.previous_page }) %][% '#' _ hash IF hash %]">[% loc('Previous') %]</a>
+ <a class="prev" href="[% c.uri_with({ $param => pager.previous_page, ajax => undefined }) %][% '#' _ hash IF hash %]">[% loc('Previous') %]</a>
[% END %]
[% tprintf( loc('%d to %d of %d'), pager.first, pager.last, pager.total_entries ) %]
[% IF pager.next_page %]
- <a class="next" href="[% c.req.uri_with({ $param => pager.next_page }) %][% '#' _ hash IF hash %]">[% loc('Next') %]</a>
+ <a class="next" href="[% c.uri_with({ $param => pager.next_page, ajax => undefined }) %][% '#' _ hash IF hash %]">[% loc('Next') %]</a>
[% END %]
</p>
[% END %]
diff --git a/templates/web/base/reports/body.html b/templates/web/base/reports/body.html
index d0961d2f6..929a4a527 100755
--- a/templates/web/base/reports/body.html
+++ b/templates/web/base/reports/body.html
@@ -17,6 +17,7 @@
[% END %]
[%
+ PROCESS "report/photo-js.html";
PROCESS "maps/${map.type}.html";
SET bodyclass = 'mappage';
INCLUDE 'header.html',
@@ -61,9 +62,15 @@
<section class="full-width">
[% INCLUDE "reports/_list-filters.html", use_form_wrapper = 1 %]
+<div class="js-pagination">
[% INCLUDE 'pagination.html', param = 'p' %]
-[% INCLUDE 'reports/_problem-list.html' %]
+</div>
+<div id="js-reports-list">
+ [% INCLUDE 'reports/_problem-list.html' %]
+</div>
+<div class="js-pagination">
[% INCLUDE 'pagination.html', param = 'p' %]
+</div>
</section>
</div>
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 7d264860f..43a0aadbb 100644
--- a/web/js/map-OpenLayers.js
+++ b/web/js/map-OpenLayers.js
@@ -272,6 +272,9 @@ var fixmystreet = fixmystreet || {};
function parse_query_string() {
var qs = {};
+ if (!location.search) {
+ return qs;
+ }
location.search.substring(1).split('&').forEach(function(i) {
var s = i.split('='),
k = s[0],
@@ -294,7 +297,15 @@ var fixmystreet = fixmystreet || {};
var qs = parse_query_string();
var filter_categories = replace_query_parameter(qs, 'filter_categories', 'filter_category');
var filter_statuses = replace_query_parameter(qs, 'statuses', 'status');
- var new_url = location.href.replace(location.search, '?' + $.param(qs));
+ delete qs['p'];
+ var new_url;
+ if ($.isEmptyObject(qs)) {
+ new_url = location.href.replace(location.search, "");
+ } else if (location.search) {
+ new_url = location.href.replace(location.search, '?' + $.param(qs));
+ } else {
+ new_url = location.href + '?' + $.param(qs);
+ }
history.pushState({
filter_change: { 'filter_categories': filter_categories, 'statuses': filter_statuses }
}, null, new_url);
@@ -421,6 +432,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) {
@@ -714,6 +732,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
@@ -761,6 +793,13 @@ 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;
+ }
+ if (typeof(obj.pagination) != 'undefined') {
+ $('.js-pagination').html(obj.pagination);
+ }
return fixmystreet.maps.markers_list( obj.pins, false );
},
CLASS_NAME: "OpenLayers.Format.FixMyStreet"