diff --git a/app/main/routes.py b/app/main/routes.py index eff101d..ed3b332 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -143,7 +143,7 @@ def get_user_locations(game, username, mode, last_update): if user is None: return None if mode == 'accumulative': - if game.end_time < last_update: + if game.end_time or datetime.min < last_update: return [] locations = user.locations_during_game(game) if not locations: diff --git a/app/static/assets/geolocation_utils.js b/app/static/assets/geolocation_utils.js new file mode 100644 index 0000000..e5b2034 --- /dev/null +++ b/app/static/assets/geolocation_utils.js @@ -0,0 +1,26 @@ +function getPosition(locationHandler){ + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition(locationHandler, showError); + + } else { + console.log('Geolocation is not supported by this browser.') + } +} + +function showError(error) { + switch(error.code) { + case error.PERMISSION_DENIED: + console.log("User denied the request for Geolocation.") + alert("Please refresh page and allow location sharing, otherwise the game won't work :'(") + break; + case error.POSITION_UNAVAILABLE: + console.log("Location information is unavailable.") + break; + case error.TIMEOUT: + console.log("The request to get user location timed out.") + break; + case error.UNKNOWN_ERROR: + console.log("An unknown error occurred.") + break; + } +} \ No newline at end of file diff --git a/app/static/assets/leaflet/utils.js b/app/static/assets/leaflet/utils.js index 4bfb76a..fc1a460 100644 --- a/app/static/assets/leaflet/utils.js +++ b/app/static/assets/leaflet/utils.js @@ -122,6 +122,9 @@ function pollLocations(url, requestedUsers, mode, playerLocations, responseHandl } function get_latest_date(playerLocations){ + if (playerLocations.length == 0){ + return new Date('0001-01-01T00:00:00Z'); + } return new Date(Math.max.apply(null, playerLocations.map(function(e) { return new Date(e.timestamp_utc); }))); diff --git a/app/static/assets/utils.js b/app/static/assets/utils.js index 8a3af8f..e4d5667 100644 --- a/app/static/assets/utils.js +++ b/app/static/assets/utils.js @@ -34,4 +34,4 @@ function updateDateTimePicker(picker, checkbox){ $(picker)[0].value = moment().format('DD-MM-YYYY HH:mm'); } } -} \ No newline at end of file +} diff --git a/app/templates/game_owner_dashboard.html b/app/templates/game_owner_dashboard.html index 4f5aeb7..86a1889 100644 --- a/app/templates/game_owner_dashboard.html +++ b/app/templates/game_owner_dashboard.html @@ -129,6 +129,15 @@ } } + function sendLocation(){ + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition(postCoordinates, showError); + + } else { + console.log('Geolocation is not supported by this browser.') + } + } + // Poll Locations usernames = JSON.parse('{{ json.dumps(game.usernames())|safe }}') setInterval(function() { @@ -138,7 +147,8 @@ 'accumulative', players, handleResponse - )}, 30 * 1000); + ) + }, 30 * 1000); function handleResponse(data){ data.forEach(function (location) { diff --git a/app/templates/game_player.html b/app/templates/game_player.html index a12c596..b111a0f 100644 --- a/app/templates/game_player.html +++ b/app/templates/game_player.html @@ -87,25 +87,28 @@ updateMarkers(); var polyline; updatePolyline(); + // zoom the map to the polyline - map.fitBounds(polyline.getBounds(), { - maxZoom : 13 - }); + if(polyline != undefined){ + map.fitBounds(polyline.getBounds(), { + maxZoom : 13 + }); + } function updateMarkers(){ if(markers != undefined){ markers.forEach(function(marker){ marker.remove() }); + markers = [] } - markers = [] for (var i = 0; i < locations.length -1; i++) { markers.push(addPlayerMarker(map, locations[i], bluePlayerIconMini)) } if(lastMarker != undefined){ lastMarker.remove() + lastMarker = addPlayerMarker(map, locations[locations.length-1], bluePlayerIcon) } - lastMarker = addPlayerMarker(map, locations[locations.length-1], bluePlayerIcon) } function updatePolyline(){ @@ -113,7 +116,7 @@ map.removeLayer(polyline) } if (locations.length == 0) { return } - polyline = L.polyline(locations.map(l => [l.latitude, l.longitude]), { + polyline = L.polyline(locations.map(l => [l.latitude, l.longitude]), { color: 'blue', opacity: 0.6, }).addTo(map); @@ -144,13 +147,16 @@ updatePolyline() updateMarkers() } - + console.log('test1') //Ajax for Generate Code button $(function () { + console.log('test2') $('a#generate_auth_hash').bind('click', function () { + console.log('test3') $.ajax({ url: "{{ url_for('auth.generate_auth_hash', username=player.user.name) }}", success: function (result) { + console.log('test4') location.reload(); } }); diff --git a/app/templates/player_base.html b/app/templates/player_base.html index 3de78be..56b5db0 100644 --- a/app/templates/player_base.html +++ b/app/templates/player_base.html @@ -8,18 +8,9 @@ {% block scripts %} {{ super() }} {% endblock %} \ No newline at end of file