From fb8ddac45d81e40daee88aab963ac09423762e76 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 4 May 2011 13:49:43 +0100 Subject: Skeleton catalyst alerts page --- perllib/FixMyStreet/App/Controller/Alert.pm | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 perllib/FixMyStreet/App/Controller/Alert.pm (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm new file mode 100644 index 000000000..3f3dc171b --- /dev/null +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -0,0 +1,45 @@ +package FixMyStreet::App::Controller::Alert; +use Moose; +use namespace::autoclean; + +BEGIN {extends 'Catalyst::Controller'; } + +=head1 NAME + +FixMyStreet::App::Controller::Alert - Catalyst Controller + +=head1 DESCRIPTION + +Catalyst Controller. + +=head1 METHODS + +=cut + + +=head2 alert + +Show the alerts page + +=cut + +sub alert :Path :Args(0) { + my ( $self, $c ) = @_; + +} + + +=head1 AUTHOR + +Struan Donald + +=head1 LICENSE + +This library is free software. You can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +__PACKAGE__->meta->make_immutable; + +1; -- cgit v1.2.3 From 6bca29716bd28f5724527e7a3037c47c225d0896 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 4 May 2011 14:16:45 +0100 Subject: rename index method/template for consistency --- perllib/FixMyStreet/App/Controller/Alert.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 3f3dc171b..3e5c4e128 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -23,7 +23,7 @@ Show the alerts page =cut -sub alert :Path :Args(0) { +sub alert_index :Path :Args(0) { my ( $self, $c ) = @_; } -- cgit v1.2.3 From 2025cde75a554048b0d3ac60c70029b98914ed37 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 4 May 2011 14:45:06 +0100 Subject: added in commented out code from alert.cgi for reference --- perllib/FixMyStreet/App/Controller/Alert.pm | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 3e5c4e128..73e54a8a2 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -26,6 +26,40 @@ Show the alerts page sub alert_index :Path :Args(0) { my ( $self, $c ) = @_; +# my $q = shift; +# my $cobrand = Page::get_cobrand($q); +# my $error = shift; +# my $errors = ''; +# $errors = '
  • ' . $error . '
' if $error; +# +# my $form_action = Cobrand::url(Page::get_cobrand($q), '/alert', $q); +# my $cobrand_form_elements = Cobrand::form_elements($cobrand, 'alerts', $q); +# my $cobrand_extra_data = Cobrand::extra_data($cobrand, $q); +# +# $out .= $errors . qq(
); +# $out .= $q->p($pc_label, ' +#'); +# $out .= $cobrand_form_elements; +# +# my %vars = (error => $error, +# header => $header, +# intro => $intro, +# pc_label => $pc_label, +# form_action => $form_action, +# input_h => \%input_h, +# submit_text => $submit_text, +# cobrand_form_elements => $cobrand_form_elements, +# cobrand_extra_data => $cobrand_extra_data, +# url_home => Cobrand::url($cobrand, '/', $q)); +# +# my $cobrand_page = Page::template_include('alert-front-page', $q, Page::template_root($q), %vars); +# $out = $cobrand_page if ($cobrand_page); +# +# return $out if $q->referer() && $q->referer() =~ /fixmystreet\.com/; +# my $recent_photos = Cobrand::recent_photos($cobrand, 10); +# $out .= '
' . $q->h2(_('Some photos of recent reports')) . $recent_photos . '
' if $recent_photos; +# +# return $out; } -- cgit v1.2.3 From 359df931543e985c87514eb84dfc7f31b488e064 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 4 May 2011 15:13:09 +0100 Subject: and move it all back to index.html as it will make things easier later --- perllib/FixMyStreet/App/Controller/Alert.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 73e54a8a2..481512623 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -23,7 +23,7 @@ Show the alerts page =cut -sub alert_index :Path :Args(0) { +sub index :Path('') :Args(0) { my ( $self, $c ) = @_; # my $q = shift; -- cgit v1.2.3 From 2ae642787ab73073eca0af7c494e00bff946441c Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 4 May 2011 17:27:45 +0100 Subject: added list method and template with no functionality --- perllib/FixMyStreet/App/Controller/Alert.pm | 276 ++++++++++++++++++++++++++++ 1 file changed, 276 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 481512623..d11c6adf7 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -63,6 +63,282 @@ sub index :Path('') :Args(0) { } + +sub list :Path('list') :Args(0) { + my ( $self, $c ) = @_; +# my ($q, @errors) = @_; +# my @vars = qw(pc rznvy lat lon); +# my %input = map { $_ => scalar $q->param($_) } @vars; +# my %input_h = map { $_ => $q->param($_) ? ent($q->param($_)) : '' } @vars; +# +# my($error, $lat, $lon); +# if ($input{lat} || $input{lon}) { +# $lat = $input{lat}; +# $lon = $input{lon}; +# } else { +# try { +# ($lat, $lon, $error) = FixMyStreet::Geocode::lookup($input{pc}, $q); +# } catch Error::Simple with { +# $error = shift; +# }; +# } +# +# return FixMyStreet::Geocode::list_choices($error, '/alert', $q) if ref($error) eq 'ARRAY'; +# return alert_front_page($q, $error) if $error; +# +# my $pretty_pc = $input_h{pc}; +# my $pretty_pc_text;# This one isnt't getting the nbsp. +# if (mySociety::PostcodeUtil::is_valid_postcode($input{pc})) { +# $pretty_pc = mySociety::PostcodeUtil::canonicalise_postcode($input{pc}); +# $pretty_pc_text = $pretty_pc; +# $pretty_pc_text =~ s/ //g; +# $pretty_pc =~ s/ / /; +# } +# +# # truncate the lat,lon for nicer urls +# ( $lat, $lon ) = map { Utils::truncate_coordinate($_) } ( $lat, $lon ); +# +# my $errors = ''; +# $errors = '
  • ' . join('
  • ', @errors) . '
' if @errors; +# +# my $cobrand = Page::get_cobrand($q); +# my @types = (Cobrand::area_types($cobrand), @$mySociety::VotingArea::council_child_types); +# my %councils = map { $_ => 1 } Cobrand::area_types($cobrand); +# +# my $areas = mySociety::MaPit::call('point', "4326/$lon,$lat", type => \@types); +# my ($success, $error_msg) = Cobrand::council_check($cobrand, { all_councils => $areas }, $q, 'alert'); +# if (!$success) { +# return alert_front_page($q, $error_msg); +# } +# +# return alert_front_page($q, _('That location does not appear to be covered by a council, perhaps it is offshore - please try somewhere more specific.')) if keys %$areas == 0; +# +# my ($options, $options_start, $options_end); +# if (mySociety::Config::get('COUNTRY') eq 'NO') { +# +# my (@options, $fylke, $kommune); +# foreach (values %$areas) { +# if ($_->{type} eq 'NKO') { +# $kommune = $_; +# } else { +# $fylke = $_; +# } +# } +# my $kommune_name = $kommune->{name}; +# my $fylke_name = $fylke->{name}; +# +# if ($fylke->{id} == 3) { # Oslo +# +# push @options, [ 'council', $fylke->{id}, Page::short_name($fylke), +# sprintf(_("Problems within %s"), $fylke_name) ]; +# +# $options_start = "
    "; +# $options = alert_list_options($q, @options); +# $options_end = "
"; +# +# } else { +# +# push @options, +# [ 'area', $kommune->{id}, Page::short_name($kommune), $kommune_name ], +# [ 'area', $fylke->{id}, Page::short_name($fylke), $fylke_name ]; +# $options_start = '
'; +# $options = $q->p($q->strong(_('Problems within the boundary of:'))) . +# $q->ul(alert_list_options($q, @options)); +# @options = (); +# push @options, +# [ 'council', $kommune->{id}, Page::short_name($kommune), $kommune_name ], +# [ 'council', $fylke->{id}, Page::short_name($fylke), $fylke_name ]; +# $options .= $q->p($q->strong(_('Or problems reported to:'))) . +# $q->ul(alert_list_options($q, @options)); +# $options_end = $q->p($q->small(_('FixMyStreet sends different categories of problem +#to the appropriate council, so problems within the boundary of a particular council +#might not match the problems sent to that council. For example, a graffiti report +#will be sent to the district council, so will appear in both of the district +#council’s alerts, but will only appear in the "Within the boundary" alert +#for the county council.'))) . '
'; +# +# } +# +# } elsif (keys %$areas == 2) { +# +# # One-tier council +# my (@options, $council, $ward); +# foreach (values %$areas) { +# if ($councils{$_->{type}}) { +# $council = $_; +# } else { +# $ward = $_; +# } +# } +# my $council_name = $council->{name}; +# my $ward_name = $ward->{name}; +# push @options, [ 'council', $council->{id}, Page::short_name($council), +# sprintf(_("Problems within %s"), $council_name) ]; +# push @options, [ 'ward', $council->{id}.':'.$ward->{id}, Page::short_name($council) . '/' +# . Page::short_name($ward), sprintf(_("Problems within %s ward"), $ward_name) ]; +# +# $options_start = "
    "; +# $options = alert_list_options($q, @options); +# $options_end = "
"; +# +# } elsif (keys %$areas == 1) { +# +# # One-tier council, no ward +# my (@options, $council); +# foreach (values %$areas) { +# $council = $_; +# } +# my $council_name = $council->{name}; +# push @options, [ 'council', $council->{id}, Page::short_name($council), +# sprintf(_("Problems within %s"), $council_name) ]; +# +# $options_start = "
    "; +# $options = alert_list_options($q, @options); +# $options_end = "
"; +# +# } elsif (keys %$areas == 4) { +# +# # Two-tier council +# my (@options, $county, $district, $c_ward, $d_ward); +# foreach (values %$areas) { +# if ($_->{type} eq 'CTY') { +# $county = $_; +# } elsif ($_->{type} eq 'DIS') { +# $district = $_; +# } elsif ($_->{type} eq 'CED') { +# $c_ward = $_; +# } elsif ($_->{type} eq 'DIW') { +# $d_ward = $_; +# } +# } +# my $district_name = $district->{name}; +# my $d_ward_name = $d_ward->{name}; +# my $county_name = $county->{name}; +# my $c_ward_name = $c_ward->{name}; +# push @options, +# [ 'area', $district->{id}, Page::short_name($district), $district_name ], +# [ 'area', $district->{id}.':'.$d_ward->{id}, Page::short_name($district) . '/' +# . Page::short_name($d_ward), "$d_ward_name ward, $district_name" ], +# [ 'area', $county->{id}, Page::short_name($county), $county_name ], +# [ 'area', $county->{id}.':'.$c_ward->{id}, Page::short_name($county) . '/' +# . Page::short_name($c_ward), "$c_ward_name ward, $county_name" ]; +# $options_start = '
'; +# $options = $q->p($q->strong(_('Problems within the boundary of:'))) . +# $q->ul(alert_list_options($q, @options)); +# @options = (); +# push @options, +# [ 'council', $district->{id}, Page::short_name($district), $district_name ], +# [ 'ward', $district->{id}.':'.$d_ward->{id}, Page::short_name($district) . '/' . Page::short_name($d_ward), +# "$district_name, within $d_ward_name ward" ]; +# if ($q->{site} ne 'emptyhomes') { +# push @options, +# [ 'council', $county->{id}, Page::short_name($county), $county_name ], +# [ 'ward', $county->{id}.':'.$c_ward->{id}, Page::short_name($county) . '/' +# . Page::short_name($c_ward), "$county_name, within $c_ward_name ward" ]; +# $options .= $q->p($q->strong(_('Or problems reported to:'))) . +# $q->ul(alert_list_options($q, @options)); +# $options_end = $q->p($q->small(_('FixMyStreet sends different categories of problem +#to the appropriate council, so problems within the boundary of a particular council +#might not match the problems sent to that council. For example, a graffiti report +#will be sent to the district council, so will appear in both of the district +#council’s alerts, but will only appear in the "Within the boundary" alert +#for the county council.'))) . '
'; +# } 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 = '
' . $q->h2(_('Photos of recent nearby reports')) . $pics . '
' if $pics; +# my $header; +# if ($pretty_pc) { +# $header = sprintf(_('Local RSS feeds and email alerts for ‘%s’'), $pretty_pc); +# } else { +# $header = _('Local RSS feeds and email alerts'); +# } +# my $out = $q->h1($header); +# my $form_action = Cobrand::url($cobrand, '/alert', $q); +# $out .= < +# +# +#$cobrand_form_elements +#$pics +# +#EOF +# $out .= $q->p(($pretty_pc ? sprintf(_('Here are the types of local problem alerts for ‘%s’.'), $pretty_pc) +# : '') . ' ' . _('Select which type of alert you’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 +# 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 .= " " . _("; +# $out .= '

' . _('(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 .= <2km / 5km +#/ 10km / 20km) +#

+#EOF +# $out .= $q->p(_('Or you can subscribe to an alert based upon what ward or council you’re in:')); +# $out .= $options_start; +# $out .= $options; +# $out .= $options_end; +# $out .= $q->p(''); +# $out .= $q->p({-id=>'alert_or'}, _('or')); +# $out .= '

' . _('Your email:') . '

+#

+#
+#'; +# 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; +} + + =head1 AUTHOR Struan Donald -- cgit v1.2.3 From b55733c9614b2f8ebd09d31f3c2750959942effa Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 4 May 2011 18:49:39 +0100 Subject: add in prettyfication of postcode --- perllib/FixMyStreet/App/Controller/Alert.pm | 39 +++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index d11c6adf7..596aeff76 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -85,16 +85,9 @@ sub list :Path('list') :Args(0) { # # return FixMyStreet::Geocode::list_choices($error, '/alert', $q) if ref($error) eq 'ARRAY'; # return alert_front_page($q, $error) if $error; -# -# my $pretty_pc = $input_h{pc}; -# my $pretty_pc_text;# This one isnt't getting the nbsp. -# if (mySociety::PostcodeUtil::is_valid_postcode($input{pc})) { -# $pretty_pc = mySociety::PostcodeUtil::canonicalise_postcode($input{pc}); -# $pretty_pc_text = $pretty_pc; -# $pretty_pc_text =~ s/ //g; -# $pretty_pc =~ s/ / /; -# } -# + + $c->forward('prettify_pc'); + # # truncate the lat,lon for nicer urls # ( $lat, $lon ) = map { Utils::truncate_coordinate($_) } ( $lat, $lon ); # @@ -338,6 +331,32 @@ sub list :Path('list') :Args(0) { # 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/ / /; + } + + $c->stash->{pretty_pc} = $pretty_pc; +} + =head1 AUTHOR -- cgit v1.2.3 From d98932ca12742253938a9dcad8c36c4cbd227db7 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 5 May 2011 11:26:24 +0100 Subject: get co-ords from request or postcode --- perllib/FixMyStreet/App/Controller/Alert.pm | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 596aeff76..ffe3c705c 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -71,20 +71,15 @@ sub list :Path('list') :Args(0) { # my %input = map { $_ => scalar $q->param($_) } @vars; # my %input_h = map { $_ => $q->param($_) ? ent($q->param($_)) : '' } @vars; # -# my($error, $lat, $lon); -# if ($input{lat} || $input{lon}) { -# $lat = $input{lat}; -# $lon = $input{lon}; -# } else { -# try { -# ($lat, $lon, $error) = FixMyStreet::Geocode::lookup($input{pc}, $q); -# } catch Error::Simple with { -# $error = shift; -# }; -# } -# + # Try to create a location for whatever we have + unless ($c->forward('/around/determine_location_from_coords') + || $c->forward('/around/determine_location_from_pc') ) { + # FIXME: do error display here # return FixMyStreet::Geocode::list_choices($error, '/alert', $q) if ref($error) eq 'ARRAY'; # return alert_front_page($q, $error) if $error; + } + + $c->log->debug( $_ ) for ( $c->stash->{pc}, $c->stash->{latitude}, $c->stash->{longitude} ); $c->forward('prettify_pc'); -- cgit v1.2.3 From a45958b500ced0943703960f9319ac480e6ce905 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 5 May 2011 15:57:25 +0100 Subject: create and use location controller --- perllib/FixMyStreet/App/Controller/Alert.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index ffe3c705c..0c434cbe0 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -72,8 +72,8 @@ sub list :Path('list') :Args(0) { # my %input_h = map { $_ => $q->param($_) ? ent($q->param($_)) : '' } @vars; # # Try to create a location for whatever we have - unless ($c->forward('/around/determine_location_from_coords') - || $c->forward('/around/determine_location_from_pc') ) { + unless ($c->forward('/location/determine_location_from_coords') + || $c->forward('/location/determine_location_from_pc') ) { # FIXME: do error display here # return FixMyStreet::Geocode::list_choices($error, '/alert', $q) if ref($error) eq 'ARRAY'; # return alert_front_page($q, $error) if $error; -- cgit v1.2.3 From ce6b34aa866e246fae2aadc9308a27638d8eccb3 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 5 May 2011 17:10:54 +0100 Subject: display choices for ambigious location searches --- perllib/FixMyStreet/App/Controller/Alert.pm | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 0c434cbe0..bdcaccc3a 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -74,6 +74,10 @@ sub list :Path('list') :Args(0) { # Try to create a location for whatever we have unless ($c->forward('/location/determine_location_from_coords') || $c->forward('/location/determine_location_from_pc') ) { + if ( $c->stash->{possible_location_matches} ) { + $c->stash->{choose_target_uri} = $c->uri_for( '/alert/list' ); + $c->detach('choose'); + } # FIXME: do error display here # return FixMyStreet::Geocode::list_choices($error, '/alert', $q) if ref($error) eq 'ARRAY'; # return alert_front_page($q, $error) if $error; @@ -352,6 +356,11 @@ sub prettify_pc : Private { $c->stash->{pretty_pc} = $pretty_pc; } +sub choose : Private { + my ( $self, $c ) = @_; + $c->stash->{template} = 'alert/choose.html'; +} + =head1 AUTHOR -- cgit v1.2.3 From a73cc4ebffb8d10db29581081bab57ae65c23209 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 5 May 2011 17:56:00 +0100 Subject: handle and display location finding errors --- perllib/FixMyStreet/App/Controller/Alert.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index bdcaccc3a..db2d06844 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -74,13 +74,13 @@ sub list :Path('list') :Args(0) { # Try to create a location for whatever we have unless ($c->forward('/location/determine_location_from_coords') || $c->forward('/location/determine_location_from_pc') ) { - if ( $c->stash->{possible_location_matches} ) { - $c->stash->{choose_target_uri} = $c->uri_for( '/alert/list' ); - $c->detach('choose'); - } - # FIXME: do error display here -# return FixMyStreet::Geocode::list_choices($error, '/alert', $q) if ref($error) eq 'ARRAY'; -# return alert_front_page($q, $error) if $error; + + if ( $c->stash->{possible_location_matches} ) { + $c->stash->{choose_target_uri} = $c->uri_for( '/alert/list' ); + $c->detach('choose'); + } + + $c->go('index') if $c->stash->{ location_error }; } $c->log->debug( $_ ) for ( $c->stash->{pc}, $c->stash->{latitude}, $c->stash->{longitude} ); -- cgit v1.2.3 From 9787559f918a136da3096d05abbb7430731ecaa9 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 6 May 2011 10:44:22 +0100 Subject: truncate lat/lon --- perllib/FixMyStreet/App/Controller/Alert.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index db2d06844..b62f8df2a 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -87,8 +87,9 @@ sub list :Path('list') :Args(0) { $c->forward('prettify_pc'); -# # truncate the lat,lon for nicer urls -# ( $lat, $lon ) = map { Utils::truncate_coordinate($_) } ( $lat, $lon ); + # truncate the lat,lon for nicer urls + ( $c->stash->{latitude}, $c->stash->{longitude} ) = map { Utils::truncate_coordinate($_) } ( $c->stash->{latitude}, $c->stash->{longitude} ); + $c->log->debug( $_ ) for ( $c->stash->{pc}, $c->stash->{latitude}, $c->stash->{longitude} ); # # my $errors = ''; # $errors = '
  • ' . join('
  • ', @errors) . '
' if @errors; -- cgit v1.2.3 From aaf60ba622748d8f5a5c4eb16fe663ff9fec5a0d Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 6 May 2011 11:24:28 +0100 Subject: created council controller and use that for load and check councils --- perllib/FixMyStreet/App/Controller/Alert.pm | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index b62f8df2a..c18ba657f 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -94,18 +94,10 @@ sub list :Path('list') :Args(0) { # my $errors = ''; # $errors = '
  • ' . join('
  • ', @errors) . '
' if @errors; # -# my $cobrand = Page::get_cobrand($q); -# my @types = (Cobrand::area_types($cobrand), @$mySociety::VotingArea::council_child_types); -# my %councils = map { $_ => 1 } Cobrand::area_types($cobrand); -# -# my $areas = mySociety::MaPit::call('point', "4326/$lon,$lat", type => \@types); -# my ($success, $error_msg) = Cobrand::council_check($cobrand, { all_councils => $areas }, $q, 'alert'); -# if (!$success) { -# return alert_front_page($q, $error_msg); -# } -# -# return alert_front_page($q, _('That location does not appear to be covered by a council, perhaps it is offshore - please try somewhere more specific.')) if keys %$areas == 0; -# + unless ( $c->forward( '/council/load_and_check_councils', 'alert' ) ) { + $c->go( 'index' ); + } + # my ($options, $options_start, $options_end); # if (mySociety::Config::get('COUNTRY') eq 'NO') { # -- cgit v1.2.3 From f8ee12145969b2e176504ed66a666269331159f7 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 6 May 2011 16:14:16 +0100 Subject: Allow us to get councils or councils and wards and control if we remove redundant councils --- perllib/FixMyStreet/App/Controller/Alert.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index c18ba657f..49a8bce8a 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -94,7 +94,8 @@ sub list :Path('list') :Args(0) { # my $errors = ''; # $errors = '
  • ' . join('
  • ', @errors) . '
' if @errors; # - unless ( $c->forward( '/council/load_and_check_councils', 'alert' ) ) { + $c->stash->{council_check_action} = 'alert'; + unless ( $c->forward( '/council/load_and_check_councils_and_wards' ) ) { $c->go( 'index' ); } -- cgit v1.2.3 From b1ca5c65e80f340c9e0bd6ee7bd6ab667073389b Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 6 May 2011 17:17:54 +0100 Subject: added in rss feed links --- perllib/FixMyStreet/App/Controller/Alert.pm | 222 ++++++++++++++-------------- 1 file changed, 107 insertions(+), 115 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') 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 = '
' . $q->h2(_('Photos of recent nearby reports')) . $pics . '
' if $pics; + +# my $form_action = Cobrand::url($cobrand, '/alert', $q); +#$cobrand_form_elements +#$pics +# +#EOF +# $out .= $errors; +# $out .= <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’re in:')); +# $out .= $options_start; +# $out .= $options; +# $out .= $options_end; +# $out .= $q->p(''); +# $out .= $q->p({-id=>'alert_or'}, _('or')); +# $out .= '

