diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 53 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 4 | ||||
-rw-r--r-- | t/app/controller/report_import.t | 26 | ||||
-rw-r--r-- | templates/web/default/around/around_index.html | 5 |
4 files changed, 69 insertions, 19 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index ae0976de8..03ad27a54 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -42,6 +42,9 @@ sub around_index : Path : Args(0) { return; } + # Check if we have a partial report + my $partial_report = $c->forward('load_partial'); + # Try to create a location for whatever we have return unless $c->forward('determine_location_from_coords') @@ -52,11 +55,59 @@ sub around_index : Path : Args(0) { # If we have a partial - redirect to /report/new so that it can be # completed. - warn "FIXME - implement"; + if ($partial_report) { + my $new_uri = $c->uri_for( + '/report/new', + { + partial => $c->stash->{partial_token}->token, + latitude => $c->stash->{latitude}, + longitude => $c->stash->{longitude}, + pc => $c->stash->{pc}, + } + ); + return $c->res->redirect($new_uri); + } # Show the nearby reports $c->detach('display_location'); +} + +=head2 load_partial + + my $partial_report = $c->forward('load_partial'); + +Check for the partial token and load the partial report. If found save it and +token to stash and return report. Otherwise return false. + +=cut + +sub load_partial : Private { + my ( $self, $c ) = @_; + + my $partial = scalar $c->req->param('partial') + || return; + + # is it in the database + my $token = + $c->model("DB::Token") + ->find( { scope => 'partial', token => $partial } ) # + || last; + + # can we get an id from it? + my $report_id = $token->data # + || last; + + # load the related problem + my $report = $c->model("DB::Problem") # + ->search( { id => $report_id, state => 'partial' } ) # + ->first + || last; + + # save what we found on the stash. + $c->stash->{partial_token} = $token; + $c->stash->{partial_report} = $report; + return $report; } =head2 display_location diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 7bb289bea..744344358 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -1109,7 +1109,9 @@ sub redirect_to_around : Private { delete $params->{$_} if !$params->{$_}; } - # FIXME add partial here. + if ( my $token = $c->stash->{partial_token} ) { + $params->{partial} = $token->token; + } my $around_uri = $c->uri_for( '/around', $params ); diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index 25f5dddf9..5bd0b21b8 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -168,16 +168,14 @@ subtest "Submit a correct entry (with location)" => sub { $mech->submit_form_ok( # { with_fields => { - service => 'test-script', - latitude => '51.5010096115539', # SW1A 1AA - longitude => '-0.141587067110009', - latitude => '', - longitude => '', - name => 'Test User ll', - email => 'test-ll@example.com', - subject => 'Test report ll', - detail => 'This is a test report ll', - photo => $sample_file, + service => 'test-script', + lat => '51.5010096115539', # SW1A 1AA + lon => '-0.141587067110009', + name => 'Test User ll', + email => 'test-ll@example.com', + subject => 'Test report ll', + detail => 'This is a test report ll', + photo => $sample_file, } }, "fill in form" @@ -220,10 +218,10 @@ subtest "Submit a correct entry (with location)" => sub { $mech->submit_form_ok( # { with_fields => { - name => 'New Test User', - email => 'test@example.com', - title => 'New Test report', - detail => 'This is a test report', + name => 'New Test User ll', + email => 'test-ll@example.com', + title => 'New Test report ll', + detail => 'This is a test report ll', phone => '01234 567 890', may_show_name => '1', } diff --git a/templates/web/default/around/around_index.html b/templates/web/default/around/around_index.html index 554e4f1b7..17be8533e 100644 --- a/templates/web/default/around/around_index.html +++ b/templates/web/default/around/around_index.html @@ -8,9 +8,8 @@ %] -<form action="[% '/around' %]" method="get" name="postcodeForm" id="postcodeForm"><label for="pc">[% loc("Enter a nearby GB postcode, or street name and area") %]:</label> - <input type="text" name="pc" value="[% pc | html %]" id="pc" size="10" maxlength="200"> - <input type="submit" value="[% loc('Go') %]" id="submit"> +<form action="[% '/around' %]" method="get" name="postcodeForm" id="postcodeForm"> + <label for="pc">[% loc("Enter a nearby GB postcode, or street name and area") %]:</label> <input type="text" name="pc" value="[% pc | html %]" id="pc" size="10" maxlength="200"> <input type="submit" value="[% loc('Go') %]" id="submit"> [% c.cobrand.form_elements %] [% IF partial_token %] |