diff options
author | Matthew Somerville <matthew@mysociety.org> | 2020-04-08 16:37:09 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2020-04-08 23:38:47 +0100 |
commit | 1fa87a4adb61c3131516e711f3cf3a83941495d5 (patch) | |
tree | fcbf4b8eb1fe8cea0465dcfe0f4181ba08dd80cd | |
parent | 75002bb7f3eb82fa1c8002e199e188501d7954a4 (diff) |
[UK] Fix Highways England categories on pin move.
If you clicked on a non-HE location (so showing non-HE categories), then
moved the pin to a HE location, the HE message box would show and update
categories (but there would be no HE ones at the time). The server would
return the new categories (including HE ones), but as the issue location
had now not changed on this second call, the categories would not update
to hide non-HE ones (it would show both HE and non-HE categories).
So, instead of going off a location, check the road name - if it has not
changed, do not recreate the whole HE message box, but do call the right
HE selected/not selected function to update the categories.
Note that this, if "Somewhere else" is selected, then causes an infinite
loop, because the highways_change event triggers a category_change event
which fires the layer's road found function, and then repeat.
The highways_change->category_change event firing, according to the code
comment, is so that asset selection can take place, or to remove stopper
messages being shown. Previously, HE did not have its own categories but
overrode the body to be sent to; HE now does have categories of its own,
so I think this code can be removed.
-rw-r--r-- | .cypress/cypress/fixtures/highways-ajax.json | 2 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/assets.js | 11 | ||||
-rw-r--r-- | web/cobrands/highways/assets.js | 35 |
3 files changed, 21 insertions, 27 deletions
diff --git a/.cypress/cypress/fixtures/highways-ajax.json b/.cypress/cypress/fixtures/highways-ajax.json index d2234bf4c..fc77ce649 100644 --- a/.cypress/cypress/fixtures/highways-ajax.json +++ b/.cypress/cypress/fixtures/highways-ajax.json @@ -33,5 +33,5 @@ "extra_name_info":"", "titles_list":null, "councils_text":"<p> These will be sent to <strong>Borsetshire County Council</strong> and also published online for others to see, in accordance with our <a href=\"/privacy\">privacy policy</a>. </p>", - "category":"<label for='form_category' id=\"form_category_label\">Category</label> <select required class=\"validCategory form-control js-grouped-select\" name=\"category\" id=\"form_category\"> <option value='-- Pick a category --'>-- Pick a category --</option> <option value='Abandoned vehicles'>Abandoned vehicles</option> <option value='Bus stops'>Bus stops</option> <option value='Dog fouling'>Dog fouling</option> <option value='Flyposting'>Flyposting</option> <option value='Flytipping'>Flytipping</option> <option value='Footpath/bridleway away from road'>Footpath/bridleway away from road</option> <option value='Graffiti'>Graffiti</option> <option value='Parks/landscapes'>Parks/landscapes</option> <option value='Pavements'>Pavements</option> <option value='Potholes'>Potholes</option> <option value='Public toilets'>Public toilets</option> <option value='Roads/highways'>Roads/highways</option> <option value='Road traffic signs'>Road traffic signs</option> <option value='Rubbish (refuse and recycling)'>Rubbish (refuse and recycling)</option> <option value='Street cleaning'>Street cleaning</option> <option value='Street lighting'>Street lighting</option> <option value='Street nameplates'>Street nameplates</option> <option value='Traffic lights'>Traffic lights</option> <option value='Trees'>Trees</option> <option value='Other'>Other</option><optgroup label=\"** Highways England **\"><option>Road markings</option><option>Sign issue</option><option>Traffic lights</option></optgroup> <optgroup label=\"Bins\"> <option value='Broken'>Broken</option> <option value='Missing'>Missing</option> <option value='Overflowing'>Overflowing</option></optgroup></select><label id=\"form_subcategory_label\" class=\"hidden\">Subcategory</label>" + "category":"<label for='form_category' id=\"form_category_label\">Category</label> <select required class=\"validCategory form-control js-grouped-select\" name=\"category\" id=\"form_category\"> <option value='-- Pick a category --'>-- Pick a category --</option> <option value='Abandoned vehicles'>Abandoned vehicles</option> <option value='Bus stops'>Bus stops</option> <option value='Dog fouling'>Dog fouling</option> <option value='Flyposting'>Flyposting</option> <option value='Flytipping'>Flytipping</option> <option value='Footpath/bridleway away from road'>Footpath/bridleway away from road</option> <option value='Graffiti'>Graffiti</option> <option value='Parks/landscapes'>Parks/landscapes</option> <option value='Pavements'>Pavements</option> <option value='Potholes'>Potholes</option> <option value='Public toilets'>Public toilets</option> <option value='Roads/highways'>Roads/highways</option> <option value='Road traffic signs'>Road traffic signs</option> <option value='Rubbish (refuse and recycling)'>Rubbish (refuse and recycling)</option> <option value='Street cleaning'>Street cleaning</option> <option value='Street lighting'>Street lighting</option> <option value='Street nameplates'>Street nameplates</option> <option value='Traffic lights'>Traffic lights</option> <option value='Trees'>Trees</option> <option value='Other'>Other</option><optgroup label=\"** Highways England **\"><option value='Road markings'>Road markings</option><option value='Sign issue'>Sign issue</option><option value='Traffic lights'>Traffic lights</option></optgroup> <optgroup label=\"Bins\"> <option value='Broken'>Broken</option> <option value='Missing'>Missing</option> <option value='Overflowing'>Overflowing</option></optgroup></select><label id=\"form_subcategory_label\" class=\"hidden\">Subcategory</label>" } diff --git a/web/cobrands/fixmystreet/assets.js b/web/cobrands/fixmystreet/assets.js index 0a08c0f69..204ceb85d 100644 --- a/web/cobrands/fixmystreet/assets.js +++ b/web/cobrands/fixmystreet/assets.js @@ -1198,17 +1198,6 @@ fixmystreet.message_controller = (function() { disable_report_form(stopper.keep_category_extras); } - // make sure we fire the code to check if an asset is selected if - // we change options in the Highways England message - $(fixmystreet).on('report_new:highways_change', function() { - if (fixmystreet.body_overrides.get_only_send() === 'Highways England') { - $('#' + stopperId).remove(); // Get rid of any stopper message - responsibility_off(); // Will also reenable form - } else { - $(fixmystreet).trigger('report_new:category_change'); - } - }); - $(fixmystreet).on('report_new:category_change', check_for_stopper); return { diff --git a/web/cobrands/highways/assets.js b/web/cobrands/highways/assets.js index 1607bc193..666c97e2b 100644 --- a/web/cobrands/highways/assets.js +++ b/web/cobrands/highways/assets.js @@ -54,22 +54,27 @@ fixmystreet.assets.add(defaults, { 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 ) { + if (fixmystreet.assets.selectedFeature()) { + $('#highways').remove(); return; } - $('#highways').remove(); - if ( !fixmystreet.assets.selectedFeature() ) { - add_highways_warning(feature.attributes.ROA_NUMBER); + var current_road_name = $('#highways strong').first().text(); + var new_road_name = feature.attributes.ROA_NUMBER; + if (current_road_name === new_road_name) { + // this could be because of a category change, or because we've + // received new data from the server (but the pin drop had + // already shown the HE message) + if ($('#js-highways:checked').length) { + he_selected(); + } else { + non_he_selected(); + } + } else { + $('#highways').remove(); + add_highways_warning(new_road_name); } }, not_found: function(layer) { - fixmystreet.body_overrides.location = null; if (fixmystreet.body_overrides.get_only_send() === 'Highways England') { fixmystreet.body_overrides.remove_only_send(); fixmystreet.body_overrides.do_not_send('Highways England'); @@ -82,10 +87,7 @@ fixmystreet.assets.add(defaults, { function regenerate_category(he_flag) { if (!fixmystreet.reporting_data) return; - fixmystreet.body_overrides.location = { - latitude: $('#fixmystreet\\.latitude').val(), - longitude: $('#fixmystreet\\.longitude').val() - }; + var old_category = $("#form_category").val(); // Restart the category dropdown from the original data (not all of it as // we keep subcategories the same) @@ -99,6 +101,9 @@ function regenerate_category(he_flag) { select = select.html(); $('#form_category').html(select); } + if ($("#form_category option[value=\"" + old_category + "\"]").length) { + $("#form_category").val(old_category); + } // Recalculate the category groups var old_category_group = $('#category_group').val() || $('#filter_group').val(); |