Skip to content

Commit

Permalink
[Oxfordshire] Fetch private street light info.
Browse files Browse the repository at this point in the history
Show unit type when selected.
  • Loading branch information
dracos committed Mar 25, 2022
1 parent 88437f1 commit f59a032
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .cypress/cypress/fixtures/oxon-street-light-private.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"private": true,
"unit_type": "Light"
}
5 changes: 5 additions & 0 deletions .cypress/cypress/fixtures/oxon-street-light-public.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"private": false,
"unit_type": "Wall Mounted Light"
}

4 changes: 4 additions & 0 deletions .cypress/cypress/fixtures/oxon-street-lights-none.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"results": [
]
}
4 changes: 4 additions & 0 deletions .cypress/cypress/fixtures/oxon-street-lights.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{"results":[
{"type":"Feature","id":"private-light","geometry":{"type":"Point","coordinates":[-1.257263,51.754730]},"properties":{"designCode":"designs_streetLights","itemId":"private-light","title":"002","subtitle":"BEAUMONT STREET","type":"Item","styleId":"5e0e0edfca31500efc379151"}},
{"type":"Feature","id":"public-light","geometry":{"type":"Point","coordinates":[-1.254822,51.754770]},"properties":{"designCode":"designs_streetLights","itemId":"public-light","title":"FP2","subtitle":"MAGDALEN STREET EAST","type":"Item","styleId":"5e0e0edfca31500efc379151"}}
]}
21 changes: 21 additions & 0 deletions .cypress/cypress/integration/oxfordshire.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
describe("Oxfordshire cobrand", function() {
it("looks up private street light information", function() {
cy.server();
cy.route('/report/new/ajax*').as('report-ajax');
cy.route('**/oxfordshire.staging/**', 'fixture:oxon-street-lights-none.json').as('empty-street-lights-layer');
cy.route('**/32538/21719/**', 'fixture:oxon-street-lights.json').as('street-lights-layer');
cy.route('**id=private-light**', 'fixture:oxon-street-light-private.json').as('street-light-private');
cy.route('**id=public-light**', 'fixture:oxon-street-light-public.json').as('street-light-public');
cy.visit('http://oxfordshire.localhost:3001/report/new?latitude=51.754926&longitude=-1.256179');
cy.wait('@report-ajax');
cy.pickCategory('Lamp Out of Light');
cy.wait('@street-lights-layer');
cy.wait('@empty-street-lights-layer');
cy.get('.js-reporting-page--next:visible').should('be.disabled');
cy.get('circle').eq(1).click(); // Click a public light
cy.get("#category_meta_message_LampOutofLight").should('not.contain', 'private street light asset');
cy.get('.js-reporting-page--next:visible').should('not.be.disabled');
cy.get('circle').eq(0).click(); // Click a private light
cy.get("#category_meta_message_LampOutofLight").should('contain', 'private street light asset');
cy.get('.js-reporting-page--next:visible').should('be.disabled');
});

it("allows inspectors to instruct defects", function() {
cy.server();
cy.route('/report/*').as('show-report');
Expand Down
2 changes: 1 addition & 1 deletion bin/fixmystreet.com/fixture
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ if ($opt->test_fixtures) {
{ area_id => 2232, categories => ['Damaged/missing cats eye'], name => 'Lincolnshire County Council' },
{ area_id => 2566, categories => [ 'General fly tipping', 'Fallen branch', 'Light Out', 'Light Dim', 'Fallen Tree', 'Damaged Tree', 'Pothole' ], name => 'Peterborough City Council' },
{ area_id => 2498, categories => [ 'Incorrect timetable', 'Glass broken', 'Mobile Crane Operation', 'Roadworks' ], name => 'TfL' },
{ area_id => 2237, categories => [ 'Flytipping', 'Roads', 'Parks' ], name => 'Oxfordshire County Council' },
{ area_id => 2237, categories => [ 'Flytipping', 'Roads', 'Parks', 'Lamp Out of Light' ], name => 'Oxfordshire County Council' },
{ area_id => 2551, categories => [ 'Abandoned vehicles', 'Dog fouling', 'Blocked drain' ], name => 'Bath and North East Somerset Council' },
{ area_id => 2238, categories => [ 'Flytipping', 'Roads', 'Parks' ], name => 'Shropshire Council' },
{ area_id => 2500, categories => [ 'Abandoned vehicles', 'Flytipping', 'Flyposting' ], name => 'Merton Council' },
Expand Down
37 changes: 33 additions & 4 deletions web/cobrands/oxfordshire/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,10 @@ var streetlight_stylemap = new OpenLayers.StyleMap({
});

var street_lighting_layer = 'layers_streetLightingAssets';
var base_url = fixmystreet.staging ?
"https://tilma.staging.mysociety.org/resource-proxy/proxy.php?https://oxfordshire.staging/${layerid}/${x}/${y}/${z}/cluster" :
"https://tilma.mysociety.org/resource-proxy/proxy.php?https://oxfordshire.assets/${layerid}/${x}/${y}/${z}/cluster";

var base_host = fixmystreet.staging ? "https://tilma.staging.mysociety.org" : "https://tilma.mysociety.org";
var base_proxy_url = fixmystreet.staging ? "https://oxfordshire.staging" : "https://oxfordshire.assets";
var base_url = base_host + "/resource-proxy/proxy.php?" + base_proxy_url + "/${layerid}/${x}/${y}/${z}/cluster";
var base_light_url = base_host + "/resource-proxy/alloy-light.php?url=" + base_proxy_url + "&id=";
var url_with_style = base_url + '?styleIds=${styleid}';

var layers = [
Expand Down Expand Up @@ -519,16 +519,45 @@ var oxfordshire_defaults = $.extend(true, {}, fixmystreet.alloyv2_defaults, {
attributes: {
// feature_id
unit_number: "title",
unit_type: "unit_type",
asset_resource_id: "itemId"
},
select_action: true,
feature_code: 'title',
asset_id_field: 'itemId',
construct_selected_asset_message: function(asset) {
var out = 'You have selected ';
out += asset.attributes.unit_type || "street light";
out += " <b>" + asset.attributes.title + '</b>.';
if (asset.attributes.private) {
out += " This private street light asset is not under the responsibility of Oxfordshire County Council and therefore we are unable to accept reports for the asset.";
}
return out;
},
actions: {
asset_found: function(asset) {
if (fixmystreet.message_controller.asset_found.call(this)) {
return;
}

var layer = this;

// Fetch item info
fixmystreet.maps.loading_spinner.show();
$.get(base_light_url + asset.attributes.itemId)
.then(function(data) {
asset.attributes.private = data.private;
asset.attributes.unit_type = data.unit_type;
var controller_fn = data.private ? 'asset_not_found' : 'asset_found';
// Prevent/allow report creation
fixmystreet.message_controller[controller_fn].call(layer);
// Update message now we have attribute information
fixmystreet.assets.named_select_action_found.call(layer, asset);
// Update hidden fields with any new attribute information
layer.setAttributeFields(asset);
})
.always(fixmystreet.maps.loading_spinner.hide);

fixmystreet.assets.named_select_action_found.call(this, asset);
var lonlat = asset.geometry.getBounds().getCenterLonLat();
// Features considered overlapping if within 1M of each other
Expand Down

0 comments on commit f59a032

Please sign in to comment.