Display who used the lasers last
This commit is contained in:
parent
1cdb236a7e
commit
3bf8743e9a
|
@ -472,7 +472,12 @@ class StatsViewSet(viewsets.ViewSet, List):
|
||||||
def track(self, request):
|
def track(self, request):
|
||||||
if 'name' in request.data:
|
if 'name' in request.data:
|
||||||
track = cache.get('track', {})
|
track = cache.get('track', {})
|
||||||
track[request.data['name']] = time.time()
|
|
||||||
|
name = request.data['name']
|
||||||
|
username = request.data.get('username', '')
|
||||||
|
username = username.split('.')[0]
|
||||||
|
|
||||||
|
track[name] = dict(time=time.time(), username=username)
|
||||||
cache.set('track', track)
|
cache.set('track', track)
|
||||||
return Response(200)
|
return Response(200)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -153,9 +153,10 @@ export function Home(props) {
|
||||||
|
|
||||||
const mcPlayers = stats && stats['minecraft_players'] ? stats['minecraft_players'] : [];
|
const mcPlayers = stats && stats['minecraft_players'] ? stats['minecraft_players'] : [];
|
||||||
|
|
||||||
const getTrackStat = (x) => stats && stats.track && stats.track[x] ? moment().unix() - stats.track[x] > 60 ? 'Free' : 'In Use' : '?';
|
const getTrackStat = (x) => stats && stats.track && stats.track[x] ? moment().unix() - stats.track[x]['time'] > 60 ? 'Free' : 'In Use' : '?';
|
||||||
const getTrackLast = (x) => stats && stats.track && stats.track[x] ? moment.unix(stats.track[x]).tz('America/Edmonton').format('llll') : 'Unknown';
|
const getTrackLast = (x) => stats && stats.track && stats.track[x] ? moment.unix(stats.track[x]['time']).tz('America/Edmonton').format('llll') : 'Unknown';
|
||||||
const getTrackAgo = (x) => stats && stats.track && stats.track[x] ? moment.unix(stats.track[x]).tz('America/Edmonton').fromNow() : '';
|
const getTrackAgo = (x) => stats && stats.track && stats.track[x] ? moment.unix(stats.track[x]['time']).tz('America/Edmonton').fromNow() : '';
|
||||||
|
const getTrackName = (x) => stats && stats.track && stats.track[x] && stats.track[x]['username'] ? stats.track[x]['username'] : 'Unknown';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
|
@ -238,7 +239,8 @@ export function Home(props) {
|
||||||
<p>
|
<p>
|
||||||
Last use:<br />
|
Last use:<br />
|
||||||
{getTrackLast('TROTECS300')}<br />
|
{getTrackLast('TROTECS300')}<br />
|
||||||
{getTrackAgo('TROTECS300')}
|
{getTrackAgo('TROTECS300')}<br />
|
||||||
|
by {getTrackName('TROTECS300')}
|
||||||
</p>
|
</p>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
} trigger={<a>[more]</a>} />
|
} trigger={<a>[more]</a>} />
|
||||||
|
@ -250,7 +252,8 @@ export function Home(props) {
|
||||||
<p>
|
<p>
|
||||||
Last use:<br />
|
Last use:<br />
|
||||||
{getTrackLast('FRICKIN-LASER')}<br />
|
{getTrackLast('FRICKIN-LASER')}<br />
|
||||||
{getTrackAgo('FRICKIN-LASER')}
|
{getTrackAgo('FRICKIN-LASER')}<br />
|
||||||
|
by {getTrackName('TROTECS300')}
|
||||||
</p>
|
</p>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
} trigger={<a>[more]</a>} />
|
} trigger={<a>[more]</a>} />
|
||||||
|
|
Loading…
Reference in New Issue
Block a user