From 0998aef4fb4e7e94b950a6b337ee0c0df72ec7de Mon Sep 17 00:00:00 2001
From: Struan Donald
Date: Fri, 8 Sep 2017 15:57:03 +0100
Subject: add is_default column to response_priorities
---
db/downgrade_0055---0054.sql | 6 ++++++
db/schema.sql | 1 +
db/schema_0055-add-default-to-reponsepriority.sql | 5 +++++
perllib/FixMyStreet/DB/Result/ResponsePriority.pm | 6 ++++--
4 files changed, 16 insertions(+), 2 deletions(-)
create mode 100644 db/downgrade_0055---0054.sql
create mode 100644 db/schema_0055-add-default-to-reponsepriority.sql
diff --git a/db/downgrade_0055---0054.sql b/db/downgrade_0055---0054.sql
new file mode 100644
index 000000000..a38d74ded
--- /dev/null
+++ b/db/downgrade_0055---0054.sql
@@ -0,0 +1,6 @@
+BEGIN;
+
+ALTER TABLE response_priorities DROP COLUMN is_default;
+
+COMMIT;
+
diff --git a/db/schema.sql b/db/schema.sql
index fedab2b9d..f428ff59d 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -144,6 +144,7 @@ CREATE TABLE response_priorities (
name text not null,
description text,
external_id text,
+ is_default boolean not null default 'f',
unique(body_id, name)
);
diff --git a/db/schema_0055-add-default-to-reponsepriority.sql b/db/schema_0055-add-default-to-reponsepriority.sql
new file mode 100644
index 000000000..0f8b72e13
--- /dev/null
+++ b/db/schema_0055-add-default-to-reponsepriority.sql
@@ -0,0 +1,5 @@
+BEGIN;
+
+ALTER TABLE response_priorities ADD is_default boolean not null default 'f';
+
+COMMIT;
diff --git a/perllib/FixMyStreet/DB/Result/ResponsePriority.pm b/perllib/FixMyStreet/DB/Result/ResponsePriority.pm
index 44635d174..df54cfa08 100644
--- a/perllib/FixMyStreet/DB/Result/ResponsePriority.pm
+++ b/perllib/FixMyStreet/DB/Result/ResponsePriority.pm
@@ -28,6 +28,8 @@ __PACKAGE__->add_columns(
{ data_type => "text", is_nullable => 1 },
"external_id",
{ data_type => "text", is_nullable => 1 },
+ "is_default",
+ { data_type => "boolean", default_value => \"false", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint("response_priorities_body_id_name_key", ["body_id", "name"]);
@@ -51,8 +53,8 @@ __PACKAGE__->has_many(
);
-# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-12-14 17:12:09
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:glsO0fLK6fNvg4TmW1DMPg
+# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-09-12 09:32:53
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:JBIHFnaLvXCAUjgwTSB3CQ
__PACKAGE__->many_to_many( contacts => 'contact_response_priorities', 'contact' );
--
cgit v1.2.3
From d9c0917b84d501e6cfca7e0113470997b6ff2f35 Mon Sep 17 00:00:00 2001
From: Struan Donald
Date: Fri, 8 Sep 2017 17:19:57 +0100
Subject: edit and display default response priority in admin
---
CHANGELOG.md | 1 +
.../App/Controller/Admin/ResponsePriorities.pm | 1 +
t/app/controller/admin.t | 20 ++++++++++++++++++++
.../web/base/admin/responsepriorities/edit.html | 12 ++++++++++++
.../web/base/admin/responsepriorities/list.html | 2 ++
5 files changed, 36 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0fc68419b..86fd35983 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,7 @@
- Clearer highlight for selected duplicate on inspect form. #1798
- Include MapIt API key on admin config page. #1778
- Redirect to same map view after inspection. #1820
+ - A default response priority can now be set #1838
- Bugfixes:
- Set up action scheduled field when report loaded. #1789
- Fix display of thumbnail images on page reload. #1815
diff --git a/perllib/FixMyStreet/App/Controller/Admin/ResponsePriorities.pm b/perllib/FixMyStreet/App/Controller/Admin/ResponsePriorities.pm
index bae0f71a7..7b206690e 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/ResponsePriorities.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/ResponsePriorities.pm
@@ -71,6 +71,7 @@ sub edit : Path : Args(2) {
$priority->name( $c->get_param('name') );
$priority->description( $c->get_param('description') );
$priority->external_id( $c->get_param('external_id') );
+ $priority->is_default( $c->get_param('is_default') ? 1 : 0 );
$priority->update_or_insert;
my @live_contact_ids = map { $_->id } @live_contacts;
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index 075ab0fd0..bd0f9e408 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -1470,6 +1470,7 @@ subtest "response priorities can be added" => sub {
name => "Cat 1A",
description => "Fixed within 24 hours",
deleted => undef,
+ is_default => undef,
"contacts[".$oxfordshirecontact->id."]" => 1,
};
$mech->submit_form_ok( { with_fields => $fields } );
@@ -1478,6 +1479,25 @@ subtest "response priorities can be added" => sub {
is $oxfordshirecontact->response_priorities->count, 1, "Response template was added to contact";
};
+subtest "response priorities can set to default" => sub {
+ my $priority_id = $oxfordshire->response_priorities->first->id;
+ is $oxfordshire->response_priorities->count, 1, "Response priority exists";
+ $mech->get_ok( "/admin/responsepriorities/" . $oxfordshire->id . "/$priority_id" );
+
+ my $fields = {
+ name => "Cat 1A",
+ description => "Fixed within 24 hours",
+ deleted => undef,
+ is_default => 1,
+ "contacts[".$oxfordshirecontact->id."]" => 1,
+ };
+ $mech->submit_form_ok( { with_fields => $fields } );
+
+ is $oxfordshire->response_priorities->count, 1, "Still one response priority";
+ is $oxfordshirecontact->response_priorities->count, 1, "Still one response template";
+ ok $oxfordshire->response_priorities->first->is_default, "Response priority set to default";
+};
+
subtest "response priorities can be listed" => sub {
$mech->get_ok( "/admin/responsepriorities/" . $oxfordshire->id );
diff --git a/templates/web/base/admin/responsepriorities/edit.html b/templates/web/base/admin/responsepriorities/edit.html
index 07d6906ba..608f19e74 100644
--- a/templates/web/base/admin/responsepriorities/edit.html
+++ b/templates/web/base/admin/responsepriorities/edit.html
@@ -28,6 +28,18 @@
+
+
+ [% loc('Select if this is the default priority') %]
+
+
+
+
+
+
[% loc('If you only want this priority to be an option for specific categories, pick them here. By default they will show for all categories.') %]
diff --git a/templates/web/base/admin/responsepriorities/list.html b/templates/web/base/admin/responsepriorities/list.html
index 80d4e2cee..eedaccfdb 100644
--- a/templates/web/base/admin/responsepriorities/list.html
+++ b/templates/web/base/admin/responsepriorities/list.html
@@ -6,6 +6,7 @@