aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Alert.pm222
-rw-r--r--t/app/controller/alert.t5
-rw-r--r--templates/web/default/alert/list.html11
3 files changed, 123 insertions, 115 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm
index 49a8bce8a..e434c4931 100644
--- a/perllib/FixMyStreet/App/Controller/Alert.pm
+++ b/perllib/FixMyStreet/App/Controller/Alert.pm
@@ -99,6 +99,104 @@ sub list :Path('list') :Args(0) {
$c->go( 'index' );
}
+ $c->forward('council_options');
+
+ my $dist = mySociety::Gaze::get_radius_containing_population($c->stash->{latitude}, $c->stash->{longitude}, 200000);
+ $dist = int($dist * 10 + 0.5);
+ $dist = $dist / 10.0;
+ $c->stash->{population_radius} = $dist;
+#
+# my $checked = '';
+# $checked = ' checked' if $q->param('feed') && $q->param('feed') eq "local:$lat:$lon";
+# my $cobrand_form_elements = Cobrand::form_elements($cobrand, 'alerts', $q);
+# my $pics = Cobrand::recent_photos($cobrand, 5, $lat, $lon, $dist);
+# $pics = '<div id="alert_photos">' . $q->h2(_('Photos of recent nearby reports')) . $pics . '</div>' if $pics;
+
+# my $form_action = Cobrand::url($cobrand, '/alert', $q);
+#$cobrand_form_elements
+#$pics
+#
+#EOF
+# $out .= $errors;
+# $out .= <<EOF;
+ $c->stash->{rss_feed_id} = sprintf( 'local:%s:%s', $c->stash->{latitude}, $c->stash->{longitude} );
+
+ my $rss_feed;
+ if ($c->stash->{pretty_pc_text}) {
+ $rss_feed = $c->cobrand->uri("/rss/pc/" . $c->stash->{pretty_pc_text}, $c->fake_q);
+ } else {
+ $rss_feed = $c->cobrand->uri( sprintf("/rss/l/%s,%s", $c->stash->{latitude},$c->stash->{longitude}), $c->fake_q);
+ }
+
+ $c->stash->{rss_feed_uri} = $rss_feed;
+
+# my $default_link = Cobrand::url($cobrand, "/alert?type=local;feed=local:$lat:$lon", $q);
+
+ $c->stash->{rss_feed_2k} = $c->cobrand->uri($rss_feed.'/2', $c->fake_q);
+ $c->stash->{rss_feed_5k} = $c->cobrand->uri($rss_feed.'/5', $c->fake_q);
+ $c->stash->{rss_feed_10k} = $c->cobrand->uri($rss_feed.'/10', $c->fake_q);
+ $c->stash->{rss_feed_20k} = $c->cobrand->uri($rss_feed.'/20', $c->fake_q);
+
+# $out .= $q->p(_('Or you can subscribe to an alert based upon what ward or council you&rsquo;re in:'));
+# $out .= $options_start;
+# $out .= $options;
+# $out .= $options_end;
+# $out .= $q->p('<input type="submit" name="rss" value="' . _('Give me an RSS feed') . '">');
+# $out .= $q->p({-id=>'alert_or'}, _('or'));
+# $out .= '<p>' . _('Your email:') . ' <input type="text" id="rznvy" name="rznvy" value="' . $input_h{rznvy} . '" size="30"></p>
+#<p><input type="submit" name="alert" value="' . _('Subscribe me to an email alert') . '"></p>
+#</div>
+#</form>';
+# my %vars = (header => $header,
+# cobrand_form_elements => $cobrand_form_elements,
+# error => $errors,
+# rss_label => $rss_label,
+# rss_feed => $rss_feed,
+# default_link => $default_link,
+# rss_details => $rss_details,
+# rss_feed_2k => $rss_feed_2k,
+# rss_feed_5k => $rss_feed_5k,
+# rss_feed_10k => $rss_feed_10k,
+# rss_feed_20k => $rss_feed_20k,
+# lat => $lat,
+# lon => $lon,
+# options => $options );
+# my $cobrand_page = Page::template_include('alert-options', $q, Page::template_root($q), %vars);
+# $out = $cobrand_page if ($cobrand_page);
+# return $out;
+}
+
+=head2 prettify_pc
+
+This will canonicalise and prettify the postcode and stick a pretty_pc and pretty_pc_text in the stash.
+
+=cut
+
+sub prettify_pc : Private {
+ my ( $self, $c ) = @_;
+
+ # FIXME previously this had been run through ent so need to do similar here or in template
+ my $pretty_pc = $c->req->params->{'pc'};
+
+# my $pretty_pc = $input_h{pc};
+# my $pretty_pc_text;# This one isnt't getting the nbsp.
+ if (mySociety::PostcodeUtil::is_valid_postcode($c->req->params->{'pc'})) {
+ $pretty_pc = mySociety::PostcodeUtil::canonicalise_postcode($c->req->params->{'pc'});
+ my $pretty_pc_text = $pretty_pc;
+ $pretty_pc_text =~ s/ //g;
+ $c->stash->{pretty_pc_text} = $pretty_pc_text;
+ # this may be better done in template
+ $pretty_pc =~ s/ /&nbsp;/;
+ }
+
+ $c->stash->{pretty_pc} = $pretty_pc;
+}
+
+
+sub council_options : Private {
+ my ( $self, $c ) = @_;
+
+ if ( $c->config->{COUNTRY} eq 'NO' ) {
# my ($options, $options_start, $options_end);
# if (mySociety::Config::get('COUNTRY') eq 'NO') {
#
@@ -146,6 +244,8 @@ sub list :Path('list') :Args(0) {
# }
#
# } elsif (keys %$areas == 2) {
+ } elsif( keys %{ $c->stash->{ all_councils } } == 2 ) {
+ $c->log->debug( 'one tier council' );
#
# # One-tier council
# my (@options, $council, $ward);
@@ -168,6 +268,8 @@ sub list :Path('list') :Args(0) {
# $options_end = "</ul>";
#
# } elsif (keys %$areas == 1) {
+ } elsif( keys %{ $c->stash->{ all_councils } } == 1 ) {
+ $c->log->debug( 'one tier council. no ward' );
#
# # One-tier council, no ward
# my (@options, $council);
@@ -183,6 +285,8 @@ sub list :Path('list') :Args(0) {
# $options_end = "</ul>";
#
# } elsif (keys %$areas == 4) {
+ } elsif( keys %{ $c->stash->{ all_councils } } == 4 ) {
+ $c->log->debug( 'two tier council' );
#
# # Two-tier council
# my (@options, $county, $district, $c_ward, $d_ward);
@@ -232,122 +336,10 @@ sub list :Path('list') :Args(0) {
# } else {
# $options_end = '';
# }
-# } else {
-# # Hopefully impossible in the UK!
-# throw Error::Simple('An area with three tiers of council? Impossible! '. $lat . ' ' . $lon . ' ' . join('|',keys %$areas));
-# }
-#
-# my $dist = mySociety::Gaze::get_radius_containing_population($lat, $lon, 200000);
-# $dist = int($dist * 10 + 0.5);
-# $dist = $dist / 10.0;
-#
-# my $checked = '';
-# $checked = ' checked' if $q->param('feed') && $q->param('feed') eq "local:$lat:$lon";
-# my $cobrand_form_elements = Cobrand::form_elements($cobrand, 'alerts', $q);
-# my $pics = Cobrand::recent_photos($cobrand, 5, $lat, $lon, $dist);
-# $pics = '<div id="alert_photos">' . $q->h2(_('Photos of recent nearby reports')) . $pics . '</div>' if $pics;
-# my $header;
-# if ($pretty_pc) {
-# $header = sprintf(_('Local RSS feeds and email alerts for &lsquo;%s&rsquo;'), $pretty_pc);
-# } else {
-# $header = _('Local RSS feeds and email alerts');
-# }
-# my $out = $q->h1($header);
-# my $form_action = Cobrand::url($cobrand, '/alert', $q);
-# $out .= <<EOF;
-#<form id="alerts" name="alerts" method="post" action="$form_action">
-#<input type="hidden" name="type" value="local">
-#<input type="hidden" name="pc" value="$input_h{pc}">
-#$cobrand_form_elements
-#$pics
-#
-#EOF
-# $out .= $q->p(($pretty_pc ? sprintf(_('Here are the types of local problem alerts for &lsquo;%s&rsquo;.'), $pretty_pc)
-# : '') . ' ' . _('Select which type of alert you&rsquo;d like and click the button for an RSS
-#feed, or enter your email address to subscribe to an email alert.'));
-# $out .= $errors;
-# $out .= $q->p(_('The simplest alert is our geographic one:'));
-# my $rss_label = sprintf(_('Problems within %skm of this location'), $dist);
-# $out .= <<EOF;
-#<p id="rss_local">
-#<input type="radio" name="feed" id="local:$lat:$lon" value="local:$lat:$lon"$checked>
-#<label for="local:$lat:$lon">$rss_label</label>
-#EOF
-# my $rss_feed;
-# if ($pretty_pc_text) {
-# $rss_feed = Cobrand::url($cobrand, "/rss/pc/$pretty_pc_text", $q);
-# } else {
-# $rss_feed = Cobrand::url($cobrand, "/rss/l/$lat,$lon", $q);
-# }
-#
-# my $default_link = Cobrand::url($cobrand, "/alert?type=local;feed=local:$lat:$lon", $q);
-# my $rss_details = _('(a default distance which covers roughly 200,000 people)');
-# $out .= $rss_details;
-# $out .= " <a href='$rss_feed'><img src='/i/feed.png' width='16' height='16' title='"
-# . _('RSS feed of nearby problems') . "' alt='" . _('RSS feed') . "' border='0'></a>";
-# $out .= '</p> <p id="rss_local_alt">' . _('(alternatively the RSS feed can be customised, within');
-# my $rss_feed_2k = Cobrand::url($cobrand, $rss_feed.'/2', $q);
-# my $rss_feed_5k = Cobrand::url($cobrand, $rss_feed.'/5', $q);
-# my $rss_feed_10k = Cobrand::url($cobrand, $rss_feed.'/10', $q);
-# my $rss_feed_20k = Cobrand::url($cobrand, $rss_feed.'/20', $q);
-# $out .= <<EOF;
-# <a href="$rss_feed_2k">2km</a> / <a href="$rss_feed_5k">5km</a>
-#/ <a href="$rss_feed_10k">10km</a> / <a href="$rss_feed_20k">20km</a>)
-#</p>
-#EOF
-# $out .= $q->p(_('Or you can subscribe to an alert based upon what ward or council you&rsquo;re in:'));
-# $out .= $options_start;
-# $out .= $options;
-# $out .= $options_end;
-# $out .= $q->p('<input type="submit" name="rss" value="' . _('Give me an RSS feed') . '">');
-# $out .= $q->p({-id=>'alert_or'}, _('or'));
-# $out .= '<p>' . _('Your email:') . ' <input type="text" id="rznvy" name="rznvy" value="' . $input_h{rznvy} . '" size="30"></p>
-#<p><input type="submit" name="alert" value="' . _('Subscribe me to an email alert') . '"></p>
-#</div>
-#</form>';
-# my %vars = (header => $header,
-# cobrand_form_elements => $cobrand_form_elements,
-# error => $errors,
-# rss_label => $rss_label,
-# rss_feed => $rss_feed,
-# default_link => $default_link,
-# rss_details => $rss_details,
-# rss_feed_2k => $rss_feed_2k,
-# rss_feed_5k => $rss_feed_5k,
-# rss_feed_10k => $rss_feed_10k,
-# rss_feed_20k => $rss_feed_20k,
-# lat => $lat,
-# lon => $lon,
-# options => $options );
-# my $cobrand_page = Page::template_include('alert-options', $q, Page::template_root($q), %vars);
-# $out = $cobrand_page if ($cobrand_page);
-# return $out;
-}
-
-=head2 prettify_pc
-
-This will canonicalise and prettify the postcode and stick a pretty_pc and pretty_pc_text in the stash.
-
-=cut
-
-sub prettify_pc : Private {
- my ( $self, $c ) = @_;
-
- # FIXME previously this had been run through ent so need to do similar here or in template
- my $pretty_pc = $c->req->params->{'pc'};
-
-# my $pretty_pc = $input_h{pc};
-# my $pretty_pc_text;# This one isnt't getting the nbsp.
- if (mySociety::PostcodeUtil::is_valid_postcode($c->req->params->{'pc'})) {
- $pretty_pc = mySociety::PostcodeUtil::canonicalise_postcode($c->req->params->{'pc'});
- my $pretty_pc_text = $pretty_pc;
- $pretty_pc_text =~ s/ //g;
- $c->stash->{pretty_pc_text} = $pretty_pc_text;
- # this may be better done in template
- $pretty_pc =~ s/ /&nbsp;/;
+ } else {
+ # Hopefully impossible in the UK!
+ throw Error::Simple('An area with three tiers of council? Impossible! '. $c->stash->{latitude}. ' ' . $c->stash->{longitude} . ' ' . join('|',keys %{ $c->stash->{all_councils} } ));
}
-
- $c->stash->{pretty_pc} = $pretty_pc;
}
sub choose : Private {
diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t
index 31b5fb3cf..ceb1a3554 100644
--- a/t/app/controller/alert.t
+++ b/t/app/controller/alert.t
@@ -24,6 +24,11 @@ $mech->get_ok('/alert/list?pc=EH99 1SP');
$mech->title_like(qr/^Local RSS feeds and email alerts/);
$mech->content_contains('Local RSS feeds and email alerts for EH99&nbsp;1SP');
$mech->content_contains('html lang="en-gb"');
+$mech->content_contains('Problems within 8.5km');
+$mech->content_contains('rss/pc/EH991SP/2');
+$mech->content_contains('rss/pc/EH991SP/5');
+$mech->content_contains('rss/pc/EH991SP/10');
+$mech->content_contains('rss/pc/EH991SP/20');
$mech->get_ok('/alert/list?pc=High Street');
$mech->content_contains('We found more than one match for that location');
diff --git a/templates/web/default/alert/list.html b/templates/web/default/alert/list.html
index fded837f2..0e5c660f6 100644
--- a/templates/web/default/alert/list.html
+++ b/templates/web/default/alert/list.html
@@ -26,6 +26,17 @@
[% loc('The simplest alert is our geographic one') %]
</p>
+ <p id="rss_local">
+ <input type="radio" name="feed" id="[% rss_feed_id %]" value="[% rss_feed_id %]">
+ <label for="[% rss_feed_id %]">[% tprintf( loc('Problems within %.1fkm of this location'), population_radius ) %]</label>
+ ([% loc('a default distance which covers roughly 200,000 people') %]) <a href='[% rss_feed_uri %]'>
+ <img src='/i/feed.png' width='16' height='16' title='[% loc('RSS feed of nearby problems') %]' alt='[% loc('RSS feed') %]' border='0'></a>
+ </p>
+
+ <p id="rss_local_alt">
+ [% loc('(alternatively the RSS feed can be customised, within') %]
+ <a href="[% rss_feed_2k %]">2km</a> / <a href="[% rss_feed_5k %]">5km</a> / <a href="[% rss_feed_10k %]">10km</a> / <a href="[% rss_feed_20k %]">20km</a>)
+
[%# FIXME errors here %]
[%# FIXME rss options here %]