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