diff options
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 20 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 9 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Open311.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 6 |
5 files changed, 30 insertions, 14 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index e64db0135..c9c3dc503 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -222,12 +222,15 @@ sub bodies : Path('bodies') : Args(0) { $c->stash->{edit_activity} = $edit_activity; - my $posted = $c->req->param('posted'); + my $posted = $c->req->param('posted') || ''; if ( $posted eq 'body' ) { $c->forward('check_token'); my $params = $c->forward('body_params'); - $c->model('DB::Body')->create( $params ); + my $body = $c->model('DB::Body')->create( $params ); + foreach ($c->req->params->{area_ids}) { + $c->model('DB::BodyArea')->create( { body => $body, area_id => $_ } ); + } $c->stash->{updated} = _('New body added'); } @@ -350,6 +353,14 @@ sub update_contacts : Private { my $params = $c->forward( 'body_params' ); $c->stash->{body}->update( $params ); + my @current = $c->stash->{body}->body_areas->all; + my %current = map { $_->area_id => 1 } @current; + foreach ($c->req->params->{area_ids}) { + $c->model('DB::BodyArea')->find_or_create( { body => $c->stash->{body}, area_id => $_ } ); + delete $current{$_}; + } + # Remove any others + $c->stash->{body}->body_areas->search( { area_id => [ keys %current ] } )->delete; $c->stash->{updated} = _('Configuration updated - contacts will be generated automatically later'); } @@ -358,10 +369,9 @@ sub update_contacts : Private { sub body_params : Private { my ( $self, $c ) = @_; - my @fields = qw/name area_id endpoint jurisdiction api_key send_method send_comments suppress_alerts comment_user_id can_be_devolved/; + my @fields = qw/name endpoint jurisdiction api_key send_method send_comments suppress_alerts comment_user_id can_be_devolved/; my %defaults = map { $_ => '' } @fields; %defaults = ( %defaults, - area_id => undef, send_comments => 0, suppress_alerts => 0, comment_user_id => undef, @@ -398,7 +408,7 @@ sub lookup_body : Private { unless $body; $c->stash->{body} = $body; - my $example_postcode = mySociety::MaPit::call('area/example_postcode', $body->area_id); + my $example_postcode = mySociety::MaPit::call('area/example_postcode', $body->body_areas->first->area_id); if ($example_postcode && ! ref $example_postcode) { $c->stash->{example_pc} = $example_postcode; } diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index 3a66cf1e0..657751e5c 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -92,15 +92,18 @@ sub index : Path : Args(0) { # Set up the data for the dropdowns - my $council_detail = mySociety::MaPit::call('area', $body->area_id ); + # Just take the first area ID we find + my $area_id = $body->body_areas->first->area_id; + + my $council_detail = mySociety::MaPit::call('area', $area_id ); $c->stash->{council} = $council_detail; - my $children = mySociety::MaPit::call('area/children', $body->area_id, + my $children = mySociety::MaPit::call('area/children', $area_id, type => $c->cobrand->area_types_children, ); $c->stash->{children} = $children; - $c->stash->{all_areas} = { $body->area_id => $council_detail }; + $c->stash->{all_areas} = { $area_id => $council_detail }; $c->forward( '/report/new/setup_categories_and_bodies' ); # See if we've had anything from the dropdowns diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm index 62cdaffaf..3a6794325 100644 --- a/perllib/FixMyStreet/App/Controller/Open311.pm +++ b/perllib/FixMyStreet/App/Controller/Open311.pm @@ -168,8 +168,8 @@ sub get_services : Private { "4326/$lon,$lat", type => $area_types); $categories = $categories->search( { - 'body.area_id' => [ keys %$all_areas ], - }, { join => 'body' } ); + 'body_areas.area_id' => [ keys %$all_areas ], + }, { join => { 'body' => 'body_areas' } } ); } my @categories = $categories->search( undef, { diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 09e46ccef..c3525b2c9 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -580,7 +580,10 @@ sub setup_categories_and_bodies : Private { my $all_areas = $c->stash->{all_areas}; my $first_area = ( values %$all_areas )[0]; - my @bodies = $c->model('DB::Body')->search( { area_id => [ keys %$all_areas ] } )->all; + my @bodies = $c->model('DB::Body')->search( + { 'body_areas.area_id' => [ keys %$all_areas ] }, + { join => 'body_areas' } + )->all; my %bodies = map { $_->id => $_ } @bodies; my $first_body = ( values %bodies )[0]; diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 630409227..bf65fe1d5 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -99,7 +99,7 @@ sub ward : Path : Args(2) { $c, latitude => @$pins ? $pins->[0]{latitude} : 0, longitude => @$pins ? $pins->[0]{longitude} : 0, - area => $c->stash->{ward} ? $c->stash->{ward}->{id} : $c->stash->{body}->area_id, + area => $c->stash->{ward} ? $c->stash->{ward}->{id} : [ keys %{$c->stash->{body}->areas} ], pins => $pins, any_zoom => 1, ); @@ -109,7 +109,7 @@ sub ward : Path : Args(2) { # List of wards # Ignore external_body special body thing unless ($c->stash->{ward} || !$c->stash->{body}->id) { - my $children = mySociety::MaPit::call('area/children', [ $c->stash->{body}->area_id ], + my $children = mySociety::MaPit::call('area/children', [ $c->stash->{body}->body_areas->first->area_id ], type => $c->cobrand->area_types_children, ); unless ($children->{error}) { @@ -301,7 +301,7 @@ sub ward_check : Private { # Could be from RSS area, or body... my $parent_id; if ( $c->stash->{body} ) { - $parent_id = $c->stash->{body}->area_id; + $parent_id = $c->stash->{body}->body_areas->first->area_id; } else { $parent_id = $c->stash->{area}->{id}; } |