Skip to content

Commit 684f1b7

Browse files
Add log for search term in suggest location to find root cause of Manticore crashes.
1 parent 7c2f0bd commit 684f1b7

File tree

2 files changed

+112
-40
lines changed

2 files changed

+112
-40
lines changed

assets/js/signup.js

+101-35
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,107 @@
1-
import Litepicker from 'litepicker/dist/nocss/litepicker.umd.js';
2-
import dayjs from 'dayjs';
1+
import VanillaCalendar, { Options, FormatDateString } from 'vanilla-calendar-pro';
2+
import 'vanilla-calendar-pro/build/vanilla-calendar.min.css';
3+
import * as dayjs from 'dayjs'
34

4-
$(function () {
5-
$('[data-toggle="popover"]').popover({ html : true });
5+
import {initializeSingleAutoComplete} from './suggest/locations';
6+
import * as L from 'leaflet';
67

7-
$("#mothertongue").select2({
8-
theme: 'bootstrap4',
9-
placeholder: 'Select a language',
10-
allowClear: true,
11-
width: 'auto'
12-
});
8+
import 'leaflet.fullscreen';
9+
import 'leaflet.fullscreen/Control.FullScreen.css';
10+
11+
const htmlTag = document.getElementsByTagName('html')[0];
12+
const lang = htmlTag.attributes['lang'].value;
1313

14+
const minimumAge = dayjs().subtract(18, 'year');
15+
const maximumAge = minimumAge.subtract(122, 'year');
1416

15-
let birthdate = document.getElementById('birthdate');
16-
let maxDate = dayjs().subtract(18, "years");
17-
18-
if (birthdate) {
19-
const picker = new Litepicker({
20-
element: birthdate,
21-
singleMode: true,
22-
allowRepick: true,
23-
dropdowns: {
24-
"minYear":1900,
25-
"maxYear":2004,
26-
"months":true,
27-
"years":true},
28-
maxDate: maxDate,
29-
numberOfMonths: 1,
30-
numberOfColumns: 1,
31-
format: "YYYY-MM-DD",
32-
position: 'top left',
33-
showTooltip: false,
34-
lang: document.documentElement.lang,
35-
setup: (picker) => {
36-
picker.on('selected', (start, end) => {
37-
});
17+
const options: Options = {
18+
input: true,
19+
type: 'default',
20+
date: {
21+
max: <FormatDateString>minimumAge.format('YYYY-MM-DD'),
22+
min: <FormatDateString>maximumAge.format('YYYY-MM-DD')
23+
},
24+
actions: {
25+
changeToInput(e, calendar, self) {
26+
if (!self.HTMLInputElement) return;
27+
if (self.selectedDates[0]) {
28+
self.HTMLInputElement.value = self.selectedDates[0];
29+
calendar.hide();
30+
} else {
31+
self.HTMLInputElement.value = '';
3832
}
39-
});
40-
}
33+
},
34+
},
35+
settings: {
36+
lang: lang,
37+
visibility: {
38+
positionToInput: 'center',
39+
theme: 'light',
40+
disabled: false,
41+
},
42+
},
43+
};
44+
45+
const birthDate = document.getElementById('signup_form_finalize_birthdate');
46+
const calendar = new VanillaCalendar(birthDate, options);
47+
calendar.init();
48+
49+
const labelText = document.getElementById('marker_label_text').value;
50+
const locationGeonameId = document.getElementById('set_location_geoname_id');
51+
const locationLatitude = document.getElementById('set_location_latitude');
52+
const locationLongitude = document.getElementById('set_location_longitude');
53+
const originalLatitude = document.getElementById('original_latitude');
54+
const originalLongitude = document.getElementById('original_longitude');
55+
56+
const myIcon = L.icon({
57+
iconUrl: 'images/icons/marker_drop.png',
58+
iconSize: [29, 24],
59+
iconAnchor: [9, 21],
60+
popupAnchor: [0, -14]
61+
});
62+
let marker = L.marker([locationLatitude.value, locationLongitude.value], {
63+
icon: myIcon,
64+
draggable: true
4165
});
66+
marker.bindPopup(labelText);
67+
marker.on('dragend', dragend);
68+
const map = L.map('map');
69+
marker.addTo(map);
70+
map.setView([locationLatitude.value, locationLongitude.value], 12);
71+
72+
// callback when a selection is done from the list of possible results
73+
const addMarkerAndMoveToNewLocation = function(element, result) {
74+
locationGeonameId.value = result.id;
75+
locationLatitude.value = result.latitude;
76+
locationLongitude.value = result.longitude;
77+
originalLatitude.value = result.latitude;
78+
originalLongitude.value = result.longitude;
79+
80+
map.removeLayer(marker);
81+
82+
marker = L.marker([locationLatitude.value, locationLongitude.value], {
83+
icon: myIcon,
84+
draggable: true
85+
});
86+
marker.bindPopup(labelText);
87+
marker.on('dragend', dragend);
88+
marker.addTo(map);
89+
map.setView(new L.LatLng(locationLatitude.value, locationLongitude.value), 12, {animate: true});
90+
};
91+
92+
// Dragging the marker around on the map changes the stored lat, long
93+
function dragend(e) {
94+
const originalLatLng = L.latLng(originalLatitude.value, originalLongitude.value);
95+
locationLatitude.value = e.target._latlng.lat;
96+
locationLongitude.value = e.target._latlng.lng;
97+
}
98+
99+
initializeSingleAutoComplete("/suggest/locations/places/exact", 'js-location-picker', addMarkerAndMoveToNewLocation);
100+
101+
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
102+
attribution: '&copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>',
103+
subdomains: ['a', 'b', 'c']
104+
}).addTo(map);
105+
106+
L.control.scale().addTo(map);
107+

src/Controller/SuggestLocationController.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Controller;
44

55
use App\Model\SuggestLocationModel;
6+
use Psr\Log\LoggerInterface;
67
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
78
use Symfony\Component\HttpFoundation\JsonResponse;
89
use Symfony\Component\HttpFoundation\Request;
@@ -11,12 +12,11 @@
1112

1213
class SuggestLocationController extends AbstractController
1314
{
14-
/**
15-
* @Route("/suggest/location", name="suggest_location")
16-
*/
17-
public function index(): Response
15+
private LoggerInterface $logger;
16+
17+
public function __construct(LoggerInterface $logger)
1818
{
19-
return $this->render('suggest_location/index.html.twig');
19+
$this->logger = $logger;
2020
}
2121

2222
/**
@@ -27,6 +27,8 @@ public function suggestExactPlaces(Request $request, SuggestLocationModel $model
2727
$response = new JsonResponse();
2828
$searchTerm = $request->query->get('term', '');
2929

30+
$this->logger->alert("Search term: {$searchTerm}");
31+
3032
$result = $model->getSuggestionsForPlacesExact($searchTerm);
3133
$response->setData($result);
3234

@@ -41,6 +43,8 @@ public function suggestPlaces(Request $request, SuggestLocationModel $model): Js
4143
$response = new JsonResponse();
4244
$searchTerm = $request->query->get('term', '');
4345

46+
$this->logger->alert("Search term: {$searchTerm}");
47+
4448
$result = $model->getSuggestionsForPlaces($searchTerm);
4549
$response->setData($result);
4650

@@ -58,6 +62,8 @@ public function suggestLocations(Request $request, SuggestLocationModel $model):
5862
$response = new JsonResponse();
5963
$searchTerm = $request->query->get('term', '');
6064

65+
$this->logger->alert("Search term: {$searchTerm}");
66+
6167
$result = $model->getSuggestionsForLocations($searchTerm);
6268
$response->setData($result);
6369

0 commit comments

Comments
 (0)