aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/Contact.pm4
-rw-r--r--perllib/FixMyStreet/Cobrand/BathNES.pm188
-rw-r--r--perllib/FixMyStreet/Geocode/Bing.pm2
-rw-r--r--perllib/FixMyStreet/Geocode/Google.pm2
-rw-r--r--perllib/FixMyStreet/Geocode/OSM.pm2
-rw-r--r--perllib/FixMyStreet/Map/BathNES.pm18
-rw-r--r--perllib/FixMyStreet/SendReport/Email/BathNES.pm16
7 files changed, 232 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm
index f2c3be47c..b124ba1c0 100644
--- a/perllib/FixMyStreet/App/Controller/Contact.pm
+++ b/perllib/FixMyStreet/App/Controller/Contact.pm
@@ -93,6 +93,10 @@ sub determine_contact_type : Private {
$c->stash->{update} = $update;
}
+
+ if ( $c->get_param("reject") && $c->user->has_permission_to(report_reject => $c->stash->{problem}->bodies_str_ids) ) {
+ $c->stash->{rejecting_report} = 1;
+ }
}
return 1;
diff --git a/perllib/FixMyStreet/Cobrand/BathNES.pm b/perllib/FixMyStreet/Cobrand/BathNES.pm
new file mode 100644
index 000000000..fa1112709
--- /dev/null
+++ b/perllib/FixMyStreet/Cobrand/BathNES.pm
@@ -0,0 +1,188 @@
+package FixMyStreet::Cobrand::BathNES;
+use parent 'FixMyStreet::Cobrand::Whitelabel';
+
+use strict;
+use warnings;
+
+use LWP::Simple;
+use URI;
+use Try::Tiny;
+use JSON::MaybeXS;
+
+sub council_area_id { return 2551; }
+sub council_area { return 'Bath and North East Somerset'; }
+sub council_name { return 'Bath and North East Somerset Council'; }
+sub council_url { return 'bathnes'; }
+
+sub contact_email {
+ my $self = shift;
+ return join( '@', 'councilconnect_rejections', 'bathnes.gov.uk' );
+}
+
+sub update_email {
+ my $self = shift;
+ return join( '@', 'highways', 'bathnes.gov.uk' );
+}
+
+sub map_type { 'BathNES' }
+
+sub example_places {
+ return ( 'BA1 1JQ', "Lansdown Grove" );
+}
+
+sub get_geocoder {
+ return 'OSM'; # default of Bing gives poor results, let's try overriding.
+}
+
+sub disambiguate_location {
+ my $self = shift;
+ my $string = shift;
+
+ my $town = 'Bath and North East Somerset';
+
+ # The council have provided a list of common typos which we should correct:
+ my %replacements = (
+ "broom" => "brougham",
+ "carnarvon" => "caernarvon",
+ "cornation" => "coronation",
+ "beafort" => "beaufort",
+ "beechan" => "beechen",
+ "malreword" => "malreward",
+ "canyerberry"=> "canterbury",
+ "clairemont"=> "claremont",
+ "salsbury"=> "salisbury",
+ "solsberry"=> "solsbury",
+ "lawn road" => "lorne",
+ "new road high littleton" => "danis house",
+ );
+
+ foreach my $original (keys %replacements) {
+ my $replacement = $replacements{$original};
+ $string =~ s/$original/$replacement/ig;
+ }
+
+ return {
+ %{ $self->SUPER::disambiguate_location() },
+ town => $town,
+ centre => '51.3559192103294,-2.47522827137605',
+ span => '0.166437921041471,0.429359043406088',
+ bounds => [ 51.2730478766607, -2.70792015294201, 51.4394857977022, -2.27856110953593 ],
+ string => $string,
+ };
+}
+
+sub pin_colour {
+ my ( $self, $p, $context ) = @_;
+ return 'grey' if $p->state eq 'not responsible';
+ return 'green' if $p->is_fixed || $p->is_closed;
+ return 'red' if $p->state eq 'confirmed';
+ return 'yellow';
+}
+
+sub send_questionnaires { 0 }
+
+sub enable_category_groups { 1 }
+
+sub default_show_name { 0 }
+
+sub default_map_zoom { 3 }
+
+sub map_js_extra {
+ my ($self, $c) = @_;
+
+ return unless $c->user_exists;
+
+ my $banes_user = $c->user->from_body && $c->user->from_body->areas->{$self->council_area_id};
+ if ( $banes_user || $c->user->is_superuser ) {
+ return ['/cobrands/bathnes/staff.js'];
+ }
+}
+
+sub category_extra_hidden {
+ my ($self, $meta) = @_;
+ my $code = $meta->{code};
+ # These two are used in the non-Open311 'Street light fault' category.
+ return 1 if $code eq 'unitid' || $code eq 'asset_details';
+ return $self->SUPER::category_extra_hidden($meta);
+}
+
+sub open311_config {
+ my ($self, $row, $h, $params) = @_;
+
+ my $extra = $row->get_extra_fields;
+ push @$extra,
+ { name => 'report_url',
+ value => $h->{url} },
+ { name => 'title',
+ value => $row->title },
+ { name => 'description',
+ value => $row->detail };
+
+ # Reports made via FMS.com or the app probably won't have a USRN
+ # value because we don't display the adopted highways layer on those
+ # frontends. Instead we'll look up the closest asset from the WFS
+ # service at the point we're sending the report over Open311.
+ if (!$row->get_extra_field_value('site_code')) {
+ if (my $usrn = $self->lookup_usrn($row)) {
+ push @$extra,
+ { name => 'site_code',
+ value => $usrn };
+ }
+ }
+
+ $row->set_extra_fields(@$extra);
+}
+
+sub available_permissions {
+ my $self = shift;
+
+ my $permissions = $self->SUPER::available_permissions();
+
+ $permissions->{Problems}->{report_reject} = "Reject reports";
+
+ return $permissions;
+}
+
+sub report_sent_confirmation_email { 1 }
+
+sub lookup_usrn {
+ my $self = shift;
+ my $row = shift;
+
+ my $buffer = 5; # metres
+ my ($x, $y) = $row->local_coords;
+ my ($w, $s, $e, $n) = ($x-$buffer, $y-$buffer, $x+$buffer, $y+$buffer);
+
+ my $uri = URI->new("https://isharemaps.bathnes.gov.uk/getows.ashx");
+ $uri->query_form(
+ REQUEST => "GetFeature",
+ SERVICE => "WFS",
+ SRSNAME => "urn:ogc:def:crs:EPSG::27700",
+ TYPENAME => "AdoptedHighways",
+ VERSION => "1.1.0",
+ mapsource => "BathNES/WFS",
+ outputformat => "application/json",
+ BBOX => "$w,$s,$e,$n"
+ );
+
+ my $response = get($uri);
+
+ my $j = JSON->new->utf8->allow_nonref;
+ try {
+ $j = $j->decode($response);
+ return $j->{features}->[0]->{properties}->{usrn};
+ } catch {
+ # There was either no asset found, or an error with the WFS
+ # call - in either case let's just proceed without the USRN.
+ return;
+ }
+
+}
+
+sub enter_postcode_text {
+ my ($self) = @_;
+ return 'Enter a location in ' . $self->council_area;
+}
+
+
+1;
diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm
index a846f3348..9e425441a 100644
--- a/perllib/FixMyStreet/Geocode/Bing.pm
+++ b/perllib/FixMyStreet/Geocode/Bing.pm
@@ -20,6 +20,8 @@ sub string {
my ( $s, $c ) = @_;
my $params = $c->cobrand->disambiguate_location($s);
+ # Allow cobrand to fixup the user input
+ $s = $params->{string} if $params->{string};
$s = FixMyStreet::Geocode::escape($s);
$s .= '+' . $params->{town} if $params->{town} and $s !~ /$params->{town}/i;
diff --git a/perllib/FixMyStreet/Geocode/Google.pm b/perllib/FixMyStreet/Geocode/Google.pm
index 162101953..ad1881541 100644
--- a/perllib/FixMyStreet/Geocode/Google.pm
+++ b/perllib/FixMyStreet/Geocode/Google.pm
@@ -19,6 +19,8 @@ sub string {
my ( $s, $c ) = @_;
my $params = $c->cobrand->disambiguate_location($s);
+ # Allow cobrand to fixup the user input
+ $s = $params->{string} if $params->{string};
my $components = "";
diff --git a/perllib/FixMyStreet/Geocode/OSM.pm b/perllib/FixMyStreet/Geocode/OSM.pm
index d237f453b..4d57007c5 100644
--- a/perllib/FixMyStreet/Geocode/OSM.pm
+++ b/perllib/FixMyStreet/Geocode/OSM.pm
@@ -26,6 +26,8 @@ sub string {
my ( $s, $c ) = @_;
my $params = $c->cobrand->disambiguate_location($s);
+ # Allow cobrand to fixup the user input
+ $s = $params->{string} if $params->{string};
$s = FixMyStreet::Geocode::escape($s);
$s .= '+' . $params->{town} if $params->{town} and $s !~ /$params->{town}/i;
diff --git a/perllib/FixMyStreet/Map/BathNES.pm b/perllib/FixMyStreet/Map/BathNES.pm
new file mode 100644
index 000000000..9c9c3c11d
--- /dev/null
+++ b/perllib/FixMyStreet/Map/BathNES.pm
@@ -0,0 +1,18 @@
+# FixMyStreet:Map::BathNES
+# More JavaScript, for street assets
+
+package FixMyStreet::Map::BathNES;
+use base 'FixMyStreet::Map::OSM';
+
+use strict;
+
+sub map_javascript { [
+ '/vendor/OpenLayers/OpenLayers.bathnes.js',
+ '/vendor/OpenLayers.Projection.OrdnanceSurvey.js',
+ '/js/map-OpenLayers.js',
+ '/js/map-OpenStreetMap.js',
+ '/cobrands/fixmystreet/assets.js',
+ '/cobrands/bathnes/js.js',
+] }
+
+1; \ No newline at end of file
diff --git a/perllib/FixMyStreet/SendReport/Email/BathNES.pm b/perllib/FixMyStreet/SendReport/Email/BathNES.pm
new file mode 100644
index 000000000..786d36d1e
--- /dev/null
+++ b/perllib/FixMyStreet/SendReport/Email/BathNES.pm
@@ -0,0 +1,16 @@
+package FixMyStreet::SendReport::Email::BathNES;
+
+use Moo;
+
+BEGIN { extends 'FixMyStreet::SendReport::Email'; }
+
+sub get_template {
+ my ( $self, $row ) = @_;
+ if ( $row->category eq 'Street Light Fault' ) {
+ return 'bathnes/submit-street-light-fault.txt';
+ } else {
+ return 'submit.txt';
+ }
+}
+
+1;