aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdmund von der Burg <evdb@mysociety.org>2011-04-13 17:47:45 +0100
committerEdmund von der Burg <evdb@mysociety.org>2011-04-13 17:47:45 +0100
commitc725851a457637daddaefc5da198e0bf3de6b236 (patch)
tree038d4f1faf830eb3a56a9e7be9ef85792eca0d5a
parenta93ff0eb307d1440cb54a8ae258b6d16d4f0c59d (diff)
Port display_location
-rw-r--r--notes/catalyst-master-merge-todos.txt4
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm258
-rw-r--r--perllib/FixMyStreet/App/View/Web.pm20
-rw-r--r--templates/web/default/around/around_index.html2
-rwxr-xr-xtemplates/web/default/around/display_location.html126
-rw-r--r--templates/web/default/common_header_tags.html4
6 files changed, 223 insertions, 191 deletions
diff --git a/notes/catalyst-master-merge-todos.txt b/notes/catalyst-master-merge-todos.txt
index f536a9d86..84f64132b 100644
--- a/notes/catalyst-master-merge-todos.txt
+++ b/notes/catalyst-master-merge-todos.txt
@@ -1,3 +1,7 @@
+display_may needs a properly faked $q so it can choose a cobrand. Or should it be ported to use new cobrand?
+
+change uri_for to use cobrand->url so we don't have to
+
should we ditch flickr import? (does not seem to be getting huge usage and those using it would probably report using another method: http://www.flickr.com/search/?w=all&q=fixmystreet&m=tags)
move all FAQ over to TT2
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index 4cdf07dad..0c6db66be 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -7,6 +7,7 @@ BEGIN { extends 'Catalyst::Controller'; }
use FixMyStreet::Map;
use List::MoreUtils qw(any);
use Encode;
+use FixMyStreet::Map;
=head1 NAME
@@ -54,7 +55,7 @@ sub around_index : Path : Args(0) {
warn "FIXME - implement";
# Show the nearby reports
- $c->forward('display_location');
+ $c->detach('display_location');
}
@@ -67,176 +68,87 @@ Display a specific lat/lng location (which may have come from a pc search).
sub display_location : Private {
my ( $self, $c ) = @_;
-# # Deal with pin hiding/age
-# my ( $hide_link, $hide_text, $all_link, $all_text, $interval );
-# if ( $input{all_pins} ) {
-# $all_link =
-# NewURL( $q, -retain => 1, no_pins => undef, all_pins => undef );
-# $all_text = _('Hide stale reports');
-# }
-# else {
-# $all_link = NewURL( $q, -retain => 1, no_pins => undef, all_pins => 1 );
-# $all_text = _('Include stale reports');
-# $interval = '6 months';
-# }
-
-# my ( $on_map_all, $on_map, $around_map, $dist ) =
-# FixMyStreet::Map::map_features( $q, $latitude, $longitude, $interval );
-# my @pins;
-# foreach (@$on_map_all) {
-# push @pins,
-# [
-# $_->{latitude}, $_->{longitude},
-# ( $_->{state} eq 'fixed' ? 'green' : 'red' ), $_->{id}
-# ];
-# }
-# my $on_list = '';
-# foreach (@$on_map) {
-# my $report_url = NewURL( $q, -url => '/report/' . $_->{id} );
-# $report_url = Cobrand::url( $cobrand, $report_url, $q );
-# $on_list .= '<li><a href="' . $report_url . '">';
-# $on_list .= ent( $_->{title} ) . '</a> <small>(';
-# $on_list .= Page::prettify_epoch( $q, $_->{time}, 1 ) . ')</small>';
-# $on_list .= ' <small>' . _('(fixed)') . '</small>'
-# if $_->{state} eq 'fixed';
-# $on_list .= '</li>';
-# }
-# $on_list = $q->li( _('No problems have been reported yet.') )
-# unless $on_list;
-#
-# my $around_list = '';
-# foreach (@$around_map) {
-# my $report_url =
-# Cobrand::url( $cobrand, NewURL( $q, -url => '/report/' . $_->{id} ),
-# $q );
-# $around_list .= '<li><a href="' . $report_url . '">';
-# my $dist = int( $_->{distance} * 10 + 0.5 );
-# $dist = $dist / 10;
-# $around_list .= ent( $_->{title} ) . '</a> <small>(';
-# $around_list .= Page::prettify_epoch( $q, $_->{time}, 1 ) . ', ';
-# $around_list .= $dist . 'km)</small>';
-# $around_list .= ' <small>' . _('(fixed)') . '</small>'
-# if $_->{state} eq 'fixed';
-# $around_list .= '</li>';
-# push @pins,
-# [
-# $_->{latitude}, $_->{longitude},
-# ( $_->{state} eq 'fixed' ? 'green' : 'red' ), $_->{id}
-# ];
-# }
-# $around_list = $q->li( _('No problems found.') )
-# unless $around_list;
-
-# if ( $input{no_pins} ) {
-# $hide_link = NewURL( $q, -retain => 1, no_pins => undef );
-# $hide_text = _('Show pins');
-# @pins = ();
-# }
-# else {
-# $hide_link = NewURL( $q, -retain => 1, no_pins => 1 );
-# $hide_text = _('Hide pins');
-# }
-
-# my $map_links =
-# "<p id='sub_map_links'><a id='hide_pins_link' rel='nofollow' href='$hide_link'>$hide_text</a>";
-# if ( mySociety::Config::get('COUNTRY') eq 'GB' ) {
-# $map_links .=
-# " | <a id='all_pins_link' rel='nofollow' href='$all_link'>$all_text</a></p> <input type='hidden' id='all_pins' name='all_pins' value='$input_h{all_pins}'>";
-# }
-# else {
-# $map_links .= "</p>";
-# }
-
-# # truncate the lat,lon for nicer rss urls, and strings for outputting
-# my ( $short_lat, $short_lon ) =
-# map { Utils::truncate_coordinate($_) } #
-# ( $latitude, $longitude );
-#
-# my $url_skip = NewURL(
-# $q,
-# -url => '/report/new',
-# -retain => 1,
-# x => undef,
-# y => undef,
-# latitude => $short_lat,
-# longitude => $short_lon,
-# submit_map => 1,
-# skipped => 1
-# );
-#
-# my $pc_h = ent( $q->param('pc') || '' );
-#
-# my $rss_url;
-# if ($pc_h) {
-# $rss_url = "/rss/pc/" . URI::Escape::uri_escape_utf8($pc_h);
-# }
-# else {
-# $rss_url = "/rss/l/$short_lat,$short_lon";
-# }
-# $rss_url = Cobrand::url( $cobrand, NewURL( $q, -url => $rss_url ), $q );
-#
-# my %vars = (
-# 'map' => FixMyStreet::Map::display_map(
-# $q,
-# latitude => $short_lat,
-# longitude => $short_lon,
-# type => 1,
-# pins => \@pins,
-# post => $map_links
-# ),
-# map_end => FixMyStreet::Map::display_map_end(1),
-# url_home => Cobrand::url( $cobrand, '/', $q ),
-# url_rss => $rss_url,
-# url_email => Cobrand::url(
-# $cobrand,
-# NewURL(
-# $q,
-# lat => $short_lat,
-# lon => $short_lon,
-# -url => '/alert',
-# feed => "local:$short_lat:$short_lon"
-# ),
-# $q
-# ),
-# url_skip => $url_skip,
-# email_me => _('Email me new local problems'),
-# rss_alt => _('RSS feed'),
-# rss_title => _('RSS feed of recent local problems'),
-# reports_on_around => $on_list,
-# reports_nearby => $around_list,
-# heading_problems => _('Problems in this area'),
-# heading_on_around => _('Reports on and around the map'),
-# heading_closest => sprintf(
-# _('Closest nearby problems <small>(within&nbsp;%skm)</small>'),
-# $dist
-# ),
-# distance => $dist,
-# pc_h => $pc_h,
-# errors => @errors
-# ? '<ul class="error"><li>' . join( '</li><li>', @errors ) . '</li></ul>'
-# : '',
-# text_to_report => _(
-# 'To report a problem, simply
-# <strong>click on the map</strong> at the correct location.'
-# ),
-# text_skip => sprintf(
-# _(
-# "<small>If you cannot see the map, <a href='%s' rel='nofollow'>skip this
-# step</a>.</small>"
-# ),
-# $url_skip
-# ),
-# );
-#
-# my %params = (
-# rss => [ _('Recent local problems, FixMyStreet'), $rss_url ],
-# js => FixMyStreet::Map::header_js(),
-# robots => 'noindex,nofollow',
-# );
-#
-# return (
-# Page::template_include( 'map', $q, Page::template_root($q), %vars ),
-# %params );
+ # set the template to use
+ $c->stash->{template} = 'around/display_location.html';
+
+ # get the lat,lng
+ my $latitude = $c->stash->{latitude};
+ my $longitude = $c->stash->{longitude};
+
+ # truncate the lat,lon for nicer rss urls, and strings for outputting
+ my $short_latitude = Utils::truncate_coordinate($latitude);
+ my $short_longitude = Utils::truncate_coordinate($longitude);
+ $c->stash->{short_latitude} = $short_latitude;
+ $c->stash->{short_longitude} = $short_longitude;
+
+ # Deal with pin hiding/age
+ my $all_pins = $c->req->param('all_pins') ? 1 : undef;
+ $c->stash->{all_pins} = $all_pins;
+
+ # Setup some bits of text
+ 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';
+
+ # get the map features
+ my ( $on_map_all, $on_map, $around_map, $distance ) =
+ FixMyStreet::Map::map_features( $c->req, $latitude, $longitude,
+ $interval );
+
+ # copy the found reports to the stash
+ $c->stash->{on_map} = $on_map;
+ $c->stash->{around_map} = $around_map;
+ $c->stash->{distance} = $distance;
+
+ # create a list of all the pins
+ my @pins = map {
+ my $pin_colour = $_->{state} eq 'fixed' ? 'green' : 'red';
+ [ $_->{latitude}, $_->{longitude}, $pin_colour, $_->{id} ];
+ } @$on_map_all, @$around_map;
+
+ { # FIXME - ideally this indented code should be in the templates
+ my $no_pins = $c->req->param('no_pins') || '';
+ my $toggle_pins_link =
+ $c->req->uri_with( { no_pins => $no_pins ? 0 : 1 } );
+ my $toggle_pins_text = $no_pins ? _('Show pins') : _('Hide pins');
+
+ my $map_links =
+ "<p id='sub_map_links'>"
+ . " <a id='hide_pins_link' rel='nofollow' href='$toggle_pins_link'>"
+ . " $toggle_pins_text" #
+ . " </a>";
+
+ $map_links .= #
+ " | " #
+ . "<a id='all_pins_link' rel='nofollow' href='$all_link'>" #
+ . " $all_text" #
+ . "</a>"
+ if mySociety::Config::get('COUNTRY') eq 'GB';
+
+ $map_links .= "</p>";
+
+ $map_links .= #
+ "<input type='hidden' id='all_pins' name='all_pins' value='" #
+ . ( $all_pins || '' ) #
+ . "'>"
+ if mySociety::Config::get('COUNTRY') eq 'GB';
+
+ $map_links .= "</p>";
+
+ $c->stash->{map_html} = FixMyStreet::Map::display_map(
+ $c->req,
+ latitude => $latitude,
+ longitude => $longitude,
+ type => 1,
+ pins => \@pins,
+ post => $map_links
+ );
+ $c->stash->{map_end_html} = FixMyStreet::Map::display_map_end(1);
+ $c->stash->{map_js} = FixMyStreet::Map::header_js();
+ }
+
+ return 1;
}
=head2 determine_location_from_coords
@@ -248,8 +160,8 @@ Use latitude and longitude if provided in parameters.
sub determine_location_from_coords : Private {
my ( $self, $c ) = @_;
- my $latitude = $c->req->param('latitude');
- my $longitude = $c->req->param('longitude');
+ my $latitude = $c->req->param('latitude') || $c->req->param('lat');
+ my $longitude = $c->req->param('longitude') || $c->req->param('lon');
if ( defined $latitude && defined $longitude ) {
$c->stash->{latitude} = $latitude;
diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm
index c8240948d..cbb68df0d 100644
--- a/perllib/FixMyStreet/App/View/Web.pm
+++ b/perllib/FixMyStreet/App/View/Web.pm
@@ -15,7 +15,9 @@ __PACKAGE__->config(
],
ENCODING => 'utf8',
render_die => 1,
- expose_methods => [ 'loc', 'nget', 'tprintf', 'display_crossell_advert' ],
+ expose_methods => [
+ 'loc', 'nget', 'tprintf', 'display_crossell_advert', 'prettify_epoch',
+ ],
);
=head1 NAME
@@ -87,5 +89,21 @@ sub display_crossell_advert {
return CrossSell::display_advert( $q, $email, $name );
}
+=head2 Page::prettify_epoch
+
+ [% pretty = prettify_epoch( $epoch, $short_bool ) %]
+
+Return a pretty version of the epoch.
+
+ $short_bool = 1; # 16:02, 29 Mar 2011
+ $short_bool = 0; # 16:02, Tuesday 29 March 2011
+
+=cut
+
+sub prettify_epoch {
+ my ( $self, $c, $epoch, $short_bool ) = @_;
+ return Page::prettify_epoch( $c->req, $epoch, $short_bool );
+}
+
1;
diff --git a/templates/web/default/around/around_index.html b/templates/web/default/around/around_index.html
index 07b3cee4d..3f86761aa 100644
--- a/templates/web/default/around/around_index.html
+++ b/templates/web/default/around/around_index.html
@@ -8,7 +8,7 @@
%]
-<form action="[% partial_token ? '/report/new' : '/' %]" method="get" name="postcodeForm" id="postcodeForm"><label for="pc">[% loc("Enter a nearby GB postcode, or street name and area") %]:</label>
+<form action="[% '/around' %]" method="get" name="postcodeForm" id="postcodeForm"><label for="pc">[% loc("Enter a nearby GB postcode, or street name and area") %]:</label>
&nbsp;<input type="text" name="pc" value="[% pc | html %]" id="pc" size="10" maxlength="200">
&nbsp;<input type="submit" value="[% loc('Go') %]" id="submit">
[% c.cobrand.form_elements %]
diff --git a/templates/web/default/around/display_location.html b/templates/web/default/around/display_location.html
index f54c68aba..89f2c79e4 100755
--- a/templates/web/default/around/display_location.html
+++ b/templates/web/default/around/display_location.html
@@ -1,28 +1,124 @@
-{{ $map }}
+[%
-<h1>{{ $heading_problems }}</h1>
+ rss_alt = loc('RSS feed');
+ rss_title = loc('RSS feed of recent local problems');
+
+ rss_url
+ = pc
+ ? c.uri_for( "/rss/pc", pc )
+ : c.uri_for( "/rss/l/$short_latitude,$short_longitude" );
+
+ email_url = c.uri_for(
+ '/alert',
+ {
+ lat => short_latitude,
+ lon => short_longitude,
+ feed => "local:$short_latitude:$short_longitude",
+ }
+ );
+
+ url_skip = c.uri_for(
+ '/report/new',
+ {
+ pc => pc
+ latitude => short_latitude,
+ longitude => short_longitude,
+ submit_map => 1,
+ skipped => 1,
+ }
+ );
+
+ INCLUDE 'header.html',
+ title => loc('Viewing a location')
+ rss => [ loc('Recent local problems, FixMyStreet'), rss_url ],
+ robots => 'noindex,nofollow';
+%]
+
+[% map_html %]
+
+<h1>[% loc('Problems in this area') %]</h1>
<p id="alert_links_area">
-<a id="email_alert" rel="nofollow" href="{{ $url_email }}">{{ $email_me }}</a>
-| <a href="{{ $url_rss }}" id="rss_alert"><span>{{ $rss_alt }}</span> <img src="/i/feed.png" width="16" height="16" title="{{ $rss_title }}" alt="{{ $rss_alt }}" border="0" style="vertical-align: top"></a>
+ <a id="email_alert" rel="nofollow" href="[% email_url | html %]">
+ [% loc('Email me new local problems') %]
+ </a> |
+ <a href="[% rss_url | html %]" id="rss_alert">
+ <span>[% rss_alt %]</span>
+ <img src="/i/feed.png" width="16" height="16" title="[% rss_title %]" alt="[% rss_alt %]" border="0" style="vertical-align: top">
+ </a>
</p>
-{{ $errors }}
+[% IF pc_error %]
+ <ul class="error">
+ <li>[% pc_error | html %]</li>
+ </ul>
+[% END %]
-<p id="text_map">{{ $text_to_report }} {{ $text_skip }}</p>
+<p id="text_map">
+ [% loc( 'To report a problem, simply <strong>click on the map</strong> at the correct location.' ) %]
+ [%
+ tprintf(
+ loc("<small>If you cannot see the map, <a href='%s' rel='nofollow'>skip this step</a>.</small>"),
+ url_skip
+ )
+ %]
+</p>
<div id="nearby_lists">
-<h2>{{ $heading_on_around }}</h2>
-<ul id="current">
-{{ $reports_on_around }}
-</ul>
+ <h2>[% loc('Reports on and around the map') %]</h2>
+
+ <ul id="current">
+ [% IF on_map.size %]
+ [% FOREACH p IN on_map %]
+ <li>
+ <a href="[% c.uri_for('/report', p.id ) %]">
+ [% p.title | html %]
+ </a>
+ <small>([% prettify_epoch( p.time, 1 ) %])</small>
+ [% IF p.state == 'fixed' %]
+ <small>[% loc('(fixed)') %]</small>
+ [% END %]
+ </li>
+ [% END %]
+ [% ELSE %]
+ <li>[% loc('No problems have been reported yet.') %]</li>
+ [% END %]
+ </ul>
+
-<h2 id="closest_problems">{{ $heading_closest }}</h2>
+ <h2 id="closest_problems">
+ [%
+ tprintf(
+ loc( 'Closest nearby problems <small>(within&nbsp;%skm)</small>' ),
+ distance
+ )
+ %]
+ </h2>
+
+ <ul id="current_near">
+ [% IF around_map.size %]
+ [% FOREACH p IN around_map %]
-<ul id="current_near">
-{{ $reports_nearby }}
-</ul>
+ [% dist = int( p.distance * 10 + 0.5 ) / 10 %]
+
+ <li>
+ <a href="[% c.uri_for('/report', p.id ) %]">
+ [% p.title | html %]
+ </a>
+ <small>([% prettify_epoch( p.time, 1 ) %], [% dist %]km)</small>)</small>
+ [% IF p.state == 'fixed' %]
+ <small>[% loc('(fixed)') %]</small>
+ [% END %]
+ </li>
+ [% END %]
+ [% ELSE %]
+ <li>[% loc('No problems found.') %]</li>
+ [% END %]
+ </ul>
</div>
-{{ $map_end }}
+
+[% map_end_html %]
+
+[% INCLUDE 'footer.html' %]
diff --git a/templates/web/default/common_header_tags.html b/templates/web/default/common_header_tags.html
index c5a68f4d1..959126ff9 100644
--- a/templates/web/default/common_header_tags.html
+++ b/templates/web/default/common_header_tags.html
@@ -5,7 +5,9 @@
[% map_js %]
[% extra_js_verbatim %]
-[% robots %]
+[% IF robots %]
+ <meta name="robots" content="[% robots %]">
+[% END %]
[% IF rss %]
<link rel="alternate" type="application/rss+xml" title="[% rss.0 %]" href="[% rss.1 %]">