' . _('Your email:') . '

+#

+#
+#'; +# 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/ / /; + } + + $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 = ""; # # } 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 = ""; # # } 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 = '
' . $q->h2(_('Photos of recent nearby reports')) . $pics . '
' if $pics; -# my $header; -# if ($pretty_pc) { -# $header = sprintf(_('Local RSS feeds and email alerts for ‘%s’'), $pretty_pc); -# } else { -# $header = _('Local RSS feeds and email alerts'); -# } -# my $out = $q->h1($header); -# my $form_action = Cobrand::url($cobrand, '/alert', $q); -# $out .= < -# -# -#$cobrand_form_elements -#$pics -# -#EOF -# $out .= $q->p(($pretty_pc ? sprintf(_('Here are the types of local problem alerts for ‘%s’.'), $pretty_pc) -# : '') . ' ' . _('Select which type of alert you’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 -# 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 .= " " . _("; -# $out .= '

' . _('(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 .= <2km / 5km -#/ 10km / 20km) -#

-#EOF -# $out .= $q->p(_('Or you can subscribe to an alert based upon what ward or council you’re in:')); -# $out .= $options_start; -# $out .= $options; -# $out .= $options_end; -# $out .= $q->p(''); -# $out .= $q->p({-id=>'alert_or'}, _('or')); -# $out .= '

' . _('Your email:') . '

-#

-#
-#'; -# 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/ / /; + } 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 { -- cgit v1.2.3 From d01b9bc2e42e46d5415a5464eb2ee063f43a8464 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 9 May 2011 12:49:18 +0100 Subject: rss feeds for single tier councils --- perllib/FixMyStreet/App/Controller/Alert.pm | 78 +++++++++++++++-------------- 1 file changed, 40 insertions(+), 38 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index e434c4931..c1b164a7c 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -196,6 +196,7 @@ sub prettify_pc : Private { 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') { @@ -243,50 +244,15 @@ sub council_options : Private { # # } # -# } elsif (keys %$areas == 2) { } elsif( keys %{ $c->stash->{ all_councils } } == 2 ) { $c->log->debug( 'one tier council' ); -# -# # One-tier council -# my (@options, $council, $ward); -# foreach (values %$areas) { -# if ($councils{$_->{type}}) { -# $council = $_; -# } else { -# $ward = $_; -# } -# } -# my $council_name = $council->{name}; -# my $ward_name = $ward->{name}; -# push @options, [ 'council', $council->{id}, Page::short_name($council), -# sprintf(_("Problems within %s"), $council_name) ]; -# push @options, [ 'ward', $council->{id}.':'.$ward->{id}, Page::short_name($council) . '/' -# . Page::short_name($ward), sprintf(_("Problems within %s ward"), $ward_name) ]; -# -# $options_start = "
    "; -# $options = alert_list_options($q, @options); -# $options_end = "
"; -# -# } elsif (keys %$areas == 1) { + $c->forward('generate_council_and_ward_options'); } elsif( keys %{ $c->stash->{ all_councils } } == 1 ) { $c->log->debug( 'one tier council. no ward' ); -# -# # One-tier council, no ward -# my (@options, $council); -# foreach (values %$areas) { -# $council = $_; -# } -# my $council_name = $council->{name}; -# push @options, [ 'council', $council->{id}, Page::short_name($council), -# sprintf(_("Problems within %s"), $council_name) ]; -# -# $options_start = "
    "; -# $options = alert_list_options($q, @options); -# $options_end = "
"; -# -# } elsif (keys %$areas == 4) { + $c->forward('generate_council_and_ward_options'); } elsif( keys %{ $c->stash->{ all_councils } } == 4 ) { $c->log->debug( 'two tier council' ); + $c->stash->{two_tier_council} = 1; # # # Two-tier council # my (@options, $county, $district, $c_ward, $d_ward); @@ -342,6 +308,42 @@ sub council_options : Private { } } +sub generate_council_and_ward_options : Private { + my ( $self, $c ) = @_; + + my %councils = map { $_ => 1 } $c->cobrand->area_types(); + + my (@options, $council, $ward); + foreach (values %{ $c->stash->{all_councils} }) { + if ($councils{$_->{type}}) { + $council = $_; + $council->{short_name} = Page::short_name( $council ); + ( $council->{id_name} = $council->{short_name} ) =~ tr/+/_/; + } else { + $ward = $_; + $ward->{short_name} = Page::short_name( $ward ); + ( $ward->{id_name} = $ward->{short_name} ) =~ tr/+/_/; + } + } + + push @options, + { + type => 'council', + id => sprintf( 'council:%s:%s', $council->{id}, $council->{id_name} ), + text => sprintf( _('Problems within %s'), $council->{name}), + uri => $c->cobrand->uri( '/rss/reports/' . $council->{short_name} ), + }; + push @options, + { + type => 'ward', + id => sprintf( 'ward:%s:%s:%s:%s', $council->{id}, $ward->{id}, $council->{id_name}, $ward->{id_name} ), + text => sprintf( _('Problems within %s ward'), $ward->{name}), + uri => $c->cobrand->uri( '/rss/reports/' . $council->{short_name} . '/' . $ward->{short_name} ), + } if $ward; + + $c->stash->{options} = \@options; +} + sub choose : Private { my ( $self, $c ) = @_; $c->stash->{template} = 'alert/choose.html'; -- cgit v1.2.3 From d3db27275ccecfe196fc9036f03288a3e5d675e3 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 9 May 2011 13:12:02 +0100 Subject: moved short_name to cobrands --- perllib/FixMyStreet/App/Controller/Alert.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index c1b164a7c..b1856b22c 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -317,11 +317,11 @@ sub generate_council_and_ward_options : Private { foreach (values %{ $c->stash->{all_councils} }) { if ($councils{$_->{type}}) { $council = $_; - $council->{short_name} = Page::short_name( $council ); + $council->{short_name} = $c->cobrand->short_name( $council ); ( $council->{id_name} = $council->{short_name} ) =~ tr/+/_/; } else { $ward = $_; - $ward->{short_name} = Page::short_name( $ward ); + $ward->{short_name} = $c->cobrand->short_name( $ward ); ( $ward->{id_name} = $ward->{short_name} ) =~ tr/+/_/; } } -- cgit v1.2.3 From da0902b7c836e514a5dd7304eb8354600e768225 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 9 May 2011 17:08:04 +0100 Subject: move rss feed option code to cobrands and deal with two tied councils --- perllib/FixMyStreet/App/Controller/Alert.pm | 129 +--------------------------- 1 file changed, 3 insertions(+), 126 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index b1856b22c..116c02a67 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -99,7 +99,9 @@ sub list :Path('list') :Args(0) { $c->go( 'index' ); } - $c->forward('council_options'); + ( $c->stash->{options}, $c->stash->{reported_to_options} ) + = $c->cobrand->council_rss_alert_options( $c->stash->{all_councils} ); + my $dist = mySociety::Gaze::get_radius_containing_population($c->stash->{latitude}, $c->stash->{longitude}, 200000); $dist = int($dist * 10 + 0.5); @@ -136,34 +138,6 @@ sub list :Path('list') :Args(0) { $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’re in:')); -# $out .= $options_start; -# $out .= $options; -# $out .= $options_end; -# $out .= $q->p(''); -# $out .= $q->p({-id=>'alert_or'}, _('or')); -# $out .= '

' . _('Your email:') . '

-#

-#
-#'; -# 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 @@ -244,106 +218,9 @@ sub council_options : Private { # # } # - } elsif( keys %{ $c->stash->{ all_councils } } == 2 ) { - $c->log->debug( 'one tier council' ); - $c->forward('generate_council_and_ward_options'); - } elsif( keys %{ $c->stash->{ all_councils } } == 1 ) { - $c->log->debug( 'one tier council. no ward' ); - $c->forward('generate_council_and_ward_options'); - } elsif( keys %{ $c->stash->{ all_councils } } == 4 ) { - $c->log->debug( 'two tier council' ); - $c->stash->{two_tier_council} = 1; -# -# # Two-tier council -# my (@options, $county, $district, $c_ward, $d_ward); -# foreach (values %$areas) { -# if ($_->{type} eq 'CTY') { -# $county = $_; -# } elsif ($_->{type} eq 'DIS') { -# $district = $_; -# } elsif ($_->{type} eq 'CED') { -# $c_ward = $_; -# } elsif ($_->{type} eq 'DIW') { -# $d_ward = $_; -# } -# } -# my $district_name = $district->{name}; -# my $d_ward_name = $d_ward->{name}; -# my $county_name = $county->{name}; -# my $c_ward_name = $c_ward->{name}; -# push @options, -# [ 'area', $district->{id}, Page::short_name($district), $district_name ], -# [ 'area', $district->{id}.':'.$d_ward->{id}, Page::short_name($district) . '/' -# . Page::short_name($d_ward), "$d_ward_name ward, $district_name" ], -# [ 'area', $county->{id}, Page::short_name($county), $county_name ], -# [ 'area', $county->{id}.':'.$c_ward->{id}, Page::short_name($county) . '/' -# . Page::short_name($c_ward), "$c_ward_name ward, $county_name" ]; -# $options_start = '
'; -# $options = $q->p($q->strong(_('Problems within the boundary of:'))) . -# $q->ul(alert_list_options($q, @options)); -# @options = (); -# push @options, -# [ 'council', $district->{id}, Page::short_name($district), $district_name ], -# [ 'ward', $district->{id}.':'.$d_ward->{id}, Page::short_name($district) . '/' . Page::short_name($d_ward), -# "$district_name, within $d_ward_name ward" ]; -# if ($q->{site} ne 'emptyhomes') { -# push @options, -# [ 'council', $county->{id}, Page::short_name($county), $county_name ], -# [ 'ward', $county->{id}.':'.$c_ward->{id}, Page::short_name($county) . '/' -# . Page::short_name($c_ward), "$county_name, within $c_ward_name ward" ]; -# $options .= $q->p($q->strong(_('Or problems reported to:'))) . -# $q->ul(alert_list_options($q, @options)); -# $options_end = $q->p($q->small(_('FixMyStreet sends different categories of problem -#to the appropriate council, so problems within the boundary of a particular council -#might not match the problems sent to that council. For example, a graffiti report -#will be sent to the district council, so will appear in both of the district -#council’s alerts, but will only appear in the "Within the boundary" alert -#for the county council.'))) . '
'; -# } else { -# $options_end = ''; -# } - } 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} } )); } } -sub generate_council_and_ward_options : Private { - my ( $self, $c ) = @_; - - my %councils = map { $_ => 1 } $c->cobrand->area_types(); - - my (@options, $council, $ward); - foreach (values %{ $c->stash->{all_councils} }) { - if ($councils{$_->{type}}) { - $council = $_; - $council->{short_name} = $c->cobrand->short_name( $council ); - ( $council->{id_name} = $council->{short_name} ) =~ tr/+/_/; - } else { - $ward = $_; - $ward->{short_name} = $c->cobrand->short_name( $ward ); - ( $ward->{id_name} = $ward->{short_name} ) =~ tr/+/_/; - } - } - - push @options, - { - type => 'council', - id => sprintf( 'council:%s:%s', $council->{id}, $council->{id_name} ), - text => sprintf( _('Problems within %s'), $council->{name}), - uri => $c->cobrand->uri( '/rss/reports/' . $council->{short_name} ), - }; - push @options, - { - type => 'ward', - id => sprintf( 'ward:%s:%s:%s:%s', $council->{id}, $ward->{id}, $council->{id_name}, $ward->{id_name} ), - text => sprintf( _('Problems within %s ward'), $ward->{name}), - uri => $c->cobrand->uri( '/rss/reports/' . $council->{short_name} . '/' . $ward->{short_name} ), - } if $ward; - - $c->stash->{options} = \@options; -} - sub choose : Private { my ( $self, $c ) = @_; $c->stash->{template} = 'alert/choose.html'; -- cgit v1.2.3 From 6ff9e651989a835c996635bf502723a4701ed483 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 10 May 2011 10:55:42 +0100 Subject: Add in RSS redirects --- perllib/FixMyStreet/App/Controller/Alert.pm | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 116c02a67..212ceb81a 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -140,6 +140,42 @@ sub list :Path('list') :Args(0) { $c->stash->{rss_feed_20k} = $c->cobrand->uri($rss_feed.'/20', $c->fake_q); } +=head2 rss + +Redirects to relevant RSS feed + +=cut + +sub rss :Path('rss') :Args(0) { + my ($self, $c) = @_; + my $feed = $c->req->params->{feed}; + + unless ( $feed ) { + $c->stash->{errors} = [ _( 'Please select the feed you want' ) ]; + $c->go( 'list' ); + } + + my $extra_params = $c->cobrand->extra_params($c->fake_q); + my $url; + if ($feed =~ /^area:(?:\d+:)+(.*)$/) { + (my $id = $1) =~ tr{:_}{/+}; + $url = $c->cobrand->base_url() . '/rss/area/' . $id; + $c->res->redirect( $url ); + } elsif ($feed =~ /^(?:council|ward):(?:\d+:)+(.*)$/) { + (my $id = $1) =~ tr{:_}{/+}; + $url = $c->cobrand->base_url() . '/rss/reports/' . $id; + $c->res->redirect( $url ); + } elsif ($feed =~ /^local:([\d\.-]+):([\d\.-]+)$/) { + (my $id = $1) =~ tr{:_}{/+}; + $url = $c->cobrand->base_url() . '/rss/l/' . $id; + $c->res->redirect( $url ); + } else { + $c->stash->{errors} = [ _( 'Illegal feed selection' ) ]; + $c->go( 'list' ); + } +} + + =head2 prettify_pc This will canonicalise and prettify the postcode and stick a pretty_pc and pretty_pc_text in the stash. -- cgit v1.2.3 From 6e23ba1293355029a96eb5a9fd59cc60974d74ae Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 10 May 2011 11:09:37 +0100 Subject: belated application of perltidy --- perllib/FixMyStreet/App/Controller/Alert.pm | 222 +++++++++++++++------------- 1 file changed, 121 insertions(+), 101 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 212ceb81a..93080c073 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -2,7 +2,7 @@ package FixMyStreet::App::Controller::Alert; use Moose; use namespace::autoclean; -BEGIN {extends 'Catalyst::Controller'; } +BEGIN { extends 'Catalyst::Controller'; } =head1 NAME @@ -16,14 +16,13 @@ Catalyst Controller. =cut - =head2 alert Show the alerts page =cut -sub index :Path('') :Args(0) { +sub index : Path('') : Args(0) { my ( $self, $c ) = @_; # my $q = shift; @@ -41,15 +40,15 @@ sub index :Path('') :Args(0) { #'); # $out .= $cobrand_form_elements; # -# my %vars = (error => $error, -# header => $header, -# intro => $intro, -# pc_label => $pc_label, -# form_action => $form_action, -# input_h => \%input_h, -# submit_text => $submit_text, -# cobrand_form_elements => $cobrand_form_elements, -# cobrand_extra_data => $cobrand_extra_data, +# my %vars = (error => $error, +# header => $header, +# intro => $intro, +# pc_label => $pc_label, +# form_action => $form_action, +# input_h => \%input_h, +# submit_text => $submit_text, +# cobrand_form_elements => $cobrand_form_elements, +# cobrand_extra_data => $cobrand_extra_data, # url_home => Cobrand::url($cobrand, '/', $q)); # # my $cobrand_page = Page::template_include('alert-front-page', $q, Page::template_root($q), %vars); @@ -62,51 +61,58 @@ sub index :Path('') :Args(0) { # return $out; } - - -sub list :Path('list') :Args(0) { +sub list : Path('list') : Args(0) { my ( $self, $c ) = @_; -# my ($q, @errors) = @_; -# my @vars = qw(pc rznvy lat lon); -# my %input = map { $_ => scalar $q->param($_) } @vars; -# my %input_h = map { $_ => $q->param($_) ? ent($q->param($_)) : '' } @vars; -# - # Try to create a location for whatever we have - unless ($c->forward('/location/determine_location_from_coords') - || $c->forward('/location/determine_location_from_pc') ) { - if ( $c->stash->{possible_location_matches} ) { - $c->stash->{choose_target_uri} = $c->uri_for( '/alert/list' ); - $c->detach('choose'); - } - - $c->go('index') if $c->stash->{ location_error }; + # my ($q, @errors) = @_; + # my @vars = qw(pc rznvy lat lon); + # my %input = map { $_ => scalar $q->param($_) } @vars; + # my %input_h = map { $_ => $q->param($_) ? ent($q->param($_)) : '' } @vars; + # + # Try to create a location for whatever we have + unless ( $c->forward('/location/determine_location_from_coords') + || $c->forward('/location/determine_location_from_pc') ) + { + + if ( $c->stash->{possible_location_matches} ) { + $c->stash->{choose_target_uri} = $c->uri_for('/alert/list'); + $c->detach('choose'); + } + + $c->go('index') if $c->stash->{location_error}; } - $c->log->debug( $_ ) for ( $c->stash->{pc}, $c->stash->{latitude}, $c->stash->{longitude} ); + $c->log->debug($_) + for ( $c->stash->{pc}, $c->stash->{latitude}, $c->stash->{longitude} ); $c->forward('prettify_pc'); # truncate the lat,lon for nicer urls - ( $c->stash->{latitude}, $c->stash->{longitude} ) = map { Utils::truncate_coordinate($_) } ( $c->stash->{latitude}, $c->stash->{longitude} ); - $c->log->debug( $_ ) for ( $c->stash->{pc}, $c->stash->{latitude}, $c->stash->{longitude} ); -# + ( $c->stash->{latitude}, $c->stash->{longitude} ) = + map { Utils::truncate_coordinate($_) } + ( $c->stash->{latitude}, $c->stash->{longitude} ); + $c->log->debug($_) + for ( $c->stash->{pc}, $c->stash->{latitude}, $c->stash->{longitude} ); + +# # my $errors = ''; # $errors = '
  • ' . join('
  • ', @errors) . '
