diff options
author | Struan Donald <struan@exo.org.uk> | 2018-10-26 11:25:01 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2018-11-19 13:27:43 +0000 |
commit | 0e8c7453c40db5ade085fb759ba73fb8ecf9b18d (patch) | |
tree | db38c5676a712bc47a12d5fa7e58f2d10042431d | |
parent | b97ea167b85dab9ef6a3781e24a457b392f4154c (diff) |
[UK] send reports on highways agency roads to highways agency
Includes an option to send to the council instead for e.g. reports on
underpasses or bridges.
Fixes #736
-rw-r--r-- | perllib/FixMyStreet/SendReport.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email/Highways.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm | 28 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email/TfL.pm | 22 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 13 | ||||
-rw-r--r-- | t/app/sendreport/email/highways.t | 32 | ||||
-rw-r--r-- | templates/web/fixmystreet-uk-councils/footer_extra_js.html | 1 | ||||
-rw-r--r-- | templates/web/fixmystreet.com/footer_extra_js.html | 1 | ||||
-rw-r--r-- | templates/web/oxfordshire/footer_extra_js.html | 2 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/assets.js | 2 | ||||
-rw-r--r-- | web/cobrands/highways/assets.js | 118 | ||||
-rw-r--r-- | web/cobrands/sass/_base.scss | 8 | ||||
-rw-r--r-- | web/js/map-fms.js | 8 |
13 files changed, 227 insertions, 20 deletions
diff --git a/perllib/FixMyStreet/SendReport.pm b/perllib/FixMyStreet/SendReport.pm index 2739e3043..db95850e6 100644 --- a/perllib/FixMyStreet/SendReport.pm +++ b/perllib/FixMyStreet/SendReport.pm @@ -6,6 +6,7 @@ use MooX::Types::MooseLike::Base qw(:all); use Module::Pluggable sub_name => 'senders', search_path => __PACKAGE__, + except => 'FixMyStreet::SendReport::Email::SingleBodyOnly', require => 1; has 'body_config' => ( is => 'rw', isa => HashRef, default => sub { {} } ); diff --git a/perllib/FixMyStreet/SendReport/Email/Highways.pm b/perllib/FixMyStreet/SendReport/Email/Highways.pm new file mode 100644 index 000000000..2a1f7b305 --- /dev/null +++ b/perllib/FixMyStreet/SendReport/Email/Highways.pm @@ -0,0 +1,11 @@ +package FixMyStreet::SendReport::Email::Highways; + +use Moo; +extends 'FixMyStreet::SendReport::Email::SingleBodyOnly'; + +has contact => ( + is => 'ro', + default => 'Pothole' +); + +1; diff --git a/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm b/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm new file mode 100644 index 000000000..cf778c549 --- /dev/null +++ b/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm @@ -0,0 +1,28 @@ +package FixMyStreet::SendReport::Email::SingleBodyOnly; + +use Moo; +extends 'FixMyStreet::SendReport::Email'; + +has contact => ( + is => 'ro', + default => sub { die 'Need to override contact' } +); + +sub build_recipient_list { + my ( $self, $row, $h ) = @_; + + return unless @{$self->bodies} == 1; + my $body = $self->bodies->[0]; + + # We don't care what the category was, look up the relevant contact + my $contact = $row->result_source->schema->resultset("Contact")->not_deleted->find({ + body_id => $body->id, + category => $self->contact, + }); + return unless $contact; + + @{$self->to} = map { [ $_, $body->name ] } split /,/, $contact->email; + return 1; +} + +1; diff --git a/perllib/FixMyStreet/SendReport/Email/TfL.pm b/perllib/FixMyStreet/SendReport/Email/TfL.pm index 801489c62..383df9792 100644 --- a/perllib/FixMyStreet/SendReport/Email/TfL.pm +++ b/perllib/FixMyStreet/SendReport/Email/TfL.pm @@ -1,23 +1,11 @@ package FixMyStreet::SendReport::Email::TfL; use Moo; -extends 'FixMyStreet::SendReport::Email'; +extends 'FixMyStreet::SendReport::Email::SingleBodyOnly'; -sub build_recipient_list { - my ( $self, $row, $h ) = @_; - - return unless @{$self->bodies} == 1; - my $body = $self->bodies->[0]; - - # We don't care what the category was, look up the Traffic lights contact - my $contact = $row->result_source->schema->resultset("Contact")->not_deleted->find({ - body_id => $body->id, - category => 'Traffic lights', - }); - return unless $contact; - - @{$self->to} = map { [ $_, $body->name ] } split /,/, $contact->email; - return 1; -} +has contact => ( + is => 'ro', + default => 'Traffic lights' +); 1; diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 6dce6711b..c2e731e61 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -41,6 +41,7 @@ for my $body ( { area_id => 2227, name => 'Hampshire County Council' }, { area_id => 2333, name => 'Hart Council' }, { area_id => 2535, name => 'Sandwell Borough Council' }, + { area_id => 1000, name => 'Highways England' }, ) { my $body_obj = $mech->create_body_ok($body->{area_id}, $body->{name}); push @bodies, $body_obj; @@ -98,6 +99,11 @@ my $contact10 = $mech->create_contact_ok( category => 'Street lighting', email => 'streetlights-2326@example.com', ); +my $contact11 = $mech->create_contact_ok( + body_id => $body_ids{1000}, # Highways + category => 'Pothole', + email => 'pothole-1000@example.com', +); # test that the various bit of form get filled in and errors correctly # generated. @@ -977,6 +983,13 @@ foreach my $test ( extra_fields => { do_not_send => 'Gloucestershire County Council' }, email_count => 1, }, + { + desc => "test single_body_only with Highways England", + category => 'Street lighting', + councils => [ 1000 ], + extra_fields => { single_body_only => 'Highways England' }, + email_count => 1, + }, ) { subtest $test->{desc} => sub { diff --git a/t/app/sendreport/email/highways.t b/t/app/sendreport/email/highways.t new file mode 100644 index 000000000..f53062336 --- /dev/null +++ b/t/app/sendreport/email/highways.t @@ -0,0 +1,32 @@ +use FixMyStreet::SendReport::Email::Highways; +use FixMyStreet::TestMech; + +my $mech = FixMyStreet::TestMech->new; + +my $bromley = $mech->create_body_ok(2482, 'Bromley Council'); +my $highways = $mech->create_body_ok(2482, 'Highways England'); + +$mech->create_contact_ok(email => 'council@example.com', body_id => $bromley->id, category => 'Graffiti'); +$mech->create_contact_ok(email => 'council@example.com', body_id => $bromley->id, category => 'Faulty street light'); +$mech->create_contact_ok(email => 'highways@example.com', body_id => $highways->id, category => 'Pothole'); + +my $row = FixMyStreet::DB->resultset('Problem')->new( { + bodies_str => '1000', + category => 'Pothole', + cobrand => '', +} ); + +my $e = FixMyStreet::SendReport::Email::Highways->new; +is $e->build_recipient_list($row), undef, 'no recipients if no body'; + +$e = FixMyStreet::SendReport::Email::Highways->new; +$e->add_body($bromley); +is $e->build_recipient_list($row), undef, 'no recipients if category missing'; + +$e = FixMyStreet::SendReport::Email::Highways->new; +$e->add_body($highways); +is $e->build_recipient_list($row), 1, 'correct recipient list count'; +is_deeply $e->to, [ [ 'highways@example.com', 'Highways England' ] ], 'correct To line'; + +done_testing(); + diff --git a/templates/web/fixmystreet-uk-councils/footer_extra_js.html b/templates/web/fixmystreet-uk-councils/footer_extra_js.html index 218607498..1742a55e2 100644 --- a/templates/web/fixmystreet-uk-councils/footer_extra_js.html +++ b/templates/web/fixmystreet-uk-councils/footer_extra_js.html @@ -1,4 +1,5 @@ [% scripts.push( version('/vendor/OpenLayers.Projection.OrdnanceSurvey.js') version('/cobrands/fixmystreet-uk-councils/js.js'), + version('/cobrands/highways/assets.js'), ) %] diff --git a/templates/web/fixmystreet.com/footer_extra_js.html b/templates/web/fixmystreet.com/footer_extra_js.html index bb7c9780c..c0c4ff80e 100644 --- a/templates/web/fixmystreet.com/footer_extra_js.html +++ b/templates/web/fixmystreet.com/footer_extra_js.html @@ -10,6 +10,7 @@ IF bodyclass.match('mappage'); scripts.push( version('/cobrands/buckinghamshire/assets.js') ); scripts.push( version('/cobrands/lincolnshire/assets.js') ); scripts.push( version('/cobrands/oxfordshire/assets.js') ); + scripts.push( version('/cobrands/highways/assets.js') ); scripts.push( version('/vendor/OpenLayers.Projection.OrdnanceSurvey.js'), ); diff --git a/templates/web/oxfordshire/footer_extra_js.html b/templates/web/oxfordshire/footer_extra_js.html index e05e16707..5e24e7321 100644 --- a/templates/web/oxfordshire/footer_extra_js.html +++ b/templates/web/oxfordshire/footer_extra_js.html @@ -1,5 +1,7 @@ [% scripts.push( + version('/cobrands/fixmystreet/assets.js'), version('/vendor/OpenLayers.Projection.OrdnanceSurvey.js'), version('/cobrands/oxfordshire/js.js'), version('/cobrands/oxfordshire/assets.js'), + version('/cobrands/highways/assets.js'), ) %] diff --git a/web/cobrands/fixmystreet/assets.js b/web/cobrands/fixmystreet/assets.js index c1347ef2f..efb827656 100644 --- a/web/cobrands/fixmystreet/assets.js +++ b/web/cobrands/fixmystreet/assets.js @@ -131,7 +131,7 @@ OpenLayers.Layer.VectorNearest = OpenLayers.Class(OpenLayers.Layer.VectorAsset, var feature = this.getFeatureAtPoint(point); if (feature == null) { // The click wasn't directly over a road, try and find one nearby - feature = this.getNearestFeature(point, 10); + feature = this.getNearestFeature(point, this.fixmystreet.nearest_radius || 10); } this.selected_feature = feature; }, diff --git a/web/cobrands/highways/assets.js b/web/cobrands/highways/assets.js new file mode 100644 index 000000000..4b6939693 --- /dev/null +++ b/web/cobrands/highways/assets.js @@ -0,0 +1,118 @@ +(function(){ + +if (!fixmystreet.maps) { + return; +} + +var defaults = { + http_options: { + url: "https://tilma.mysociety.org/mapserver/highways", + params: { + SERVICE: "WFS", + VERSION: "1.1.0", + REQUEST: "GetFeature", + SRSNAME: "urn:ogc:def:crs:EPSG::3857" + } + }, + format_class: OpenLayers.Format.GML.v3.MultiCurveFix, + asset_type: 'area', + // this covers zoomed right out on Cumbrian sections of + // the M6 + max_resolution: 20, + min_resolution: 0.5971642833948135, + asset_id_field: 'CENTRAL_AS', + geometryName: 'msGeometry', + srsName: "EPSG:3857", + strategy_class: OpenLayers.Strategy.FixMyStreet +}; + +var highways_stylemap = new OpenLayers.StyleMap({ + 'default': new OpenLayers.Style({ + fill: false, + stroke: false, + }) +}); + +fixmystreet.assets.add($.extend(true, {}, defaults, { + http_options: { + params: { + TYPENAME: "Highways" + } + }, + stylemap: highways_stylemap, + always_visible: true, + + non_interactive: true, + road: true, + all_categories: true, + // motorways are wide and the lines to define them are narrow so we + // need a bit more margin for error in finding the nearest to stop + // clicking in the middle of them being undetected + nearest_radius: 15, + actions: { + found: function(layer, feature) { + // if we've changed location then we want to reset things otherwise + // this is probably just being called again by a category change + var lat = $('#fixmystreet\\.latitude').val(), + lon = $('#fixmystreet\\.longitude').val(); + if ( fixmystreet.body_overrides.location && + lat == fixmystreet.body_overrides.location.latitude && + lon == fixmystreet.body_overrides.location.longitude ) { + return; + } + $('#highways').remove(); + if ( !fixmystreet.assets.selectedFeature() ) { + fixmystreet.body_overrides.only_send('Highways England'); + add_highways_warning(feature.attributes.ROA_NUMBER); + } + }, + not_found: function(layer) { + fixmystreet.body_overrides.location = null; + fixmystreet.body_overrides.remove_only_send(); + $('#highways').remove(); + } + } +})); + +function add_highways_warning(road_name) { + var $warning = $('<div class="box-warning" id="highways"><p>It looks like you clicked on the <strong>' + road_name + '</strong> which is managed by <strong>Highways England</strong>. ' + + 'Does your report concern something on this road, or somewhere else (e.g a road crossing it)?<p></div>'); + var $radios = $('<p class="segmented-control segmented-control--radio"></p>'); + + $('<input>') + .attr('type', 'radio') + .attr('name', 'highways-choice') + .attr('id', 'js-highways') + .prop('checked', true) + .on('click', function() { + fixmystreet.body_overrides.location = null; + fixmystreet.body_overrides.only_send('Highways England'); + }) + .appendTo($radios); + $('<label>') + .attr('for', 'js-highways') + .text('On the ' + road_name) + .addClass('btn') + .appendTo($radios); + $('<input>') + .attr('type', 'radio') + .attr('name', 'highways-choice') + .attr('id', 'js-not-highways') + .on('click', function() { + fixmystreet.body_overrides.location = { + latitude: $('#fixmystreet\\.latitude').val(), + longitude: $('#fixmystreet\\.longitude').val() + }; + fixmystreet.body_overrides.remove_only_send(); + }) + .appendTo($radios); + $('<label>') + .attr('for', 'js-not-highways') + .text('Somewhere else') + .addClass('btn') + .appendTo($radios); + $radios.appendTo($warning); + $('.change_location').after($warning); +} + +})(); diff --git a/web/cobrands/sass/_base.scss b/web/cobrands/sass/_base.scss index 7715ff5e3..9f8778c90 100644 --- a/web/cobrands/sass/_base.scss +++ b/web/cobrands/sass/_base.scss @@ -2445,6 +2445,14 @@ a#geolocate_link.loading, .btn--geolocate.loading { margin-bottom: 0; } } + + .segmented-control { + .btn { + &:last-child { + margin-bottom: 1em; + } + } + } } .asset-spot:before { diff --git a/web/js/map-fms.js b/web/js/map-fms.js index 3e23b7590..ac27cfbce 100644 --- a/web/js/map-fms.js +++ b/web/js/map-fms.js @@ -39,10 +39,14 @@ OpenLayers.Layer.BingUK = OpenLayers.Class(OpenLayers.Layer.Bing, { var c = this.map.getCenter(); var in_uk = c ? this.in_uk(c) : true; if (z >= 16 && in_uk) { - copyrights = 'Contains Ordnance Survey data © Crown copyright and database right 2016'; + copyrights = 'Contains Highways England and Ordnance Survey data © Crown copyright and database right 2016'; } else { logo = '<a href="https://www.bing.com/maps/"><img border=0 src="//dev.virtualearth.net/Branding/logo_powered_by.png"></a>'; - copyrights = '© 2016 <a href="https://www.bing.com/maps/">Microsoft</a>. © AND, Navteq, Ordnance Survey'; + if (in_uk) { + copyrights = '© 2016 <a href="https://www.bing.com/maps/">Microsoft</a>. © AND, Navteq, Highways England, Ordnance Survey'; + } else { + copyrights = '© 2016 <a href="https://www.bing.com/maps/">Microsoft</a>. © AND, Navteq, Ordnance Survey'; + } } this._updateAttribution(copyrights, logo); }, |