diff options
-rw-r--r-- | conf/httpd.conf | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 61 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 8 | ||||
-rwxr-xr-x | web/ajax.cgi | 214 |
4 files changed, 175 insertions, 109 deletions
diff --git a/conf/httpd.conf b/conf/httpd.conf index 1508c96af..aa9739d25 100644 --- a/conf/httpd.conf +++ b/conf/httpd.conf @@ -105,7 +105,6 @@ RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f RewriteRule /(.+) /$1 [L] # Explicitly capture all cgi files so that we can remove them one by one -RewriteRule ^/ajax(.*) /ajax.cgi$1 [L] RewriteRule ^/alert(.*) /alert.cgi$1 [L] RewriteRule ^/confirm(.*) /confirm.cgi$1 [L] RewriteRule ^/contact(.*) /contact.cgi$1 [L] diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 03ad27a54..09f015055 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -140,7 +140,7 @@ sub display_location : Private { my $all_link = $c->req->uri_with( { no_pins => undef, all_pins => undef } ); my $all_text = $all_pins ? _('Hide stale reports') : _('Include stale reports'); - my $interval = $all_pins ? undef : '6 months'; + my $interval = $all_pins ? undef : $c->cobrand->on_map_default_max_pin_age; # get the map features my ( $on_map_all, $on_map, $around_map, $distance ) = @@ -319,6 +319,65 @@ sub check_location_is_acceptable : Private { return $c->forward('/report/new/load_and_check_councils'); } +=head2 /ajax + +Handle the ajax calls that the map makes when it is dragged. The info returned +is used to update the pins on the map and the text descriptions on the side of +the map. + +=cut + +sub ajax : Path('/ajax') { + my ( $self, $c ) = @_; + + # Our current X/Y middle of visible map + my $x = ( $c->req->param('x') || 0 ) + 0; + my $y = ( $c->req->param('y') || 0 ) + 0; + + # Where we started as that's the (0,0) we have to work to + my $sx = ( $c->req->param('sx') || 0 ) + 0; + my $sy = ( $c->req->param('sy') || 0 ) + 0; + + # how far back should we go? + my $all_pins = $c->req->param('all_pins') ? 1 : undef; + my $interval = $all_pins ? undef : $c->cobrand->on_map_default_max_pin_age; + + # extract the data from the map + my ( $pins, $on_map, $around_map, $dist ) = + FixMyStreet::Map::map_pins( $c->fake_q, $x, $y, $sx, $sy, $interval ); + + # render templates to get the html + # my $on_map_list_html = $c->forward( + # "View::Web", "render", + my $on_map_list_html = + $c->view('Web') + ->render( $c, 'around/on_map_list_items.html', { on_map => $on_map } ); + + # my $around_map_list_html = $c->forward( + # "View::Web", "render", + my $around_map_list_html = $c->view('Web')->render( + $c, + 'around/around_map_list_items.html', + { around_map => $around_map, dist => $dist } + ); + + # JSON encode the response + my $body = JSON->new->utf8(1)->pretty(1)->encode( + { + pins => $pins, + current => $on_map_list_html, + current_near => $around_map_list_html, + } + ); + + # assume this is not cacheable - may need to be more fine-grained later + $c->res->content_type('text/javascript; charset=utf-8'); + $c->res->header( 'Cache_Control' => 'max-age=0' ); + + # Set the body - note that the js needs the surrounding brackets. + $c->res->body("($body)"); +} + __PACKAGE__->meta->make_immutable; 1; diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 9a2788c08..2a4bfa243 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -414,6 +414,14 @@ Return the maximum number of items to be given in the list of reports on the map sub on_map_list_limit { return undef; } +=head2 on_map_default_max_pin_age + +Return the default maximum age for pins. + +=cut + +sub on_map_default_max_pin_age { return '6 months'; } + =head2 allow_photo_upload Return a boolean indicating whether the cobrand allows photo uploads diff --git a/web/ajax.cgi b/web/ajax.cgi index f13529852..a25269070 100755 --- a/web/ajax.cgi +++ b/web/ajax.cgi @@ -1,107 +1,107 @@ -#!/usr/bin/perl -w -I../perllib - -# ajax.cgi: -# Updating the pins as you drag the map -# -# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. -# Email: matthew@mysociety.org. WWW: http://www.mysociety.org -# -# $Id: ajax.cgi,v 1.19 2009-12-15 17:53:52 louise Exp $ - -use strict; -use Standard; -use mySociety::Web qw(ent NewURL); - -sub main { - my $q = shift; - - my @vars = qw(x y sx sy all_pins); - my %input = map { $_ => $q->param($_) || '' } @vars; - my %input_h = map { $_ => $q->param($_) ? ent($q->param($_)) : '' } @vars; - - # Our current X/Y middle of visible map - my $x = $input{x}; - my $y = $input{y}; - $x ||= 0; $x += 0; - $y ||= 0; $y += 0; - - # Where we started as that's the (0,0) we have to work to - my $sx = $input{sx}; - my $sy = $input{sy}; - $sx ||= 0; $sx += 0; - $sy ||= 0; $sy += 0; - - my $interval; - unless ($input{all_pins}) { - $interval = '6 months'; - } - my ($pins, $on_map, $around_map, $dist) = FixMyStreet::Map::map_pins($q, $x, $y, $sx, $sy, $interval); - my $cobrand = Page::get_cobrand($q); - my $list = ''; - my $link = ''; - foreach (@$on_map) { - $link = Cobrand::url($cobrand, NewURL($q, -retain => 1, - -url => '/report/' . $_->{id}, - pc => undef, - x => undef, - y => undef, - sx => undef, - sy => undef, - all_pins => undef, - no_pins => undef), $q); - $list .= '<li><a href="' . $link . '">'; - $list .= ent($_->{title}) . '</a> <small>('; - $list .= Page::prettify_epoch($q, $_->{time}, 1) . ')</small>'; - $list .= ' <small>' . _('(fixed)') . '</small>' if $_->{state} eq 'fixed'; - $list .= '</li>'; - } - my $om_list = $list; - - $list = ''; - foreach (@$around_map) { - my $dist = int($_->{distance}*10+.5)/10; - $link = Cobrand::url($cobrand, NewURL($q, -retain => 1, - -url => '/report/' . $_->{id}, - pc => undef, - x => undef, - y => undef, - sx => undef, - sy => undef, - all_pins => undef, - no_pins => undef), $q); - $list .= '<li><a href="' . $link . '">'; - $list .= ent($_->{title}) . '</a> <small>('; - $list .= Page::prettify_epoch($q, $_->{time}, 1) . ', '; - $list .= $dist . 'km)</small>'; - $list .= ' <small>' . _('(fixed)') . '</small>' if $_->{state} eq 'fixed'; - $list .= '</li>'; - } - my $am_list = $list; - - #$list = ''; - #foreach (@$fixed) { - # $list .= '<li><a href="/report/' . $_->{id} . '">'; - # $list .= $_->{title} . ' <small>(' . int($_->{distance}*10+.5)/10 . 'km)</small>'; - # $list .= '</a></li>'; - #} - #my $f_list = $list; - - # For now, assume this is not cacheable - may need to be more fine-grained later - print $q->header(-charset => 'utf-8', -content_type => 'text/javascript', -Cache_Control => 'max-age=0'); - - - $pins =~ s/'/\\'/g; - $om_list =~ s/'/\\'/g; - $am_list =~ s/'/\\'/g; - #$f_list =~ s/'/\\'/g; - print <<EOF; -({ -'pins': '$pins', -'current': '$om_list', -'current_near': '$am_list' -}) -EOF -} - -Page::do_fastcgi(\&main); - +# #!/usr/bin/perl -w -I../perllib +# +# # ajax.cgi: +# # Updating the pins as you drag the map +# # +# # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. +# # Email: matthew@mysociety.org. WWW: http://www.mysociety.org +# # +# # $Id: ajax.cgi,v 1.19 2009-12-15 17:53:52 louise Exp $ +# +# use strict; +# use Standard; +# use mySociety::Web qw(ent NewURL); +# +# sub main { +# my $q = shift; +# +# my @vars = qw(x y sx sy all_pins); +# my %input = map { $_ => $q->param($_) || '' } @vars; +# my %input_h = map { $_ => $q->param($_) ? ent($q->param($_)) : '' } @vars; +# +# # Our current X/Y middle of visible map +# my $x = $input{x}; +# my $y = $input{y}; +# $x ||= 0; $x += 0; +# $y ||= 0; $y += 0; +# +# # Where we started as that's the (0,0) we have to work to +# my $sx = $input{sx}; +# my $sy = $input{sy}; +# $sx ||= 0; $sx += 0; +# $sy ||= 0; $sy += 0; +# +# my $interval; +# unless ($input{all_pins}) { +# $interval = '6 months'; +# } +# my ($pins, $on_map, $around_map, $dist) = FixMyStreet::Map::map_pins($q, $x, $y, $sx, $sy, $interval); +# my $cobrand = Page::get_cobrand($q); +# my $list = ''; +# my $link = ''; +# foreach (@$on_map) { +# $link = Cobrand::url($cobrand, NewURL($q, -retain => 1, +# -url => '/report/' . $_->{id}, +# pc => undef, +# x => undef, +# y => undef, +# sx => undef, +# sy => undef, +# all_pins => undef, +# no_pins => undef), $q); +# $list .= '<li><a href="' . $link . '">'; +# $list .= ent($_->{title}) . '</a> <small>('; +# $list .= Page::prettify_epoch($q, $_->{time}, 1) . ')</small>'; +# $list .= ' <small>' . _('(fixed)') . '</small>' if $_->{state} eq 'fixed'; +# $list .= '</li>'; +# } +# my $om_list = $list; +# +# $list = ''; +# foreach (@$around_map) { +# my $dist = int($_->{distance}*10+.5)/10; +# $link = Cobrand::url($cobrand, NewURL($q, -retain => 1, +# -url => '/report/' . $_->{id}, +# pc => undef, +# x => undef, +# y => undef, +# sx => undef, +# sy => undef, +# all_pins => undef, +# no_pins => undef), $q); +# $list .= '<li><a href="' . $link . '">'; +# $list .= ent($_->{title}) . '</a> <small>('; +# $list .= Page::prettify_epoch($q, $_->{time}, 1) . ', '; +# $list .= $dist . 'km)</small>'; +# $list .= ' <small>' . _('(fixed)') . '</small>' if $_->{state} eq 'fixed'; +# $list .= '</li>'; +# } +# my $am_list = $list; +# +# #$list = ''; +# #foreach (@$fixed) { +# # $list .= '<li><a href="/report/' . $_->{id} . '">'; +# # $list .= $_->{title} . ' <small>(' . int($_->{distance}*10+.5)/10 . 'km)</small>'; +# # $list .= '</a></li>'; +# #} +# #my $f_list = $list; +# +# # For now, assume this is not cacheable - may need to be more fine-grained later +# print $q->header(-charset => 'utf-8', -content_type => 'text/javascript', -Cache_Control => 'max-age=0'); +# +# +# $pins =~ s/'/\\'/g; +# $om_list =~ s/'/\\'/g; +# $am_list =~ s/'/\\'/g; +# #$f_list =~ s/'/\\'/g; +# print <<EOF; +# ({ +# 'pins': '$pins', +# 'current': '$om_list', +# 'current_near': '$am_list' +# }) +# EOF +# } +# +# Page::do_fastcgi(\&main); +# |