' if @errors; # $c->stash->{council_check_action} = 'alert'; - unless ( $c->forward( '/council/load_and_check_councils_and_wards' ) ) { - $c->go( 'index' ); + unless ( $c->forward('/council/load_and_check_councils_and_wards') ) { + $c->go('index'); } - ( $c->stash->{options}, $c->stash->{reported_to_options} ) - = $c->cobrand->council_rss_alert_options( $c->stash->{all_councils} ); + ( $c->stash->{options}, $c->stash->{reported_to_options} ) = + $c->cobrand->council_rss_alert_options( $c->stash->{all_councils} ); + 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 $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"; @@ -114,30 +120,41 @@ sub list :Path('list') :Args(0) { # my $pics = Cobrand::recent_photos($cobrand, 5, $lat, $lon, $dist); # $pics = '
' . $q->h2(_('Photos of recent nearby reports')) . $pics . '
' if $pics; -# my $form_action = Cobrand::url($cobrand, '/alert', $q); -#$cobrand_form_elements -#$pics -# -#EOF -# $out .= $errors; -# $out .= <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); - } + # my $form_action = Cobrand::url($cobrand, '/alert', $q); + #$cobrand_form_elements + #$pics + # + #EOF + # $out .= $errors; + # $out .= <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; + $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); + $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 ); } =head2 rss @@ -146,35 +163,37 @@ Redirects to relevant RSS feed =cut -sub rss :Path('rss') :Args(0) { - my ($self, $c) = @_; - my $feed = $c->req->params->{feed}; - - unless ( $feed ) { - $c->stash->{errors} = [ _( 'Please select the feed you want' ) ]; - $c->go( 'list' ); - } - - my $extra_params = $c->cobrand->extra_params($c->fake_q); - my $url; - if ($feed =~ /^area:(?:\d+:)+(.*)$/) { - (my $id = $1) =~ tr{:_}{/+}; - $url = $c->cobrand->base_url() . '/rss/area/' . $id; - $c->res->redirect( $url ); - } elsif ($feed =~ /^(?:council|ward):(?:\d+:)+(.*)$/) { - (my $id = $1) =~ tr{:_}{/+}; - $url = $c->cobrand->base_url() . '/rss/reports/' . $id; - $c->res->redirect( $url ); - } elsif ($feed =~ /^local:([\d\.-]+):([\d\.-]+)$/) { - (my $id = $1) =~ tr{:_}{/+}; - $url = $c->cobrand->base_url() . '/rss/l/' . $id; - $c->res->redirect( $url ); - } else { - $c->stash->{errors} = [ _( 'Illegal feed selection' ) ]; - $c->go( 'list' ); - } -} +sub rss : Path('rss') : Args(0) { + my ( $self, $c ) = @_; + my $feed = $c->req->params->{feed}; + unless ($feed) { + $c->stash->{errors} = [ _('Please select the feed you want') ]; + $c->go('list'); + } + + my $extra_params = $c->cobrand->extra_params( $c->fake_q ); + my $url; + if ( $feed =~ /^area:(?:\d+:)+(.*)$/ ) { + ( my $id = $1 ) =~ tr{:_}{/+}; + $url = $c->cobrand->base_url() . '/rss/area/' . $id; + $c->res->redirect($url); + } + elsif ( $feed =~ /^(?:council|ward):(?:\d+:)+(.*)$/ ) { + ( my $id = $1 ) =~ tr{:_}{/+}; + $url = $c->cobrand->base_url() . '/rss/reports/' . $id; + $c->res->redirect($url); + } + elsif ( $feed =~ /^local:([\d\.-]+):([\d\.-]+)$/ ) { + ( my $id = $1 ) =~ tr{:_}{/+}; + $url = $c->cobrand->base_url() . '/rss/l/' . $id; + $c->res->redirect($url); + } + else { + $c->stash->{errors} = [ _('Illegal feed selection') ]; + $c->go('list'); + } +} =head2 prettify_pc @@ -185,16 +204,19 @@ This will canonicalise and prettify the postcode and stick a pretty_pc and prett sub prettify_pc : Private { my ( $self, $c ) = @_; - # FIXME previously this had been run through ent so need to do similar here or in template +# 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 = $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/ / /; } @@ -202,12 +224,11 @@ sub prettify_pc : Private { $c->stash->{pretty_pc} = $pretty_pc; } - sub council_options : Private { - my ( $self, $c ) = @_; + my ( $self, $c ) = @_; + if ( $c->config->{COUNTRY} eq 'NO' ) { - if ( $c->config->{COUNTRY} eq 'NO' ) { # my ($options, $options_start, $options_end); # if (mySociety::Config::get('COUNTRY') eq 'NO') { # @@ -226,7 +247,7 @@ sub council_options : Private { # # push @options, [ 'council', $fylke->{id}, Page::short_name($fylke), # sprintf(_("Problems within %s"), $fylke_name) ]; -# +# # $options_start = "
    "; # $options = alert_list_options($q, @options); # $options_end = "
