Browse Source

Update dashboard tables when new locations get pulled

testing
Burathar 4 years ago
parent
commit
1c48c6942f
  1. 8
      app/static/assets/leaflet/utils.js
  2. 20
      app/templates/game_hunter_dashboard.html
  3. 18
      app/templates/game_owner_dashboard.html

8
app/static/assets/leaflet/utils.js

@ -67,13 +67,17 @@ function addPlayerMarker(map, player, icon=bluePlayerIcon){ @@ -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(`<b>${player['username']}</b><br>
${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){

20
app/templates/game_hunter_dashboard.html

@ -36,12 +36,16 @@ @@ -36,12 +36,16 @@
<span
style="color:gray;">{{ bunny.player_caught_by_players | selectattr('catching_player', '==', player) | selectattr('review.name', '==', 'none') |list|length}}</span>
</td>
<td>{% with location = bunny.last_location(offset=hunter_delay) %}
{% if location %}{{ moment(location.timestamp).fromNow()}}
{% else %}
{{ location }}
{% endif %}
{% endwith %}</td>
<td>
<p id='last_location_{{ bunny.user.name }}'>
{% with location = bunny.last_location(offset=hunter_delay) %}
{% if location %}{{ moment(location.timestamp).fromNow()}}
{% else %}
{{ location }}
{% endif %}
{% endwith %}
</p>
</td>
<td>
<a
href="{{ url_for('main.catch_bunny', game_name=game.name, bunny_name=bunny.user.name) }}">
@ -96,6 +100,8 @@ @@ -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 @@ @@ -110,7 +116,7 @@
handleResponse
)
getPosition(updateMyLocation)
}, 10 * 1000);
}, 30 * 1000);
function handleResponse(data){
data.forEach(function (location) {

18
app/templates/game_owner_dashboard.html

@ -45,12 +45,16 @@ @@ -45,12 +45,16 @@
<td>{{ player.found_objectives | list | length }}</td>
<td>{{ player.accepted_caught_players() | list | length }}</td>
<td>{{ player.accepted_caught_by_players() | list | length }}</td>
<td>{% with location = player.last_location() %}
{% if location %}{{ moment(location.timestamp).fromNow()}}
{% else %}
{{ location }}
{% endif %}
{% endwith %}</td>
<td>
<p id='last_location_{{ player.user.name }}'>
{% with location = player.last_location() %}
{% if location %}{{ moment(location.timestamp).fromNow()}}
{% else %}
{{ location }}
{% endif %}
{% endwith %}
</p>
</td>
<td><a href="{{ url_for('main.remove_player', game_name=game.name, username=player.user.name) }}">
<button class="btn btn-danger">Delete</button></a>
</td>
@ -130,6 +134,8 @@ @@ -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()
}
}

Loading…
Cancel
Save