aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2012-04-23 15:40:54 +0100
committerMatthew Somerville <matthew@mysociety.org>2012-04-23 15:40:54 +0100
commit4f4dd76967e1bff4be4e11a405a2438bfcd25de4 (patch)
tree91612efa34216288c1de66f5354325047677ad0f
parent03b77ccde074e1d3545ebfcc8589054d48146bf2 (diff)
Have a whole fake mapit (for #182) that works if MAPIT_URL is set accordingly.
-rw-r--r--perllib/FixMyStreet/App/Controller/Council.pm9
-rwxr-xr-xperllib/FixMyStreet/App/Controller/FakeMapit.pm53
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm4
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm4
-rw-r--r--perllib/FixMyStreet/Cobrand/FixMyStreet.pm3
5 files changed, 61 insertions, 12 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Council.pm b/perllib/FixMyStreet/App/Controller/Council.pm
index b488346f8..1d801c292 100644
--- a/perllib/FixMyStreet/App/Controller/Council.pm
+++ b/perllib/FixMyStreet/App/Controller/Council.pm
@@ -38,15 +38,6 @@ there are no councils then return false.
sub load_and_check_councils : Private {
my ( $self, $c ) = @_;
- # If no mapit is set up, let it through wherever
- unless ($c->config->{MAPIT_URL}) {
- my $area = { "name" => "Default Area", "type" => "ZZZ", "id" => 0 };
- $c->stash->{all_areas} = { 0 => $area };
- $c->stash->{all_councils} = { 0 => $area };
- $c->stash->{all_council_names} = [ 'Default Area' ];
- return 1;
- }
-
my $latitude = $c->stash->{latitude};
my $longitude = $c->stash->{longitude};
diff --git a/perllib/FixMyStreet/App/Controller/FakeMapit.pm b/perllib/FixMyStreet/App/Controller/FakeMapit.pm
new file mode 100755
index 000000000..57c2e7c27
--- /dev/null
+++ b/perllib/FixMyStreet/App/Controller/FakeMapit.pm
@@ -0,0 +1,53 @@
+package FixMyStreet::App::Controller::FakeMapit;
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'Catalyst::Controller'; }
+
+=head1 NAME
+
+FixMyStreet::App::Controller::FakeMapit - Catalyst Controller
+
+=head1 DESCRIPTION
+
+A controller to fake mapit when we don't have it. If you set MAPIT_URL to
+.../fakemapit/ it should all just work, with a mapit that assumes the whole
+world is one area, with ID 0 and name "Default Area".
+
+=head1 METHODS
+
+=cut
+
+my $area = { "name" => "Default Area", "type" => "ZZZ", "id" => 0 };
+
+sub output : Private {
+ my ( $self, $c, $data ) = @_;
+ my $body = JSON->new->utf8(1)->encode( $data );
+ $c->res->content_type('application/json; charset=utf-8');
+ $c->res->body( $body );
+}
+
+sub point : Local {
+ my ( $self, $c ) = @_;
+ $c->detach( 'output', [ { 0 => $area } ] );
+}
+
+sub area : Local {
+ my ( $self, $c ) = @_;
+ $c->detach( 'output', [ $area ] );
+}
+
+sub areas : Local {
+ my ( $self, $c ) = @_;
+ $c->detach( 'output', [ { 0 => $area } ] );
+}
+
+sub children : Path('area/0/children') : Args(0) {
+ my ( $self, $c ) = @_;
+ $c->detach( 'output', [ {} ] );
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index 9fb72121e..c5f709054 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -43,6 +43,7 @@ sub index : Path : Args(0) {
$c->stash->{message} = _("Unable to look up areas in MaPit. Please try again later.") . ' ' .
sprintf(_('The error was: %s'), $@);
$c->stash->{template} = 'errors/generic.html';
+ return;
}
# For each area, add its link and perhaps alter its name if we need to for
@@ -70,6 +71,7 @@ sub index : Path : Args(0) {
$c->stash->{message} = _("There was a problem showing the All Reports page. Please try again later.") . ' ' .
sprintf(_('The error was: %s'), $@);
$c->stash->{template} = 'errors/generic.html';
+ return;
}
# Down here so that error pages aren't cached.
@@ -126,7 +128,7 @@ sub ward : Path : Args(2) {
# List of wards
unless ($c->stash->{ward}) {
- my $children = mySociety::MaPit::call('area/children', $c->stash->{council}->{id},
+ my $children = mySociety::MaPit::call('area/children', [ $c->stash->{council}->{id} ],
type => $mySociety::VotingArea::council_child_types,
);
foreach (values %$children) {
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index c26ea63b3..6ed946801 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -597,8 +597,8 @@ The MaPit types this site handles
=cut
-sub area_types { return qw(DIS LBO MTD UTA CTY COI); }
-sub area_min_generation { 10 }
+sub area_types { qw(ZZZ) }
+sub area_min_generation { '' }
=head2 contact_name, contact_email
diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
index 4ead28196..f6571fed5 100644
--- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
+++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
@@ -1,6 +1,9 @@
package FixMyStreet::Cobrand::FixMyStreet;
use base 'FixMyStreet::Cobrand::Default';
+sub area_types { return qw(DIS LBO MTD UTA CTY COI); }
+sub area_min_generation { 10 }
+
# FixMyStreet should return all cobrands
sub restriction {
return {};