"; @@ -258,11 +279,10 @@ sub council_options : Private { } sub choose : Private { - my ( $self, $c ) = @_; - $c->stash->{template} = 'alert/choose.html'; + my ( $self, $c ) = @_; + $c->stash->{template} = 'alert/choose.html'; } - =head1 AUTHOR Struan Donald -- cgit v1.2.3 From 7011ca98493656f98433d644ffa922c8b3720adc Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 10 May 2011 11:56:07 +0100 Subject: add subscribe target and get to rss through that instead --- perllib/FixMyStreet/App/Controller/Alert.pm | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 93080c073..ef37e53c3 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -25,6 +25,7 @@ Show the alerts page sub index : Path('') : Args(0) { my ( $self, $c ) = @_; + # my $q = shift; # my $cobrand = Page::get_cobrand($q); # my $error = shift; @@ -157,13 +158,27 @@ sub list : Path('list') : Args(0) { $c->cobrand->uri( $rss_feed . '/20', $c->fake_q ); } +=head2 subscribe + +Target for subscribe form + +=cut + +sub subscribe : Path('subscribe') : Args(0) { + my ( $self, $c ) = @_; + + if ( $c->req->param( 'rss' ) ) { + $c->detach( 'rss' ); + } +} + =head2 rss Redirects to relevant RSS feed =cut -sub rss : Path('rss') : Args(0) { +sub rss : Private { my ( $self, $c ) = @_; my $feed = $c->req->params->{feed}; -- cgit v1.2.3 From a1fa6aa37ce73e2a637e4bac565cd0a199f551e2 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 10 May 2011 16:16:02 +0100 Subject: local alert email signup --- perllib/FixMyStreet/App/Controller/Alert.pm | 97 +++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index ef37e53c3..3d2c86970 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -4,6 +4,8 @@ use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } +use mySociety::EmailUtil qw(is_valid_email); + =head1 NAME FixMyStreet::App::Controller::Alert - Catalyst Controller @@ -65,6 +67,9 @@ sub index : Path('') : Args(0) { sub list : Path('list') : Args(0) { my ( $self, $c ) = @_; + $c->stash->{rznvy} = $c->req->param('rznvy'); + $c->stash->{selected_feed} = $c->req->param('feed'); + # my ($q, @errors) = @_; # my @vars = qw(pc rznvy lat lon); # my %input = map { $_ => scalar $q->param($_) } @vars; @@ -169,6 +174,8 @@ sub subscribe : Path('subscribe') : Args(0) { if ( $c->req->param( 'rss' ) ) { $c->detach( 'rss' ); + } elsif ( $c->req->param( 'rznvy' ) ) { + $c->detach( 'subscribe_email' ); } } @@ -210,6 +217,96 @@ sub rss : Private { } } +=head2 subscribe_email + +Sign up to email alerts + +=cut + +sub subscribe_email : Private { + my ( $self, $c ) = @_; + + my $type = $c->req->param('type'); + $c->stash->{email_type} = 'alert'; + + my @errors; + push @errors, _('Please enter a valid email address') unless is_valid_email($c->req->param('rznvy')); + push @errors, _('Please select the type of alert you want') if $type && $type eq 'local' && !$c->req->param('feed'); + if (@errors) { + $c->stash->{errors} = \@errors; + $c->go('list'); +# return alert_updates_form($q, @errors) if $type && $type eq 'updates'; +# return alert_list($q, @errors) if $type && $type eq 'local'; +# return alert_front_page($q, @errors); + } + + my $alert_id; + my $email = $c->req->param('rznvy'); +# my $cobrand = Page::get_cobrand($q); +# my $cobrand_data = Cobrand::extra_alert_data($cobrand, $q); + if ($type eq 'updates') { +# my $id = $q->param('id'); +# $alert_id = FixMyStreet::Alert::create($email, 'new_updates', $cobrand, $cobrand_data, $id); + } elsif ($type eq 'problems') { +# $alert_id = FixMyStreet::Alert::create($email, 'new_problems', $cobrand, $cobrand_data); + } elsif ($type eq 'local') { + my $feed = $c->req->param('feed'); + + my ( $type, @params ); + if ($feed =~ /^area:(?:\d+:)?(\d+)/) { + $type = 'area_problems'; + push @params, $1; + } elsif ($feed =~ /^council:(\d+)/) { + $type = 'council_problems'; + push @params, $1, $1; + } elsif ($feed =~ /^ward:(\d+):(\d+)/) { + $type = 'ward_problems'; + push @params, $1, $2; + } elsif ($feed =~ m{ \A local: ( [\+\-]? \d+ \.? \d* ) : ( [\+\-]? \d+ \.? \d* ) }xms ) { + $type = 'local_problems'; + push @params, $1, $2; +# my $lat = $1; +# my $lon = $2; +# $alert_id = FixMyStreet::Alert::create($email, 'local_problems', $cobrand, $cobrand_data, $lon, $lat); + } + + my $options = { + email => $email, + alert_type => $type + }; + + if ( scalar @params == 1 ) { + $options->{parameter} = $params[0]; + } elsif ( scalar @params == 2 ) { + $options->{parameter} = $params[0]; + $options->{parameter2} = $params[1]; + } + + my $alert = $c->model('DB::Alert')->find( + $options + ); + + unless ( $alert ) { + $options->{cobrand} = $c->cobrand->moniker(); + $options->{cobrand_data} = $c->cobrand->extra_update_data(); + + $alert = $c->model('DB::Alert')->new( $options ); + $alert->insert(); + } + + $c->log->debug( 'created alert ' . $alert->id ); + $c->stash->{template} = 'email_sent.html'; + } else { + throw FixMyStreet::Alert::Error('Invalid type'); + } +# +# my %h = (); +# $h{url} = Page::base_url_with_lang($q, undef, 1) . '/A/' +# . mySociety::AuthToken::store('alert', { id => $alert_id, type => 'subscribe', email => $email } ); +# dbh()->commit(); +# return Page::send_confirmation_email($q, $email, undef, 'alert', %h); +} + =head2 prettify_pc This will canonicalise and prettify the postcode and stick a pretty_pc and pretty_pc_text in the stash. -- cgit v1.2.3 From 00177a5cd2ebbfeb08082712c1a1c392276c4a83 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 10 May 2011 17:23:20 +0100 Subject: send out alert subscription email confirmations --- perllib/FixMyStreet/App/Controller/Alert.pm | 104 ++++++++++++++++++---------- 1 file changed, 66 insertions(+), 38 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 3d2c86970..12624b8f2 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -27,7 +27,6 @@ Show the alerts page sub index : Path('') : Args(0) { my ( $self, $c ) = @_; - # my $q = shift; # my $cobrand = Page::get_cobrand($q); # my $error = shift; @@ -67,7 +66,7 @@ sub index : Path('') : Args(0) { sub list : Path('list') : Args(0) { my ( $self, $c ) = @_; - $c->stash->{rznvy} = $c->req->param('rznvy'); + $c->stash->{rznvy} = $c->req->param('rznvy'); $c->stash->{selected_feed} = $c->req->param('feed'); # my ($q, @errors) = @_; @@ -172,10 +171,11 @@ Target for subscribe form sub subscribe : Path('subscribe') : Args(0) { my ( $self, $c ) = @_; - if ( $c->req->param( 'rss' ) ) { - $c->detach( 'rss' ); - } elsif ( $c->req->param( 'rznvy' ) ) { - $c->detach( 'subscribe_email' ); + if ( $c->req->param('rss') ) { + $c->detach('rss'); + } + elsif ( $c->req->param('rznvy') ) { + $c->detach('subscribe_email'); } } @@ -230,81 +230,109 @@ sub subscribe_email : Private { $c->stash->{email_type} = 'alert'; my @errors; - push @errors, _('Please enter a valid email address') unless is_valid_email($c->req->param('rznvy')); - push @errors, _('Please select the type of alert you want') if $type && $type eq 'local' && !$c->req->param('feed'); + push @errors, _('Please enter a valid email address') + unless is_valid_email( $c->req->param('rznvy') ); + push @errors, _('Please select the type of alert you want') + if $type && $type eq 'local' && !$c->req->param('feed'); if (@errors) { $c->stash->{errors} = \@errors; $c->go('list'); -# return alert_updates_form($q, @errors) if $type && $type eq 'updates'; -# return alert_list($q, @errors) if $type && $type eq 'local'; -# return alert_front_page($q, @errors); + + # return alert_updates_form($q, @errors) if $type && $type eq 'updates'; + # return alert_list($q, @errors) if $type && $type eq 'local'; + # return alert_front_page($q, @errors); } - my $alert_id; + my $alert; my $email = $c->req->param('rznvy'); -# my $cobrand = Page::get_cobrand($q); -# my $cobrand_data = Cobrand::extra_alert_data($cobrand, $q); - if ($type eq 'updates') { + + # my $cobrand = Page::get_cobrand($q); + # my $cobrand_data = Cobrand::extra_alert_data($cobrand, $q); + if ( $type eq 'updates' ) { + # my $id = $q->param('id'); # $alert_id = FixMyStreet::Alert::create($email, 'new_updates', $cobrand, $cobrand_data, $id); - } elsif ($type eq 'problems') { + } + elsif ( $type eq 'problems' ) { + # $alert_id = FixMyStreet::Alert::create($email, 'new_problems', $cobrand, $cobrand_data); - } elsif ($type eq 'local') { + } + elsif ( $type eq 'local' ) { my $feed = $c->req->param('feed'); my ( $type, @params ); - if ($feed =~ /^area:(?:\d+:)?(\d+)/) { + if ( $feed =~ /^area:(?:\d+:)?(\d+)/ ) { $type = 'area_problems'; push @params, $1; - } elsif ($feed =~ /^council:(\d+)/) { + } + elsif ( $feed =~ /^council:(\d+)/ ) { $type = 'council_problems'; push @params, $1, $1; - } elsif ($feed =~ /^ward:(\d+):(\d+)/) { + } + elsif ( $feed =~ /^ward:(\d+):(\d+)/ ) { $type = 'ward_problems'; push @params, $1, $2; - } elsif ($feed =~ m{ \A local: ( [\+\-]? \d+ \.? \d* ) : ( [\+\-]? \d+ \.? \d* ) }xms ) { + } + elsif ( $feed =~ + m{ \A local: ( [\+\-]? \d+ \.? \d* ) : ( [\+\-]? \d+ \.? \d* ) }xms + ) + { $type = 'local_problems'; push @params, $1, $2; + # my $lat = $1; # my $lon = $2; # $alert_id = FixMyStreet::Alert::create($email, 'local_problems', $cobrand, $cobrand_data, $lon, $lat); } my $options = { - email => $email, - alert_type => $type + email => $email, + alert_type => $type }; if ( scalar @params == 1 ) { $options->{parameter} = $params[0]; - } elsif ( scalar @params == 2 ) { - $options->{parameter} = $params[0]; + } + elsif ( scalar @params == 2 ) { + $options->{parameter} = $params[0]; $options->{parameter2} = $params[1]; } - my $alert = $c->model('DB::Alert')->find( - $options - ); + $alert = $c->model('DB::Alert')->find( $options ); - unless ( $alert ) { - $options->{cobrand} = $c->cobrand->moniker(); + unless ($alert) { + $options->{cobrand} = $c->cobrand->moniker(); $options->{cobrand_data} = $c->cobrand->extra_update_data(); - $alert = $c->model('DB::Alert')->new( $options ); + $alert = $c->model('DB::Alert')->new($options); $alert->insert(); } $c->log->debug( 'created alert ' . $alert->id ); $c->stash->{template} = 'email_sent.html'; - } else { + } + else { throw FixMyStreet::Alert::Error('Invalid type'); } -# -# my %h = (); -# $h{url} = Page::base_url_with_lang($q, undef, 1) . '/A/' -# . mySociety::AuthToken::store('alert', { id => $alert_id, type => 'subscribe', email => $email } ); -# dbh()->commit(); -# return Page::send_confirmation_email($q, $email, undef, 'alert', %h); + + my $token = $c->model("DB::Token")->create( + { + scope => 'alert', + data => { id => $alert->id, type => 'subscribe', email => $email } + } + ); + + $c->stash->{token_url} = $c->uri_for_email( '/A', $token->token ); + + my $sender = mySociety::Config::get('CONTACT_EMAIL'); + + $c->send_email( + 'alert-confirm.txt', + { + to => $email, + from => $sender + } + ); } =head2 prettify_pc -- cgit v1.2.3 From 5f1db7700255e00ce492d57939f861f76b6ddadf Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 11 May 2011 11:37:36 +0100 Subject: confirm alert subscription --- perllib/FixMyStreet/App/Controller/Alert.pm | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 12624b8f2..742aa6c1d 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -298,7 +298,7 @@ sub subscribe_email : Private { $options->{parameter2} = $params[1]; } - $alert = $c->model('DB::Alert')->find( $options ); + $alert = $c->model('DB::Alert')->find($options); unless ($alert) { $options->{cobrand} = $c->cobrand->moniker(); @@ -335,6 +335,28 @@ sub subscribe_email : Private { ); } +=head2 confirm + +Confirm signup to an alert + +=cut + +sub confirm : Private { + my ( $self, $c ) = @_; + + my $alert = $c->stash->{alert}; + $c->stash->{template} = 'alert/confirm.html'; + + if ( $c->stash->{confirm_type} eq 'subscribe' ) { + $alert->confirm(); + $alert->update; + } + elsif ( $c->stash->{confirm_type} eq 'unsubscribe' ) { + $alert->delete(); + $alert->update; + } +} + =head2 prettify_pc This will canonicalise and prettify the postcode and stick a pretty_pc and pretty_pc_text in the stash. -- cgit v1.2.3 From c3adef1dea602a181521f2bc0848ec47d67198d0 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 11 May 2011 14:55:39 +0100 Subject: moving alerts to use users instead of email in table --- perllib/FixMyStreet/App/Controller/Alert.pm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 742aa6c1d..595f6d252 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -243,8 +243,11 @@ sub subscribe_email : Private { # return alert_front_page($q, @errors); } - my $alert; my $email = $c->req->param('rznvy'); + $c->stash->{email} = $email; + $c->forward( 'process_user' ); + + my $alert; # my $cobrand = Page::get_cobrand($q); # my $cobrand_data = Cobrand::extra_alert_data($cobrand, $q); @@ -286,7 +289,7 @@ sub subscribe_email : Private { } my $options = { - email => $email, + user => $c->stash->{alert_user}, alert_type => $type }; @@ -440,6 +443,14 @@ sub council_options : Private { } } +sub process_user : Private { + my ( $self, $c ) = @_; + + my $email = $c->stash->{email}; + my $alert_user = $c->model('DB::User')->find_or_new( { email => $email } ); + $c->stash->{alert_user} = $alert_user; +} + sub choose : Private { my ( $self, $c ) = @_; $c->stash->{template} = 'alert/choose.html'; -- cgit v1.2.3 From 6cd84f2e112b0f388266d6c64b634f31bafb264d Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 11 May 2011 16:48:51 +0100 Subject: Automatically fill in email address of logged in user --- perllib/FixMyStreet/App/Controller/Alert.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 595f6d252..28b338563 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -69,6 +69,10 @@ sub list : Path('list') : Args(0) { $c->stash->{rznvy} = $c->req->param('rznvy'); $c->stash->{selected_feed} = $c->req->param('feed'); + if ( $c->user ) { + $c->stash->{rznvy} ||= $c->user->email; + } + # my ($q, @errors) = @_; # my @vars = qw(pc rznvy lat lon); # my %input = map { $_ => scalar $q->param($_) } @vars; @@ -245,7 +249,7 @@ sub subscribe_email : Private { my $email = $c->req->param('rznvy'); $c->stash->{email} = $email; - $c->forward( 'process_user' ); + $c->forward('process_user'); my $alert; -- cgit v1.2.3 From 64f98502ae9d9c60973862f10ddae8fcce363f9d Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 May 2011 10:08:49 +0100 Subject: add recent local problems photos to alert list page --- perllib/FixMyStreet/App/Controller/Alert.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 28b338563..f88e57d1a 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -122,6 +122,12 @@ sub list : Path('list') : Args(0) { $dist = $dist / 10.0; $c->stash->{population_radius} = $dist; + + $c->stash->{photos} = $c->cobrand->recent_photos( + 5, + $c->stash->{latitude}, + $c->stash->{longitude}, $dist + ); # # my $checked = ''; # $checked = ' checked' if $q->param('feed') && $q->param('feed') eq "local:$lat:$lon"; @@ -344,7 +350,7 @@ sub subscribe_email : Private { =head2 confirm -Confirm signup to an alert +Confirm signup to an alert. Forwarded here from Tokens. =cut -- cgit v1.2.3 From f192e02e1a1a4ad6754e55ca7045c734f345c148 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 May 2011 10:20:36 +0100 Subject: recent report photos for alerts front page --- perllib/FixMyStreet/App/Controller/Alert.pm | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index f88e57d1a..3a968ee1d 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -56,11 +56,9 @@ sub index : Path('') : Args(0) { # my $cobrand_page = Page::template_include('alert-front-page', $q, Page::template_root($q), %vars); # $out = $cobrand_page if ($cobrand_page); # -# return $out if $q->referer() && $q->referer() =~ /fixmystreet\.com/; -# my $recent_photos = Cobrand::recent_photos($cobrand, 10); -# $out .= '
' . $q->h2(_('Some photos of recent reports')) . $recent_photos . '
' if $recent_photos; -# -# return $out; + unless ( $c->req->referer && $c->req->referer =~ /fixmystreet\.com/ ) { + $c->stash->{photos} = $c->cobrand->recent_photos(10); + } } sub list : Path('list') : Args(0) { -- cgit v1.2.3 From eeea97e7ef61c939a706cb1be87b28f2600e4e8c Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 May 2011 11:03:39 +0100 Subject: Add cobrand form elements to alert front page --- perllib/FixMyStreet/App/Controller/Alert.pm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 3a968ee1d..8b481b7cf 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -55,6 +55,8 @@ sub index : Path('') : Args(0) { # # my $cobrand_page = Page::template_include('alert-front-page', $q, Page::template_root($q), %vars); # $out = $cobrand_page if ($cobrand_page); + + $c->stash->{cobrand_form_elements} = $c->cobrand->form_elements('alerts'); # unless ( $c->req->referer && $c->req->referer =~ /fixmystreet\.com/ ) { $c->stash->{photos} = $c->cobrand->recent_photos(10); -- cgit v1.2.3 From 3d22d7252e67df65b9bd7442b8363b212af15c87 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 May 2011 11:04:23 +0100 Subject: removed old commented out code --- perllib/FixMyStreet/App/Controller/Alert.pm | 31 +---------------------------- 1 file changed, 1 insertion(+), 30 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 8b481b7cf..38220faf8 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -27,37 +27,8 @@ Show the alerts page sub index : Path('') : Args(0) { my ( $self, $c ) = @_; -# my $q = shift; -# my $cobrand = Page::get_cobrand($q); -# my $error = shift; -# my $errors = ''; -# $errors = '
  • ' . $error . '
