aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2012-12-19 14:19:30 +0000
committerMatthew Somerville <matthew@mysociety.org>2012-12-19 14:43:26 +0000
commit1c1e454cc049531fc99c5c4d4eed293aab40d406 (patch)
treeb9263249c6e8eccfaaab7ed9dc75986749da1080
parent3e30cee562d3eae98d73e63dc2d9708b09e24e81 (diff)
Allow bodies to have parent bodies.
-rw-r--r--db/schema.sql1
-rw-r--r--db/schema_0034-add-body-parent.sql5
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm4
-rw-r--r--perllib/FixMyStreet/DB/Result/Body.pm27
-rw-r--r--perllib/FixMyStreet/DB/Result/BodyArea.pm5
-rw-r--r--templates/web/default/admin/body-form.html14
6 files changed, 47 insertions, 9 deletions
diff --git a/db/schema.sql b/db/schema.sql
index e8ec42859..d8cc0675a 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -55,6 +55,7 @@ create table users (
create table body (
id serial primary key,
name text not null,
+ parent integer references body(id),
endpoint text,
jurisdiction text,
api_key text,
diff --git a/db/schema_0034-add-body-parent.sql b/db/schema_0034-add-body-parent.sql
new file mode 100644
index 000000000..9360fbcb3
--- /dev/null
+++ b/db/schema_0034-add-body-parent.sql
@@ -0,0 +1,5 @@
+begin;
+
+ALTER TABLE body ADD parent INTEGER REFERENCES body(id);
+
+commit;
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index d3b6a39ee..641aad219 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -280,6 +280,7 @@ sub body : Path('body') : Args(1) {
$c->forward( 'check_page_allowed' );
$c->forward( 'get_token' );
$c->forward( 'lookup_body' );
+ $c->forward( 'fetch_all_bodies' );
$c->forward( 'body_form_dropdowns' );
if ( $c->req->param('posted') ) {
@@ -380,13 +381,14 @@ sub update_contacts : Private {
sub body_params : Private {
my ( $self, $c ) = @_;
- my @fields = qw/name 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 parent/;
my %defaults = map { $_ => '' } @fields;
%defaults = ( %defaults,
send_comments => 0,
suppress_alerts => 0,
comment_user_id => undef,
can_be_devolved => 0,
+ parent => undef,
);
my %params = map { $_ => $c->req->param($_) || $defaults{$_} } @fields;
return \%params;
diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm
index a4da74f80..27ea1897e 100644
--- a/perllib/FixMyStreet/DB/Result/Body.pm
+++ b/perllib/FixMyStreet/DB/Result/Body.pm
@@ -18,6 +18,8 @@ __PACKAGE__->add_columns(
is_nullable => 0,
sequence => "body_id_seq",
},
+ "name",
+ { data_type => "text", is_nullable => 0 },
"endpoint",
{ data_type => "text", is_nullable => 1 },
"jurisdiction",
@@ -34,11 +36,17 @@ __PACKAGE__->add_columns(
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
"can_be_devolved",
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
- "name",
- { data_type => "text", is_nullable => 0 },
+ "parent",
+ { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->has_many(
+ "bodies",
+ "FixMyStreet::DB::Result::Body",
+ { "foreign.parent" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+__PACKAGE__->has_many(
"body_areas",
"FixMyStreet::DB::Result::BodyArea",
{ "foreign.body_id" => "self.id" },
@@ -61,6 +69,17 @@ __PACKAGE__->has_many(
{ "foreign.body_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
+__PACKAGE__->belongs_to(
+ "parent",
+ "FixMyStreet::DB::Result::Body",
+ { id => "parent" },
+ {
+ is_deferrable => 1,
+ join_type => "LEFT",
+ on_delete => "CASCADE",
+ on_update => "CASCADE",
+ },
+);
__PACKAGE__->has_many(
"users",
"FixMyStreet::DB::Result::User",
@@ -69,8 +88,8 @@ __PACKAGE__->has_many(
);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-14 17:54:33
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:2Z3gCosNomCTcjrwWy/RNA
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-19 12:47:10
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:DdtXjMWRpz20ZHjtY3oP2w
sub url {
my ( $self, $c ) = @_;
diff --git a/perllib/FixMyStreet/DB/Result/BodyArea.pm b/perllib/FixMyStreet/DB/Result/BodyArea.pm
index 508203cc8..844a3277d 100644
--- a/perllib/FixMyStreet/DB/Result/BodyArea.pm
+++ b/perllib/FixMyStreet/DB/Result/BodyArea.pm
@@ -16,6 +16,7 @@ __PACKAGE__->add_columns(
"area_id",
{ data_type => "integer", is_nullable => 0 },
);
+__PACKAGE__->add_unique_constraint("body_areas_body_id_area_id_idx", ["body_id", "area_id"]);
__PACKAGE__->belongs_to(
"body",
"FixMyStreet::DB::Result::Body",
@@ -24,8 +25,8 @@ __PACKAGE__->belongs_to(
);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-14 17:54:33
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:jTU6Nu/MQEvg9o8Hf5YQUQ
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-19 12:47:10
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:aAr+Nadyu8IckZlK6+PTNg
__PACKAGE__->set_primary_key(__PACKAGE__->columns);
diff --git a/templates/web/default/admin/body-form.html b/templates/web/default/admin/body-form.html
index 222d9b04c..e6d7322ea 100644
--- a/templates/web/default/admin/body-form.html
+++ b/templates/web/default/admin/body-form.html
@@ -6,8 +6,18 @@
</p>
<p>
+ <label for="parent">Parent</label>
+ <select name="parent" id="parent">
+ <option value=""> -- Select a body -- </option>
+ [% FOR b IN bodies %]
+ <option value="[% b.id %]"[% ' selected' IF body.parent.id == b.id %]>[% b.name %]</option>
+ [% END %]
+ </select>
+ </p>
+
+ <p>
<label for="area_ids">Area covered</label>
- <select name="area_ids" multiple>
+ <select name="area_ids" id="area_ids" multiple>
<option value=""> -- Select an area -- </option>
[% FOR area IN areas %]
[% SET aid = area.id %]
@@ -18,7 +28,7 @@
<p>
<label for="send_method">Send Method</label>
- <select name="send_method">
+ <select name="send_method" id="send_method">
<option value=""> -- Select a method -- </option>
[% FOR method IN send_methods %]
<option value="[% method %]"[% ' selected' IF body.send_method == method %]>[% method %]</option>