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){
player['latitude'], player['latitude'],
player['longitude'] player['longitude']
], {icon: icon}).addTo(map); ], {icon: icon}).addTo(map);
var timestamp_utc = moment.utc(player['timestamp_utc']).toDate() var timestamp_local = toMomentLocal(player['timestamp_utc']).format('YYYY-MM-DD HH:mm')
var timestamp_local = moment(timestamp_utc).local().format('YYYY-MM-DD HH:mm');
playerMarker.bindTooltip(`<b>${player['username']}</b><br> playerMarker.bindTooltip(`<b>${player['username']}</b><br>
${timestamp_local}`).openPopup(); ${timestamp_local}`).openPopup();
return playerMarker return playerMarker
} }
function toMomentLocal(timestamp_utc_string){
var timestamp_utc = moment.utc(timestamp_utc_string).toDate()
return moment(timestamp_utc).local()
}
var myLocationMarker var myLocationMarker
function updateMyLocation(position){ function updateMyLocation(position){
if(myLocationMarker == undefined){ if(myLocationMarker == undefined){

20
app/templates/game_hunter_dashboard.html

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

18
app/templates/game_owner_dashboard.html

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