' if $error; -# -# my $form_action = Cobrand::url(Page::get_cobrand($q), '/alert', $q); -# my $cobrand_form_elements = Cobrand::form_elements($cobrand, 'alerts', $q); -# my $cobrand_extra_data = Cobrand::extra_data($cobrand, $q); -# -# $out .= $errors . qq(
); -# $out .= $q->p($pc_label, ' -#'); -# $out .= $cobrand_form_elements; -# -# my %vars = (error => $error, -# header => $header, -# intro => $intro, -# pc_label => $pc_label, -# form_action => $form_action, -# input_h => \%input_h, -# submit_text => $submit_text, -# cobrand_form_elements => $cobrand_form_elements, -# cobrand_extra_data => $cobrand_extra_data, -# url_home => Cobrand::url($cobrand, '/', $q)); -# -# my $cobrand_page = Page::template_include('alert-front-page', $q, Page::template_root($q), %vars); -# $out = $cobrand_page if ($cobrand_page); - $c->stash->{cobrand_form_elements} = $c->cobrand->form_elements('alerts'); -# + unless ( $c->req->referer && $c->req->referer =~ /fixmystreet\.com/ ) { $c->stash->{photos} = $c->cobrand->recent_photos(10); } -- cgit v1.2.3 From 629441ccda35f5956f01907d3c43a9a1847f5885 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 May 2011 11:08:05 +0100 Subject: Add cobrand form elements to alert list page --- perllib/FixMyStreet/App/Controller/Alert.pm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 38220faf8..d22cc710f 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -99,6 +99,8 @@ sub list : Path('list') : Args(0) { $c->stash->{latitude}, $c->stash->{longitude}, $dist ); + + $c->stash->{cobrand_form_elements} = $c->cobrand->form_elements('alerts'); # # my $checked = ''; # $checked = ' checked' if $q->param('feed') && $q->param('feed') eq "local:$lat:$lon"; -- cgit v1.2.3 From d5fa6de56ce14cd32877fc451d2355900eb5b649 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 May 2011 11:09:09 +0100 Subject: removed old commented out code --- perllib/FixMyStreet/App/Controller/Alert.pm | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index d22cc710f..53defe05e 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -44,12 +44,7 @@ sub list : Path('list') : Args(0) { $c->stash->{rznvy} ||= $c->user->email; } - # my ($q, @errors) = @_; - # my @vars = qw(pc rznvy lat lon); - # my %input = map { $_ => scalar $q->param($_) } @vars; - # my %input_h = map { $_ => $q->param($_) ? ent($q->param($_)) : '' } @vars; - # - # Try to create a location for whatever we have + # Try to create a location for whatever we have unless ( $c->forward('/location/determine_location_from_coords') || $c->forward('/location/determine_location_from_pc') ) { @@ -74,10 +69,6 @@ sub list : Path('list') : Args(0) { $c->log->debug($_) for ( $c->stash->{pc}, $c->stash->{latitude}, $c->stash->{longitude} ); -# -# my $errors = ''; -# $errors = '
  • ' . join('
  • ', @errors) . '
