Skip to content

Commit

Permalink
Improve handling of swap with lat/lng
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Aug 10, 2024
1 parent 33641a0 commit 6d9e96a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
31 changes: 20 additions & 11 deletions app/javascript/controllers/autocompleter_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ export default class extends Controller {
}
if (type == undefined) { return; }

let location = false;
if (detail.hasOwnProperty("request_params") &&
detail.request_params.hasOwnProperty("lat") &&
detail.request_params.hasOwnProperty("lng")) {
location = detail.request_params;
}

if (!AUTOCOMPLETER_TYPES.hasOwnProperty(type)) {
alert("MOAutocompleter: Invalid type: \"" + type + "\"");
} else {
Expand All @@ -235,11 +242,13 @@ export default class extends Controller {
!this.keepBtnTarget?.classList?.contains('active')) {
this.clearHiddenId();
}
this.constrainedSelectionUI();
this.constrainedSelectionUI(location);
}
}

constrainedSelectionUI() {
// Depending on the type of autocompleter, the UI may need to change.
// detail may also contain request_params for lat/lng.
constrainedSelectionUI(location = false) {
if (this.TYPE === "location_google") {
this.verbose("autocompleter: swapped to location_google");
this.element.classList.add('create');
Expand All @@ -250,7 +259,7 @@ export default class extends Controller {
} else {
this.verbose("autocompleter: no map wrap");
}
this.activateMapOutlet();
this.activateMapOutlet(location);
} else if (this.ACT_LIKE_SELECT) {
this.verbose("autocompleter: swapped to ACT_LIKE_SELECT");
this.deactivateMapOutlet();
Expand All @@ -272,7 +281,7 @@ export default class extends Controller {
}

// Connects the location_google autocompleter to call map controller methods
activateMapOutlet() {
activateMapOutlet(location = false) {
if (!this.hasMapOutlet) {
this.verbose("autocompleter: no map outlet");
return;
Expand All @@ -289,13 +298,13 @@ export default class extends Controller {
// set the map to stop ignoring place input
this.mapOutlet.ignorePlaceInput = false;

// 2024-08-09: Don't geocode lat/lng when switching to location_google.
// This is for custom locations and should pay attention to place_name only.
// let location
// if (location = this.mapOutlet.validateLatLngInputs(false)) {
// this.mapOutlet.tryToGeocode();
// } else
if (this.mapOutlet.hasLockBoxBtnTarget) {
// 2024-08-09: Unless the swap call (form-exif) sent request_params lat/lng,
// don't geocode lat/lng when switching to location_google. Usually, this is
// for geolocating place_names and should pay attention to text only.
if (location) {
// this.mapOutlet.geocodeLatLng(location);
this.mapOutlet.tryToGeocode();
} else if (this.mapOutlet.hasLockBoxBtnTarget) {
this.mapOutlet.lockBoxBtnTarget.classList.remove("d-none");
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/system/observation_form_system_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ def test_post_edit_and_destroy_with_details_and_location
all('[id^="project_id_"]', visible: :all).each do |project_checkbox|
project_checkbox.trigger("click") if project_checkbox.checked?
end
step_nav_3 = find("#step-nav-3")
within(step_nav_3) { click_on(:BACK.l) }

# submit_observation_form_with_errors
within("#observation_form") { click_commit }
Expand Down

0 comments on commit 6d9e96a

Please sign in to comment.