diff options
Diffstat (limited to 'web')
-rwxr-xr-x | web/ajax.cgi | 80 | ||||
-rwxr-xr-x | web/alert.cgi | 6 | ||||
-rw-r--r-- | web/css/core.css | 16 | ||||
-rwxr-xr-x | web/index.cgi | 137 | ||||
-rw-r--r-- | web/js.js | 22 |
5 files changed, 164 insertions, 97 deletions
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 – 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> - <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 %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 .= ' <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 .= ' <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); -} - @@ -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 */ } |