' if @errors; -# $c->stash->{council_check_action} = 'alert'; unless ( $c->forward('/council/load_and_check_councils_and_wards') ) { $c->go('index'); @@ -101,20 +92,7 @@ sub list : Path('list') : Args(0) { ); $c->stash->{cobrand_form_elements} = $c->cobrand->form_elements('alerts'); -# -# 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 = '
' . $q->h2(_('Photos of recent nearby reports')) . $pics . '
' if $pics; - - # my $form_action = Cobrand::url($cobrand, '/alert', $q); - #$cobrand_form_elements - #$pics - # - #EOF - # $out .= $errors; - # $out .= <stash->{rss_feed_id} = sprintf( 'local:%s:%s', $c->stash->{latitude}, $c->stash->{longitude} ); @@ -135,8 +113,6 @@ sub list : Path('list') : Args(0) { $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} = -- cgit v1.2.3 From c0cfc5f8d5c9b1c1728e603a368fbe4570393615 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 May 2011 11:41:06 +0100 Subject: move creating local alert to own method --- perllib/FixMyStreet/App/Controller/Alert.pm | 113 +++++++++++++++------------- 1 file changed, 61 insertions(+), 52 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 53defe05e..370992854 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -220,57 +220,7 @@ sub subscribe_email : Private { # $alert_id = FixMyStreet::Alert::create($email, 'new_problems', $cobrand, $cobrand_data); } elsif ( $type eq 'local' ) { - my $feed = $c->req->param('feed'); - - my ( $type, @params ); - if ( $feed =~ /^area:(?:\d+:)?(\d+)/ ) { - $type = 'area_problems'; - push @params, $1; - } - elsif ( $feed =~ /^council:(\d+)/ ) { - $type = 'council_problems'; - push @params, $1, $1; - } - elsif ( $feed =~ /^ward:(\d+):(\d+)/ ) { - $type = 'ward_problems'; - push @params, $1, $2; - } - elsif ( $feed =~ - m{ \A local: ( [\+\-]? \d+ \.? \d* ) : ( [\+\-]? \d+ \.? \d* ) }xms - ) - { - $type = 'local_problems'; - push @params, $1, $2; - -# my $lat = $1; -# my $lon = $2; -# $alert_id = FixMyStreet::Alert::create($email, 'local_problems', $cobrand, $cobrand_data, $lon, $lat); - } - - my $options = { - user => $c->stash->{alert_user}, - alert_type => $type - }; - - if ( scalar @params == 1 ) { - $options->{parameter} = $params[0]; - } - elsif ( scalar @params == 2 ) { - $options->{parameter} = $params[0]; - $options->{parameter2} = $params[1]; - } - - $alert = $c->model('DB::Alert')->find($options); - - unless ($alert) { - $options->{cobrand} = $c->cobrand->moniker(); - $options->{cobrand_data} = $c->cobrand->extra_update_data(); - - $alert = $c->model('DB::Alert')->new($options); - $alert->insert(); - } - - $c->log->debug( 'created alert ' . $alert->id ); + $c->forward('create_local_alert'); $c->stash->{template} = 'email_sent.html'; } else { @@ -280,7 +230,7 @@ sub subscribe_email : Private { my $token = $c->model("DB::Token")->create( { scope => 'alert', - data => { id => $alert->id, type => 'subscribe', email => $email } + data => { id => $c->stash->{alert}->id, type => 'subscribe', email => $email } } ); @@ -319,6 +269,65 @@ sub confirm : Private { } } +=head2 create_local_alert + +Create a local alert + +=cut + +sub create_local_alert : Private { + my ( $self, $c ) = @_; + + my $feed = $c->req->param('feed'); + + my ( $type, @params, $alert ); + if ( $feed =~ /^area:(?:\d+:)?(\d+)/ ) { + $type = 'area_problems'; + push @params, $1; + } + elsif ( $feed =~ /^council:(\d+)/ ) { + $type = 'council_problems'; + push @params, $1, $1; + } + elsif ( $feed =~ /^ward:(\d+):(\d+)/ ) { + $type = 'ward_problems'; + push @params, $1, $2; + } + elsif ( $feed =~ + m{ \A local: ( [\+\-]? \d+ \.? \d* ) : ( [\+\-]? \d+ \.? \d* ) }xms ) + { + $type = 'local_problems'; + push @params, $1, $2; + } + + my $options = { + user => $c->stash->{alert_user}, + alert_type => $type + }; + + if ( scalar @params == 1 ) { + $options->{parameter} = $params[0]; + } + elsif ( scalar @params == 2 ) { + $options->{parameter} = $params[0]; + $options->{parameter2} = $params[1]; + } + + $alert = $c->model('DB::Alert')->find($options); + + unless ($alert) { + $options->{cobrand} = $c->cobrand->moniker(); + $options->{cobrand_data} = $c->cobrand->extra_update_data(); + + $alert = $c->model('DB::Alert')->new($options); + $alert->insert(); + } + + $c->stash->{alert} = $alert; + + $c->log->debug( 'created alert ' . $alert->id ); +} + =head2 prettify_pc This will canonicalise and prettify the postcode and stick a pretty_pc and pretty_pc_text in the stash. -- cgit v1.2.3 From 105291154c3dfaa905202ff576c51097759094df Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 May 2011 11:50:32 +0100 Subject: move confirmation email sending to own method --- perllib/FixMyStreet/App/Controller/Alert.pm | 56 +++++++++++++++++++---------- 1 file changed, 37 insertions(+), 19 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 370992854..56464dd64 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -221,30 +221,12 @@ sub subscribe_email : Private { } elsif ( $type eq 'local' ) { $c->forward('create_local_alert'); - $c->stash->{template} = 'email_sent.html'; } else { throw FixMyStreet::Alert::Error('Invalid type'); } - my $token = $c->model("DB::Token")->create( - { - scope => 'alert', - data => { id => $c->stash->{alert}->id, type => 'subscribe', email => $email } - } - ); - - $c->stash->{token_url} = $c->uri_for_email( '/A', $token->token ); - - my $sender = mySociety::Config::get('CONTACT_EMAIL'); - - $c->send_email( - 'alert-confirm.txt', - { - to => $email, - from => $sender - } - ); + $c->forward('send_confirmation_email'); } =head2 confirm @@ -328,6 +310,42 @@ sub create_local_alert : Private { $c->log->debug( 'created alert ' . $alert->id ); } +=head2 send_confirmation_email + +Generate a token and send out an alert subscription confirmation email and +then display confirmation page. + +=cut + +sub send_confirmation_email : Private { + my ( $self, $c ) = @_; + + my $token = $c->model("DB::Token")->create( + { + scope => 'alert', + data => { + id => $c->stash->{alert}->id, + type => 'subscribe', + email => $c->stash->{alert}->user->email + } + } + ); + + $c->stash->{token_url} = $c->uri_for_email( '/A', $token->token ); + + my $sender = mySociety::Config::get('CONTACT_EMAIL'); + + $c->send_email( + 'alert-confirm.txt', + { + to => $c->stash->{alert}->user->email, + from => $sender + } + ); + + $c->stash->{template} = 'email_sent.html'; +} + =head2 prettify_pc This will canonicalise and prettify the postcode and stick a pretty_pc and pretty_pc_text in the stash. -- cgit v1.2.3 From a9b2134ef5c94a74f840315aee987bfc57680c69 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 May 2011 13:14:23 +0100 Subject: problem update alert subscription --- perllib/FixMyStreet/App/Controller/Alert.pm | 54 +++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 10 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 56464dd64..6cf0ecc09 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -195,23 +195,17 @@ sub subscribe_email : Private { if $type && $type eq 'local' && !$c->req->param('feed'); if (@errors) { $c->stash->{errors} = \@errors; - $c->go('list'); - - # return alert_updates_form($q, @errors) if $type && $type eq 'updates'; - # return alert_list($q, @errors) if $type && $type eq 'local'; - # return alert_front_page($q, @errors); + $c->go('updates') if $type && $type eq 'updates'; + $c->go('list') if $type && $type eq 'local'; + $c->go('index'); } my $email = $c->req->param('rznvy'); $c->stash->{email} = $email; $c->forward('process_user'); - my $alert; - - # my $cobrand = Page::get_cobrand($q); - # my $cobrand_data = Cobrand::extra_alert_data($cobrand, $q); if ( $type eq 'updates' ) { - + $c->forward('create_update_alert'); # my $id = $q->param('id'); # $alert_id = FixMyStreet::Alert::create($email, 'new_updates', $cobrand, $cobrand_data, $id); } @@ -229,6 +223,14 @@ sub subscribe_email : Private { $c->forward('send_confirmation_email'); } +sub updates : Path('updates') : Args(0) { + my ( $self, $c ) = @_; + + $c->stash->{email} = $c->req->param('rznvy'); + $c->stash->{problem_id} = $c->req->param('id'); + $c->stash->{cobrand_form_elements} = $c->cobrand->form_elements('alerts'); +} + =head2 confirm Confirm signup to an alert. Forwarded here from Tokens. @@ -251,6 +253,38 @@ sub confirm : Private { } } +=head2 create_update_alert + +Create an update alert + +=cut + +sub create_update_alert : Private { + my ( $self, $c ) = @_; + + my $report_id = $c->req->param('id'); + + my $options = { + user => $c->stash->{alert_user}, + alert_type => 'new_updates', + parameter => $report_id, + }; + + my $alert = $c->model('DB::Alert')->find($options); + + unless ($alert) { + $options->{cobrand} = $c->cobrand->moniker(); + $options->{cobrand_data} = $c->cobrand->extra_update_data(); + + $alert = $c->model('DB::Alert')->new($options); + $alert->insert(); + } + + $c->stash->{alert} = $alert; + + $c->log->debug( 'created alert ' . $alert->id ); +} + =head2 create_local_alert Create a local alert -- cgit v1.2.3 From 4fec50eb2381d08c1e9282cbc2b159d45ec2a30b Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 May 2011 13:28:42 +0100 Subject: tidy up to remove repeated code --- perllib/FixMyStreet/App/Controller/Alert.pm | 66 +++++++++++++++-------------- 1 file changed, 35 insertions(+), 31 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 6cf0ecc09..33d9da2e1 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -205,21 +205,20 @@ sub subscribe_email : Private { $c->forward('process_user'); if ( $type eq 'updates' ) { - $c->forward('create_update_alert'); -# my $id = $q->param('id'); -# $alert_id = FixMyStreet::Alert::create($email, 'new_updates', $cobrand, $cobrand_data, $id); + $c->forward('set_update_alert_options'); } elsif ( $type eq 'problems' ) { # $alert_id = FixMyStreet::Alert::create($email, 'new_problems', $cobrand, $cobrand_data); } elsif ( $type eq 'local' ) { - $c->forward('create_local_alert'); + $c->forward('set_local_alert_options'); } else { throw FixMyStreet::Alert::Error('Invalid type'); } + $c->forward('create_alert'); $c->forward('send_confirmation_email'); } @@ -253,22 +252,17 @@ sub confirm : Private { } } -=head2 create_update_alert +=head2 create_alert -Create an update alert +Take the alert options from the stash and use these to create a new +alert. If it finds an existing alert that's the same then use that -=cut +=cut -sub create_update_alert : Private { +sub create_alert : Private { my ( $self, $c ) = @_; - my $report_id = $c->req->param('id'); - - my $options = { - user => $c->stash->{alert_user}, - alert_type => 'new_updates', - parameter => $report_id, - }; + my $options = $c->stash->{alert_options}; my $alert = $c->model('DB::Alert')->find($options); @@ -285,13 +279,34 @@ sub create_update_alert : Private { $c->log->debug( 'created alert ' . $alert->id ); } -=head2 create_local_alert +=head2 set_update_alert_options -Create a local alert +Set up the options in the stash required to create a problem update alert =cut -sub create_local_alert : Private { +sub set_update_alert_options : Private { + my ( $self, $c ) = @_; + + my $report_id = $c->req->param('id'); + + my $options = { + user => $c->stash->{alert_user}, + alert_type => 'new_updates', + parameter => $report_id, + }; + + $c->stash->{alert_options} = $options; + $c->forward('create_alert'); +} + +=head2 set_local_alert_options + +Set up the options in the stash required to create a local problems alert + +=cut + +sub set_local_alert_options : Private { my ( $self, $c ) = @_; my $feed = $c->req->param('feed'); @@ -316,6 +331,7 @@ sub create_local_alert : Private { push @params, $1, $2; } + my $options = { user => $c->stash->{alert_user}, alert_type => $type @@ -329,19 +345,7 @@ sub create_local_alert : Private { $options->{parameter2} = $params[1]; } - $alert = $c->model('DB::Alert')->find($options); - - unless ($alert) { - $options->{cobrand} = $c->cobrand->moniker(); - $options->{cobrand_data} = $c->cobrand->extra_update_data(); - - $alert = $c->model('DB::Alert')->new($options); - $alert->insert(); - } - - $c->stash->{alert} = $alert; - - $c->log->debug( 'created alert ' . $alert->id ); + $c->stash->{alert_options} = $options; } =head2 send_confirmation_email -- cgit v1.2.3 From 14dfac073cb4c45a1f5b2c01a7e1e15307fdb64c Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 May 2011 14:45:55 +0100 Subject: move lat/long rss feed generation to own method --- perllib/FixMyStreet/App/Controller/Alert.pm | 69 ++++++++++++++++++----------- 1 file changed, 43 insertions(+), 26 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 33d9da2e1..ed0e80a51 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -62,6 +62,8 @@ sub list : Path('list') : Args(0) { $c->forward('prettify_pc'); + $c->forward('setup_location_info'); + # truncate the lat,lon for nicer urls ( $c->stash->{latitude}, $c->stash->{longitude} ) = map { Utils::truncate_coordinate($_) } @@ -93,32 +95,7 @@ sub list : Path('list') : Args(0) { $c->stash->{cobrand_form_elements} = $c->cobrand->form_elements('alerts'); - $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; - - $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 ); + $c->forward( 'setup_rss_feeds' ); } =head2 subscribe @@ -475,6 +452,46 @@ sub process_user : Private { $c->stash->{alert_user} = $alert_user; } +=head2 setup_rss_feeds + +Takes the latitide and longitude from the stash and uses them to generate uris +for the local rss feeds + +=cut + +sub setup_rss_feeds : Private { + my ( $self, $c ) = @_; + + $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; + + $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 ); + + return 1; +} + sub choose : Private { my ( $self, $c ) = @_; $c->stash->{template} = 'alert/choose.html'; -- cgit v1.2.3 From bae6a35bb125ccb372dde0b4a311b839095bd61e Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 May 2011 14:48:31 +0100 Subject: better method name --- perllib/FixMyStreet/App/Controller/Alert.pm | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index ed0e80a51..09f62d8ec 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -62,8 +62,6 @@ sub list : Path('list') : Args(0) { $c->forward('prettify_pc'); - $c->forward('setup_location_info'); - # truncate the lat,lon for nicer urls ( $c->stash->{latitude}, $c->stash->{longitude} ) = map { Utils::truncate_coordinate($_) } @@ -95,7 +93,7 @@ sub list : Path('list') : Args(0) { $c->stash->{cobrand_form_elements} = $c->cobrand->form_elements('alerts'); - $c->forward( 'setup_rss_feeds' ); + $c->forward( 'setup_coordinate_rss_feeds' ); } =head2 subscribe @@ -452,14 +450,14 @@ sub process_user : Private { $c->stash->{alert_user} = $alert_user; } -=head2 setup_rss_feeds +=head2 setup_coordinate_rss_feeds Takes the latitide and longitude from the stash and uses them to generate uris for the local rss feeds =cut -sub setup_rss_feeds : Private { +sub setup_coordinate_rss_feeds : Private { my ( $self, $c ) = @_; $c->stash->{rss_feed_id} = -- cgit v1.2.3 From 86d96e9047e20e2d92d2d5edbc9505d82eb6498c Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 May 2011 14:49:47 +0100 Subject: remove unwanted debugging code --- perllib/FixMyStreet/App/Controller/Alert.pm | 5 ----- 1 file changed, 5 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 09f62d8ec..7ea3a1e7f 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -57,17 +57,12 @@ sub list : Path('list') : Args(0) { $c->go('index') if $c->stash->{location_error}; } - $c->log->debug($_) - for ( $c->stash->{pc}, $c->stash->{latitude}, $c->stash->{longitude} ); - $c->forward('prettify_pc'); # truncate the lat,lon for nicer urls ( $c->stash->{latitude}, $c->stash->{longitude} ) = map { Utils::truncate_coordinate($_) } ( $c->stash->{latitude}, $c->stash->{longitude} ); - $c->log->debug($_) - for ( $c->stash->{pc}, $c->stash->{latitude}, $c->stash->{longitude} ); $c->stash->{council_check_action} = 'alert'; unless ( $c->forward('/council/load_and_check_councils_and_wards') ) { -- cgit v1.2.3 From 52115baa1092fb9da6a037fa142ebd08389465fd Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 May 2011 14:54:22 +0100 Subject: extract council based rss feeds to method --- perllib/FixMyStreet/App/Controller/Alert.pm | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 7ea3a1e7f..e60c485ae 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -64,13 +64,7 @@ sub list : Path('list') : Args(0) { map { Utils::truncate_coordinate($_) } ( $c->stash->{latitude}, $c->stash->{longitude} ); - $c->stash->{council_check_action} = 'alert'; - unless ( $c->forward('/council/load_and_check_councils_and_wards') ) { - $c->go('index'); - } - - ( $c->stash->{options}, $c->stash->{reported_to_options} ) = - $c->cobrand->council_rss_alert_options( $c->stash->{all_councils} ); + $c->forward('setup_council_rss_feeds'); my $dist = mySociety::Gaze::get_radius_containing_population( $c->stash->{latitude}, @@ -485,6 +479,24 @@ sub setup_coordinate_rss_feeds : Private { return 1; } +=head2 setup_council_rss_feeds + +Generate the details required to display the council/ward/area RSS feeds + +=cut + +sub setup_council_rss_feeds : Private { + my ( $self, $c ) = @_; + + $c->stash->{council_check_action} = 'alert'; + unless ( $c->forward('/council/load_and_check_councils_and_wards') ) { + $c->go('index'); + } + + ( $c->stash->{options}, $c->stash->{reported_to_options} ) = + $c->cobrand->council_rss_alert_options( $c->stash->{all_councils} ); +} + sub choose : Private { my ( $self, $c ) = @_; $c->stash->{template} = 'alert/choose.html'; -- cgit v1.2.3 From 2678748fb464a559cc4b1e79f1fe60f49e750a4e Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 May 2011 14:59:53 +0100 Subject: move all the location setup stuff to one method --- perllib/FixMyStreet/App/Controller/Alert.pm | 70 +++++++++++++++++------------ 1 file changed, 41 insertions(+), 29 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index e60c485ae..2f2e32922 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -37,6 +37,7 @@ sub index : Path('') : Args(0) { sub list : Path('list') : Args(0) { my ( $self, $c ) = @_; + # setup the various parameters we need $c->stash->{rznvy} = $c->req->param('rznvy'); $c->stash->{selected_feed} = $c->req->param('feed'); @@ -44,44 +45,19 @@ sub list : Path('list') : Args(0) { $c->stash->{rznvy} ||= $c->user->email; } - # Try to create a location for whatever we have - unless ( $c->forward('/location/determine_location_from_coords') - || $c->forward('/location/determine_location_from_pc') ) - { - - if ( $c->stash->{possible_location_matches} ) { - $c->stash->{choose_target_uri} = $c->uri_for('/alert/list'); - $c->detach('choose'); - } - - $c->go('index') if $c->stash->{location_error}; - } - $c->forward('prettify_pc'); - - # truncate the lat,lon for nicer urls - ( $c->stash->{latitude}, $c->stash->{longitude} ) = - map { Utils::truncate_coordinate($_) } - ( $c->stash->{latitude}, $c->stash->{longitude} ); - - $c->forward('setup_council_rss_feeds'); - - 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; - + $c->forward('determine_location'); $c->stash->{photos} = $c->cobrand->recent_photos( 5, $c->stash->{latitude}, - $c->stash->{longitude}, $dist + $c->stash->{longitude}, + $c->stash->{population_radius} ); $c->stash->{cobrand_form_elements} = $c->cobrand->form_elements('alerts'); + $c->forward('setup_council_rss_feeds'); $c->forward( 'setup_coordinate_rss_feeds' ); } @@ -497,6 +473,42 @@ sub setup_council_rss_feeds : Private { $c->cobrand->council_rss_alert_options( $c->stash->{all_councils} ); } +=head2 determine_location + +Do all the things we need to do to work out where the alert is for +and to setup the location related things for later + +=cut + +sub determine_location : Private { + my ( $self, $c ) = @_; + + # Try to create a location for whatever we have + unless ( $c->forward('/location/determine_location_from_coords') + || $c->forward('/location/determine_location_from_pc') ) + { + + if ( $c->stash->{possible_location_matches} ) { + $c->stash->{choose_target_uri} = $c->uri_for('/alert/list'); + $c->detach('choose'); + } + + $c->go('index') if $c->stash->{location_error}; + } + + # truncate the lat,lon for nicer urls + ( $c->stash->{latitude}, $c->stash->{longitude} ) = + map { Utils::truncate_coordinate($_) } + ( $c->stash->{latitude}, $c->stash->{longitude} ); + + 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; +} + sub choose : Private { my ( $self, $c ) = @_; $c->stash->{template} = 'alert/choose.html'; -- cgit v1.2.3 From 5865134cb78e1c1b8d77e94e4ff35020345066f5 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 12 May 2011 16:02:18 +0100 Subject: move list request setup to own method and tidy up list --- perllib/FixMyStreet/App/Controller/Alert.pm | 90 +++++++++++++++++++++-------- 1 file changed, 67 insertions(+), 23 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 2f2e32922..701485676 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -30,35 +30,20 @@ sub index : Path('') : Args(0) { $c->stash->{cobrand_form_elements} = $c->cobrand->form_elements('alerts'); unless ( $c->req->referer && $c->req->referer =~ /fixmystreet\.com/ ) { - $c->stash->{photos} = $c->cobrand->recent_photos(10); + $c->forward( 'add_recent_photos', [10] ); } } sub list : Path('list') : Args(0) { my ( $self, $c ) = @_; - # setup the various parameters we need - $c->stash->{rznvy} = $c->req->param('rznvy'); - $c->stash->{selected_feed} = $c->req->param('feed'); - - if ( $c->user ) { - $c->stash->{rznvy} ||= $c->user->email; - } - - $c->forward('prettify_pc'); - $c->forward('determine_location'); - - $c->stash->{photos} = $c->cobrand->recent_photos( - 5, - $c->stash->{latitude}, - $c->stash->{longitude}, - $c->stash->{population_radius} - ); - - $c->stash->{cobrand_form_elements} = $c->cobrand->form_elements('alerts'); - - $c->forward('setup_council_rss_feeds'); - $c->forward( 'setup_coordinate_rss_feeds' ); + return + unless $c->forward('setup_request') + && $c->forward('prettify_pc') + && $c->forward('determine_location') + && $c->forward( 'add_recent_photos', [5] ) + && $c->forward('setup_council_rss_feeds') + && $c->forward('setup_coordinate_rss_feeds'); } =head2 subscribe @@ -351,6 +336,8 @@ sub prettify_pc : Private { } $c->stash->{pretty_pc} = $pretty_pc; + + return 1; } sub council_options : Private { @@ -471,6 +458,8 @@ sub setup_council_rss_feeds : Private { ( $c->stash->{options}, $c->stash->{reported_to_options} ) = $c->cobrand->council_rss_alert_options( $c->stash->{all_councils} ); + + return 1; } =head2 determine_location @@ -507,6 +496,39 @@ sub determine_location : Private { $dist = int( $dist * 10 + 0.5 ); $dist = $dist / 10.0; $c->stash->{population_radius} = $dist; + + return 1; +} + +=head2 add_recent_photos + + $c->forward( 'add_recent_photos', [ $num_photos ] ); + +Adds the most recent $num_photos to the template. If there is coordinate +and population radius information in the stash uses that to limit it. + +=cut + +sub add_recent_photos : Private { + my ( $self, $c, $num_photos ) = @_; + + if ( $c->stash->{latitude} + and $c->stash->{longitude} + and $c->stash->{population_radius} ) + { + + $c->stash->{photos} = $c->cobrand->recent_photos( + $num_photos, + $c->stash->{latitude}, + $c->stash->{longitude}, + $c->stash->{population_radius} + ); + } + else { + $c->stash->{photos} = $c->cobrand->recent_photos($num_photos); + } + + return 1; } sub choose : Private { @@ -514,6 +536,28 @@ sub choose : Private { $c->stash->{template} = 'alert/choose.html'; } + +=head2 setup_request + +Setup the variables we need for the rest of the request + +=cut + +sub setup_request : Private { + my ( $self, $c ) = @_; + + $c->stash->{rznvy} = $c->req->param('rznvy'); + $c->stash->{selected_feed} = $c->req->param('feed'); + + if ( $c->user ) { + $c->stash->{rznvy} ||= $c->user->email; + } + + $c->stash->{cobrand_form_elements} = $c->cobrand->form_elements('alerts'); + + return 1; +} + =head1 AUTHOR Struan Donald -- cgit v1.2.3 From 3697d6efaa4c11908b2c051b1986a98643c199ac Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 23 May 2011 16:25:56 +0100 Subject: make sure contents of pc get filtered before display --- perllib/FixMyStreet/App/Controller/Alert.pm | 3 --- 1 file changed, 3 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 701485676..96498e1ab 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -318,11 +318,8 @@ This will canonicalise and prettify the postcode and stick a pretty_pc and prett 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( -- cgit v1.2.3 From 57a399a9c21667f0058a127120ea3f8f8fa635fc Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 24 May 2011 13:15:52 +0100 Subject: move fiksgatami rss option list generating to cobrand --- perllib/FixMyStreet/App/Controller/Alert.pm | 56 +---------------------------- 1 file changed, 1 insertion(+), 55 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 96498e1ab..aa51f1ba3 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -337,60 +337,6 @@ sub prettify_pc : Private { return 1; } -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') { -# -# my (@options, $fylke, $kommune); -# foreach (values %$areas) { -# if ($_->{type} eq 'NKO') { -# $kommune = $_; -# } else { -# $fylke = $_; -# } -# } -# my $kommune_name = $kommune->{name}; -# my $fylke_name = $fylke->{name}; -# -# if ($fylke->{id} == 3) { # Oslo -# -# push @options, [ 'council', $fylke->{id}, Page::short_name($fylke), -# sprintf(_("Problems within %s"), $fylke_name) ]; -# -# $options_start = "
    "; -# $options = alert_list_options($q, @options); -# $options_end = "
"; -# -# } else { -# -# push @options, -# [ 'area', $kommune->{id}, Page::short_name($kommune), $kommune_name ], -# [ 'area', $fylke->{id}, Page::short_name($fylke), $fylke_name ]; -# $options_start = '
'; -# $options = $q->p($q->strong(_('Problems within the boundary of:'))) . -# $q->ul(alert_list_options($q, @options)); -# @options = (); -# push @options, -# [ 'council', $kommune->{id}, Page::short_name($kommune), $kommune_name ], -# [ 'council', $fylke->{id}, Page::short_name($fylke), $fylke_name ]; -# $options .= $q->p($q->strong(_('Or problems reported to:'))) . -# $q->ul(alert_list_options($q, @options)); -# $options_end = $q->p($q->small(_('FixMyStreet sends different categories of problem -#to the appropriate council, so problems within the boundary of a particular council -#might not match the problems sent to that council. For example, a graffiti report -#will be sent to the district council, so will appear in both of the district -#council’s alerts, but will only appear in the "Within the boundary" alert -#for the county council.'))) . '
'; -# -# } -# - } -} - sub process_user : Private { my ( $self, $c ) = @_; @@ -454,7 +400,7 @@ sub setup_council_rss_feeds : Private { } ( $c->stash->{options}, $c->stash->{reported_to_options} ) = - $c->cobrand->council_rss_alert_options( $c->stash->{all_councils} ); + $c->cobrand->council_rss_alert_options( $c->stash->{all_councils}, $c ); return 1; } -- cgit v1.2.3 From fb5609544efd4b47d00c5c74ea837eb7fc8e3d0c Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 26 May 2011 12:30:33 +0100 Subject: no way to sign up to new_problems alerts so not porting --- perllib/FixMyStreet/App/Controller/Alert.pm | 4 ---- 1 file changed, 4 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index aa51f1ba3..7ea0d77e3 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -132,10 +132,6 @@ sub subscribe_email : Private { if ( $type eq 'updates' ) { $c->forward('set_update_alert_options'); } - elsif ( $type eq 'problems' ) { - -# $alert_id = FixMyStreet::Alert::create($email, 'new_problems', $cobrand, $cobrand_data); - } elsif ( $type eq 'local' ) { $c->forward('set_local_alert_options'); } -- cgit v1.2.3 From 408b256e4f863a43c4f81209106b4ac23aaa666a Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 26 May 2011 14:33:50 +0100 Subject: If the user already exists in the database then don't sent them a confirmation email when signing up to alerts --- perllib/FixMyStreet/App/Controller/Alert.pm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 7ea0d77e3..b836f5a79 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -140,7 +140,12 @@ sub subscribe_email : Private { } $c->forward('create_alert'); - $c->forward('send_confirmation_email'); + if ( $c->stash->{alert}->confirmed ) { + $c->stash->{confirm_type} = 'created'; + $c->stash->{template} = 'alert/confirm.html'; + } else { + $c->forward('send_confirmation_email'); + } } sub updates : Path('updates') : Args(0) { @@ -190,14 +195,13 @@ sub create_alert : Private { unless ($alert) { $options->{cobrand} = $c->cobrand->moniker(); $options->{cobrand_data} = $c->cobrand->extra_update_data(); + $options->{confirmed} = 1 if $c->stash->{alert_user}->in_storage; $alert = $c->model('DB::Alert')->new($options); $alert->insert(); } $c->stash->{alert} = $alert; - - $c->log->debug( 'created alert ' . $alert->id ); } =head2 set_update_alert_options -- cgit v1.2.3 From 4308906bc2695f1fd034b8f5f1a6be657e6d4dfe Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 26 May 2011 18:21:10 +0100 Subject: put all confirmation templates under tokens for consistency --- perllib/FixMyStreet/App/Controller/Alert.pm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index b836f5a79..db9602ff5 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -142,7 +142,7 @@ sub subscribe_email : Private { $c->forward('create_alert'); if ( $c->stash->{alert}->confirmed ) { $c->stash->{confirm_type} = 'created'; - $c->stash->{template} = 'alert/confirm.html'; + $c->stash->{template} = 'tokens/confirm_alert.html'; } else { $c->forward('send_confirmation_email'); } @@ -166,7 +166,6 @@ sub confirm : Private { my ( $self, $c ) = @_; my $alert = $c->stash->{alert}; - $c->stash->{template} = 'alert/confirm.html'; if ( $c->stash->{confirm_type} eq 'subscribe' ) { $alert->confirm(); -- cgit v1.2.3 From 0c93edcb7b5634f10438d810407b18cb2fa6ba0c Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 27 May 2011 11:24:49 +0100 Subject: only confirm alerts on submission if user is logged in also, tests to make sure we send out emails if a logged in user subscribes with a different address --- perllib/FixMyStreet/App/Controller/Alert.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index db9602ff5..45696e4e7 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -194,7 +194,10 @@ sub create_alert : Private { unless ($alert) { $options->{cobrand} = $c->cobrand->moniker(); $options->{cobrand_data} = $c->cobrand->extra_update_data(); - $options->{confirmed} = 1 if $c->stash->{alert_user}->in_storage; + + if ( $c->user && $c->user->id == $c->stash->{alert_user}->id ) { + $options->{confirmed} = 1; + } $alert = $c->model('DB::Alert')->new($options); $alert->insert(); @@ -221,7 +224,6 @@ sub set_update_alert_options : Private { }; $c->stash->{alert_options} = $options; - $c->forward('create_alert'); } =head2 set_local_alert_options @@ -255,7 +257,6 @@ sub set_local_alert_options : Private { push @params, $1, $2; } - my $options = { user => $c->stash->{alert_user}, alert_type => $type -- cgit v1.2.3 From f24f8ee1d1f110f7ba575a714e883f255a1f9f95 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 27 May 2011 12:10:15 +0100 Subject: do not fall over if the user visits /alert/subscribe with no parameters or no email --- perllib/FixMyStreet/App/Controller/Alert.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 45696e4e7..b8b7cce40 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -58,9 +58,14 @@ sub subscribe : Path('subscribe') : Args(0) { if ( $c->req->param('rss') ) { $c->detach('rss'); } - elsif ( $c->req->param('rznvy') ) { + # if it exists then it's been submitted so we should + # go to subscribe email and let it work out the next step + elsif ( exists $c->req->params->{'rznvy'} ) { $c->detach('subscribe_email'); } + + # shouldn't get to here but if we have then do something sensible + $c->go('index'); } =head2 rss -- cgit v1.2.3 From 34e78aa47e8cad5ba237705dd8a2fa1d1403ff20 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 3 Jun 2011 15:20:39 +0100 Subject: Better alert page title handling. --- perllib/FixMyStreet/App/Controller/Alert.pm | 3 --- 1 file changed, 3 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index b8b7cce40..98e1236e1 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -332,9 +332,6 @@ sub prettify_pc : Private { 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/ / /; } $c->stash->{pretty_pc} = $pretty_pc; -- cgit v1.2.3 From c10a787f1f529cadae06fd9c8dff58ca7224d223 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 3 Jun 2011 15:48:26 +0100 Subject: Fix RSS lat/lon redirect from alert list page; break setenv.pl's ARGV feature. --- perllib/FixMyStreet/App/Controller/Alert.pm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 98e1236e1..bea5345e3 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -96,8 +96,7 @@ sub rss : Private { $c->res->redirect($url); } elsif ( $feed =~ /^local:([\d\.-]+):([\d\.-]+)$/ ) { - ( my $id = $1 ) =~ tr{:_}{/+}; - $url = $c->cobrand->base_url() . '/rss/l/' . $id; + $url = $c->cobrand->base_url() . '/rss/l/' . $1 . ',' . $2; $c->res->redirect($url); } else { -- cgit v1.2.3 From 5d2261eb81e9e28bbaa1f52c668be164bb7a597d Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 3 Jun 2011 20:21:13 +0100 Subject: Sign up new report to email alert if logged in as well as when confirmed by email. Allow disabling rather than deleting of alerts. Revert quoting as it breaks timestamps and literal SQL. --- perllib/FixMyStreet/App/Controller/Alert.pm | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index bea5345e3..70a86a936 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -140,7 +140,7 @@ sub subscribe_email : Private { $c->forward('set_local_alert_options'); } else { - throw FixMyStreet::Alert::Error('Invalid type'); + $c->detach( '/page_error_404_not_found', [ 'Invalid type' ] ); } $c->forward('create_alert'); @@ -162,7 +162,7 @@ sub updates : Path('updates') : Args(0) { =head2 confirm -Confirm signup to an alert. Forwarded here from Tokens. +Confirm signup to or unsubscription from an alert. Forwarded here from Tokens. =cut @@ -173,11 +173,9 @@ sub confirm : Private { if ( $c->stash->{confirm_type} eq 'subscribe' ) { $alert->confirm(); - $alert->update; } elsif ( $c->stash->{confirm_type} eq 'unsubscribe' ) { - $alert->delete(); - $alert->update; + $alert->disable(); } } @@ -198,6 +196,7 @@ sub create_alert : Private { unless ($alert) { $options->{cobrand} = $c->cobrand->moniker(); $options->{cobrand_data} = $c->cobrand->extra_update_data(); + $options->{lang} = $c->stash->{lang_code}; if ( $c->user && $c->user->id == $c->stash->{alert_user}->id ) { $options->{confirmed} = 1; -- cgit v1.2.3 From b019beb393534919c249fa16e7ab07ac63fa52c5 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 3 Jun 2011 22:18:05 +0100 Subject: Fix bug whereby lat/lon were being stored the wrong way round in local alerts. --- perllib/FixMyStreet/App/Controller/Alert.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 70a86a936..d8e783431 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -257,7 +257,7 @@ sub set_local_alert_options : Private { m{ \A local: ( [\+\-]? \d+ \.? \d* ) : ( [\+\-]? \d+ \.? \d* ) }xms ) { $type = 'local_problems'; - push @params, $1, $2; + push @params, $2, $1; # Note alert parameters are lon,lat } my $options = { -- cgit v1.2.3 From b388fd0be5296426225089ed188b3c1cdd802415 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Sat, 4 Jun 2011 00:52:02 +0100 Subject: Migrate alert sending script, add test for it, fix some small bugs and strings. --- perllib/FixMyStreet/App/Controller/Alert.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index d8e783431..b3067abc9 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -63,6 +63,9 @@ sub subscribe : Path('subscribe') : Args(0) { elsif ( exists $c->req->params->{'rznvy'} ) { $c->detach('subscribe_email'); } + elsif ( $c->req->params->{'id'} ) { + $c->go('updates'); + } # shouldn't get to here but if we have then do something sensible $c->go('index'); @@ -198,7 +201,7 @@ sub create_alert : Private { $options->{cobrand_data} = $c->cobrand->extra_update_data(); $options->{lang} = $c->stash->{lang_code}; - if ( $c->user && $c->user->id == $c->stash->{alert_user}->id ) { + if ( $c->user && $c->stash->{alert_user}->in_storage && $c->user->id == $c->stash->{alert_user}->id ) { $options->{confirmed} = 1; } -- cgit v1.2.3 From a6c11ec2e1fa29ffc28fed8fa0102f2fb9d61845 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 6 Jun 2011 11:15:01 +0100 Subject: Get rid of some more fake_q etc. --- perllib/FixMyStreet/App/Controller/Alert.pm | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index b3067abc9..b5258ae79 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -86,7 +86,6 @@ sub rss : Private { $c->go('list'); } - my $extra_params = $c->cobrand->extra_params( $c->fake_q ); my $url; if ( $feed =~ /^area:(?:\d+:)+(.*)$/ ) { ( my $id = $1 ) =~ tr{:_}{/+}; @@ -363,27 +362,22 @@ sub setup_coordinate_rss_feeds : Private { my $rss_feed; if ( $c->stash->{pretty_pc_text} ) { - $rss_feed = - $c->cobrand->uri( "/rss/pc/" . $c->stash->{pretty_pc_text}, - $c->fake_q ); + $rss_feed = $c->uri_for( "/rss/pc/" . $c->stash->{pretty_pc_text} ); } else { - $rss_feed = $c->cobrand->uri( + $rss_feed = $c->uri_for( sprintf( "/rss/l/%s,%s", $c->stash->{latitude}, - $c->stash->{longitude} ), - $c->fake_q + $c->stash->{longitude} ) ); } $c->stash->{rss_feed_uri} = $rss_feed; - $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 ); + $c->stash->{rss_feed_2k} = $c->uri_for( $rss_feed . '/2' ); + $c->stash->{rss_feed_5k} = $c->uri_for( $rss_feed . '/5' ); + $c->stash->{rss_feed_10k} = $c->uri_for( $rss_feed . '/10' ); + $c->stash->{rss_feed_20k} = $c->uri_for( $rss_feed . '/20' ); return 1; } -- cgit v1.2.3 From 988fa9695dc0446887a30d6489786ab1323363c4 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 7 Jun 2011 16:28:47 +0100 Subject: Improve email headers in emails sent. --- perllib/FixMyStreet/App/Controller/Alert.pm | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Alert.pm') diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index b5258ae79..e7eab09b8 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -301,15 +301,7 @@ sub send_confirmation_email : Private { $c->stash->{token_url} = $c->uri_for_email( '/A', $token->token ); - my $sender = mySociety::Config::get('CONTACT_EMAIL'); - - $c->send_email( - 'alert-confirm.txt', - { - to => $c->stash->{alert}->user->email, - from => $sender - } - ); + $c->send_email( 'alert-confirm.txt', { to => $c->stash->{alert}->user->email } ); $c->stash->{template} = 'email_sent.html'; } -- cgit v1.2.3