aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatthew <matthew>2008-09-16 15:45:09 +0000
committermatthew <matthew>2008-09-16 15:45:09 +0000
commitb7545d35f57d4967cc81f80606132345755ed84e (patch)
tree8fc5bd4c7e7af30df425622deb05a7f191f28f1a
parent3f58bc0b7b6be8018ab2835c35b825fd9be887bb (diff)
Update pins/list as you drag the map, rearrange list display.
-rw-r--r--perllib/Memcached.pm31
-rw-r--r--perllib/Page.pm73
-rw-r--r--perllib/Problems.pm117
-rwxr-xr-xweb/ajax.cgi80
-rwxr-xr-xweb/alert.cgi6
-rw-r--r--web/css/core.css16
-rwxr-xr-xweb/index.cgi137
-rw-r--r--web/js.js22
8 files changed, 343 insertions, 139 deletions
diff --git a/perllib/Memcached.pm b/perllib/Memcached.pm
new file mode 100644
index 000000000..99ee60be1
--- /dev/null
+++ b/perllib/Memcached.pm
@@ -0,0 +1,31 @@
+#
+# Memcached.pm:
+# Trying out memcached on FixMyStreet
+#
+# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
+#
+# $Id: Memcached.pm,v 1.1 2008-09-16 15:45:09 matthew Exp $
+#
+
+package Memcached;
+
+use strict;
+use Cache::Memcached;
+
+my $memcache = new Cache::Memcached {
+ 'servers' => [ '127.0.0.1:11211' ],
+ 'namespace' => 'fms',
+ 'debug' => 0,
+ 'compress_threshold' => 10_000,
+};
+
+sub get {
+ $memcache->get(@_);
+}
+
+sub set {
+ $memcache->set(@_);
+}
+
+1;
diff --git a/perllib/Page.pm b/perllib/Page.pm
index 6cacf18be..164ccca76 100644
--- a/perllib/Page.pm
+++ b/perllib/Page.pm
@@ -6,7 +6,7 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: Page.pm,v 1.107 2008-09-10 11:37:36 matthew Exp $
+# $Id: Page.pm,v 1.108 2008-09-16 15:45:09 matthew Exp $
#
package Page;
@@ -25,6 +25,8 @@ use Problems;
use mySociety::Config;
use mySociety::DBHandle qw/dbh select_all/;
use mySociety::EvEl;
+use mySociety::Gaze;
+use mySociety::GeoUtil;
use mySociety::Locale;
use mySociety::MaPit;
use mySociety::PostcodeUtil;
@@ -221,7 +223,7 @@ EOF
<a href="http://www.mysociety.org/"><img id="logo" src="/i/mysociety-dark.png" alt="View mySociety.org"><span id="logoie"></span></a>
<p id="footer">Built by <a href="http://www.mysociety.org/">mySociety</a>,
-using some <a href="https://secure.mysociety.org/cvstrac/dir?d=mysociety/bci">clever</a> <a
+using some <a href="https://secure.mysociety.org/cvstrac/dir?d=mysociety/bci">clever</a>&nbsp;<a
href="https://secure.mysociety.org/cvstrac/dir?d=mysociety/services/TilMa">code</a>. Formerly <a href="/faq#nfi">Neighbourhood Fix-It</a>.</p>
$track
@@ -292,8 +294,8 @@ sub display_map {
$out .= <<EOF;
<form action="./" method="post" id="mapForm"$encoding>
<input type="hidden" name="submit_map" value="1">
-<input type="hidden" name="x" value="$x">
-<input type="hidden" name="y" value="$y">
+<input type="hidden" name="x" id="formX" value="$x">
+<input type="hidden" name="y" id="formY" value="$y">
<input type="hidden" name="pc" value="$pc_enc">
EOF
$img_type = '<input type="image"';
@@ -311,7 +313,7 @@ var start_x = $px; var start_y = $py;
$params{pre}
<div id="map"><div id="drag">
$img_type alt="NW map tile" id="t2.2" name="tile_$tl" src="$tl_src" style="top:0px; left:0;">$img_type alt="NE map tile" id="t2.3" name="tile_$tr" src="$tr_src" style="top:0px; left:$imgw;"><br>$img_type alt="SW map tile" id="t3.2" name="tile_$bl" src="$bl_src" style="top:$imgh; left:0;">$img_type alt="SE map tile" id="t3.3" name="tile_$br" src="$br_src" style="top:$imgh; left:$imgw;">
- $params{pins}
+ <div id="pins">$params{pins}</div>
</div>
EOF
$out .= '<div id="watermark"></div>';
@@ -347,6 +349,66 @@ sub display_pin {
return $out;
}
+sub map_pins {
+ my ($q, $x, $y, $sx, $sy) = @_;
+
+ my $pins = '';
+ my $min_e = Page::tile_to_os($x-2); # Extra space to left/below due to rounding, I think
+ my $min_n = Page::tile_to_os($y-2);
+ #my $map_le = Page::tile_to_os($x);
+ #my $map_ln = Page::tile_to_os($y);
+ my $mid_e = Page::tile_to_os($x+1);
+ my $mid_n = Page::tile_to_os($y+1);
+ #my $map_re = Page::tile_to_os($x+2);
+ #my $map_rn = Page::tile_to_os($y+2);
+ my $max_e = Page::tile_to_os($x+3);
+ my $max_n = Page::tile_to_os($y+3);
+
+ my $around_map = Problems::around_map($min_e, $max_e, $min_n, $max_n);
+ my @ids = ();
+ #my $count_prob = 1;
+ #my $count_fixed = 1;
+ foreach (@$around_map) {
+ push(@ids, $_->{id});
+ my $px = Page::os_to_px($_->{easting}, $sx);
+ my $py = Page::os_to_px($_->{northing}, $sy, 1);
+ my $col = $_->{state} eq 'fixed' ? 'green' : 'red';
+ $pins .= Page::display_pin($q, $px, $py, $col); # , $count_prob++);
+ }
+
+ my ($lat, $lon) = mySociety::GeoUtil::national_grid_to_wgs84($mid_e, $mid_n, 'G');
+ my $dist = mySociety::Gaze::get_radius_containing_population($lat, $lon, 200000);
+ $dist = int($dist*10+0.5)/10;
+
+ # XXX: Change to only show problems with extract(epoch from ms_current_timestamp()-lastupdate) < 8 weeks
+ # And somehow display/link to old problems somewhere else...
+ my $nearby = [];
+ #if (@$current_map < 9) {
+ my $limit = 9; # - @$current_map;
+ $nearby = Problems::nearby($dist, join(',', @ids), $limit, $mid_e, $mid_n);
+ foreach (@$nearby) {
+ my $px = Page::os_to_px($_->{easting}, $sx);
+ my $py = Page::os_to_px($_->{northing}, $sy, 1);
+ my $col = $_->{state} eq 'fixed' ? 'green' : 'red';
+ $pins .= Page::display_pin($q, $px, $py, $col); #, $count_prob++);
+ }
+ #} else {
+ # @$current_map = @$current_map[0..8];
+ #}
+
+ #my $fixed = Problems::fixed_nearby($dist, $mid_e, $mid_n);
+ #foreach (@$fixed) {
+ # my $px = Page::os_to_px($_->{easting}, $sx);
+ # my $py = Page::os_to_px($_->{northing}, $sy, 1);
+ # $pins .= Page::display_pin($q, $px, $py, 'green'); # , $count_fixed++);
+ #}
+ #if (@$fixed > 9) {
+ # @$fixed = @$fixed[0..8];
+ #}
+
+ return ($pins, $around_map, $nearby, $dist); # , $current_map, $current, '', $dist); # $fixed, $dist);
+}
+
sub compass ($$$) {
my ($q, $x, $y) = @_;
my @compass;
@@ -451,6 +513,7 @@ sub send_email {
my $action = ($thing eq 'alert') ? 'confirmed' : 'posted';
$thing .= ' report' if $thing eq _('problem');
+ $thing = 'expression of interest' if $thing eq 'tms';
my $out = <<EOF;
<h1>Nearly Done! Now check your email...</h1>
<p>The confirmation email <strong>may</strong> take a few minutes to arrive &mdash; <em>please</em> be patient.</p>
diff --git a/perllib/Problems.pm b/perllib/Problems.pm
index 38dbdef07..72b3a7ebc 100644
--- a/perllib/Problems.pm
+++ b/perllib/Problems.pm
@@ -6,49 +6,74 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: Problems.pm,v 1.4 2008-09-10 11:37:36 matthew Exp $
+# $Id: Problems.pm,v 1.5 2008-09-16 15:45:09 matthew Exp $
#
package Problems;
use strict;
+# use Memcached;
use mySociety::DBHandle qw/dbh select_all/;
use mySociety::Web qw/ent/;
my $site_restriction = '';
+my $site_key = 0;
sub set_site_restriction {
my $site = shift;
my @cats = Page::scambs_categories();
my $cats = join("','", @cats);
$site_restriction = " and council=2260 and category in
- ('$cats') "
+ ('$cats') "
if $site eq 'scambs';
+ $site_key = 1;
}
# Front page statistics
sub recent_fixed {
- dbh()->selectrow_array("select count(*) from problem
- where state='fixed' and lastupdate>ms_current_timestamp()-'1 month'::interval
- $site_restriction");
+ my $result;
+ #my $key = "recent_fixed:$site_key";
+ #$result = Memcached::get($key);
+ #unless ($result) {
+ $result = dbh()->selectrow_array("select count(*) from problem
+ where state='fixed' and lastupdate>ms_current_timestamp()-'1 month'::interval
+ $site_restriction");
+ # Memcached::set($key, $result, 3600);
+ #}
+ return $result;
}
sub number_comments {
- if ($site_restriction) {
- dbh()->selectrow_array("select count(*) from comment, problem
- where comment.problem_id=problem.id and comment.state='confirmed'
- $site_restriction");
- } else {
- dbh()->selectrow_array("select count(*) from comment
- where state='confirmed'");
- }
+ my $result;
+ #my $key = "number_comments:$site_key";
+ #$result = Memcached::get($key);
+ #unless ($result) {
+ if ($site_restriction) {
+ $result = dbh()->selectrow_array("select count(*) from comment, problem
+ where comment.problem_id=problem.id and comment.state='confirmed'
+ $site_restriction");
+ } else {
+ $result = dbh()->selectrow_array("select count(*) from comment
+ where state='confirmed'");
+ }
+ # Memcached::set($key, $result, 3600);
+ #}
+ return $result;
}
sub recent_new {
my $interval = shift;
- dbh()->selectrow_array("select count(*) from problem
- where state in ('confirmed','fixed') and confirmed>ms_current_timestamp()-'$interval'::interval
- $site_restriction");
+ my $result;
+ #(my $key = $interval) =~ s/\s+//g;
+ #$key = "recent_new:$site_key:$key";
+ #my $result = Memcached::get($key);
+ #unless ($result) {
+ $result = dbh()->selectrow_array("select count(*) from problem
+ where state in ('confirmed','fixed') and confirmed>ms_current_timestamp()-'$interval'::interval
+ $site_restriction");
+ # Memcached::set($key, $result, 3600);
+ #}
+ return $result;
}
# Front page recent lists
@@ -57,17 +82,27 @@ sub recent_photos {
my ($num, $e, $n, $dist) = @_;
my $probs;
if ($e) {
- $probs = select_all("select id, title
- from problem_find_nearby(?, ?, ?) as nearby, problem
- where nearby.problem_id = problem.id
- and state in ('confirmed', 'fixed') and photo is not null
- $site_restriction
- order by confirmed desc limit $num", $e, $n, $dist);
+ #my $key = "recent_photos:$site_key:$num:$e:$n:$dist";
+ #$probs = Memcached::get($key);
+ #unless ($probs) {
+ $probs = select_all("select id, title
+ from problem_find_nearby(?, ?, ?) as nearby, problem
+ where nearby.problem_id = problem.id
+ and state in ('confirmed', 'fixed') and photo is not null
+ $site_restriction
+ order by confirmed desc limit $num", $e, $n, $dist);
+ # Memcached::set($key, $probs, 3600);
+ #}
} else {
- $probs = select_all("select id, title from problem
- where state in ('confirmed', 'fixed') and photo is not null
- $site_restriction
- order by confirmed desc limit $num");
+ #my $key = "recent_photos:$site_key:$num";
+ #$probs = Memcached::get($key);
+ #unless ($probs) {
+ $probs = select_all("select id, title from problem
+ where state in ('confirmed', 'fixed') and photo is not null
+ $site_restriction
+ order by confirmed desc limit $num");
+ # Memcached::set($key, $probs, 3600);
+ #}
}
my $out = '';
foreach (@$probs) {
@@ -80,30 +115,38 @@ sub recent_photos {
}
sub recent {
- select_all("select id,title from problem
- where state in ('confirmed', 'fixed')
- $site_restriction
- order by confirmed desc limit 5");
+ my $result;
+ #my $key = "recent:$site_key";
+ #$result = Memcached::get($key);
+ #unless ($result) {
+ $result = select_all("select id,title from problem
+ where state in ('confirmed', 'fixed')
+ $site_restriction
+ order by confirmed desc limit 5");
+ # Memcached::set($key, $result, 3600);
+ #}
+ return $result;
}
# Problems around a location
-sub current_on_map {
+sub around_map {
my ($min_e, $max_e, $min_n, $max_n) = @_;
select_all(
- "select id,title,easting,northing from problem where state='confirmed'
- and easting>=? and easting<? and northing>=? and northing<?
+ "select id,title,easting,northing,state from problem
+ where state in ('confirmed', 'fixed')
+ and easting>=? and easting<? and northing>=? and northing<?
$site_restriction
order by created desc", $min_e, $max_e, $min_n, $max_n);
}
-sub current_nearby {
+sub nearby {
my ($dist, $ids, $limit, $mid_e, $mid_n) = @_;
select_all(
- "select id, title, easting, northing, distance
+ "select id, title, easting, northing, distance, state
from problem_find_nearby(?, ?, $dist) as nearby, problem
where nearby.problem_id = problem.id
- and state = 'confirmed'" . ($ids ? ' and id not in (' . $ids . ')' : '') . "
+ and state in ('confirmed', 'fixed')" . ($ids ? ' and id not in (' . $ids . ')' : '') . "
$site_restriction
order by distance, created desc limit $limit", $mid_e, $mid_n);
}
@@ -115,7 +158,7 @@ sub fixed_nearby {
from problem_find_nearby(?, ?, $dist) as nearby, problem
where nearby.problem_id = problem.id and state='fixed'
$site_restriction
- order by created desc limit 9", $mid_e, $mid_n);
+ order by lastupdate desc", $mid_e, $mid_n);
}
# Fetch an individual problem
diff --git a/web/ajax.cgi b/web/ajax.cgi
new file mode 100755
index 000000000..7efae6de5
--- /dev/null
+++ b/web/ajax.cgi
@@ -0,0 +1,80 @@
+#!/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.1 2008-09-16 15:45:10 matthew Exp $
+
+use strict;
+use Standard;
+use mySociety::Web qw(ent NewURL);
+
+sub main {
+ my $q = shift;
+
+ my @vars = qw(x y sx sy);
+ my %input = map { $_ => $q->param($_) || '' } @vars;
+ my %input_h = map { $_ => $q->param($_) ? ent($q->param($_)) : '' } @vars;
+
+ # Our current X/Y bottom left 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 ($pins, $on_map, $around_map, $dist) = Page::map_pins($q, $x, $y, $sx, $sy);
+
+ my $list = '';
+ foreach (@$on_map) {
+ $list .= '<li><a href="' . NewURL($q, id=>$_->{id}, x=>undef, y=>undef) . '">';
+ $list .= $_->{title};
+ $list .= '</a>';
+ $list .= ' <small>(fixed)</small>' if $_->{state} eq 'fixed';
+ $list .= '</li>';
+ }
+ my $om_list = $list;
+
+ $list = '';
+ foreach (@$around_map) {
+ $list .= '<li><a href="' . NewURL($q, id=>$_->{id}, x=>undef, y=>undef) . '">';
+ $list .= $_->{title} . ' <small>(' . int($_->{distance}/100+.5)/10 . 'km)</small>';
+ $list .= '</a>';
+ $list .= ' <small>(fixed)</small>' if $_->{state} eq 'fixed';
+ $list .= '</li>';
+ }
+ my $am_list = $list;
+
+ #$list = '';
+ #foreach (@$fixed) {
+ # $list .= '<li><a href="' . NewURL($q, id=>$_->{id}, x=>undef, y=>undef) . '">';
+ # $list .= $_->{title} . ' <small>(' . int($_->{distance}/100+.5)/10 . 'km)</small>';
+ # $list .= '</a></li>';
+ #}
+ #my $f_list = $list;
+
+ print $q->header(-charset => 'utf-8', -content_type => 'text/javascript');
+
+ $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);
+
diff --git a/web/alert.cgi b/web/alert.cgi
index c7a7910a3..dbb131684 100755
--- a/web/alert.cgi
+++ b/web/alert.cgi
@@ -6,7 +6,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: alert.cgi,v 1.29 2008-07-10 21:20:02 matthew Exp $
+# $Id: alert.cgi,v 1.30 2008-09-16 15:45:10 matthew Exp $
use strict;
use Standard;
@@ -163,7 +163,7 @@ but will only appear in the "Within the boundary" alert for the county council.'
} else {
# Hopefully impossible in the UK!
- throw Error::Simple('An area with three tiers of council? Impossible!');
+ throw Error::Simple('An area with three tiers of council? Impossible! '. $e . ' ' . $n . ' ' . join('|',keys %$areas));
}
my ($lat, $lon) = mySociety::GeoUtil::national_grid_to_wgs84($e, $n, 'G');
@@ -230,7 +230,7 @@ sub alert_list_options {
. '</label> <a href="/rss/';
$out .= $type eq 'area' ? 'area' : 'reports';
$out .= '/' . $rss . '"><img src="/i/feed.png" width="16" height="16"
-title="' . sprintf(_('RSS feed of local problems at %s'), $text) . '" alt="' . _('RSS feed') . '" border="0"></a>';
+title="' . sprintf(_('RSS feed of %s'), $text) . '" alt="' . _('RSS feed') . '" border="0"></a>';
}
return $out;
}
diff --git a/web/css/core.css b/web/css/core.css
index 20969ef1d..078b4bfc8 100644
--- a/web/css/core.css
+++ b/web/css/core.css
@@ -268,13 +268,25 @@ p#copyright {
margin: 0;
}
-#closest_problems {
+#nearby_lists h2 {
+ margin-top: 0.5em;
margin-bottom: 0;
}
#alert_links {
float: right;
}
-#rss_link {
+#alert_links_area {
+ background-color: #ffeecc;
+ border: solid 1px #ff9900;
+ border-width: 1px 0;
+ padding: 3px 10px;
+ margin: 0;
+}
+#rss_alert {
+ text-decoration: none;
+}
+#rss_alert span {
+ text-decoration: underline;
}
#email_alert {
}
diff --git a/web/index.cgi b/web/index.cgi
index 5dd2e41a0..c96d49065 100755
--- a/web/index.cgi
+++ b/web/index.cgi
@@ -6,7 +6,7 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: index.cgi,v 1.205 2008-09-10 12:04:12 matthew Exp $
+# $Id: index.cgi,v 1.206 2008-09-16 15:45:10 matthew Exp $
use strict;
use Standard;
@@ -22,8 +22,6 @@ use mySociety::AuthToken;
use mySociety::Config;
use mySociety::DBHandle qw(select_all);
use mySociety::EmailUtil;
-use mySociety::Gaze;
-use mySociety::GeoUtil;
use mySociety::MaPit;
use mySociety::PostcodeUtil;
use mySociety::Random;
@@ -82,6 +80,7 @@ sub front_page {
$out .= '<p id="error">' . $error . '</p>' if ($error);
my $fixed = Problems::recent_fixed();
my $updates = Problems::number_comments();
+ $updates =~ s/(\d\d\d)$/,$1/;
my $new = Problems::recent_new('1 week');
my $new_text = 'in past week';
if ($new > $fixed) {
@@ -132,7 +131,7 @@ EOF
$out .= $q->div({-id => 'front_stats'},
$q->div("<big>$new</big> report" . ($new!=1?'s':''), $new_text),
($q->{site} ne 'emptyhomes' && $q->div("<big>$fixed</big> fixed in past month")),
- $q->div("<big>$updates</big> update" . ($updates!=1?'s':''), "on reports"),
+ $q->div("<big>$updates</big> update" . ($updates ne '1'?'s':''), "on reports"),
);
$out .= <<EOF;
@@ -676,9 +675,19 @@ sub display_location {
return Page::geocode_choice($error, '/') if (ref($error) eq 'ARRAY');
return front_page($q, $error) if ($error);
- my ($pins, $current_map, $current, $fixed, $dist) = map_pins($q, $x, $y);
+ my ($pins, $on_map, $around_map, $dist) = Page::map_pins($q, $x, $y, $x, $y);
my $out = Page::display_map($q, x => $x, y => $y, type => 1, pins => $pins );
$out .= $q->h1(_('Problems in this area'));
+ my $email_me = _('Email me new local problems');
+ my $rss_title = _('RSS feed of recent local problems');
+ my $rss_alt = _('RSS feed');
+ my $u_pc = uri_escape($input{pc});
+ $out .= <<EOF;
+ <p id="alert_links_area">
+ <a id="email_alert" href="/alert?pc=$u_pc;type=local;feed=local:$x:$y;alert=Subscribe">$email_me</a>
+ | <a href="/rss/$x,$y" id="rss_alert"><span>RSS feed</span> <img src="/i/feed.png" width="16" height="16" title="$rss_title" alt="$rss_alt" border="0" style="vertical-align: top"></a>
+ </p>
+EOF
if (@errors) {
$out .= '<ul id="error"><li>' . join('</li><li>', @errors) . '</li></ul>';
}
@@ -689,53 +698,48 @@ or are using a text only browser, for example &ndash; and you
wish to report a problem, please
<a href='%s'>skip this step</a> and we will ask you
to describe the location of the problem instead.</small>"), $skipurl));
- $out .= '<div>' . $q->h2(_('Recent problems reported near here'));
+ $out .= '<div id="nearby_lists">' . $q->h2(_('Reports on and around the map'));
my $list = '';
- foreach (@$current_map) {
+ foreach (@$on_map) {
$list .= '<li><a href="' . NewURL($q, id=>$_->{id}, x=>undef, y=>undef) . '">';
$list .= $_->{title};
- $list .= '</a></li>';
+ $list .= '</a>';
+ $list .= ' <small>(fixed)</small>' if $_->{state} eq 'fixed';
+ $list .= '</li>';
}
- if (@$current_map) {
- $out .= '<ol id="current">' . $list . '</ol>';
+ if (@$on_map) {
+ $out .= '<ul id="current">' . $list . '</ul>';
} else {
$out .= $q->p(_('No problems have been reported yet.'));
}
- $out .= $q->h2({-id => 'closest_problems'}, sprintf(_('Closest problems within %skm'), $dist));
- my $email_me = _('Email me problems');
- my $rss_title = _('RSS feed of recent local problems');
- my $rss_alt = _('RSS feed');
- my $u_pc = uri_escape($input{pc});
- $out .= <<EOF;
- <div id="alert_links">
- <a id="email_alert" href="/alert?pc=$u_pc;type=local;feed=local:$x:$y;alert=Subscribe">$email_me</a>
- &nbsp; <span id="rss_link"><a href="/rss/$x,$y"><img src="/i/feed.png" width="16" height="16" title="$rss_title" alt="$rss_alt" border="0" style="vertical-align: middle"></a></span>
- </div>
-EOF
+ $out .= $q->h2({-id => 'closest_problems'}, sprintf(_('Other nearby problems <small>within&nbsp;%skm</small>'), $dist));
$list = '';
- foreach (@$current) {
+ foreach (@$around_map) {
$list .= '<li><a href="' . NewURL($q, id=>$_->{id}, x=>undef, y=>undef) . '">';
$list .= $_->{title} . ' <small>(' . int($_->{distance}/100+.5)/10 . 'km)</small>';
- $list .= '</a></li>';
- }
- if (@$current) {
- my $list_start = @$current_map + 1;
- $out .= '<ol id="current_near" start="' . $list_start . '">' . $list . '</ol>';
+ $list .= '</a>';
+ $list .= ' <small>(fixed)</small>' if $_->{state} eq 'fixed';
+ $list .= '</li>';
+ }
+ if (@$around_map) {
+ #my $list_start = @$on_map + 1;
+ #$out .= '<ul id="current_near" start="' . $list_start . '">' . $list . '</ul>';
+ $out .= '<ul id="current_near">' . $list . '</ul>';
} else {
- $out .= $q->p(_('No problems have been reported yet.'));
- }
- $out .= $q->h2(sprintf(_('Recently fixed problems within %skm'), $dist));
- $list = '';
- foreach (@$fixed) {
- $list .= '<li><a href="' . NewURL($q, id=>$_->{id}, x=>undef, y=>undef) . '">';
- $list .= $_->{title} . ' <small>(' . int($_->{distance}/100+.5)/10 . 'km)</small>';
- $list .= '</a></li>';
- }
- if (@$fixed) {
- $out .= "<ol>$list</ol>\n";
- } else {
- $out .= $q->p(_('No problems have been fixed yet'));
- }
+ $out .= $q->p(_('No problems found.'));
+ }
+ #$out .= $q->h2(sprintf(_('Recently fixed problems within %skm'), $dist));
+ #$list = '';
+ #foreach (@$fixed) {
+ # $list .= '<li><a href="' . NewURL($q, id=>$_->{id}, x=>undef, y=>undef) . '">';
+ # $list .= $_->{title} . ' <small>(' . int($_->{distance}/100+.5)/10 . 'km)</small>';
+ # $list .= '</a></li>';
+ #}
+ #if (@$fixed) {
+ # $out .= "<ul id='fixed_near'>$list</ul>\n";
+ #} else {
+ # $out .= $q->p(_('No problems have been fixed yet'));
+ #}
$out .= '</div>';
$out .= Page::display_map_end(1);
@@ -804,7 +808,7 @@ sub display_problem {
<input type="submit" value="Subscribe">
</form>
EOF
- $out .= ' &nbsp; <span id="rss_link"><a href="/rss/'.$input_h{id}.'"><img src="/i/feed.png" width="16" height="16" title="' . _('RSS feed') . '" alt="' . _('RSS feed of updates to this problem') . '" border="0" style="vertical-align: middle"></a></span>';
+ $out .= ' &nbsp; <a href="/rss/'.$input_h{id}.'"><img src="/i/feed.png" width="16" height="16" title="' . _('RSS feed') . '" alt="' . _('RSS feed of updates to this problem') . '" border="0" style="vertical-align: middle"></a>';
$out .= '</div>';
$out .= Page::display_problem_updates($input{id});
@@ -861,52 +865,3 @@ EOF
return ($out, %params);
}
-sub map_pins {
- my ($q, $x, $y) = @_;
-
- my $pins = '';
- my $min_e = Page::tile_to_os($x-1);
- my $min_n = Page::tile_to_os($y-1);
- my $mid_e = Page::tile_to_os($x+1);
- my $mid_n = Page::tile_to_os($y+1);
- my $max_e = Page::tile_to_os($x+3);
- my $max_n = Page::tile_to_os($y+3);
-
- my $current_map = Problems::current_on_map($min_e, $max_e, $min_n, $max_n);
- my @ids = ();
- my $count_prob = 1;
- my $count_fixed = 1;
- foreach (@$current_map) {
- push(@ids, $_->{id});
- my $px = Page::os_to_px($_->{easting}, $x);
- my $py = Page::os_to_px($_->{northing}, $y, 1);
- $pins .= Page::display_pin($q, $px, $py, 'red', $count_prob++);
- }
-
- my ($lat, $lon) = mySociety::GeoUtil::national_grid_to_wgs84($mid_e, $mid_n, 'G');
- my $dist = mySociety::Gaze::get_radius_containing_population($lat, $lon, 200000);
- $dist = int($dist*10+0.5)/10;
-
- # XXX: Change to only show problems with extract(epoch from ms_current_timestamp()-lastupdate) < 8 weeks
- # And somehow display/link to old problems somewhere else...
- my $current = [];
- if (@$current_map < 9) {
- my $limit = 9 - @$current_map;
- $current = Problems::current_nearby($dist, join(',', @ids), $limit, $mid_e, $mid_n);
- foreach (@$current) {
- my $px = Page::os_to_px($_->{easting}, $x);
- my $py = Page::os_to_px($_->{northing}, $y, 1);
- $pins .= Page::display_pin($q, $px, $py, 'red', $count_prob++);
- }
- } else {
- @$current_map = @$current_map[0..8];
- }
- my $fixed = Problems::fixed_nearby($dist, $mid_e, $mid_n);
- foreach (@$fixed) {
- my $px = Page::os_to_px($_->{easting}, $x);
- my $py = Page::os_to_px($_->{northing}, $y, 1);
- $pins .= Page::display_pin($q, $px, $py, 'green', $count_fixed++);
- }
- return ($pins, $current_map, $current, $fixed, $dist);
-}
-
diff --git a/web/js.js b/web/js.js
index 2a52ab423..7f4add8c1 100644
--- a/web/js.js
+++ b/web/js.js
@@ -249,10 +249,30 @@ function update_tiles(dx, dy, force) {
tile_y += vertical;
var url = [ '/tilma/tileserver/10k-full/', x, '-', (x+5), ',', y, '-', (y+5), '/JSON' ].join('');
- var req = YAHOO.util.Connect.asyncRequest('GET', url, {
+ YAHOO.util.Connect.asyncRequest('GET', url, {
success: urls_loaded, failure: urls_not_loaded,
argument: [tile_x, tile_y]
});
+
+ if (force) return;
+
+ url = [ '/ajax?sx=', document.getElementById('formX').value, ';sy=',
+ document.getElementById('formY').value, ';x=', (x+2), ';y=', (y+2)
+ ].join('');
+ YAHOO.util.Connect.asyncRequest('GET', url, {
+ success: pins_loaded
+ });
+}
+
+function pins_loaded(o) {
+ var data = eval(o.responseText);
+ document.getElementById('pins').innerHTML = data.pins;
+ if (typeof(data.current) != 'undefined')
+ document.getElementById('current').innerHTML = data.current;
+ if (typeof(data.current_near) != 'undefined')
+ document.getElementById('current_near').innerHTML = data.current_near;
+ if (typeof(data.fixed_near) != 'undefined')
+ document.getElementById('fixed_near').innerHTML = data.fixed_near;
}
function urls_not_loaded(o) { /* Nothing yet */ }