diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports/New.pm | 140 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Barnet.pm | 6 | ||||
-rw-r--r-- | templates/web/default/reports/new/fill_in_details.html | 14 | ||||
-rw-r--r-- | templates/web/default/reports/new/report_new.html | 4 |
4 files changed, 149 insertions, 15 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Reports/New.pm b/perllib/FixMyStreet/App/Controller/Reports/New.pm index be1b47c66..7b0b6cc81 100644 --- a/perllib/FixMyStreet/App/Controller/Reports/New.pm +++ b/perllib/FixMyStreet/App/Controller/Reports/New.pm @@ -72,11 +72,13 @@ sub report_new : Path : Args(0) { # FIXME - deal with partial reports here - # work out the location for this report + # work out the location for this report and do some checks $c->forward('determine_location') || return; + $c->forward('check_councils') || return; # create a problem from the submitted details - $c->forward('prepare_item') || return; + $c->stash->{template} = "reports/new/fill_in_details.html"; + $c->forward('prepare_report') || return; } @@ -92,10 +94,22 @@ sub determine_location : Private { my ( $self, $c ) = @_; return - $c->forward('determine_location_from_tile_click') - || $c->forward('determine_location_from_coords') - || $c->forward('determine_location_from_pc') - || undef; + unless $c->forward('determine_location_from_tile_click') + || $c->forward('determine_location_from_coords') + || $c->forward('determine_location_from_pc'); + + # Check this location is okay to be displayed for the cobrand + my ( $success, $error_msg ) = $c->cobrand->council_check( # + { lat => $c->stash->{latitude}, lon => $c->stash->{longitude} }, + 'submit_problem' + ); + + # all good + return 1 if $success; + + # show error + $c->stash->{pc_error} = $error_msg; + return; } =head2 determine_location_from_tile_click @@ -104,15 +118,45 @@ sub determine_location : Private { sub determine_location_from_tile_click : Private { my ( $self, $c ) = @_; + + warn "FIXME - implement"; + + # # Get tile co-ordinates if map clicked + # ( $input{x} ) = $input{x} =~ /^(\d+)/; + # $input{x} ||= 0; + # ( $input{y} ) = $input{y} =~ /^(\d+)/; + # $input{y} ||= 0; + # my @ps = $q->param; + # foreach (@ps) { + # ( $pin_tile_x, $pin_tile_y, $pin_x ) = ( $1, $2, $q->param($_) ) + # if /^tile_(\d+)\.(\d+)\.x$/; + # $pin_y = $q->param($_) if /\.y$/; + # } + +# # tilma map was clicked on +# ($latitude, $longitude) = FixMyStreet::Map::click_to_wgs84($pin_tile_x, $pin_x, $pin_tile_y, $pin_y); + return; } =head2 determine_location_from_coords +Use latitude and longitude if provided in parameters. + =cut sub determine_location_from_coords : Private { my ( $self, $c ) = @_; + + my $latitude = $c->req->param('latitude'); + my $longitude = $c->req->param('longitude'); + + if ( defined $latitude && defined $longitude ) { + $c->stash->{latitude} = $latitude; + $c->stash->{longitude} = $longitude; + return 1; + } + return; } @@ -131,9 +175,9 @@ If no matches are found returns false. sub determine_location_from_pc : Private { my ( $self, $c ) = @_; - # check for something to search for + # check for something to search my $pc = $c->req->param('pc') || return; - $c->stash->{pc} = $pc; + $c->stash->{pc} = $pc; # for template my ( $latitude, $longitude, $error ) = eval { FixMyStreet::Geocode::lookup( $pc, $c->req ) }; @@ -158,13 +202,77 @@ sub determine_location_from_pc : Private { return; } - # FIXME - handle other errors here + # pass errors back to the template $c->stash->{pc_error} = $error; - return; } -=head2 prepare_item +=head2 check_councils + +Load all the councils and check that they are ok. Do a small amount of cleanup. + +=cut + +sub check_councils : Private { + my ( $self, $c ) = @_; + my $latitude = $c->stash->{latitude}; + my $longitude = $c->stash->{longitude}; + + # Look up councils and do checks for the point we've got + my @area_types = $c->cobrand->area_types(); + + # XXX: I think we want in_gb_locale around the next line, needs testing + my $all_councils = + mySociety::MaPit::call( 'point', "4326/$longitude,$latitude", + type => \@area_types ); + + # Let cobrand do a check + my ( $success, $error_msg ) = + $c->cobrand->council_check( { all_councils => $all_councils }, + 'submit_problem' ); + if ( !$success ) { + $c->stash->{location_error} = $error_msg; + return; + } + + # UK specific tweaks + # FIXME - move into cobrand + if ( mySociety::Config::get('COUNTRY') eq 'GB' ) { + + # Ipswich & St Edmundsbury are responsible for everything in their + # areas, not Suffolk + delete $all_councils->{2241} + if $all_councils->{2446} # + || $all_councils->{2443}; + + # Norwich is responsible for everything in its areas, not Norfolk + delete $all_councils->{2233} # + if $all_councils->{2391}; + } + + # Norway specific tweaks + # FIXME - move into cobrand + if ( mySociety::Config::get('COUNTRY') eq 'NO' ) { + + # Oslo is both a kommune and a fylke, we only want to show it once + delete $all_councils->{301} # + if $all_councils->{3}; + } + + # were councils found for this location + if ( !scalar keys %$all_councils ) { + $c->stash->{location_error} = + _( 'That spot does not appear to be covered by a council. If you' + . ' have tried to report an issue past the shoreline, for' + . ' example, please specify the closest point on land.' ); + return; + } + + # all good if we have some councils left + return 1; +} + +=head2 prepare_report Looking at the parameters passed in create a new item and return it. Does not save anything to the database. If no item can be created (ie no information @@ -172,10 +280,16 @@ provided) returns undef. =cut -sub prepare_item : Private { +sub prepare_report : Private { my ( $self, $c ) = @_; - die; + # create a new report, but don't save it yet + my $report = $c->model('DB::Problem')->new( + { + latitude => $c->stash->{latitude}, + longitude => $c->stash->{longitude}, + } + ); return; diff --git a/perllib/FixMyStreet/Cobrand/Barnet.pm b/perllib/FixMyStreet/Cobrand/Barnet.pm index 7f8638c21..4d20d6522 100644 --- a/perllib/FixMyStreet/Cobrand/Barnet.pm +++ b/perllib/FixMyStreet/Cobrand/Barnet.pm @@ -27,12 +27,14 @@ sub site_title { } sub enter_postcode_text { - my ( $self ) = @_; + my ($self) = @_; return 'Enter a Barnet postcode, or street name and area:'; } sub council_check { - my ( $self, $params, $q, $context ) = @_; + my ( $self, $params, $context ) = @_; + my $q = $self->request; + my $councils; if ( $params->{all_councils} ) { $councils = $params->{all_councils}; diff --git a/templates/web/default/reports/new/fill_in_details.html b/templates/web/default/reports/new/fill_in_details.html new file mode 100644 index 000000000..bebf4366a --- /dev/null +++ b/templates/web/default/reports/new/fill_in_details.html @@ -0,0 +1,14 @@ +[% INCLUDE 'header.html', title => loc('Enter report details') %] + +<h1>[% loc('Enter report details') %]</h1> + + +<p>MAP</p> + +<p>FORM</p> + + + + + +[% INCLUDE 'footer.html' %]
\ No newline at end of file diff --git a/templates/web/default/reports/new/report_new.html b/templates/web/default/reports/new/report_new.html index 49aeb2e3b..c684465ba 100644 --- a/templates/web/default/reports/new/report_new.html +++ b/templates/web/default/reports/new/report_new.html @@ -2,6 +2,10 @@ <h1>[% loc('Create a report') %]</h1> +[% IF location_error %] + <div class="error">[% location_error %]</div> +[% END %] + Please select where to create this report: <form action="[% c.uri_for() %]" method="POST"> |