From 1c48c6942f2d96c68c74de287738158bcf8e33ab Mon Sep 17 00:00:00 2001 From: Burathar Date: Wed, 19 Aug 2020 11:37:53 +0200 Subject: [PATCH] Update dashboard tables when new locations get pulled --- app/static/assets/leaflet/utils.js | 8 ++++++-- app/templates/game_hunter_dashboard.html | 20 +++++++++++++------- app/templates/game_owner_dashboard.html | 18 ++++++++++++------ 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/app/static/assets/leaflet/utils.js b/app/static/assets/leaflet/utils.js index 2baab25..438d1ec 100644 --- a/app/static/assets/leaflet/utils.js +++ b/app/static/assets/leaflet/utils.js @@ -67,13 +67,17 @@ function addPlayerMarker(map, player, icon=bluePlayerIcon){ player['latitude'], player['longitude'] ], {icon: icon}).addTo(map); - var timestamp_utc = moment.utc(player['timestamp_utc']).toDate() - var timestamp_local = moment(timestamp_utc).local().format('YYYY-MM-DD HH:mm'); + var timestamp_local = toMomentLocal(player['timestamp_utc']).format('YYYY-MM-DD HH:mm') playerMarker.bindTooltip(`${player['username']}
${timestamp_local}`).openPopup(); return playerMarker } +function toMomentLocal(timestamp_utc_string){ + var timestamp_utc = moment.utc(timestamp_utc_string).toDate() + return moment(timestamp_utc).local() +} + var myLocationMarker function updateMyLocation(position){ if(myLocationMarker == undefined){ diff --git a/app/templates/game_hunter_dashboard.html b/app/templates/game_hunter_dashboard.html index 24c53ac..4b15e2a 100644 --- a/app/templates/game_hunter_dashboard.html +++ b/app/templates/game_hunter_dashboard.html @@ -36,12 +36,16 @@ {{ bunny.player_caught_by_players | selectattr('catching_player', '==', player) | selectattr('review.name', '==', 'none') |list|length}} - {% with location = bunny.last_location(offset=hunter_delay) %} - {% if location %}{{ moment(location.timestamp).fromNow()}} - {% else %} - {{ location }} - {% endif %} - {% endwith %} + +

+ {% with location = bunny.last_location(offset=hunter_delay) %} + {% if location %}{{ moment(location.timestamp).fromNow()}} + {% else %} + {{ location }} + {% endif %} + {% endwith %} +

+ @@ -96,6 +100,8 @@ bunnieMarkers = [] for (var i = 0; i < bunnies.length; i++) { bunnieMarkers.push(addPlayerMarker(map, bunnies[i], greenPlayerIcon)) + // Update table lastlocation column + $('#last_location_' + bunnies[i].username)[0].innerHTML = toMomentLocal(bunnies[i].timestamp_utc).fromNow() } } @@ -110,7 +116,7 @@ handleResponse ) getPosition(updateMyLocation) - }, 10 * 1000); + }, 30 * 1000); function handleResponse(data){ data.forEach(function (location) { diff --git a/app/templates/game_owner_dashboard.html b/app/templates/game_owner_dashboard.html index 5e69343..013b272 100644 --- a/app/templates/game_owner_dashboard.html +++ b/app/templates/game_owner_dashboard.html @@ -45,12 +45,16 @@ {{ player.found_objectives | list | length }} {{ player.accepted_caught_players() | list | length }} {{ player.accepted_caught_by_players() | list | length }} - {% with location = player.last_location() %} - {% if location %}{{ moment(location.timestamp).fromNow()}} - {% else %} - {{ location }} - {% endif %} - {% endwith %} + +

+ {% with location = player.last_location() %} + {% if location %}{{ moment(location.timestamp).fromNow()}} + {% else %} + {{ location }} + {% endif %} + {% endwith %} +

+
@@ -130,6 +134,8 @@ playerMarkers = [] for (var i = 0; i < players.length; i++) { playerMarkers.push(addPlayerMarker(map, players[i], bluePlayerIcon)) + // Update table lastlocation column + $('#last_location_' + players[i].username)[0].innerHTML = toMomentLocal(players[i].timestamp_utc).fromNow() } }